electron/brightray/browser/browser_client.cc

99 lines
2.9 KiB
C++
Raw Normal View History

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.
#include "browser/browser_client.h"
2013-03-13 19:12:05 +00:00
#include "browser/browser_context.h"
#include "browser/browser_main_parts.h"
#include "browser/media/media_capture_devices_dispatcher.h"
#include "browser/notification_presenter.h"
2013-03-13 19:12:05 +00:00
#include "base/base_paths.h"
#include "base/path_service.h"
#include "content/public/common/url_constants.h"
2013-03-13 19:12:05 +00:00
namespace brightray {
namespace {
BrowserClient* g_browser_client;
}
BrowserClient* BrowserClient::Get() {
return g_browser_client;
}
BrowserClient::BrowserClient()
: browser_main_parts_() {
DCHECK(!g_browser_client);
g_browser_client = this;
2013-03-13 19:12:05 +00:00
}
BrowserClient::~BrowserClient() {
}
BrowserContext* BrowserClient::browser_context() {
return browser_main_parts_->browser_context();
}
NotificationPresenter* BrowserClient::notification_presenter() {
#if defined(OS_MACOSX) || defined(OS_LINUX)
if (!notification_presenter_)
notification_presenter_.reset(NotificationPresenter::Create());
#endif
return notification_presenter_.get();
}
BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts(
const content::MainFunctionParams&) {
2013-03-13 19:12:05 +00:00
return new BrowserMainParts;
}
content::BrowserMainParts* BrowserClient::CreateBrowserMainParts(
const content::MainFunctionParams& parameters) {
DCHECK(!browser_main_parts_);
browser_main_parts_ = OverrideCreateBrowserMainParts(parameters);
return browser_main_parts_;
2013-03-13 19:12:05 +00:00
}
net::URLRequestContextGetter* BrowserClient::CreateRequestContext(
content::BrowserContext* browser_context,
content::ProtocolHandlerMap* protocol_handlers,
2014-08-31 10:43:01 +00:00
content::URLRequestInterceptorScopedVector protocol_interceptors) {
auto context = static_cast<BrowserContext*>(browser_context);
return context->CreateRequestContext(protocol_handlers, protocol_interceptors.Pass());
2013-03-13 19:12:05 +00:00
}
void BrowserClient::ShowDesktopNotification(
const content::ShowDesktopNotificationHostMsgParams& params,
content::RenderFrameHost* render_frame_host,
content::DesktopNotificationDelegate* delegate,
base::Closure* cancel_callback) {
auto presenter = notification_presenter();
if (presenter)
presenter->ShowNotification(params, delegate, cancel_callback);
2013-03-29 13:36:07 +00:00
}
content::MediaObserver* BrowserClient::GetMediaObserver() {
return MediaCaptureDevicesDispatcher::GetInstance();
}
void BrowserClient::GetAdditionalAllowedSchemesForFileSystem(
std::vector<std::string>* additional_schemes) {
additional_schemes->push_back(content::kChromeDevToolsScheme);
additional_schemes->push_back(content::kChromeUIScheme);
}
base::FilePath BrowserClient::GetDefaultDownloadDirectory() {
// ~/Downloads
base::FilePath path;
if (PathService::Get(base::DIR_HOME, &path))
path = path.Append(FILE_PATH_LITERAL("Downloads"));
return path;
}
} // namespace brightray