2013-03-13 19:12:05 +00: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.
|
|
|
|
|
2013-07-31 18:08:45 +00:00
|
|
|
#include "browser/browser_client.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2013-07-31 18:08:45 +00:00
|
|
|
#include "browser/browser_context.h"
|
|
|
|
#include "browser/browser_main_parts.h"
|
2015-01-10 01:14:52 +00:00
|
|
|
#include "browser/devtools_manager_delegate.h"
|
2013-07-31 18:08:45 +00:00
|
|
|
#include "browser/media/media_capture_devices_dispatcher.h"
|
2015-03-09 02:37:13 +00:00
|
|
|
#include "browser/platform_notification_service_impl.h"
|
2013-03-13 19:12:05 +00:00
|
|
|
|
2014-07-28 09:48:55 +00:00
|
|
|
#include "base/base_paths.h"
|
|
|
|
#include "base/path_service.h"
|
2015-04-21 13:42:49 +00:00
|
|
|
#include "content/public/common/content_descriptors.h"
|
2014-07-09 07:38:53 +00:00
|
|
|
#include "content/public/common/url_constants.h"
|
2015-04-21 13:42:49 +00:00
|
|
|
#include "gin/public/isolate_holder.h"
|
2014-07-09 07:38:53 +00:00
|
|
|
|
2013-03-13 19:12:05 +00:00
|
|
|
namespace brightray {
|
|
|
|
|
2013-04-18 03:27:53 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
BrowserClient* g_browser_client;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserClient* BrowserClient::Get() {
|
|
|
|
return g_browser_client;
|
|
|
|
}
|
|
|
|
|
2013-04-24 14:54:53 +00:00
|
|
|
BrowserClient::BrowserClient()
|
2015-04-21 13:42:49 +00:00
|
|
|
: browser_main_parts_(nullptr) {
|
2013-04-18 03:27:53 +00:00
|
|
|
DCHECK(!g_browser_client);
|
|
|
|
g_browser_client = this;
|
2015-04-21 13:42:49 +00:00
|
|
|
|
|
|
|
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
|
|
|
v8_natives_fd_.reset(-1);
|
|
|
|
v8_snapshot_fd_.reset(-1);
|
|
|
|
#endif // OS_POSIX && !OS_MACOSX
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BrowserClient::~BrowserClient() {
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserContext* BrowserClient::browser_context() {
|
|
|
|
return browser_main_parts_->browser_context();
|
|
|
|
}
|
|
|
|
|
2013-11-17 22:39:01 +00:00
|
|
|
BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts(
|
|
|
|
const content::MainFunctionParams&) {
|
2013-03-13 19:12:05 +00:00
|
|
|
return new BrowserMainParts;
|
|
|
|
}
|
|
|
|
|
2013-11-17 22:39:01 +00:00
|
|
|
content::BrowserMainParts* BrowserClient::CreateBrowserMainParts(
|
|
|
|
const content::MainFunctionParams& parameters) {
|
2013-03-27 12:54:19 +00:00
|
|
|
DCHECK(!browser_main_parts_);
|
|
|
|
browser_main_parts_ = OverrideCreateBrowserMainParts(parameters);
|
|
|
|
return browser_main_parts_;
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-17 22:39:01 +00:00
|
|
|
net::URLRequestContextGetter* BrowserClient::CreateRequestContext(
|
|
|
|
content::BrowserContext* browser_context,
|
2014-06-26 20:27:22 +00:00
|
|
|
content::ProtocolHandlerMap* protocol_handlers,
|
2014-08-31 10:43:01 +00:00
|
|
|
content::URLRequestInterceptorScopedVector protocol_interceptors) {
|
2013-11-17 22:39:01 +00:00
|
|
|
auto context = static_cast<BrowserContext*>(browser_context);
|
2014-06-26 20:27:22 +00:00
|
|
|
return context->CreateRequestContext(protocol_handlers, protocol_interceptors.Pass());
|
2013-03-13 19:12:05 +00:00
|
|
|
}
|
|
|
|
|
2013-07-31 18:08:45 +00:00
|
|
|
content::MediaObserver* BrowserClient::GetMediaObserver() {
|
|
|
|
return MediaCaptureDevicesDispatcher::GetInstance();
|
|
|
|
}
|
|
|
|
|
2015-03-09 02:37:13 +00:00
|
|
|
content::PlatformNotificationService* BrowserClient::GetPlatformNotificationService() {
|
|
|
|
return PlatformNotificationServiceImpl::GetInstance();
|
|
|
|
}
|
|
|
|
|
2014-07-09 07:38:53 +00:00
|
|
|
void BrowserClient::GetAdditionalAllowedSchemesForFileSystem(
|
|
|
|
std::vector<std::string>* additional_schemes) {
|
|
|
|
additional_schemes->push_back(content::kChromeDevToolsScheme);
|
|
|
|
additional_schemes->push_back(content::kChromeUIScheme);
|
|
|
|
}
|
|
|
|
|
2015-07-14 17:42:52 +00:00
|
|
|
net::NetLog* BrowserClient::GetNetLog() {
|
|
|
|
return browser_context()->GetNetLog();
|
|
|
|
}
|
|
|
|
|
2014-07-28 09:48:55 +00: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 23:18:24 +00:00
|
|
|
content::DevToolsManagerDelegate* BrowserClient::GetDevToolsManagerDelegate() {
|
2015-01-10 01:14:52 +00:00
|
|
|
return new DevToolsManagerDelegate;
|
2015-01-02 23:18:24 +00:00
|
|
|
}
|
|
|
|
|
2015-04-21 13:42:49 +00:00
|
|
|
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
|
|
|
void BrowserClient::GetAdditionalMappedFilesForChildProcess(
|
|
|
|
const base::CommandLine& command_line,
|
|
|
|
int child_process_id,
|
|
|
|
content::FileDescriptorInfo* mappings) {
|
|
|
|
if (v8_snapshot_fd_.get() == -1 && v8_natives_fd_.get() == -1) {
|
|
|
|
base::FilePath v8_data_path;
|
|
|
|
PathService::Get(gin::IsolateHolder::kV8SnapshotBasePathKey, &v8_data_path);
|
|
|
|
DCHECK(!v8_data_path.empty());
|
|
|
|
|
|
|
|
int file_flags = base::File::FLAG_OPEN | base::File::FLAG_READ;
|
|
|
|
base::FilePath v8_natives_data_path =
|
|
|
|
v8_data_path.AppendASCII(gin::IsolateHolder::kNativesFileName);
|
|
|
|
base::FilePath v8_snapshot_data_path =
|
|
|
|
v8_data_path.AppendASCII(gin::IsolateHolder::kSnapshotFileName);
|
|
|
|
base::File v8_natives_data_file(v8_natives_data_path, file_flags);
|
|
|
|
base::File v8_snapshot_data_file(v8_snapshot_data_path, file_flags);
|
|
|
|
DCHECK(v8_natives_data_file.IsValid());
|
|
|
|
DCHECK(v8_snapshot_data_file.IsValid());
|
|
|
|
v8_natives_fd_.reset(v8_natives_data_file.TakePlatformFile());
|
|
|
|
v8_snapshot_fd_.reset(v8_snapshot_data_file.TakePlatformFile());
|
|
|
|
}
|
|
|
|
mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get());
|
|
|
|
mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-17 22:39:01 +00:00
|
|
|
} // namespace brightray
|