browser_client.cc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE-CHROMIUM file.
  4. #include "brightray/browser/browser_client.h"
  5. #include "base/lazy_instance.h"
  6. #include "base/path_service.h"
  7. #include "brightray/browser/browser_context.h"
  8. #include "brightray/browser/browser_main_parts.h"
  9. #include "brightray/browser/devtools_manager_delegate.h"
  10. #include "brightray/browser/media/media_capture_devices_dispatcher.h"
  11. #include "brightray/browser/notification_presenter.h"
  12. #include "brightray/browser/platform_notification_service.h"
  13. #include "content/public/browser/browser_thread.h"
  14. #include "content/public/common/url_constants.h"
  15. using content::BrowserThread;
  16. namespace brightray {
  17. namespace {
  18. BrowserClient* g_browser_client;
  19. base::LazyInstance<std::string>::DestructorAtExit
  20. g_io_thread_application_locale = LAZY_INSTANCE_INITIALIZER;
  21. std::string g_application_locale;
  22. void SetApplicationLocaleOnIOThread(const std::string& locale) {
  23. DCHECK_CURRENTLY_ON(BrowserThread::IO);
  24. g_io_thread_application_locale.Get() = locale;
  25. }
  26. } // namespace
  27. // static
  28. void BrowserClient::SetApplicationLocale(const std::string& locale) {
  29. DCHECK_CURRENTLY_ON(BrowserThread::UI);
  30. if (!BrowserThread::PostTask(
  31. BrowserThread::IO, FROM_HERE,
  32. base::BindOnce(&SetApplicationLocaleOnIOThread, locale))) {
  33. g_io_thread_application_locale.Get() = locale;
  34. }
  35. g_application_locale = locale;
  36. }
  37. BrowserClient* BrowserClient::Get() {
  38. return g_browser_client;
  39. }
  40. BrowserClient::BrowserClient() : browser_main_parts_(nullptr) {
  41. DCHECK(!g_browser_client);
  42. g_browser_client = this;
  43. }
  44. BrowserClient::~BrowserClient() {}
  45. void BrowserClient::WebNotificationAllowed(
  46. int render_process_id,
  47. const base::Callback<void(bool, bool)>& callback) {
  48. callback.Run(false, true);
  49. }
  50. NotificationPresenter* BrowserClient::GetNotificationPresenter() {
  51. if (!notification_presenter_) {
  52. // Create a new presenter if on OS X, Linux, or Windows 7+
  53. notification_presenter_.reset(NotificationPresenter::Create());
  54. }
  55. return notification_presenter_.get();
  56. }
  57. BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts(
  58. const content::MainFunctionParams&) {
  59. return new BrowserMainParts;
  60. }
  61. content::BrowserMainParts* BrowserClient::CreateBrowserMainParts(
  62. const content::MainFunctionParams& parameters) {
  63. DCHECK(!browser_main_parts_);
  64. browser_main_parts_ = OverrideCreateBrowserMainParts(parameters);
  65. return browser_main_parts_;
  66. }
  67. content::MediaObserver* BrowserClient::GetMediaObserver() {
  68. return MediaCaptureDevicesDispatcher::GetInstance();
  69. }
  70. content::PlatformNotificationService*
  71. BrowserClient::GetPlatformNotificationService() {
  72. if (!notification_service_)
  73. notification_service_.reset(new PlatformNotificationService(this));
  74. return notification_service_.get();
  75. }
  76. void BrowserClient::GetAdditionalAllowedSchemesForFileSystem(
  77. std::vector<std::string>* additional_schemes) {
  78. additional_schemes->push_back(content::kChromeDevToolsScheme);
  79. additional_schemes->push_back(content::kChromeUIScheme);
  80. }
  81. void BrowserClient::GetAdditionalWebUISchemes(
  82. std::vector<std::string>* additional_schemes) {
  83. additional_schemes->push_back(content::kChromeDevToolsScheme);
  84. }
  85. net::NetLog* BrowserClient::GetNetLog() {
  86. return &net_log_;
  87. }
  88. base::FilePath BrowserClient::GetDefaultDownloadDirectory() {
  89. // ~/Downloads
  90. base::FilePath path;
  91. if (PathService::Get(base::DIR_HOME, &path))
  92. path = path.Append(FILE_PATH_LITERAL("Downloads"));
  93. return path;
  94. }
  95. content::DevToolsManagerDelegate* BrowserClient::GetDevToolsManagerDelegate() {
  96. return new DevToolsManagerDelegate;
  97. }
  98. std::string BrowserClient::GetApplicationLocale() {
  99. if (BrowserThread::CurrentlyOn(BrowserThread::IO))
  100. return g_io_thread_application_locale.Get();
  101. return g_application_locale;
  102. }
  103. } // namespace brightray