diff --git a/libcef/common/main_delegate.cc b/libcef/common/main_delegate.cc index 519446b5c..f0043a40a 100644 --- a/libcef/common/main_delegate.cc +++ b/libcef/common/main_delegate.cc @@ -28,6 +28,7 @@ #include "chrome/common/chrome_switches.h" #include "components/content_settings/core/common/content_settings_pattern.h" #include "components/viz/common/features.h" +#include "content/browser/browser_process_sub_thread.h" #include "content/public/browser/browser_main_runner.h" #include "content/public/browser/render_process_host.h" #include "content/public/common/content_features.h" @@ -243,9 +244,12 @@ bool IsScaleFactorSupported(ui::ScaleFactor scale_factor) { // Used to run the UI on a separate thread. class CefUIThread : public base::Thread { public: - explicit CefUIThread(const content::MainFunctionParams& main_function_params) + CefUIThread( + const content::MainFunctionParams& main_function_params, + std::unique_ptr service_manager_thread) : base::Thread("CefUIThread"), - main_function_params_(main_function_params) {} + main_function_params_(main_function_params), + service_manager_thread_(std::move(service_manager_thread)) {} void Init() override { #if defined(OS_WIN) @@ -257,7 +261,8 @@ class CefUIThread : public base::Thread { browser_runner_.reset(content::BrowserMainRunner::Create()); // Initialize browser process state. Uses the current thread's mesage loop. - int exit_code = browser_runner_->Initialize(main_function_params_); + int exit_code = browser_runner_->Initialize( + main_function_params_, std::move(service_manager_thread_)); CHECK_EQ(exit_code, -1); } @@ -274,6 +279,7 @@ class CefUIThread : public base::Thread { protected: content::MainFunctionParams main_function_params_; + std::unique_ptr service_manager_thread_; std::unique_ptr browser_runner_; }; @@ -573,6 +579,13 @@ void CefMainDelegate::SandboxInitialized(const std::string& process_type) { int CefMainDelegate::RunProcess( const std::string& process_type, const content::MainFunctionParams& main_function_params) { + return RunProcess(process_type, main_function_params, nullptr); +} + +int CefMainDelegate::RunProcess( + const std::string& process_type, + const content::MainFunctionParams& main_function_params, + std::unique_ptr service_manager_thread) { if (process_type.empty()) { const CefSettings& settings = CefContext::Get()->settings(); if (!settings.multi_threaded_message_loop) { @@ -582,13 +595,15 @@ int CefMainDelegate::RunProcess( // Initialize browser process state. Results in a call to // CefBrowserMain::PreMainMessageLoopStart() which creates the UI message // loop. - int exit_code = browser_runner_->Initialize(main_function_params); + int exit_code = browser_runner_->Initialize( + main_function_params, std::move(service_manager_thread)); if (exit_code >= 0) return exit_code; } else { // Run the UI on a separate thread. std::unique_ptr thread; - thread.reset(new CefUIThread(main_function_params)); + thread.reset(new CefUIThread(main_function_params, + std::move(service_manager_thread))); base::Thread::Options options; options.message_loop_type = base::MessageLoop::TYPE_UI; if (!thread->StartWithOptions(options)) { diff --git a/libcef/common/main_delegate.h b/libcef/common/main_delegate.h index bf70c5529..61244be18 100644 --- a/libcef/common/main_delegate.h +++ b/libcef/common/main_delegate.h @@ -38,6 +38,10 @@ class CefMainDelegate : public content::ContentMainDelegate { int RunProcess( const std::string& process_type, const content::MainFunctionParams& main_function_params) override; + int RunProcess(const std::string& process_type, + const content::MainFunctionParams& main_function_params, + std::unique_ptr + service_manager_thread) override; void ProcessExiting(const std::string& process_type) override; #if defined(OS_LINUX) void ZygoteForked() override; diff --git a/patch/patch.cfg b/patch/patch.cfg index 58c52324b..12045dd47 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -368,4 +368,9 @@ patches = [ # https://bugs.chromium.org/p/chromium/issues/detail?id=729800#c48 'name': 'net_cookies_729800', }, + { + # Pass BrowserProcessSubThread to ContentMainDelegate::RunProcess. + # https://bitbucket.org/chromiumembedded/cef/issues/2456 + 'name': 'content_runprocess_2456', + }, ] diff --git a/patch/patches/content_runprocess_2456.patch b/patch/patches/content_runprocess_2456.patch new file mode 100644 index 000000000..57e49cbc2 --- /dev/null +++ b/patch/patches/content_runprocess_2456.patch @@ -0,0 +1,102 @@ +diff --git content/app/content_main_runner_impl.cc content/app/content_main_runner_impl.cc +index 83e8990edf17..89bdab3f3885 100644 +--- content/app/content_main_runner_impl.cc ++++ content/app/content_main_runner_impl.cc +@@ -603,7 +603,8 @@ int RunBrowserProcessMain( + ContentMainDelegate* delegate, + std::unique_ptr service_manager_thread) { + if (delegate) { +- int exit_code = delegate->RunProcess("", main_function_params); ++ int exit_code = delegate->RunProcess("", main_function_params, ++ std::move(service_manager_thread)); + #if defined(OS_ANDROID) + // In Android's browser process, the negative exit code doesn't mean the + // default behavior should be used as the UI message loop is managed by +diff --git content/browser/browser_main_runner_impl.h content/browser/browser_main_runner_impl.h +index adb084fe27c6..42a6fdc2d67f 100644 +--- content/browser/browser_main_runner_impl.h ++++ content/browser/browser_main_runner_impl.h +@@ -42,7 +42,7 @@ class BrowserMainRunnerImpl : public BrowserMainRunner { + // on which ServiceManager is currently running. + int Initialize( + const MainFunctionParams& parameters, +- std::unique_ptr service_manager_thread); ++ std::unique_ptr service_manager_thread) override; + + private: + // True if we have started to initialize the runner. +diff --git content/public/app/content_main_delegate.cc content/public/app/content_main_delegate.cc +index c4bdfd36ad0c..f6830c35fd1d 100644 +--- content/public/app/content_main_delegate.cc ++++ content/public/app/content_main_delegate.cc +@@ -6,6 +6,7 @@ + + #include "base/logging.h" + #include "build/build_config.h" ++#include "content/browser/browser_process_sub_thread.h" + #include "content/public/gpu/content_gpu_client.h" + #include "content/public/renderer/content_renderer_client.h" + #include "content/public/utility/content_utility_client.h" +@@ -26,6 +27,13 @@ int ContentMainDelegate::RunProcess( + return -1; + } + ++int ContentMainDelegate::RunProcess( ++ const std::string& process_type, ++ const MainFunctionParams& main_function_params, ++ std::unique_ptr service_manager_thread) { ++ return RunProcess(process_type, main_function_params); ++} ++ + ui::DataPack* ContentMainDelegate::LoadServiceManifestDataPack() { + return nullptr; + } +diff --git content/public/app/content_main_delegate.h content/public/app/content_main_delegate.h +index b5d8b1889d60..ea6af1600c36 100644 +--- content/public/app/content_main_delegate.h ++++ content/public/app/content_main_delegate.h +@@ -30,6 +30,7 @@ class DataPack; + + namespace content { + ++class BrowserProcessSubThread; + class ContentBrowserClient; + class ContentGpuClient; + class ContentRendererClient; +@@ -60,6 +61,12 @@ class CONTENT_EXPORT ContentMainDelegate { + const std::string& process_type, + const MainFunctionParams& main_function_params); + ++ // Asks the embedder to start a process. Return -1 for the default behavior. ++ virtual int RunProcess( ++ const std::string& process_type, ++ const MainFunctionParams& main_function_params, ++ std::unique_ptr service_manager_thread); ++ + // Called right before the process exits. + virtual void ProcessExiting(const std::string& process_type) {} + +diff --git content/public/browser/browser_main_runner.h content/public/browser/browser_main_runner.h +index c01be956eded..8cbd8d894ac5 100644 +--- content/public/browser/browser_main_runner.h ++++ content/public/browser/browser_main_runner.h +@@ -10,6 +10,7 @@ + + namespace content { + ++class BrowserProcessSubThread; + struct MainFunctionParams; + + // This class is responsible for browser initialization, running and shutdown. +@@ -26,7 +27,10 @@ class CONTENT_EXPORT BrowserMainRunner { + // Initialize all necessary browser state. The |parameters| values will be + // copied. Returning a non-negative value indicates that initialization + // failed, and the returned value is used as the exit code for the process. +- virtual int Initialize(const content::MainFunctionParams& parameters) = 0; ++ virtual int Initialize(const MainFunctionParams& parameters) = 0; ++ virtual int Initialize( ++ const MainFunctionParams& parameters, ++ std::unique_ptr service_manager_thread) = 0; + + #if defined(OS_ANDROID) + // Run all queued startup tasks. Only defined on Android because other