2012-04-03 01:34:16 +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 file.
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_main.h"
|
2012-05-18 20:32:28 +00:00
|
|
|
|
2016-01-06 14:20:54 -05:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2012-05-18 20:32:28 +00:00
|
|
|
#include <string>
|
|
|
|
|
2019-03-22 18:11:51 -04:00
|
|
|
#include "libcef/browser/browser_context.h"
|
2018-02-02 17:43:33 -05:00
|
|
|
#include "libcef/browser/browser_context_keyed_service_factories.h"
|
2013-09-03 16:43:31 +00:00
|
|
|
#include "libcef/browser/content_browser_client.h"
|
2015-03-02 20:25:14 +00:00
|
|
|
#include "libcef/browser/context.h"
|
2019-02-12 13:43:44 -05:00
|
|
|
#include "libcef/browser/devtools/devtools_manager_delegate.h"
|
2015-07-16 17:40:01 -04: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 14:14:09 -05:00
|
|
|
#include "libcef/browser/net/chrome_scheme_handler.h"
|
2019-07-17 14:47:27 -04:00
|
|
|
#include "libcef/browser/printing/constrained_window_views_client.h"
|
2016-11-23 15:54:29 -05:00
|
|
|
#include "libcef/browser/printing/printing_message_filter.h"
|
2015-02-13 23:17:08 +00:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2015-07-16 17:40:01 -04:00
|
|
|
#include "libcef/common/extensions/extensions_client.h"
|
|
|
|
#include "libcef/common/extensions/extensions_util.h"
|
2015-11-25 21:53:12 -05:00
|
|
|
#include "libcef/common/net/net_resource_provider.h"
|
2012-04-03 01:34:16 +00:00
|
|
|
|
|
|
|
#include "base/bind.h"
|
2013-07-24 20:15:18 +00:00
|
|
|
#include "base/message_loop/message_loop.h"
|
2013-06-22 02:06:32 +00:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2018-08-09 16:18:24 -04:00
|
|
|
#include "base/task/post_task.h"
|
2019-05-02 12:16:44 -04:00
|
|
|
#include "chrome/browser/browser_process.h"
|
|
|
|
#include "chrome/browser/net/system_network_context_manager.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "chrome/browser/plugins/plugin_finder.h"
|
2019-07-17 14:47:27 -04:00
|
|
|
#include "components/constrained_window/constrained_window_views.h"
|
2012-04-03 01:34:16 +00:00
|
|
|
#include "content/public/browser/gpu_data_manager.h"
|
2020-04-14 15:31:00 -04:00
|
|
|
#include "content/public/browser/network_service_instance.h"
|
2015-07-16 17:40:01 -04:00
|
|
|
#include "extensions/browser/extension_system.h"
|
|
|
|
#include "extensions/common/constants.h"
|
2012-04-03 01:34:16 +00:00
|
|
|
#include "net/base/net_module.h"
|
2018-05-21 15:54:08 +03:00
|
|
|
#include "services/service_manager/embedder/result_codes.h"
|
2012-04-03 01:34:16 +00:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
|
2019-02-27 19:17:21 +00:00
|
|
|
#if defined(USE_AURA) && defined(USE_X11)
|
|
|
|
#include "ui/events/devices/x11/touch_factory_x11.h"
|
|
|
|
#endif
|
|
|
|
|
2013-12-07 01:55:22 +00:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
#include "ui/aura/env.h"
|
2016-05-24 19:35:43 -04:00
|
|
|
#include "ui/display/screen.h"
|
2013-12-07 01:55:22 +00:00
|
|
|
#include "ui/views/widget/desktop_aura/desktop_screen.h"
|
2017-04-26 12:49:30 -04:00
|
|
|
#include "ui/wm/core/wm_state.h"
|
2014-05-06 17:20:43 +00:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2020-03-19 11:34:15 -04:00
|
|
|
#include "chrome/browser/chrome_browser_main_win.h"
|
2020-04-15 21:26:27 -04:00
|
|
|
#include "chrome/browser/win/parental_controls.h"
|
2020-03-03 19:29:39 -05:00
|
|
|
#include "components/os_crypt/os_crypt.h"
|
2014-05-06 17:20:43 +00:00
|
|
|
#include "ui/base/cursor/cursor_loader_win.h"
|
|
|
|
#endif
|
2013-12-07 01:55:22 +00:00
|
|
|
#endif // defined(USE_AURA)
|
|
|
|
|
2019-10-15 11:11:59 +00:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
#include "chrome/browser/ui/views/chrome_layout_provider.h"
|
|
|
|
#include "chrome/browser/ui/views/chrome_views_delegate.h"
|
|
|
|
#else
|
|
|
|
#include "ui/views/test/desktop_test_views_delegate.h"
|
|
|
|
#endif
|
|
|
|
#endif // defined(TOOLKIT_VIEWS)
|
|
|
|
|
2014-06-12 20:28:58 +00:00
|
|
|
#if defined(USE_AURA) && defined(OS_LINUX)
|
2019-06-05 16:15:45 +02:00
|
|
|
#include "ui/base/ime/init/input_method_initializer.h"
|
2014-05-22 21:01:22 +00:00
|
|
|
#endif
|
|
|
|
|
2014-07-10 15:41:30 +00:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
#include "libcef/browser/printing/print_dialog_linux.h"
|
|
|
|
#endif
|
|
|
|
|
2012-04-03 01:34:16 +00:00
|
|
|
CefBrowserMainParts::CefBrowserMainParts(
|
|
|
|
const content::MainFunctionParams& parameters)
|
2020-01-15 14:36:24 +01:00
|
|
|
: BrowserMainParts(), devtools_delegate_(nullptr) {}
|
2012-04-03 01:34:16 +00:00
|
|
|
|
2018-03-20 16:15:08 -04:00
|
|
|
CefBrowserMainParts::~CefBrowserMainParts() {
|
2019-07-17 14:47:27 -04:00
|
|
|
constrained_window::SetConstrainedWindowViewsClient(nullptr);
|
2012-04-03 01:34:16 +00:00
|
|
|
}
|
|
|
|
|
2018-02-14 19:12:09 -05:00
|
|
|
int CefBrowserMainParts::PreEarlyInitialization() {
|
2014-06-12 20:28:58 +00:00
|
|
|
#if defined(USE_AURA) && defined(OS_LINUX)
|
2014-05-22 21:01:22 +00:00
|
|
|
// TODO(linux): Consider using a real input method or
|
|
|
|
// views::LinuxUI::SetInstance.
|
|
|
|
ui::InitializeInputMethodForTesting();
|
|
|
|
#endif
|
2018-03-20 16:15:08 -04:00
|
|
|
|
2018-05-21 15:54:08 +03:00
|
|
|
return service_manager::RESULT_CODE_NORMAL_EXIT;
|
2014-05-22 21:01:22 +00:00
|
|
|
}
|
|
|
|
|
2013-12-07 01:55:22 +00:00
|
|
|
void CefBrowserMainParts::ToolkitInitialized() {
|
2019-07-17 14:47:27 -04:00
|
|
|
SetConstrainedWindowViewsClient(CreateCefConstrainedWindowViewsClient());
|
2013-12-07 01:55:22 +00:00
|
|
|
#if defined(USE_AURA)
|
2014-05-29 17:15:34 +00:00
|
|
|
CHECK(aura::Env::GetInstance());
|
2013-12-07 01:55:22 +00:00
|
|
|
|
2017-04-26 12:49:30 -04:00
|
|
|
wm_state_.reset(new wm::WMState);
|
|
|
|
|
2014-05-06 17:20:43 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
ui::CursorLoaderWin::SetCursorResourceModule(
|
|
|
|
CefContentBrowserClient::Get()->GetResourceDllName());
|
2013-12-07 01:55:22 +00:00
|
|
|
#endif
|
2014-05-06 17:20:43 +00:00
|
|
|
#endif // defined(USE_AURA)
|
2019-10-15 11:11:59 +00:00
|
|
|
|
|
|
|
#if defined(TOOLKIT_VIEWS)
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
views_delegate_ = std::make_unique<ChromeViewsDelegate>();
|
|
|
|
layout_provider_ = ChromeLayoutProvider::CreateLayoutProvider();
|
|
|
|
#else
|
|
|
|
views_delegate_ = std::make_unique<views::DesktopTestViewsDelegate>();
|
|
|
|
#endif
|
|
|
|
#endif // defined(TOOLKIT_VIEWS)
|
2018-03-20 16:15:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PreMainMessageLoopStart() {
|
2019-02-27 19:17:21 +00:00
|
|
|
#if defined(USE_AURA) && defined(USE_X11)
|
|
|
|
ui::TouchFactory::SetTouchDeviceListFromCommandLine();
|
|
|
|
#endif
|
|
|
|
|
2020-03-03 19:29:39 -05:00
|
|
|
#if defined(OS_WIN)
|
2019-07-29 17:27:12 -04:00
|
|
|
// Initialize the OSCrypt.
|
|
|
|
PrefService* local_state = g_browser_process->local_state();
|
|
|
|
DCHECK(local_state);
|
2020-03-03 19:29:39 -05:00
|
|
|
bool os_crypt_init = OSCrypt::Init(local_state);
|
|
|
|
DCHECK(os_crypt_init);
|
2020-03-19 11:34:15 -04:00
|
|
|
|
|
|
|
// installer_util references strings that are normally compiled into
|
|
|
|
// setup.exe. In Chrome, these strings are in the locale files.
|
|
|
|
ChromeBrowserMainPartsWin::SetupInstallerUtilStrings();
|
|
|
|
#endif // defined(OS_WIN)
|
2013-12-07 01:55:22 +00:00
|
|
|
}
|
|
|
|
|
2013-03-12 20:23:24 +00:00
|
|
|
void CefBrowserMainParts::PostMainMessageLoopStart() {
|
2014-07-10 15:41:30 +00:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
printing::PrintingContextLinux::SetCreatePrintDialogFunction(
|
|
|
|
&CefPrintDialogLinux::CreatePrintDialog);
|
2015-03-24 18:40:08 +03:00
|
|
|
printing::PrintingContextLinux::SetPdfPaperSizeFunction(
|
|
|
|
&CefPrintDialogLinux::GetPdfPaperSize);
|
2014-07-10 15:41:30 +00:00
|
|
|
#endif
|
2013-03-12 20:23:24 +00:00
|
|
|
}
|
|
|
|
|
2012-04-03 01:34:16 +00:00
|
|
|
int CefBrowserMainParts::PreCreateThreads() {
|
2015-06-11 18:08:33 -04:00
|
|
|
#if defined(OS_WIN)
|
2012-06-28 17:21:18 +00:00
|
|
|
PlatformInitialize();
|
2015-06-11 18:08:33 -04:00
|
|
|
#endif
|
|
|
|
|
2013-06-24 18:57:05 +00:00
|
|
|
net::NetModule::SetResourceProvider(&NetResourceProvider);
|
2012-06-28 17:21:18 +00:00
|
|
|
|
2019-05-02 12:16:44 -04:00
|
|
|
// Initialize these objects before IO access restrictions are applied and
|
2012-06-28 17:21:18 +00:00
|
|
|
// before the IO thread is started.
|
|
|
|
content::GpuDataManager::GetInstance();
|
2019-07-29 17:27:12 -04:00
|
|
|
SystemNetworkContextManager::CreateInstance(g_browser_process->local_state());
|
2012-06-28 17:21:18 +00:00
|
|
|
|
2012-04-03 01:34:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PreMainMessageLoopRun() {
|
2017-09-06 17:40:58 -04:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
display::Screen::SetScreenInstance(views::CreateDesktopScreen());
|
|
|
|
#endif
|
|
|
|
|
2015-07-16 17:40:01 -04: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 17:40:01 -04:00
|
|
|
extensions::ExtensionsBrowserClient::Set(extensions_browser_client_.get());
|
|
|
|
|
|
|
|
extensions::CefExtensionSystemFactory::GetInstance();
|
|
|
|
}
|
|
|
|
|
2018-02-02 17:43:33 -05:00
|
|
|
// Register additional KeyedService factories here. See
|
|
|
|
// ChromeBrowserMainExtraPartsProfiles for details.
|
|
|
|
cef::EnsureBrowserContextKeyedServiceFactoriesBuilt();
|
|
|
|
|
2016-11-23 15:54:29 -05:00
|
|
|
printing::CefPrintingMessageFilter::EnsureShutdownNotifierFactoryBuilt();
|
|
|
|
|
2019-10-01 13:55:16 +00:00
|
|
|
background_task_runner_ = base::CreateSingleThreadTaskRunner(
|
|
|
|
{base::ThreadPool(), base::TaskPriority::BEST_EFFORT,
|
2018-03-20 16:15:08 -04:00
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
2019-10-01 13:55:16 +00:00
|
|
|
user_visible_task_runner_ = base::CreateSingleThreadTaskRunner(
|
|
|
|
{base::ThreadPool(), base::TaskPriority::USER_VISIBLE,
|
2018-03-20 16:15:08 -04:00
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
2019-10-01 13:55:16 +00:00
|
|
|
user_blocking_task_runner_ = base::CreateSingleThreadTaskRunner(
|
|
|
|
{base::ThreadPool(), base::TaskPriority::USER_BLOCKING,
|
2018-03-20 16:15:08 -04:00
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
|
|
|
|
2015-03-02 20:25:14 +00:00
|
|
|
CefRequestContextSettings settings;
|
|
|
|
CefContext::Get()->PopulateRequestContextSettings(&settings);
|
|
|
|
|
2017-05-04 17:53:27 -04:00
|
|
|
// Create the global RequestContext.
|
|
|
|
global_request_context_ =
|
|
|
|
CefRequestContextImpl::CreateGlobalRequestContext(settings);
|
2019-03-22 18:11:51 -04:00
|
|
|
CefBrowserContext* browser_context = static_cast<CefBrowserContext*>(
|
2017-05-04 17:53:27 -04:00
|
|
|
global_request_context_->GetBrowserContext());
|
2013-05-08 18:21:18 +00:00
|
|
|
|
2017-05-04 17:53:27 -04:00
|
|
|
CefDevToolsManagerDelegate::StartHttpHandler(browser_context);
|
2015-06-11 18:08:33 -04:00
|
|
|
|
2020-04-15 21:26:27 -04:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
// Windows parental controls calls can be slow, so we do an early init here
|
|
|
|
// that calculates this value off of the UI thread.
|
|
|
|
InitializeWinParentalControls();
|
|
|
|
#endif
|
2020-04-14 15:31:00 -04:00
|
|
|
|
2015-09-09 16:05:39 +02:00
|
|
|
// Triggers initialization of the singleton instance on UI thread.
|
|
|
|
PluginFinder::GetInstance()->Init();
|
2016-08-31 14:25:56 +03:00
|
|
|
|
2016-11-07 14:14:09 -05:00
|
|
|
scheme::RegisterWebUIControllerFactory();
|
2012-04-03 01:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserMainParts::PostMainMessageLoopRun() {
|
2016-10-17 14:14:44 -04:00
|
|
|
// NOTE: Destroy objects in reverse order of creation.
|
|
|
|
CefDevToolsManagerDelegate::StopHttpHandler();
|
|
|
|
|
2017-08-03 18:55:19 -04: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());
|
2020-01-15 14:36:24 +01:00
|
|
|
global_request_context_ = nullptr;
|
2012-04-03 01:34:16 +00:00
|
|
|
}
|
|
|
|
|
2012-06-28 17:21:18 +00:00
|
|
|
void CefBrowserMainParts::PostDestroyThreads() {
|
2018-09-04 11:43:21 +02:00
|
|
|
if (extensions::ExtensionsEnabled()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
extensions::ExtensionsBrowserClient::Set(nullptr);
|
2018-09-04 11:43:21 +02:00
|
|
|
extensions_browser_client_.reset();
|
|
|
|
}
|
|
|
|
|
2019-10-15 11:11:59 +00:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
|
|
|
views_delegate_.reset();
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
layout_provider_.reset();
|
2013-12-07 01:55:22 +00:00
|
|
|
#endif
|
2019-10-15 11:11:59 +00:00
|
|
|
#endif // defined(TOOLKIT_VIEWS)
|
2013-09-03 16:43:31 +00:00
|
|
|
}
|