diff options
Diffstat (limited to 'src/core/browser_main_parts_qt.cpp')
-rw-r--r-- | src/core/browser_main_parts_qt.cpp | 241 |
1 files changed, 124 insertions, 117 deletions
diff --git a/src/core/browser_main_parts_qt.cpp b/src/core/browser_main_parts_qt.cpp index c1f4cbb2d..9021dbb98 100644 --- a/src/core/browser_main_parts_qt.cpp +++ b/src/core/browser_main_parts_qt.cpp @@ -1,86 +1,68 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "browser_main_parts_qt.h" #include "api/qwebenginemessagepumpscheduler_p.h" -#include "base/message_loop/message_loop.h" -#include "base/message_loop/message_loop_current.h" +#include "base/message_loop/message_pump.h" #include "base/message_loop/message_pump_for_ui.h" #include "base/process/process.h" +#include "base/task/current_thread.h" #include "base/task/sequence_manager/sequence_manager_impl.h" #include "base/task/sequence_manager/thread_controller_with_message_pump_impl.h" +#include "base/task/task_traits.h" +#include "base/task/thread_pool.h" #include "base/threading/thread_restrictions.h" #include "chrome/browser/tab_contents/form_interaction_tab_helper.h" +#include "components/device_event_log/device_event_log.h" +#include "components/performance_manager/embedder/graph_features.h" #include "components/performance_manager/embedder/performance_manager_lifetime.h" -#include "components/performance_manager/embedder/performance_manager_registry.h" #include "components/performance_manager/public/graph/graph.h" #include "components/performance_manager/public/performance_manager.h" #include "content/public/browser/browser_main_parts.h" +#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_security_policy.h" -#include "content/public/browser/system_connector.h" -#include "content/public/common/service_manager_connection.h" +#include "content/public/common/content_features.h" +#include "content/public/common/result_codes.h" #include "extensions/buildflags/buildflags.h" +#include "ppapi/buildflags/buildflags.h" +#include "select_file_dialog_factory_qt.h" +#include "services/service_manager/public/cpp/connector.h" +#include "services/service_manager/public/cpp/service.h" +#include "type_conversion.h" +#include "ui/display/screen.h" + #if BUILDFLAG(ENABLE_EXTENSIONS) #include "extensions/common/constants.h" #include "extensions/common/extensions_client.h" #include "extensions/extensions_browser_client_qt.h" #include "extensions/extension_system_factory_qt.h" #include "common/extensions/extensions_client_qt.h" -#endif //BUILDFLAG(ENABLE_EXTENSIONS) -#include "services/service_manager/public/cpp/connector.h" -#include "services/service_manager/public/cpp/service.h" -#include "ui/display/screen.h" +#endif // BUILDFLAG(ENABLE_EXTENSIONS) + +#if BUILDFLAG(ENABLE_PLUGINS) +#include "content/public/browser/plugin_service.h" +#include "extensions/plugin_service_filter_qt.h" +#endif // BUILDFLAG(ENABLE_PLUGINS) #include "web_engine_context.h" +#include "web_usb_detector_qt.h" +#include <QDeadlineTimer> #include <QtGui/qtgui-config.h> +#include <QStandardPaths> #if QT_CONFIG(opengl) #include "ui/gl/gl_context.h" #include <QOpenGLContext> #endif -#if defined(OS_MACOSX) -#include "base/message_loop/message_pump_mac.h" +#if BUILDFLAG(IS_MAC) +#include "base/message_loop/message_pump_apple.h" +#include "services/device/public/cpp/geolocation/geolocation_manager.h" +#include "services/device/public/cpp/geolocation/system_geolocation_source.h" #include "ui/base/idle/idle.h" #endif @@ -90,6 +72,10 @@ #include "desktop_screen_qt.h" #endif +#if defined(Q_OS_LINUX) +#include "components/os_crypt/sync/key_storage_config_linux.h" +#include "components/os_crypt/sync/os_crypt.h" +#endif namespace QtWebEngineCore { @@ -136,12 +122,17 @@ public: { // NOTE: This method may called from any thread at any time. ensureDelegate(); - m_scheduler.scheduleWork(); + m_scheduler.scheduleImmediateWork(); } - void ScheduleDelayedWork(const base::TimeTicks &delayed_work_time) override + void ScheduleDelayedWork(const Delegate::NextWorkInfo &next_work_info) override { // NOTE: This method may called from any thread at any time. + ScheduleDelayedWork(next_work_info.delayed_run_time); + } + + void ScheduleDelayedWork(const base::TimeTicks &delayed_work_time) + { ensureDelegate(); m_scheduler.scheduleDelayedWork(GetTimeIntervalMilliseconds(delayed_work_time)); } @@ -150,67 +141,24 @@ private: void ensureDelegate() { if (!m_delegate) { - auto seqMan = base::MessageLoopCurrent::GetCurrentSequenceManagerImpl(); + auto seqMan = base::CurrentThread::Get()->GetCurrentSequenceManagerImpl(); m_delegate = static_cast<base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl *>( seqMan->controller_.get()); } } - // Both Qt and Chromium keep track of the current GL context by using - // thread-local variables, and naturally they are completely unaware of each - // other. As a result, when a QOpenGLContext is made current, the previous - // gl::GLContext is not released, and vice-versa. This is fine as long as - // each thread uses exclusively either Qt or Chromium GL bindings, which is - // usually the case. - // - // The only exception is when the GL driver is considered thread-unsafe - // (QOpenGLContext::supportsThreadedOpenGL() is false), in which case we - // have to run all GL operations, including Chromium's GPU service, on the - // UI thread. Now the bindings are being mixed and both Qt and Chromium get - // quite confused regarding the current state of the surface. - // - // To get this to work we have to release the current QOpenGLContext before - // executing any tasks from Chromium's GPU service and the gl::GLContext - // afterwards. Since GPU service just posts tasks to the UI thread task - // runner, we'll have to instrument the entire UI thread message pump. - class ScopedGLContextChecker - { -#if QT_CONFIG(opengl) - public: - ScopedGLContextChecker() - { - if (!m_enabled) - return; - - if (QOpenGLContext *context = QOpenGLContext::currentContext()) - context->doneCurrent(); - } - - ~ScopedGLContextChecker() - { - if (!m_enabled) - return; - - if (gl::GLContext *context = gl::GLContext::GetCurrent()) - context->ReleaseCurrent(nullptr); - } - - private: - bool m_enabled = WebEngineContext::isGpuServiceOnUIThread(); -#endif // QT_CONFIG(opengl) - }; - void handleScheduledWork() { - ScopedGLContextChecker glContextChecker; - + QDeadlineTimer timer(std::chrono::milliseconds(2)); base::MessagePump::Delegate::NextWorkInfo more_work_info = m_delegate->DoWork(); + while (more_work_info.is_immediate() && !timer.hasExpired()) + more_work_info = m_delegate->DoWork(); if (more_work_info.is_immediate()) - return ScheduleWork(); + return m_scheduler.scheduleImmediateWork(); if (m_delegate->DoIdleWork()) - return ScheduleWork(); + return m_scheduler.scheduleIdleWork(); ScheduleDelayedWork(more_work_info.delayed_run_time); } @@ -219,6 +167,25 @@ private: QWebEngineMessagePumpScheduler m_scheduler; }; +#if BUILDFLAG(IS_MAC) +class FakeGeolocationSource : public device::SystemGeolocationSource +{ +public: + FakeGeolocationSource() = default; + ~FakeGeolocationSource() override = default; + + // SystemGeolocationSource implementation: + void StartWatchingPosition(bool) override {} + void StopWatchingPosition() override {} + void RegisterPermissionUpdateCallback(PermissionUpdateCallback callback) + { + callback.Run(device::LocationSystemPermissionStatus::kDenied); + } + void RegisterPositionUpdateCallback(PositionUpdateCallback callback) {} + void RequestPermission() override {} +}; +#endif // BUILDFLAG(IS_MAC) + std::unique_ptr<base::MessagePump> messagePumpFactory() { static bool madePrimaryPump = false; @@ -226,8 +193,8 @@ std::unique_ptr<base::MessagePump> messagePumpFactory() madePrimaryPump = true; return std::make_unique<MessagePumpForUIQt>(); } -#if defined(OS_MACOSX) - return base::MessagePumpMac::Create(); +#if BUILDFLAG(IS_MAC) + return base::message_pump_apple::Create(); #else return std::make_unique<base::MessagePumpForUI>(); #endif @@ -238,27 +205,60 @@ int BrowserMainPartsQt::PreEarlyInitialization() #if BUILDFLAG(ENABLE_EXTENSIONS) content::ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeScheme(extensions::kExtensionScheme); #endif //ENABLE_EXTENSIONS - return 0; + return content::RESULT_CODE_NORMAL_EXIT; } -void BrowserMainPartsQt::PreMainMessageLoopStart() +void BrowserMainPartsQt::PreCreateMainMessageLoop() { +#if BUILDFLAG(IS_MAC) + m_geolocationManager = std::make_unique<device::GeolocationManager>(std::make_unique<FakeGeolocationSource>()); +#endif +} + +void BrowserMainPartsQt::PostCreateMainMessageLoop() +{ + if (!device_event_log::IsInitialized()) + device_event_log::Initialize(0 /* default max entries */); + +#if defined(Q_OS_LINUX) + auto config = std::make_unique<os_crypt::Config>(); + config->product_name = "Qt WebEngine"; + config->should_use_preference = false; + config->user_data_path = toFilePath(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + OSCrypt::SetConfig(std::move(config)); +#endif } -void BrowserMainPartsQt::PreMainMessageLoopRun() +int BrowserMainPartsQt::PreMainMessageLoopRun() { + ui::SelectFileDialog::SetFactory(std::make_unique<SelectFileDialogFactoryQt>()); + #if BUILDFLAG(ENABLE_EXTENSIONS) extensions::ExtensionsClient::Set(new extensions::ExtensionsClientQt()); extensions::ExtensionsBrowserClient::Set(new extensions::ExtensionsBrowserClientQt()); extensions::ExtensionSystemFactoryQt::GetInstance(); -#endif //ENABLE_EXTENSIONS + +#if BUILDFLAG(ENABLE_PLUGINS) + content::PluginService *plugin_service = content::PluginService::GetInstance(); + plugin_service->SetFilter(extensions::PluginServiceFilterQt::GetInstance()); +#endif // BUILDFLAG(ENABLE_PLUGINS) +#endif // BUILDFLAG(ENABLE_EXTENSIONS) + + if (base::FeatureList::IsEnabled(features::kWebUsb)) { + m_webUsbDetector.reset(new WebUsbDetectorQt()); + content::GetUIThreadTaskRunner({ base::TaskPriority::BEST_EFFORT }) + ->PostTask(FROM_HERE, + base::BindOnce(&WebUsbDetectorQt::Initialize, + base::Unretained(m_webUsbDetector.get()))); + } + return content::RESULT_CODE_NORMAL_EXIT; } void BrowserMainPartsQt::PostMainMessageLoopRun() { - performance_manager_registry_->TearDown(); - performance_manager_registry_.reset(); - performance_manager::DestroyPerformanceManager(std::move(performance_manager_)); + performance_manager_lifetime_.reset(); + + m_webUsbDetector.reset(); // The ProfileQt's destructor uses the MessageLoop so it should be deleted // right before the RenderProcessHostImpl's destructor destroys it. @@ -267,19 +267,19 @@ void BrowserMainPartsQt::PostMainMessageLoopRun() int BrowserMainPartsQt::PreCreateThreads() { - base::ThreadRestrictions::SetIOAllowed(true); - -#if defined(OS_MACOSX) +#if BUILDFLAG(IS_MAC) ui::InitIdleMonitor(); #endif // Like ChromeBrowserMainExtraPartsViews::PreCreateThreads does. #if defined(Q_OS_WIN) display::Screen::SetScreenInstance(new display::win::ScreenWin); +#elif defined(Q_OS_DARWIN) + display::Screen::SetScreenInstance(display::CreateNativeScreen()); #else display::Screen::SetScreenInstance(new DesktopScreenQt); #endif - return 0; + return content::RESULT_CODE_NORMAL_EXIT; } static void CreatePoliciesAndDecorators(performance_manager::Graph *graph) @@ -289,10 +289,17 @@ static void CreatePoliciesAndDecorators(performance_manager::Graph *graph) void BrowserMainPartsQt::PostCreateThreads() { - performance_manager_ = - performance_manager::CreatePerformanceManagerWithDefaultDecorators( - base::BindOnce(&QtWebEngineCore::CreatePoliciesAndDecorators)); - performance_manager_registry_ = performance_manager::PerformanceManagerRegistry::Create(); + performance_manager_lifetime_ = + std::make_unique<performance_manager::PerformanceManagerLifetime>( + performance_manager::GraphFeatures::WithDefault(), + base::BindOnce(&QtWebEngineCore::CreatePoliciesAndDecorators)); } +#if BUILDFLAG(IS_MAC) +device::GeolocationManager *BrowserMainPartsQt::GetGeolocationManager() +{ + return m_geolocationManager.get(); +} +#endif + } // namespace QtWebEngineCore |