2012-04-03 03:34:16 +02: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 file.
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_main.h"
|
2012-05-18 22:32:28 +02:00
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2012-05-18 22:32:28 +02:00
|
|
|
#include <string>
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/browser_context_impl.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "libcef/browser/browser_context_proxy.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "libcef/browser/browser_message_loop.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "libcef/browser/content_browser_client.h"
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "libcef/browser/context.h"
|
2016-10-17 20:14:44 +02:00
|
|
|
#include "libcef/browser/devtools_manager_delegate.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/browser/extensions/browser_context_keyed_service_factories.h"
|
|
|
|
#include "libcef/browser/extensions/extension_system_factory.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "libcef/browser/extensions/extensions_browser_client.h"
|
2016-11-07 20:14:09 +01:00
|
|
|
#include "libcef/browser/net/chrome_scheme_handler.h"
|
2016-11-23 21:54:29 +01:00
|
|
|
#include "libcef/browser/printing/printing_message_filter.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "libcef/common/extensions/extensions_client.h"
|
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/common/net/net_resource_provider.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#include "base/bind.h"
|
|
|
|
#include "base/command_line.h"
|
2013-07-24 22:15:18 +02:00
|
|
|
#include "base/message_loop/message_loop.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "chrome/browser/plugins/plugin_finder.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "content/public/browser/child_process_security_policy.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/gpu_data_manager.h"
|
|
|
|
#include "content/public/common/content_switches.h"
|
2016-08-31 13:25:56 +02:00
|
|
|
#include "device/geolocation/access_token_store.h"
|
|
|
|
#include "device/geolocation/geolocation_delegate.h"
|
|
|
|
#include "device/geolocation/geolocation_provider.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "extensions/browser/extension_system.h"
|
|
|
|
#include "extensions/common/constants.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "net/base/net_module.h"
|
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
2013-12-07 02:55:22 +01:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
#include "ui/aura/env.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "ui/display/screen.h"
|
2013-12-07 02:55:22 +01:00
|
|
|
#include "ui/views/test/desktop_test_views_delegate.h"
|
|
|
|
#include "ui/views/widget/desktop_aura/desktop_screen.h"
|
2017-04-26 18:49:30 +02:00
|
|
|
#include "ui/wm/core/wm_state.h"
|
2014-05-06 19:20:43 +02:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "ui/base/cursor/cursor_loader_win.h"
|
|
|
|
#endif
|
2013-12-07 02:55:22 +01:00
|
|
|
#endif // defined(USE_AURA)
|
|
|
|
|
2014-06-12 22:28:58 +02:00
|
|
|
#if defined(USE_AURA) && defined(OS_LINUX)
|
2014-05-22 23:01:22 +02:00
|
|
|
#include "ui/base/ime/input_method_initializer.h"
|
|
|
|
#endif
|
|
|
|
|
2014-07-10 17:41:30 +02:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
#include "libcef/browser/printing/print_dialog_linux.h"
|
|
|
|
#endif
|
|
|
|
|
2016-08-31 13:25:56 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// In-memory store for access tokens used by geolocation.
|
|
|
|
class CefAccessTokenStore : public device::AccessTokenStore {
|
|
|
|
public:
|
|
|
|
// |system_context| is used by NetworkLocationProvider to communicate with a
|
|
|
|
// remote geolocation service.
|
|
|
|
explicit CefAccessTokenStore(net::URLRequestContextGetter* system_context)
|
|
|
|
: system_context_(system_context) {}
|
|
|
|
|
|
|
|
void LoadAccessTokens(const LoadAccessTokensCallback& callback) override {
|
|
|
|
callback.Run(access_token_map_, system_context_);
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void SaveAccessToken(const GURL& server_url,
|
|
|
|
const base::string16& access_token) override {
|
2016-08-31 13:25:56 +02:00
|
|
|
access_token_map_[server_url] = access_token;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
net::URLRequestContextGetter* system_context_;
|
|
|
|
AccessTokenMap access_token_map_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefAccessTokenStore);
|
|
|
|
};
|
|
|
|
|
|
|
|
// A provider of services for geolocation.
|
|
|
|
class CefGeolocationDelegate : public device::GeolocationDelegate {
|
|
|
|
public:
|
|
|
|
explicit CefGeolocationDelegate(net::URLRequestContextGetter* system_context)
|
|
|
|
: system_context_(system_context) {}
|
|
|
|
|
|
|
|
scoped_refptr<device::AccessTokenStore> CreateAccessTokenStore() override {
|
|
|
|
return new CefAccessTokenStore(system_context_);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
net::URLRequestContextGetter* system_context_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefGeolocationDelegate);
|
|
|
|
};
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2016-08-31 13:25:56 +02:00
|
|
|
} // namespace
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefBrowserMainParts::CefBrowserMainParts(
|
|
|
|
const content::MainFunctionParams& parameters)
|
2017-05-17 11:29:28 +02:00
|
|
|
: BrowserMainParts(), devtools_delegate_(NULL) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserMainParts::~CefBrowserMainParts() {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-04-11 20:00:55 +02:00
|
|
|
void CefBrowserMainParts::PreMainMessageLoopStart() {
|
2013-04-16 00:16:01 +02:00
|
|
|
if (!base::MessageLoop::current()) {
|
2012-04-11 20:00:55 +02:00
|
|
|
// Create the browser message loop.
|
|
|
|
message_loop_.reset(new CefBrowserMessageLoop());
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-05-22 23:01:22 +02:00
|
|
|
void CefBrowserMainParts::PreEarlyInitialization() {
|
2014-06-12 22:28:58 +02:00
|
|
|
#if defined(USE_AURA) && defined(OS_LINUX)
|
2014-05-22 23:01:22 +02:00
|
|
|
// TODO(linux): Consider using a real input method or
|
|
|
|
// views::LinuxUI::SetInstance.
|
|
|
|
ui::InitializeInputMethodForTesting();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-12-07 02:55:22 +01:00
|
|
|
void CefBrowserMainParts::ToolkitInitialized() {
|
|
|
|
#if defined(USE_AURA)
|
2014-05-29 19:15:34 +02:00
|
|
|
CHECK(aura::Env::GetInstance());
|
2013-12-07 02:55:22 +01:00
|
|
|
|
|
|
|
new views::DesktopTestViewsDelegate;
|
2014-05-06 19:20:43 +02:00
|
|
|
|
2017-04-26 18:49:30 +02:00
|
|
|
wm_state_.reset(new wm::WMState);
|
|
|
|
|
2014-05-06 19:20:43 +02:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
ui::CursorLoaderWin::SetCursorResourceModule(
|
|
|
|
CefContentBrowserClient::Get()->GetResourceDllName());
|
2013-12-07 02:55:22 +01:00
|
|
|
#endif
|
2014-05-06 19:20:43 +02:00
|
|
|
#endif // defined(USE_AURA)
|
2013-12-07 02:55:22 +01:00
|
|
|
}
|
|
|
|
|
2013-03-12 21:23:24 +01:00
|
|
|
void CefBrowserMainParts::PostMainMessageLoopStart() {
|
2014-07-10 17:41:30 +02:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
printing::PrintingContextLinux::SetCreatePrintDialogFunction(
|
|
|
|
&CefPrintDialogLinux::CreatePrintDialog);
|
2015-03-24 16:40:08 +01:00
|
|
|
printing::PrintingContextLinux::SetPdfPaperSizeFunction(
|
|
|
|
&CefPrintDialogLinux::GetPdfPaperSize);
|
2014-07-10 17:41:30 +02:00
|
|
|
#endif
|
2013-03-12 21:23:24 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
int CefBrowserMainParts::PreCreateThreads() {
|
2015-06-12 00:08:33 +02:00
|
|
|
#if defined(OS_WIN)
|
2012-06-28 19:21:18 +02:00
|
|
|
PlatformInitialize();
|
2015-06-12 00:08:33 +02:00
|
|
|
#endif
|
|
|
|
|
2013-06-24 20:57:05 +02:00
|
|
|
net::NetModule::SetResourceProvider(&NetResourceProvider);
|
2012-06-28 19:21:18 +02:00
|
|
|
|
|
|
|
// Initialize the GpuDataManager before IO access restrictions are applied and
|
|
|
|
// before the IO thread is started.
|
|
|
|
content::GpuDataManager::GetInstance();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PreMainMessageLoopRun() {
|
2017-09-06 23:40:58 +02:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
display::Screen::SetScreenInstance(views::CreateDesktopScreen());
|
|
|
|
#endif
|
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
if (extensions::ExtensionsEnabled()) {
|
|
|
|
// Initialize extension global objects before creating the global
|
|
|
|
// BrowserContext.
|
|
|
|
extensions_client_.reset(new extensions::CefExtensionsClient());
|
|
|
|
extensions::ExtensionsClient::Set(extensions_client_.get());
|
2017-05-17 11:29:28 +02:00
|
|
|
extensions_browser_client_.reset(
|
|
|
|
new extensions::CefExtensionsBrowserClient);
|
2015-07-16 23:40:01 +02:00
|
|
|
extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get());
|
|
|
|
|
|
|
|
// Register additional KeyedService factories here. See
|
|
|
|
// ChromeBrowserMainExtraPartsProfiles for details.
|
|
|
|
extensions::cef::EnsureBrowserContextKeyedServiceFactoriesBuilt();
|
|
|
|
extensions::CefExtensionSystemFactory::GetInstance();
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
printing::CefPrintingMessageFilter::EnsureShutdownNotifierFactoryBuilt();
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContextSettings settings;
|
|
|
|
CefContext::Get()->PopulateRequestContextSettings(&settings);
|
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
// Create the global RequestContext.
|
|
|
|
global_request_context_ =
|
|
|
|
CefRequestContextImpl::CreateGlobalRequestContext(settings);
|
|
|
|
CefBrowserContextImpl* browser_context = static_cast<CefBrowserContextImpl*>(
|
|
|
|
global_request_context_->GetBrowserContext());
|
2013-05-08 20:21:18 +02:00
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
CefDevToolsManagerDelegate::StartHttpHandler(browser_context);
|
2015-06-12 00:08:33 +02:00
|
|
|
|
2015-09-09 16:05:39 +02:00
|
|
|
// Triggers initialization of the singleton instance on UI thread.
|
|
|
|
PluginFinder::GetInstance()->Init();
|
2016-08-31 13:25:56 +02:00
|
|
|
|
|
|
|
device::GeolocationProvider::SetGeolocationDelegate(
|
|
|
|
new CefGeolocationDelegate(
|
2017-05-04 23:53:27 +02:00
|
|
|
browser_context->request_context_getter().get()));
|
2016-11-07 20:14:09 +01:00
|
|
|
|
|
|
|
scheme::RegisterWebUIControllerFactory();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PostMainMessageLoopRun() {
|
2016-10-17 20:14:44 +02:00
|
|
|
// NOTE: Destroy objects in reverse order of creation.
|
|
|
|
CefDevToolsManagerDelegate::StopHttpHandler();
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// There should be no additional references to the global CefRequestContext
|
|
|
|
// during shutdown. Did you forget to release a CefBrowser reference?
|
|
|
|
DCHECK(global_request_context_->HasOneRef());
|
2017-05-04 23:53:27 +02:00
|
|
|
global_request_context_ = NULL;
|
2016-10-17 20:14:44 +02:00
|
|
|
|
2015-07-16 23:40:01 +02:00
|
|
|
if (extensions::ExtensionsEnabled()) {
|
|
|
|
extensions::ExtensionsBrowserClient::Set(NULL);
|
|
|
|
extensions_browser_client_.reset();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-06-28 19:21:18 +02:00
|
|
|
void CefBrowserMainParts::PostDestroyThreads() {
|
2013-12-07 02:55:22 +01:00
|
|
|
#if defined(USE_AURA)
|
2015-07-24 02:06:56 +02:00
|
|
|
// Delete the DesktopTestViewsDelegate.
|
|
|
|
delete views::ViewsDelegate::GetInstance();
|
2013-12-07 02:55:22 +01:00
|
|
|
#endif
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|