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.
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
#include "libcef/browser/alloy/alloy_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>
|
|
|
|
|
2019-03-22 23:11:51 +01:00
|
|
|
#include "libcef/browser/browser_context.h"
|
2018-02-02 23:43:33 +01:00
|
|
|
#include "libcef/browser/browser_context_keyed_service_factories.h"
|
2015-03-02 21:25:14 +01:00
|
|
|
#include "libcef/browser/context.h"
|
2019-02-12 19:43:44 +01:00
|
|
|
#include "libcef/browser/devtools/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"
|
2019-07-17 20:47:27 +02:00
|
|
|
#include "libcef/browser/printing/constrained_window_views_client.h"
|
2015-02-14 00:17:08 +01:00
|
|
|
#include "libcef/browser/thread_util.h"
|
2020-06-28 23:05:36 +02:00
|
|
|
#include "libcef/common/app_manager.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-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"
|
2019-05-02 18:16:44 +02:00
|
|
|
#include "chrome/browser/browser_process.h"
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "chrome/browser/media/router/chrome_media_router_factory.h"
|
2019-05-02 18:16:44 +02:00
|
|
|
#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 20:47:27 +02:00
|
|
|
#include "components/constrained_window/constrained_window_views.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "content/public/browser/gpu_data_manager.h"
|
2020-04-14 21:31:00 +02:00
|
|
|
#include "content/public/browser/network_service_instance.h"
|
2020-10-08 21:54:42 +02:00
|
|
|
#include "content/public/common/result_codes.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"
|
|
|
|
|
2019-02-27 20:17:21 +01:00
|
|
|
#if defined(USE_AURA) && defined(USE_X11)
|
|
|
|
#include "ui/events/devices/x11/touch_factory_x11.h"
|
|
|
|
#endif
|
|
|
|
|
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/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)
|
2020-03-19 16:34:15 +01:00
|
|
|
#include "chrome/browser/chrome_browser_main_win.h"
|
2020-04-16 03:26:27 +02:00
|
|
|
#include "chrome/browser/win/parental_controls.h"
|
2020-03-04 01:29:39 +01:00
|
|
|
#include "components/os_crypt/os_crypt.h"
|
2014-05-06 19:20:43 +02:00
|
|
|
#endif
|
2013-12-07 02:55:22 +01:00
|
|
|
#endif // defined(USE_AURA)
|
|
|
|
|
2019-10-15 13:11:59 +02:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2020-08-29 00:39:23 +02:00
|
|
|
#if defined(OS_MAC)
|
2019-10-15 13:11:59 +02:00
|
|
|
#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 22:28:58 +02: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 23:01:22 +02:00
|
|
|
#endif
|
|
|
|
|
2014-07-10 17:41:30 +02:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
#include "libcef/browser/printing/print_dialog_linux.h"
|
|
|
|
#endif
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyBrowserMainParts::AlloyBrowserMainParts(
|
2012-04-03 03:34:16 +02:00
|
|
|
const content::MainFunctionParams& parameters)
|
2020-01-15 14:36:24 +01:00
|
|
|
: BrowserMainParts(), devtools_delegate_(nullptr) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
AlloyBrowserMainParts::~AlloyBrowserMainParts() {
|
2019-07-17 20:47:27 +02:00
|
|
|
constrained_window::SetConstrainedWindowViewsClient(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
int AlloyBrowserMainParts::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
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
return content::RESULT_CODE_NORMAL_EXIT;
|
2014-05-22 23:01:22 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyBrowserMainParts::ToolkitInitialized() {
|
2019-07-17 20:47:27 +02:00
|
|
|
SetConstrainedWindowViewsClient(CreateCefConstrainedWindowViewsClient());
|
2013-12-07 02:55:22 +01:00
|
|
|
#if defined(USE_AURA)
|
2014-05-29 19:15:34 +02:00
|
|
|
CHECK(aura::Env::GetInstance());
|
2013-12-07 02:55:22 +01:00
|
|
|
|
2017-04-26 18:49:30 +02:00
|
|
|
wm_state_.reset(new wm::WMState);
|
2014-05-06 19:20:43 +02:00
|
|
|
#endif // defined(USE_AURA)
|
2019-10-15 13:11:59 +02:00
|
|
|
|
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2020-08-29 00:39:23 +02:00
|
|
|
#if defined(OS_MAC)
|
2019-10-15 13:11:59 +02:00
|
|
|
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 21:15:08 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyBrowserMainParts::PreMainMessageLoopStart() {
|
2019-02-27 20:17:21 +01:00
|
|
|
#if defined(USE_AURA) && defined(USE_X11)
|
|
|
|
ui::TouchFactory::SetTouchDeviceListFromCommandLine();
|
|
|
|
#endif
|
|
|
|
|
2020-03-04 01:29:39 +01:00
|
|
|
#if defined(OS_WIN)
|
2019-07-29 23:27:12 +02:00
|
|
|
// Initialize the OSCrypt.
|
|
|
|
PrefService* local_state = g_browser_process->local_state();
|
|
|
|
DCHECK(local_state);
|
2020-03-04 01:29:39 +01:00
|
|
|
bool os_crypt_init = OSCrypt::Init(local_state);
|
|
|
|
DCHECK(os_crypt_init);
|
2020-03-19 16:34:15 +01: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)
|
2020-10-08 21:54:42 +02:00
|
|
|
|
|
|
|
media_router::ChromeMediaRouterFactory::DoPlatformInit();
|
2013-12-07 02:55:22 +01:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyBrowserMainParts::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
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
int AlloyBrowserMainParts::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
|
|
|
|
2019-05-02 18:16:44 +02:00
|
|
|
// Initialize these objects before IO access restrictions are applied and
|
2012-06-28 19:21:18 +02:00
|
|
|
// before the IO thread is started.
|
|
|
|
content::GpuDataManager::GetInstance();
|
2019-07-29 23:27:12 +02:00
|
|
|
SystemNetworkContextManager::CreateInstance(g_browser_process->local_state());
|
2012-06-28 19:21:18 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyBrowserMainParts::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());
|
|
|
|
|
|
|
|
extensions::CefExtensionSystemFactory::GetInstance();
|
|
|
|
}
|
|
|
|
|
2018-02-02 23:43:33 +01:00
|
|
|
// Register additional KeyedService factories here. See
|
|
|
|
// ChromeBrowserMainExtraPartsProfiles for details.
|
|
|
|
cef::EnsureBrowserContextKeyedServiceFactoriesBuilt();
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
background_task_runner_ = base::CreateSingleThreadTaskRunner(
|
|
|
|
{base::ThreadPool(), base::TaskPriority::BEST_EFFORT,
|
2018-03-20 21:15:08 +01:00
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
2019-10-01 15:55:16 +02:00
|
|
|
user_visible_task_runner_ = base::CreateSingleThreadTaskRunner(
|
|
|
|
{base::ThreadPool(), base::TaskPriority::USER_VISIBLE,
|
2018-03-20 21:15:08 +01:00
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
2019-10-01 15:55:16 +02:00
|
|
|
user_blocking_task_runner_ = base::CreateSingleThreadTaskRunner(
|
|
|
|
{base::ThreadPool(), base::TaskPriority::USER_BLOCKING,
|
2018-03-20 21:15:08 +01:00
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
CefRequestContextSettings settings;
|
2020-04-23 23:45:04 +02:00
|
|
|
CefContext::Get()->PopulateGlobalRequestContextSettings(&settings);
|
2015-03-02 21:25:14 +01:00
|
|
|
|
2017-05-04 23:53:27 +02:00
|
|
|
// Create the global RequestContext.
|
|
|
|
global_request_context_ =
|
|
|
|
CefRequestContextImpl::CreateGlobalRequestContext(settings);
|
2020-07-01 02:57:00 +02:00
|
|
|
auto browser_context =
|
|
|
|
global_request_context_->GetBrowserContext()->AsBrowserContext();
|
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
|
|
|
|
2020-04-16 03:26:27 +02: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 21:31:00 +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();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyBrowserMainParts::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());
|
2020-01-15 14:36:24 +01:00
|
|
|
global_request_context_ = nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 20:29:44 +02:00
|
|
|
void AlloyBrowserMainParts::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 13:11:59 +02:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
|
|
|
views_delegate_.reset();
|
2020-08-29 00:39:23 +02:00
|
|
|
#if defined(OS_MAC)
|
2019-10-15 13:11:59 +02:00
|
|
|
layout_provider_.reset();
|
2013-12-07 02:55:22 +01:00
|
|
|
#endif
|
2019-10-15 13:11:59 +02:00
|
|
|
#endif // defined(TOOLKIT_VIEWS)
|
2013-09-03 18:43:31 +02:00
|
|
|
}
|