| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | // Copyright (c) 2012 The Chromium Authors. All rights reserved.
 | 
					
						
							|  |  |  | // Use of this source code is governed by a BSD-style license that can be
 | 
					
						
							|  |  |  | // found in the LICENSE-CHROMIUM file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-18 15:58:12 -07:00
										 |  |  | #include "brightray/browser/browser_client.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 14:51:29 +05:30
										 |  |  | #include "base/lazy_instance.h"
 | 
					
						
							| 
									
										
										
										
											2015-12-24 22:20:47 +08:00
										 |  |  | #include "base/path_service.h"
 | 
					
						
							| 
									
										
										
										
											2017-05-18 15:58:12 -07:00
										 |  |  | #include "brightray/browser/browser_context.h"
 | 
					
						
							|  |  |  | #include "brightray/browser/browser_main_parts.h"
 | 
					
						
							|  |  |  | #include "brightray/browser/devtools_manager_delegate.h"
 | 
					
						
							|  |  |  | #include "brightray/browser/media/media_capture_devices_dispatcher.h"
 | 
					
						
							|  |  |  | #include "brightray/browser/notification_presenter.h"
 | 
					
						
							|  |  |  | #include "brightray/browser/platform_notification_service.h"
 | 
					
						
							| 
									
										
										
										
											2017-12-16 14:51:29 +05:30
										 |  |  | #include "content/public/browser/browser_thread.h"
 | 
					
						
							| 
									
										
										
										
											2014-07-09 15:38:53 +08:00
										 |  |  | #include "content/public/common/url_constants.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 14:51:29 +05:30
										 |  |  | using content::BrowserThread; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | namespace brightray { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-17 23:27:53 -04:00
										 |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BrowserClient* g_browser_client; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 14:51:29 +05:30
										 |  |  | base::LazyInstance<std::string>::DestructorAtExit | 
					
						
							|  |  |  |     g_io_thread_application_locale = LAZY_INSTANCE_INITIALIZER; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | std::string g_application_locale; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SetApplicationLocaleOnIOThread(const std::string& locale) { | 
					
						
							|  |  |  |   DCHECK_CURRENTLY_ON(BrowserThread::IO); | 
					
						
							|  |  |  |   g_io_thread_application_locale.Get() = locale; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-31 20:18:20 +02:00
										 |  |  | }  // namespace
 | 
					
						
							| 
									
										
										
										
											2013-04-17 23:27:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 14:51:29 +05:30
										 |  |  | // static
 | 
					
						
							|  |  |  | void BrowserClient::SetApplicationLocale(const std::string& locale) { | 
					
						
							|  |  |  |   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!BrowserThread::PostTask( | 
					
						
							|  |  |  |           BrowserThread::IO, FROM_HERE, | 
					
						
							|  |  |  |           base::BindOnce(&SetApplicationLocaleOnIOThread, locale))) { | 
					
						
							|  |  |  |     g_io_thread_application_locale.Get() = locale; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   g_application_locale = locale; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-17 23:27:53 -04:00
										 |  |  | BrowserClient* BrowserClient::Get() { | 
					
						
							|  |  |  |   return g_browser_client; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  | BrowserClient::BrowserClient() : browser_main_parts_(nullptr) { | 
					
						
							| 
									
										
										
										
											2013-04-17 23:27:53 -04:00
										 |  |  |   DCHECK(!g_browser_client); | 
					
						
							|  |  |  |   g_browser_client = this; | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-17 21:56:12 -04:00
										 |  |  | BrowserClient::~BrowserClient() {} | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-24 22:20:47 +08:00
										 |  |  | NotificationPresenter* BrowserClient::GetNotificationPresenter() { | 
					
						
							|  |  |  |   if (!notification_presenter_) { | 
					
						
							| 
									
										
										
										
											2017-05-30 19:06:51 +10:00
										 |  |  |     // Create a new presenter if on OS X, Linux, or Windows 7+
 | 
					
						
							| 
									
										
										
										
											2015-12-24 22:20:47 +08:00
										 |  |  |     notification_presenter_.reset(NotificationPresenter::Create()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return notification_presenter_.get(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-17 17:39:01 -05:00
										 |  |  | BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts( | 
					
						
							|  |  |  |     const content::MainFunctionParams&) { | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  |   return new BrowserMainParts; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-17 17:39:01 -05:00
										 |  |  | content::BrowserMainParts* BrowserClient::CreateBrowserMainParts( | 
					
						
							|  |  |  |     const content::MainFunctionParams& parameters) { | 
					
						
							| 
									
										
										
										
											2013-03-27 08:54:19 -04:00
										 |  |  |   DCHECK(!browser_main_parts_); | 
					
						
							|  |  |  |   browser_main_parts_ = OverrideCreateBrowserMainParts(parameters); | 
					
						
							|  |  |  |   return browser_main_parts_; | 
					
						
							| 
									
										
										
										
											2013-03-13 15:12:05 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-31 11:08:45 -07:00
										 |  |  | content::MediaObserver* BrowserClient::GetMediaObserver() { | 
					
						
							|  |  |  |   return MediaCaptureDevicesDispatcher::GetInstance(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-23 15:47:30 -07:00
										 |  |  | content::PlatformNotificationService* | 
					
						
							|  |  |  | BrowserClient::GetPlatformNotificationService() { | 
					
						
							| 
									
										
										
										
											2015-12-24 22:20:47 +08:00
										 |  |  |   if (!notification_service_) | 
					
						
							|  |  |  |     notification_service_.reset(new PlatformNotificationService(this)); | 
					
						
							|  |  |  |   return notification_service_.get(); | 
					
						
							| 
									
										
										
										
											2015-03-08 19:37:13 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-09 15:38:53 +08:00
										 |  |  | void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( | 
					
						
							|  |  |  |     std::vector<std::string>* additional_schemes) { | 
					
						
							|  |  |  |   additional_schemes->push_back(content::kChromeDevToolsScheme); | 
					
						
							|  |  |  |   additional_schemes->push_back(content::kChromeUIScheme); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-29 22:30:21 +05:30
										 |  |  | void BrowserClient::GetAdditionalWebUISchemes( | 
					
						
							|  |  |  |     std::vector<std::string>* additional_schemes) { | 
					
						
							|  |  |  |   additional_schemes->push_back(content::kChromeDevToolsScheme); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-23 19:02:13 +09:00
										 |  |  | net::NetLog* BrowserClient::GetNetLog() { | 
					
						
							|  |  |  |   return &net_log_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-28 17:48:55 +08:00
										 |  |  | base::FilePath BrowserClient::GetDefaultDownloadDirectory() { | 
					
						
							|  |  |  |   // ~/Downloads
 | 
					
						
							|  |  |  |   base::FilePath path; | 
					
						
							|  |  |  |   if (PathService::Get(base::DIR_HOME, &path)) | 
					
						
							|  |  |  |     path = path.Append(FILE_PATH_LITERAL("Downloads")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return path; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 15:18:24 -08:00
										 |  |  | content::DevToolsManagerDelegate* BrowserClient::GetDevToolsManagerDelegate() { | 
					
						
							| 
									
										
										
										
											2015-01-09 17:14:52 -08:00
										 |  |  |   return new DevToolsManagerDelegate; | 
					
						
							| 
									
										
										
										
											2015-01-02 15:18:24 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-16 14:51:29 +05:30
										 |  |  | std::string BrowserClient::GetApplicationLocale() { | 
					
						
							|  |  |  |   if (BrowserThread::CurrentlyOn(BrowserThread::IO)) | 
					
						
							|  |  |  |     return g_io_thread_application_locale.Get(); | 
					
						
							|  |  |  |   return g_application_locale; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-17 17:39:01 -05:00
										 |  |  | }  // namespace brightray
 |