From a15d3db7538b131ea445d36eddb97852c46e587c Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 24 Feb 2022 15:27:04 +0100 Subject: Refactor custom handlers Reimplement the chrome specific classes, as we use very little of them, and move everything to a subdir. Change-Id: I93873399b1bea46c08ed171b7dc75ad252f20108 Reviewed-by: Kirill Burtsev --- src/core/CMakeLists.txt | 6 +- .../qwebengineregisterprotocolhandlerrequest.cpp | 2 +- src/core/configure/BUILD.root.gn.in | 5 - src/core/content_browser_client_qt.cpp | 2 +- .../protocol_handler_registry_delegate_qt.cpp | 72 +++++++++++++ .../protocol_handler_registry_delegate_qt.h | 71 +++++++++++++ .../protocol_handler_registry_factory.cpp | 111 +++++++++++++++++++++ .../protocol_handler_registry_factory.h | 93 +++++++++++++++++ .../register_protocol_handler_request_controller.h | 62 ++++++++++++ ...er_protocol_handler_request_controller_impl.cpp | 85 ++++++++++++++++ ...ster_protocol_handler_request_controller_impl.h | 74 ++++++++++++++ .../register_protocol_handler_request_controller.h | 62 ------------ ...er_protocol_handler_request_controller_impl.cpp | 84 ---------------- ...ster_protocol_handler_request_controller_impl.h | 74 -------------- src/core/web_contents_delegate_qt.cpp | 5 +- 15 files changed, 577 insertions(+), 231 deletions(-) create mode 100644 src/core/custom_handlers/protocol_handler_registry_delegate_qt.cpp create mode 100644 src/core/custom_handlers/protocol_handler_registry_delegate_qt.h create mode 100644 src/core/custom_handlers/protocol_handler_registry_factory.cpp create mode 100644 src/core/custom_handlers/protocol_handler_registry_factory.h create mode 100644 src/core/custom_handlers/register_protocol_handler_request_controller.h create mode 100644 src/core/custom_handlers/register_protocol_handler_request_controller_impl.cpp create mode 100644 src/core/custom_handlers/register_protocol_handler_request_controller_impl.h delete mode 100644 src/core/register_protocol_handler_request_controller.h delete mode 100644 src/core/register_protocol_handler_request_controller_impl.cpp delete mode 100644 src/core/register_protocol_handler_request_controller_impl.h 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 + +#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 + +#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::get(); +} + +// static +custom_handlers::ProtocolHandlerRegistry *ProtocolHandlerRegistryFactory::GetForBrowserContext(content::BrowserContext *context) +{ + return static_cast(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()); + + // 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 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() override; + + // BrowserContextKeyedServiceFactory implementation. + KeyedService *BuildServiceInstanceFor(content::BrowserContext *profile) const override; +}; + +} // namespace QtWebEngineCore + +#endif // PROTOCOL_HANDLER_REGISTRY_FACTORY_H_ diff --git a/src/core/custom_handlers/register_protocol_handler_request_controller.h b/src/core/custom_handlers/register_protocol_handler_request_controller.h new file mode 100644 index 000000000..2f9c9fc49 --- /dev/null +++ b/src/core/custom_handlers/register_protocol_handler_request_controller.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_H +#define REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_H + +#include "request_controller.h" + +namespace QtWebEngineCore { + +class RegisterProtocolHandlerRequestController : public RequestController { +public: + RegisterProtocolHandlerRequestController(QUrl origin, QString scheme) + : RequestController(std::move(origin)) + , m_scheme(std::move(scheme)) + {} + + QString scheme() const { return m_scheme; } + +private: + QString m_scheme; +}; + +} // namespace QtWebEngineCore + +#endif // REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_H diff --git a/src/core/custom_handlers/register_protocol_handler_request_controller_impl.cpp b/src/core/custom_handlers/register_protocol_handler_request_controller_impl.cpp new file mode 100644 index 000000000..ba9bf2610 --- /dev/null +++ b/src/core/custom_handlers/register_protocol_handler_request_controller_impl.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +#include "custom_handlers/register_protocol_handler_request_controller_impl.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 { + +RegisterProtocolHandlerRequestControllerImpl::RegisterProtocolHandlerRequestControllerImpl( + content::WebContents *webContents, + content::ProtocolHandler handler) + : RegisterProtocolHandlerRequestController( + toQt(handler.url()), + toQt(handler.protocol())) + , content::WebContentsObserver(webContents) + , m_handler(handler) +{} + +RegisterProtocolHandlerRequestControllerImpl::~RegisterProtocolHandlerRequestControllerImpl() +{ + reject(); +} + +custom_handlers::ProtocolHandlerRegistry *RegisterProtocolHandlerRequestControllerImpl::protocolHandlerRegistry() +{ + content::WebContents *webContents = web_contents(); + if (!webContents) + return nullptr; + content::BrowserContext *context = webContents->GetBrowserContext(); + return ProtocolHandlerRegistryFactory::GetForBrowserContext(context); +} + +void RegisterProtocolHandlerRequestControllerImpl::accepted() +{ + if (custom_handlers::ProtocolHandlerRegistry *registry = protocolHandlerRegistry()) + registry->OnAcceptRegisterProtocolHandler(m_handler); +} + +void RegisterProtocolHandlerRequestControllerImpl::rejected() +{ + if (custom_handlers::ProtocolHandlerRegistry *registry = protocolHandlerRegistry()) + registry->OnIgnoreRegisterProtocolHandler(m_handler); +} + +} // namespace QtWebEngineCore diff --git a/src/core/custom_handlers/register_protocol_handler_request_controller_impl.h b/src/core/custom_handlers/register_protocol_handler_request_controller_impl.h new file mode 100644 index 000000000..2c3fce09e --- /dev/null +++ b/src/core/custom_handlers/register_protocol_handler_request_controller_impl.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_IMPL_H +#define REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_IMPL_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" + +namespace custom_handlers { +class ProtocolHandlerRegistry; +} + +namespace QtWebEngineCore { + +class RegisterProtocolHandlerRequestControllerImpl final : public RegisterProtocolHandlerRequestController, + private content::WebContentsObserver { +public: + RegisterProtocolHandlerRequestControllerImpl( + content::WebContents *webContents, + content::ProtocolHandler handler); + + ~RegisterProtocolHandlerRequestControllerImpl(); + +protected: + void accepted() override; + void rejected() override; + +private: + custom_handlers::ProtocolHandlerRegistry *protocolHandlerRegistry(); + content::ProtocolHandler m_handler; +}; + +} // namespace QtWebEngineCore + +#endif // REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_IMPL_H diff --git a/src/core/register_protocol_handler_request_controller.h b/src/core/register_protocol_handler_request_controller.h deleted file mode 100644 index 2f9c9fc49..000000000 --- a/src/core/register_protocol_handler_request_controller.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_H -#define REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_H - -#include "request_controller.h" - -namespace QtWebEngineCore { - -class RegisterProtocolHandlerRequestController : public RequestController { -public: - RegisterProtocolHandlerRequestController(QUrl origin, QString scheme) - : RequestController(std::move(origin)) - , m_scheme(std::move(scheme)) - {} - - QString scheme() const { return m_scheme; } - -private: - QString m_scheme; -}; - -} // namespace QtWebEngineCore - -#endif // REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_H diff --git a/src/core/register_protocol_handler_request_controller_impl.cpp b/src/core/register_protocol_handler_request_controller_impl.cpp deleted file mode 100644 index 961ca82b4..000000000 --- a/src/core/register_protocol_handler_request_controller_impl.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ -#include "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 "type_conversion.h" - -namespace QtWebEngineCore { - -RegisterProtocolHandlerRequestControllerImpl::RegisterProtocolHandlerRequestControllerImpl( - content::WebContents *webContents, - content::ProtocolHandler handler) - : RegisterProtocolHandlerRequestController( - toQt(handler.url()), - toQt(handler.protocol())) - , content::WebContentsObserver(webContents) - , m_handler(handler) -{} - -RegisterProtocolHandlerRequestControllerImpl::~RegisterProtocolHandlerRequestControllerImpl() -{ - reject(); -} - -custom_handlers::ProtocolHandlerRegistry *RegisterProtocolHandlerRequestControllerImpl::protocolHandlerRegistry() -{ - content::WebContents *webContents = web_contents(); - if (!webContents) - return nullptr; - content::BrowserContext *context = webContents->GetBrowserContext(); - return ProtocolHandlerRegistryFactory::GetForBrowserContext(context); -} - -void RegisterProtocolHandlerRequestControllerImpl::accepted() -{ - if (custom_handlers::ProtocolHandlerRegistry *registry = protocolHandlerRegistry()) - registry->OnAcceptRegisterProtocolHandler(m_handler); -} - -void RegisterProtocolHandlerRequestControllerImpl::rejected() -{ - if (custom_handlers::ProtocolHandlerRegistry *registry = protocolHandlerRegistry()) - registry->OnIgnoreRegisterProtocolHandler(m_handler); -} - -} // namespace QtWebEngineCore diff --git a/src/core/register_protocol_handler_request_controller_impl.h b/src/core/register_protocol_handler_request_controller_impl.h deleted file mode 100644 index 102c943be..000000000 --- a/src/core/register_protocol_handler_request_controller_impl.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - -#ifndef REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_IMPL_H -#define REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_IMPL_H - -#include "register_protocol_handler_request_controller.h" - -#include "content/public/browser/web_contents_observer.h" -#include "content/public/common/custom_handlers/protocol_handler.h" - -namespace custom_handlers { -class ProtocolHandlerRegistry; -} - -namespace QtWebEngineCore { - -class RegisterProtocolHandlerRequestControllerImpl final : public RegisterProtocolHandlerRequestController, - private content::WebContentsObserver { -public: - RegisterProtocolHandlerRequestControllerImpl( - content::WebContents *webContents, - content::ProtocolHandler handler); - - ~RegisterProtocolHandlerRequestControllerImpl(); - -protected: - void accepted() override; - void rejected() override; - -private: - custom_handlers::ProtocolHandlerRegistry *protocolHandlerRegistry(); - content::ProtocolHandler m_handler; -}; - -} // namespace QtWebEngineCore - -#endif // REGISTER_PROTOCOL_HANDLER_REQUEST_CONTROLLER_IMPL_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" -- cgit v1.2.3