diff options
Diffstat (limited to 'src')
12 files changed, 360 insertions, 14 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 15152af7f..83f914856 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -98,6 +98,10 @@ foreach(arch ${archs}) content_client_qt.cpp content_client_qt.h content_main_delegate_qt.cpp content_main_delegate_qt.h content_utility_client_qt.cpp content_utility_client_qt.h + custom_handlers/protocol_handler_registry_delegate_qt.h custom_handlers/protocol_handler_registry_delegate_qt.cpp + custom_handlers/protocol_handler_registry_factory.h custom_handlers/protocol_handler_registry_factory.cpp + custom_handlers/register_protocol_handler_request_controller.h + custom_handlers/register_protocol_handler_request_controller_impl.cpp custom_handlers/register_protocol_handler_request_controller_impl.h delegated_frame_host_client_qt.cpp delegated_frame_host_client_qt.h desktop_screen_qt.cpp desktop_screen_qt.h devtools_frontend_qt.cpp devtools_frontend_qt.h @@ -146,8 +150,6 @@ foreach(arch ${archs}) quota_permission_context_qt.cpp quota_permission_context_qt.h quota_request_controller.h quota_request_controller_impl.cpp quota_request_controller_impl.h - register_protocol_handler_request_controller.h - register_protocol_handler_request_controller_impl.cpp register_protocol_handler_request_controller_impl.h render_view_context_menu_qt.cpp render_view_context_menu_qt.h render_widget_host_view_qt.cpp render_widget_host_view_qt.h render_widget_host_view_qt_delegate.h diff --git a/src/core/api/qwebengineregisterprotocolhandlerrequest.cpp b/src/core/api/qwebengineregisterprotocolhandlerrequest.cpp index bb59282ea..1d4a866a9 100644 --- a/src/core/api/qwebengineregisterprotocolhandlerrequest.cpp +++ b/src/core/api/qwebengineregisterprotocolhandlerrequest.cpp @@ -39,7 +39,7 @@ #include "qwebengineregisterprotocolhandlerrequest.h" -#include "register_protocol_handler_request_controller.h" +#include "custom_handlers/register_protocol_handler_request_controller.h" QT_BEGIN_NAMESPACE diff --git a/src/core/configure/BUILD.root.gn.in b/src/core/configure/BUILD.root.gn.in index e685eabbf..a5a27e4f0 100644 --- a/src/core/configure/BUILD.root.gn.in +++ b/src/core/configure/BUILD.root.gn.in @@ -223,11 +223,6 @@ source_set("qtwebengine_sources") { sources = [ "//chrome/browser/accessibility/accessibility_ui.cc", "//chrome/browser/accessibility/accessibility_ui.h", - "//chrome/browser/custom_handlers/chrome_protocol_handler_registry_delegate.cc", - "//chrome/browser/custom_handlers/chrome_protocol_handler_registry_delegate.h", - "//chrome/browser/custom_handlers/protocol_handler_registry_factory.h", - "//chrome/browser/custom_handlers/protocol_handler_registry_factory.cc", - "//chrome/browser/custom_handlers/protocol_handler_registry_factory.h", "//chrome/browser/devtools/devtools_eye_dropper.cc", "//chrome/browser/devtools/devtools_eye_dropper.h", "//chrome/browser/media/webrtc/desktop_media_list.h", diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 70c1ad839..bede258f3 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -41,7 +41,6 @@ #include "base/files/file_util.h" #include "base/task/post_task.h" -#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" #include "chrome/browser/tab_contents/form_interaction_tab_helper.h" #include "components/custom_handlers/protocol_handler_registry.h" #include "components/error_page/common/error.h" @@ -91,6 +90,7 @@ #include "browser_message_filter_qt.h" #include "certificate_error_controller.h" #include "client_cert_select_controller.h" +#include "custom_handlers/protocol_handler_registry_factory.h" #include "devtools_manager_delegate_qt.h" #include "login_delegate_qt.h" #include "media_capture_devices_dispatcher.h" diff --git a/src/core/custom_handlers/protocol_handler_registry_delegate_qt.cpp b/src/core/custom_handlers/protocol_handler_registry_delegate_qt.cpp new file mode 100644 index 000000000..5c1273bdf --- /dev/null +++ b/src/core/custom_handlers/protocol_handler_registry_delegate_qt.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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$ +** +****************************************************************************/ + +// based on chrome/browser/custom_handlers/chrome_protocol_handler_registry_delegate.cc: +// Copyright 2021 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 "protocol_handler_registry_delegate_qt.h" + +#include "content/public/browser/child_process_security_policy.h" +#include "url/url_util_qt.h" + +namespace QtWebEngineCore { + +using content::ChildProcessSecurityPolicy; + +ProtocolHandlerRegistryDelegateQt::ProtocolHandlerRegistryDelegateQt() = default; + +ProtocolHandlerRegistryDelegateQt::~ProtocolHandlerRegistryDelegateQt() = default; + +// ProtocolHandlerRegistry::Delegate: +void ProtocolHandlerRegistryDelegateQt::RegisterExternalHandler(const std::string &protocol) +{ + ChildProcessSecurityPolicy *policy = ChildProcessSecurityPolicy::GetInstance(); + if (!policy->IsWebSafeScheme(protocol)) { + policy->RegisterWebSafeScheme(protocol); + } +} + +bool ProtocolHandlerRegistryDelegateQt::IsExternalHandlerRegistered(const std::string &protocol) +{ + return url::IsHandledProtocol(protocol); +} + +} // namespace QtWebEngineCore diff --git a/src/core/custom_handlers/protocol_handler_registry_delegate_qt.h b/src/core/custom_handlers/protocol_handler_registry_delegate_qt.h new file mode 100644 index 000000000..9c4c7d88f --- /dev/null +++ b/src/core/custom_handlers/protocol_handler_registry_delegate_qt.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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$ +** +****************************************************************************/ + +// based on chrome/browser/custom_handlers/chrome_protocol_handler_registry_delegate.h: +// Copyright 2021 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. + +#ifndef PROTOCOL_HANDLER_REGISTRY_DELEGATE_QT_H_ +#define PROTOCOL_HANDLER_REGISTRY_DELEGATE_QT_H_ + +#include <string> + +#include "components/custom_handlers/protocol_handler_registry.h" + +namespace QtWebEngineCore { + +// This class implements the ProtocolHandlerRegistry::Delegate +// abstract class to provide an OS dependent implementation +class ProtocolHandlerRegistryDelegateQt : public custom_handlers::ProtocolHandlerRegistry::Delegate { +public: + ProtocolHandlerRegistryDelegateQt(); + ~ProtocolHandlerRegistryDelegateQt() override; + + ProtocolHandlerRegistryDelegateQt(const ProtocolHandlerRegistryDelegateQt &other) = delete; + ProtocolHandlerRegistryDelegateQt &operator=(const ProtocolHandlerRegistryDelegateQt &other) = delete; + + // ProtocolHandlerRegistry::Delegate: + void RegisterExternalHandler(const std::string &protocol) override; + bool IsExternalHandlerRegistered(const std::string &protocol) override; +}; + +} // namespace QtWebEngineCore + +#endif // PROTOCOL_HANDLER_REGISTRY_DELEGATE_QT_H_ diff --git a/src/core/custom_handlers/protocol_handler_registry_factory.cpp b/src/core/custom_handlers/protocol_handler_registry_factory.cpp new file mode 100644 index 000000000..a34facd36 --- /dev/null +++ b/src/core/custom_handlers/protocol_handler_registry_factory.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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$ +** +****************************************************************************/ + +// based on chrome/browser/custom_handlers/protocol_handler_registry_factory.cc +// 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 "protocol_handler_registry_factory.h" + +#include <memory> + +#include "base/memory/singleton.h" +#include "components/custom_handlers/protocol_handler_registry.h" +#include "components/keyed_service/content/browser_context_dependency_manager.h" + +#include "protocol_handler_registry_delegate_qt.h" + +namespace QtWebEngineCore { + +// static +ProtocolHandlerRegistryFactory *ProtocolHandlerRegistryFactory::GetInstance() +{ + return base::Singleton<ProtocolHandlerRegistryFactory>::get(); +} + +// static +custom_handlers::ProtocolHandlerRegistry *ProtocolHandlerRegistryFactory::GetForBrowserContext(content::BrowserContext *context) +{ + return static_cast<custom_handlers::ProtocolHandlerRegistry *>(GetInstance()->GetServiceForBrowserContext(context, true)); +} + +ProtocolHandlerRegistryFactory::ProtocolHandlerRegistryFactory() + : BrowserContextKeyedServiceFactory("ProtocolHandlerRegistry", BrowserContextDependencyManager::GetInstance()) {} + +ProtocolHandlerRegistryFactory::~ProtocolHandlerRegistryFactory() +{ +} + +// Will be created when initializing profile_io_data, so we might +// as well have the framework create this along with other +// PKSs to preserve orderly civic conduct :) +bool ProtocolHandlerRegistryFactory::ServiceIsCreatedWithBrowserContext() const +{ + return true; +} + +// Allows the produced registry to be used in incognito mode. +content::BrowserContext *ProtocolHandlerRegistryFactory::GetBrowserContextToUse(content::BrowserContext *context) const +{ + return context; +// return chrome::GetBrowserContextRedirectedInIncognito(context); +} + +// Do not create this service for tests. MANY tests will fail +// due to the threading requirements of this service. ALSO, +// not creating this increases test isolation (which is GOOD!) +bool ProtocolHandlerRegistryFactory::ServiceIsNULLWhileTesting() const +{ + return true; +} + +KeyedService *ProtocolHandlerRegistryFactory::BuildServiceInstanceFor(content::BrowserContext *context) const +{ + custom_handlers::ProtocolHandlerRegistry *registry = + new custom_handlers::ProtocolHandlerRegistry(context, + std::make_unique<ProtocolHandlerRegistryDelegateQt>()); + + // Must be called as a part of the creation process. + registry->InitProtocolSettings(); + + return registry; +} + +} // namespace QtWebEngineCore diff --git a/src/core/custom_handlers/protocol_handler_registry_factory.h b/src/core/custom_handlers/protocol_handler_registry_factory.h new file mode 100644 index 000000000..6042b4da4 --- /dev/null +++ b/src/core/custom_handlers/protocol_handler_registry_factory.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2022 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$ +** +****************************************************************************/ + +// based on chrome/browser/custom_handlers/protocol_handler_registry_factory.h: +// 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. + +#ifndef PROTOCOL_HANDLER_REGISTRY_FACTORY_H_ +#define PROTOCOL_HANDLER_REGISTRY_FACTORY_H_ + +#include "components/keyed_service/content/browser_context_keyed_service_factory.h" + +namespace custom_handlers { +class ProtocolHandlerRegistry; +} + +namespace base { +template <typename T> struct DefaultSingletonTraits; +} + +namespace QtWebEngineCore { + +// Singleton that owns all ProtocolHandlerRegistrys and associates them with +// Profiles. Listens for the Profile's destruction notification and cleans up +// the associated ProtocolHandlerRegistry. +class ProtocolHandlerRegistryFactory : public BrowserContextKeyedServiceFactory { +public: + // Returns the singleton instance of the ProtocolHandlerRegistryFactory. + static ProtocolHandlerRegistryFactory *GetInstance(); + + // Returns the ProtocolHandlerRegistry that provides intent registration for + // |context|. Ownership stays with this factory object. + static custom_handlers::ProtocolHandlerRegistry *GetForBrowserContext(content::BrowserContext *context); + + ProtocolHandlerRegistryFactory(const ProtocolHandlerRegistryFactory &) = delete; + ProtocolHandlerRegistryFactory &operator=(const ProtocolHandlerRegistryFactory &) = delete; + +protected: + // BrowserContextKeyedServiceFactory implementation. + bool ServiceIsCreatedWithBrowserContext() const override; + content::BrowserContext *GetBrowserContextToUse(content::BrowserContext *context) const override; + bool ServiceIsNULLWhileTesting() const override; + +private: + friend struct base::DefaultSingletonTraits<ProtocolHandlerRegistryFactory>; + + ProtocolHandlerRegistryFactory(); + ~ProtocolHandlerRegistryFactory() override; + + // BrowserContextKeyedServiceFactory implementation. + KeyedService *BuildServiceInstanceFor(content::BrowserContext *profile) const override; +}; + +} // namespace QtWebEngineCore + +#endif // PROTOCOL_HANDLER_REGISTRY_FACTORY_H_ diff --git a/src/core/register_protocol_handler_request_controller.h b/src/core/custom_handlers/register_protocol_handler_request_controller.h index 2f9c9fc49..2f9c9fc49 100644 --- a/src/core/register_protocol_handler_request_controller.h +++ b/src/core/custom_handlers/register_protocol_handler_request_controller.h diff --git a/src/core/register_protocol_handler_request_controller_impl.cpp b/src/core/custom_handlers/register_protocol_handler_request_controller_impl.cpp index 961ca82b4..ba9bf2610 100644 --- a/src/core/register_protocol_handler_request_controller_impl.cpp +++ b/src/core/custom_handlers/register_protocol_handler_request_controller_impl.cpp @@ -36,11 +36,12 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -#include "register_protocol_handler_request_controller_impl.h" +#include "custom_handlers/register_protocol_handler_request_controller_impl.h" -#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" #include "components/custom_handlers/protocol_handler_registry.h" #include "content/public/browser/web_contents.h" + +#include "custom_handlers/protocol_handler_registry_factory.h" #include "type_conversion.h" namespace QtWebEngineCore { diff --git a/src/core/register_protocol_handler_request_controller_impl.h b/src/core/custom_handlers/register_protocol_handler_request_controller_impl.h index 102c943be..2c3fce09e 100644 --- a/src/core/register_protocol_handler_request_controller_impl.h +++ b/src/core/custom_handlers/register_protocol_handler_request_controller_impl.h @@ -40,7 +40,7 @@ #ifndef REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_IMPL_H #define REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_IMPL_H -#include "register_protocol_handler_request_controller.h" +#include "custom_handlers/register_protocol_handler_request_controller.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/common/custom_handlers/protocol_handler.h" diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 97843315a..292043f78 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -46,12 +46,13 @@ #include "profile_adapter.h" #include "color_chooser_controller.h" #include "color_chooser_qt.h" +#include "custom_handlers/protocol_handler_registry_factory.h" +#include "custom_handlers/register_protocol_handler_request_controller_impl.h" #include "file_picker_controller.h" #include "media_capture_devices_dispatcher.h" #include "profile_qt.h" #include "qwebengineloadinginfo.h" #include "qwebengineregisterprotocolhandlerrequest.h" -#include "register_protocol_handler_request_controller_impl.h" #include "render_widget_host_view_qt.h" #include "type_conversion.h" #include "visited_links_manager_qt.h" @@ -62,7 +63,7 @@ #include "web_engine_error.h" #include "web_engine_settings.h" #include "certificate_error_controller.h" -#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" + #include "components/custom_handlers/protocol_handler_registry.h" #include "components/web_cache/browser/web_cache_manager.h" #include "content/browser/renderer_host/render_frame_host_impl.h" |