2020-06-25 04:34:12 +02:00
|
|
|
// Copyright 2019 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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/chrome/chrome_browser_main_extra_parts_cef.h"
|
2020-07-04 04:51:17 +02:00
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
#include "base/task/thread_pool.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/alloy/dialogs/alloy_constrained_window_views_client.h"
|
|
|
|
#include "cef/libcef/browser/chrome/chrome_context_menu_handler.h"
|
|
|
|
#include "cef/libcef/browser/chrome/chrome_startup_browser_creator.h"
|
|
|
|
#include "cef/libcef/browser/context.h"
|
|
|
|
#include "cef/libcef/browser/file_dialog_runner.h"
|
|
|
|
#include "cef/libcef/browser/permission_prompt.h"
|
2023-02-17 20:08:00 +01:00
|
|
|
#include "chrome/browser/profiles/profile.h"
|
2024-04-17 18:01:26 +02:00
|
|
|
#include "chrome/browser/ui/views/chrome_constrained_window_views_client.h"
|
|
|
|
#include "components/constrained_window/constrained_window_views.h"
|
2020-06-25 04:34:12 +02:00
|
|
|
|
2023-11-29 02:33:44 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
|
|
|
#include "base/linux_util.h"
|
2024-10-18 17:51:06 +02:00
|
|
|
#include "cef/libcef/browser/printing/print_dialog_linux.h"
|
2023-11-29 02:33:44 +01:00
|
|
|
#endif
|
|
|
|
|
2023-11-21 17:24:20 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
#include "chrome/browser/win/app_icon.h"
|
|
|
|
#endif
|
|
|
|
|
2020-06-25 04:34:12 +02:00
|
|
|
ChromeBrowserMainExtraPartsCef::ChromeBrowserMainExtraPartsCef() = default;
|
|
|
|
|
|
|
|
ChromeBrowserMainExtraPartsCef::~ChromeBrowserMainExtraPartsCef() = default;
|
|
|
|
|
2022-01-25 21:26:51 +01:00
|
|
|
void ChromeBrowserMainExtraPartsCef::PostProfileInit(Profile* profile,
|
|
|
|
bool is_initial_profile) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!is_initial_profile) {
|
2022-01-25 21:26:51 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-01-25 21:26:51 +01:00
|
|
|
|
2020-07-04 04:51:17 +02:00
|
|
|
CefRequestContextSettings settings;
|
|
|
|
CefContext::Get()->PopulateGlobalRequestContextSettings(&settings);
|
|
|
|
|
2023-02-17 20:08:00 +01:00
|
|
|
// Use the existing path for the initial profile.
|
|
|
|
CefString(&settings.cache_path) = profile->GetPath().value();
|
|
|
|
|
2020-07-04 04:51:17 +02:00
|
|
|
// Create the global RequestContext.
|
|
|
|
global_request_context_ =
|
|
|
|
CefRequestContextImpl::CreateGlobalRequestContext(settings);
|
|
|
|
}
|
|
|
|
|
2023-11-29 02:33:44 +01:00
|
|
|
void ChromeBrowserMainExtraPartsCef::PostBrowserStart() {
|
|
|
|
// Register the callback before ChromeBrowserMainParts::PostBrowserStart
|
|
|
|
// allows ProcessSingleton to begin processing messages.
|
|
|
|
startup_browser_creator::RegisterProcessCommandLineCallback();
|
|
|
|
|
|
|
|
#if BUILDFLAG(IS_LINUX)
|
|
|
|
// This may be called indirectly via StartupBrowserCreator::LaunchBrowser.
|
|
|
|
// Call it here before blocking is disallowed to avoid assertions.
|
|
|
|
base::GetLinuxDistro();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
void ChromeBrowserMainExtraPartsCef::PreMainMessageLoopRun() {
|
2021-04-21 00:52:34 +02:00
|
|
|
background_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
|
|
|
|
{base::TaskPriority::BEST_EFFORT,
|
2020-06-25 04:34:12 +02:00
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
2021-04-21 00:52:34 +02:00
|
|
|
user_visible_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
|
|
|
|
{base::TaskPriority::USER_VISIBLE,
|
2020-06-25 04:34:12 +02:00
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
2021-04-21 00:52:34 +02:00
|
|
|
user_blocking_task_runner_ = base::ThreadPool::CreateSingleThreadTaskRunner(
|
|
|
|
{base::TaskPriority::USER_BLOCKING,
|
2020-06-25 04:34:12 +02:00
|
|
|
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
|
2021-02-16 00:24:28 +01:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
context_menu::RegisterCallbacks();
|
2022-04-15 21:55:23 +02:00
|
|
|
file_dialog_runner::RegisterFactory();
|
2022-07-07 12:01:24 +02:00
|
|
|
permission_prompt::RegisterCreateCallback();
|
2023-11-21 17:24:20 +01:00
|
|
|
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
const auto& settings = CefContext::Get()->settings();
|
|
|
|
if (settings.chrome_app_icon_id > 0) {
|
|
|
|
SetExeAppIconResourceId(settings.chrome_app_icon_id);
|
|
|
|
}
|
|
|
|
#endif
|
2020-06-25 04:34:12 +02:00
|
|
|
}
|
2024-04-17 18:01:26 +02:00
|
|
|
|
|
|
|
void ChromeBrowserMainExtraPartsCef::ToolkitInitialized() {
|
|
|
|
// Override the default Chrome client.
|
|
|
|
SetConstrainedWindowViewsClient(CreateAlloyConstrainedWindowViewsClient(
|
|
|
|
CreateChromeConstrainedWindowViewsClient()));
|
2024-10-18 17:51:06 +02:00
|
|
|
|
|
|
|
#if BUILDFLAG(IS_LINUX)
|
|
|
|
auto printing_delegate = new CefPrintingContextLinuxDelegate();
|
|
|
|
auto default_delegate =
|
|
|
|
ui::PrintingContextLinuxDelegate::SetInstance(printing_delegate);
|
|
|
|
printing_delegate->SetDefaultDelegate(default_delegate);
|
|
|
|
#endif // BUILDFLAG(IS_LINUX)
|
2024-04-17 18:01:26 +02:00
|
|
|
}
|