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"
|
2018-02-02 23:43:33 +01:00
|
|
|
#include "libcef/browser/browser_context_keyed_service_factories.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/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"
|
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"
|
2018-08-09 22:18:24 +02:00
|
|
|
#include "base/task/post_task.h"
|
2018-03-20 21:15:08 +01:00
|
|
|
#include "chrome/browser/chrome_browser_main_extra_parts.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "chrome/browser/plugins/plugin_finder.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/gpu_data_manager.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"
|
2018-05-21 14:54:08 +02:00
|
|
|
#include "services/service_manager/embedder/result_codes.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#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
|
|
|
|
|
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
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
CefBrowserMainParts::~CefBrowserMainParts() {
|
|
|
|
for (int i = static_cast<int>(chrome_extra_parts_.size()) - 1; i >= 0; --i)
|
|
|
|
delete chrome_extra_parts_[i];
|
|
|
|
chrome_extra_parts_.clear();
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
void CefBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
|
|
|
|
chrome_extra_parts_.push_back(parts);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
int 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
|
2018-03-20 21:15:08 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->PreEarlyInitialization();
|
|
|
|
|
2018-05-21 14:54:08 +02:00
|
|
|
return service_manager::RESULT_CODE_NORMAL_EXIT;
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
void CefBrowserMainParts::PostEarlyInitialization() {
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->PostEarlyInitialization();
|
|
|
|
}
|
|
|
|
|
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)
|
2018-03-20 21:15:08 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->ToolkitInitialized();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PreMainMessageLoopStart() {
|
|
|
|
if (!base::MessageLoop::current()) {
|
|
|
|
// Create the browser message loop.
|
|
|
|
message_loop_.reset(new CefBrowserMessageLoop());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->PreMainMessageLoopStart();
|
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
|
2018-03-20 21:15:08 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->PostMainMessageLoopStart();
|
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();
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->PreCreateThreads();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
void CefBrowserMainParts::ServiceManagerConnectionStarted(
|
|
|
|
content::ServiceManagerConnection* connection) {
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->ServiceManagerConnectionStarted(connection);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
void CefBrowserMainParts::PreMainMessageLoopRun() {
|
2017-09-06 23:40:58 +02:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
display::Screen::SetScreenInstance(views::CreateDesktopScreen());
|
|
|
|
#endif
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
// CEF's profile is a BrowserContext.
|
|
|
|
PreProfileInit();
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
extensions::CefExtensionSystemFactory::GetInstance();
|
|
|
|
}
|
|
|
|
|
2018-02-02 23:43:33 +01:00
|
|
|
// Register additional KeyedService factories here. See
|
|
|
|
// ChromeBrowserMainExtraPartsProfiles for details.
|
|
|
|
cef::EnsureBrowserContextKeyedServiceFactoriesBuilt();
|
|
|
|
|
2016-11-23 21:54:29 +01:00
|
|
|
printing::CefPrintingMessageFilter::EnsureShutdownNotifierFactoryBuilt();
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
background_task_runner_ = base::CreateSingleThreadTaskRunnerWithTraits(
|
2018-07-31 21:21:39 +02:00
|
|
|
{base::TaskPriority::BEST_EFFORT,
|
2018-03-20 21:15:08 +01:00
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
|
|
|
user_visible_task_runner_ = base::CreateSingleThreadTaskRunnerWithTraits(
|
|
|
|
{base::TaskPriority::USER_VISIBLE,
|
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
|
|
|
user_blocking_task_runner_ = base::CreateSingleThreadTaskRunnerWithTraits(
|
|
|
|
{base::TaskPriority::USER_BLOCKING,
|
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
|
|
|
|
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
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
PostProfileInit();
|
|
|
|
|
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
|
|
|
|
2016-11-07 20:14:09 +01:00
|
|
|
scheme::RegisterWebUIControllerFactory();
|
2018-03-20 21:15:08 +01:00
|
|
|
|
|
|
|
// These have no equivalent in CEF.
|
|
|
|
PreBrowserStart();
|
|
|
|
PostBrowserStart();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->PreMainMessageLoopRun();
|
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();
|
|
|
|
}
|
2018-03-20 21:15:08 +01:00
|
|
|
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->PostMainMessageLoopRun();
|
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
|
|
|
}
|
2018-03-20 21:15:08 +01:00
|
|
|
|
|
|
|
void CefBrowserMainParts::PreProfileInit() {
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->PreProfileInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PostProfileInit() {
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->PostProfileInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PreBrowserStart() {
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->PreBrowserStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PostBrowserStart() {
|
|
|
|
for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
|
|
|
|
chrome_extra_parts_[i]->PostBrowserStart();
|
|
|
|
}
|