diff options
Diffstat (limited to 'src/core/renderer')
13 files changed, 982 insertions, 12 deletions
diff --git a/src/core/renderer/content_renderer_client_qt.cpp b/src/core/renderer/content_renderer_client_qt.cpp index 5aaf7ab7b..296e78b07 100644 --- a/src/core/renderer/content_renderer_client_qt.cpp +++ b/src/core/renderer/content_renderer_client_qt.cpp @@ -40,6 +40,8 @@ #include "renderer/content_renderer_client_qt.h" #include "common/qt_messages.h" +#include "extensions/buildflags/buildflags.h" +#include "printing/buildflags/buildflags.h" #include "renderer/content_settings_observer_qt.h" #include "base/strings/string_split.h" #if QT_CONFIG(webengine_spellchecker) @@ -85,6 +87,12 @@ #if QT_CONFIG(webengine_webchannel) #include "renderer/web_channel_ipc_transport.h" #endif + +#if BUILDFLAG(ENABLE_EXTENSIONS) +#include "common/extensions/extensions_client_qt.h" +#include "extensions/extensions_renderer_client_qt.h" +#endif //ENABLE_EXTENSIONS + #include "services/service_manager/public/cpp/binder_registry.h" #include "services/service_manager/public/cpp/connector.h" @@ -106,6 +114,10 @@ static const char kHttpErrorDomain[] = "http"; ContentRendererClientQt::ContentRendererClientQt() { +#if BUILDFLAG(ENABLE_EXTENSIONS) + extensions::ExtensionsClient::Set(extensions::ExtensionsClientQt::GetInstance()); + extensions::ExtensionsRendererClient::Set(ExtensionsRendererClientQt::GetInstance()); +#endif } ContentRendererClientQt::~ContentRendererClientQt() @@ -139,6 +151,9 @@ void ContentRendererClientQt::RenderThreadStarted() blink::WebString file(blink::WebString::FromASCII("file")); blink::WebSecurityPolicy::AddOriginAccessAllowListEntry(qrc, file, blink::WebString(), true, network::mojom::CORSOriginAccessMatchPriority::kDefaultPriority); +#if BUILDFLAG(ENABLE_EXTENSIONS) + ExtensionsRendererClientQt::GetInstance()->RenderThreadStarted(); +#endif } void ContentRendererClientQt::RenderViewCreated(content::RenderView* render_view) @@ -150,11 +165,12 @@ void ContentRendererClientQt::RenderViewCreated(content::RenderView* render_view void ContentRendererClientQt::RenderFrameCreated(content::RenderFrame* render_frame) { - new QtWebEngineCore::RenderFrameObserverQt(render_frame); + QtWebEngineCore::RenderFrameObserverQt *render_frame_observer = new QtWebEngineCore::RenderFrameObserverQt(render_frame); #if QT_CONFIG(webengine_webchannel) if (render_frame->IsMainFrame()) new WebChannelIPCTransport(render_frame); #endif + UserResourceController::instance()->renderFrameCreated(render_frame); new QtWebEngineCore::ContentSettingsObserverQt(render_frame); @@ -167,17 +183,41 @@ void ContentRendererClientQt::RenderFrameCreated(content::RenderFrame* render_fr render_frame, base::WrapUnique(new PrintWebViewHelperDelegateQt())); #endif // QT_CONFIG(webengine_printing_and_pdf) +#if BUILDFLAG(ENABLE_EXTENSIONS) + auto registry = std::make_unique<service_manager::BinderRegistry>(); + ExtensionsRendererClientQt::GetInstance()->RenderFrameCreated(render_frame, render_frame_observer->registry()); +#endif } -void ContentRendererClientQt::RunScriptsAtDocumentEnd(content::RenderFrame* render_frame) +void ContentRendererClientQt::RunScriptsAtDocumentStart(content::RenderFrame *render_frame) +{ +#if BUILDFLAG(ENABLE_EXTENSIONS) + ExtensionsRendererClientQt::GetInstance()->RunScriptsAtDocumentStart(render_frame); + // |render_frame| might be dead by now. +#endif +} + +void ContentRendererClientQt::RunScriptsAtDocumentEnd(content::RenderFrame *render_frame) { // Check whether the render_frame has been created and has not been detached yet. // Otherwise the WebFrame is not available. RenderFrameObserverQt *render_frame_observer = RenderFrameObserverQt::Get(render_frame); - if (!render_frame_observer || render_frame_observer->isFrameDetached()) - return; // The frame is invisible to scripts. - UserResourceController::instance()->RunScriptsAtDocumentEnd(render_frame); + if (render_frame_observer && !render_frame_observer->isFrameDetached()) + UserResourceController::instance()->RunScriptsAtDocumentEnd(render_frame); + +#if BUILDFLAG(ENABLE_EXTENSIONS) + ExtensionsRendererClientQt::GetInstance()->RunScriptsAtDocumentEnd(render_frame); + // |render_frame| might be dead by now. +#endif +} + +void ContentRendererClientQt::RunScriptsAtDocumentIdle(content::RenderFrame *render_frame) +{ +#if BUILDFLAG(ENABLE_EXTENSIONS) + ExtensionsRendererClientQt::GetInstance()->RunScriptsAtDocumentIdle(render_frame); + // |render_frame| might be dead by now. +#endif } bool ContentRendererClientQt::HasErrorPage(int httpStatusCode) @@ -261,6 +301,29 @@ blink::WebPrescientNetworking *ContentRendererClientQt::GetPrescientNetworking() return m_prescientNetworkingDispatcher.get(); } +bool ContentRendererClientQt::OverrideCreatePlugin( + content::RenderFrame* render_frame, + const blink::WebPluginParams& params, blink::WebPlugin** plugin) +{ +#if BUILDFLAG(ENABLE_EXTENSIONS) + if (!ExtensionsRendererClientQt::GetInstance()->OverrideCreatePlugin(render_frame, params)) + return false; +#endif //ENABLE_EXTENSIONS + return content::ContentRendererClient::OverrideCreatePlugin(render_frame, params, plugin); +} + +content::BrowserPluginDelegate* ContentRendererClientQt::CreateBrowserPluginDelegate(content::RenderFrame *render_frame, + const content::WebPluginInfo &info, + const std::string &mime_type, + const GURL &original_url) +{ +#if BUILDFLAG(ENABLE_EXTENSIONS) + return ExtensionsRendererClientQt::GetInstance()->CreateBrowserPluginDelegate(render_frame, info, mime_type, original_url); +#else + return nullptr; +#endif +} + void ContentRendererClientQt::OnStart() { context()->connector()->BindConnectorRequest(std::move(m_connectorRequest)); @@ -489,6 +552,21 @@ void ContentRendererClientQt::InitSpellCheck() } #endif +void ContentRendererClientQt::WillSendRequest(blink::WebLocalFrame *frame, + ui::PageTransition transition_type, + const blink::WebURL &url, + const url::Origin *initiator_origin, + GURL *new_url, + bool *attach_same_site_cookies) +{ +#if BUILDFLAG(ENABLE_EXTENSIONS) + ExtensionsRendererClientQt::GetInstance()->WillSendRequest(frame, transition_type, url, initiator_origin, new_url, attach_same_site_cookies); + if (!new_url->is_empty()) + return; +#endif + content::ContentRendererClient::WillSendRequest(frame, transition_type, url, initiator_origin, new_url, attach_same_site_cookies); +} + void ContentRendererClientQt::CreateRendererService(service_manager::mojom::ServiceRequest service_request) { m_serviceContext = std::make_unique<service_manager::ServiceContext>( diff --git a/src/core/renderer/content_renderer_client_qt.h b/src/core/renderer/content_renderer_client_qt.h index 2a353caa6..8955a3797 100644 --- a/src/core/renderer/content_renderer_client_qt.h +++ b/src/core/renderer/content_renderer_client_qt.h @@ -96,7 +96,20 @@ public: blink::WebPrescientNetworking* GetPrescientNetworking() override; void AddSupportedKeySystems(std::vector<std::unique_ptr<media::KeySystemProperties>>* key_systems) override; - void RunScriptsAtDocumentEnd(content::RenderFrame* render_frame) override; + void RunScriptsAtDocumentStart(content::RenderFrame *render_frame) override; + void RunScriptsAtDocumentEnd(content::RenderFrame *render_frame) override; + void RunScriptsAtDocumentIdle(content::RenderFrame *render_frame) override; + bool OverrideCreatePlugin(content::RenderFrame* render_frame, + const blink::WebPluginParams& params, blink::WebPlugin** plugin) override; + content::BrowserPluginDelegate* CreateBrowserPluginDelegate(content::RenderFrame* render_frame, + const content::WebPluginInfo& info, const std::string& mime_type, const GURL& original_url) override; + + void WillSendRequest(blink::WebLocalFrame *frame, + ui::PageTransition transition_type, + const blink::WebURL &url, + const url::Origin *initiator_origin, + GURL *new_url, + bool *attach_same_site_cookies) override; void CreateRendererService(service_manager::mojom::ServiceRequest service_request) override; diff --git a/src/core/renderer/extensions/extensions_dispatcher_delegate_qt.cpp b/src/core/renderer/extensions/extensions_dispatcher_delegate_qt.cpp new file mode 100644 index 000000000..418429330 --- /dev/null +++ b/src/core/renderer/extensions/extensions_dispatcher_delegate_qt.cpp @@ -0,0 +1,52 @@ +/**************************************************************************** +** +** 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 "extensions_dispatcher_delegate_qt.h" + +namespace QtWebEngineCore { + +ExtensionsDispatcherDelegateQt::ExtensionsDispatcherDelegateQt() +{ +} + +ExtensionsDispatcherDelegateQt::~ExtensionsDispatcherDelegateQt() +{ +} + +} //namespace QtWebEngineCore diff --git a/src/core/renderer/extensions/extensions_dispatcher_delegate_qt.h b/src/core/renderer/extensions/extensions_dispatcher_delegate_qt.h new file mode 100644 index 000000000..25aa18e71 --- /dev/null +++ b/src/core/renderer/extensions/extensions_dispatcher_delegate_qt.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 EXTENSIONSDISPATCHERDELEGATEQT_H +#define EXTENSIONSDISPATCHERDELEGATEQT_H + +#include "base/macros.h" +#include "extensions/renderer/dispatcher_delegate.h" + +namespace QtWebEngineCore { + +class ExtensionsDispatcherDelegateQt : public extensions::DispatcherDelegate +{ +public: + ExtensionsDispatcherDelegateQt(); + ~ExtensionsDispatcherDelegateQt() override; + +private: + DISALLOW_COPY_AND_ASSIGN(ExtensionsDispatcherDelegateQt); +}; + +} // namespace QtWebEngineCore + +#endif // EXTENSIONSDISPATCHERDELEGATEQT_H diff --git a/src/core/renderer/extensions/extensions_renderer_client_qt.cpp b/src/core/renderer/extensions/extensions_renderer_client_qt.cpp new file mode 100644 index 000000000..c41d9e6a4 --- /dev/null +++ b/src/core/renderer/extensions/extensions_renderer_client_qt.cpp @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// based on chrome/renderer/extensions/chrome_extensions_renderer_client.cc: +// Copyright (c) 2014 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 "extensions_renderer_client_qt.h" + +#include "extensions_dispatcher_delegate_qt.h" +#include "renderer_permissions_policy_delegate_qt.h" +#include "resource_request_policy_qt.h" + +#include "base/command_line.h" +#include "base/lazy_instance.h" +#include "content/public/common/content_constants.h" +#include "content/public/common/content_switches.h" +#include "content/public/renderer/render_frame.h" +#include "content/public/renderer/render_thread.h" +#include "extensions/common/constants.h" +#include "extensions/common/switches.h" +#include "extensions/renderer/dispatcher.h" +#include "extensions/renderer/extension_frame_helper.h" +#include "extensions/renderer/extensions_render_frame_observer.h" +#include "extensions/renderer/guest_view/extensions_guest_view_container.h" +#include "extensions/renderer/guest_view/extensions_guest_view_container_dispatcher.h" +#include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.h" +#include "extensions/renderer/renderer_extension_registry.h" +#include "extensions/renderer/script_context.h" +#include "third_party/blink/public/platform/web_url.h" +#include "third_party/blink/public/web/web_plugin_params.h" + +namespace chrome { +const char kExtensionInvalidRequestURL[] = "chrome-extension://invalid/"; +const char kExtensionResourceInvalidRequestURL[] = "chrome-extension-resource://invalid/"; +} + +namespace QtWebEngineCore { + +ExtensionsRendererClientQt::ExtensionsRendererClientQt() +{ +} + +ExtensionsRendererClientQt::~ExtensionsRendererClientQt() +{ +} + +// Returns true if the current render process was launched incognito. +bool ExtensionsRendererClientQt::IsIncognitoProcess() const +{ + return false; +} + +// Returns the lowest isolated world ID available to extensions. +// Must be greater than 0. See blink::WebFrame::executeScriptInIsolatedWorld +// (third_party/WebKit/public/web/WebFrame.h) for additional context. +int ExtensionsRendererClientQt::GetLowestIsolatedWorldId() const +{ + return 257; +} + +// static +ExtensionsRendererClientQt *ExtensionsRendererClientQt::GetInstance() +{ + static base::LazyInstance<ExtensionsRendererClientQt>::Leaky client = + LAZY_INSTANCE_INITIALIZER; + return client.Pointer(); +} + +extensions::Dispatcher *ExtensionsRendererClientQt::GetDispatcher() +{ + return extension_dispatcher_.get(); +} + +void ExtensionsRendererClientQt::OnExtensionLoaded(const extensions::Extension &extension) +{ + resource_request_policy_->OnExtensionLoaded(extension); +} + +void ExtensionsRendererClientQt::OnExtensionUnloaded(const extensions::ExtensionId &extension_id) +{ + resource_request_policy_->OnExtensionUnloaded(extension_id); +} + +void ExtensionsRendererClientQt::RenderThreadStarted() +{ + content::RenderThread *thread = content::RenderThread::Get(); + // ChromeRenderViewTest::SetUp() creates its own ExtensionDispatcher and + // injects it using SetExtensionDispatcher(). Don't overwrite it. + if (!extension_dispatcher_) + extension_dispatcher_.reset(new extensions::Dispatcher(std::make_unique<ExtensionsDispatcherDelegateQt>())); + permissions_policy_delegate_.reset(new RendererPermissionsPolicyDelegateQt(extension_dispatcher_.get())); + resource_request_policy_.reset(new extensions::ResourceRequestPolicyQt(extension_dispatcher_.get())); + guest_view_container_dispatcher_.reset(new extensions::ExtensionsGuestViewContainerDispatcher()); + + thread->AddObserver(extension_dispatcher_.get()); + thread->AddObserver(guest_view_container_dispatcher_.get()); +} + +void ExtensionsRendererClientQt::RenderFrameCreated(content::RenderFrame *render_frame, + service_manager::BinderRegistry *registry) +{ + new extensions::ExtensionsRenderFrameObserver(render_frame, registry); + new extensions::ExtensionFrameHelper(render_frame, + extension_dispatcher_.get()); + extension_dispatcher_->OnRenderFrameCreated(render_frame); +} + +bool ExtensionsRendererClientQt::OverrideCreatePlugin(content::RenderFrame *render_frame, + const blink::WebPluginParams ¶ms) +{ + if (params.mime_type.Utf8() != content::kBrowserPluginMimeType) + return true; + bool guest_view_api_available = false; + return !guest_view_api_available; +} + +void ExtensionsRendererClientQt::WillSendRequest(blink::WebLocalFrame *frame, + ui::PageTransition transition_type, + const blink::WebURL &url, + const url::Origin *initiator_origin, + GURL *new_url, + bool *attach_same_site_cookies) +{ + if (url.ProtocolIs(extensions::kExtensionScheme) && + !resource_request_policy_->CanRequestResource(url, frame, transition_type)) { + *new_url = GURL(chrome::kExtensionInvalidRequestURL); + } +} + +bool ExtensionsRendererClientQt::ShouldFork(blink::WebLocalFrame *frame, + const GURL &url, + bool is_initial_navigation, + bool is_server_redirect, + bool *send_referrer) +{ + return false; // TODO: Fix this to a sensible value +} + +content::BrowserPluginDelegate *ExtensionsRendererClientQt::CreateBrowserPluginDelegate(content::RenderFrame *render_frame, + const content::WebPluginInfo &info, + const std::string &mime_type, + const GURL &original_url) +{ + if (mime_type == content::kBrowserPluginMimeType) + return new extensions::ExtensionsGuestViewContainer(render_frame); + return new extensions::MimeHandlerViewContainer(render_frame, info, mime_type, original_url); +} + +void ExtensionsRendererClientQt::RunScriptsAtDocumentStart(content::RenderFrame *render_frame) +{ + extension_dispatcher_->RunScriptsAtDocumentStart(render_frame); +} + +void ExtensionsRendererClientQt::RunScriptsAtDocumentEnd(content::RenderFrame *render_frame) +{ + extension_dispatcher_->RunScriptsAtDocumentEnd(render_frame); +} + +void ExtensionsRendererClientQt::RunScriptsAtDocumentIdle(content::RenderFrame *render_frame) +{ + extension_dispatcher_->RunScriptsAtDocumentIdle(render_frame); +} + + +} // namespace QtWebEngineCore diff --git a/src/core/renderer/extensions/extensions_renderer_client_qt.h b/src/core/renderer/extensions/extensions_renderer_client_qt.h new file mode 100644 index 000000000..2d45d255a --- /dev/null +++ b/src/core/renderer/extensions/extensions_renderer_client_qt.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** 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 EXTENSIONSRENDERERCLIENTQT_H +#define EXTENSIONSRENDERERCLIENTQT_H + +#include <memory> +#include <string> + +#include "base/macros.h" +#include "extensions/renderer/extensions_renderer_client.h" +#include "services/service_manager/public/cpp/binder_registry.h" +#include "ui/base/page_transition_types.h" + +class GURL; + +namespace blink { +class WebLocalFrame; +struct WebPluginParams; +class WebURL; +} + +namespace content { +class BrowserPluginDelegate; +class RenderFrame; +class RenderView; +struct WebPluginInfo; +} + +namespace url { +class Origin; +} + +namespace extensions { +class Dispatcher; +class ExtensionsGuestViewContainerDispatcher; +class ResourceRequestPolicyQt; +} + +namespace QtWebEngineCore { + +class ExtensionsDispatcherDelegateQt; +class RendererPermissionsPolicyDelegateQt; + +class ExtensionsRendererClientQt : public extensions::ExtensionsRendererClient +{ +public: + ExtensionsRendererClientQt(); + ~ExtensionsRendererClientQt() override; + + // extensions::ExtensionsRendererClient implementation. + bool IsIncognitoProcess() const override; + int GetLowestIsolatedWorldId() const override; + extensions::Dispatcher *GetDispatcher() override; + void OnExtensionLoaded(const extensions::Extension &extension) override; + void OnExtensionUnloaded(const extensions::ExtensionId &extension_id) override; + + // Match ContentRendererClientQt's method names... + void RenderThreadStarted(); + void RenderFrameCreated(content::RenderFrame *, service_manager::BinderRegistry *); + bool OverrideCreatePlugin(content::RenderFrame *render_frame, + const blink::WebPluginParams ¶ms); + void WillSendRequest(blink::WebLocalFrame *frame, + ui::PageTransition transition_type, + const blink::WebURL &url, + const url::Origin *initiator_origin, + GURL *new_url, + bool *attach_same_site_cookies); + + static bool ShouldFork(blink::WebLocalFrame *frame, + const GURL &url, + bool is_initial_navigation, + bool is_server_redirect, + bool *send_referrer); + static content::BrowserPluginDelegate *CreateBrowserPluginDelegate(content::RenderFrame *render_frame, + const content::WebPluginInfo &info, + const std::string &mime_type, + const GURL &original_url); + + void RunScriptsAtDocumentStart(content::RenderFrame *render_frame); + void RunScriptsAtDocumentEnd(content::RenderFrame *render_frame); + void RunScriptsAtDocumentIdle(content::RenderFrame *render_frame); + + extensions::Dispatcher *extension_dispatcher() + { return extension_dispatcher_.get(); } + + static ExtensionsRendererClientQt *GetInstance(); + +private: + std::unique_ptr<ExtensionsDispatcherDelegateQt> extension_dispatcher_delegate_; + std::unique_ptr<RendererPermissionsPolicyDelegateQt> permissions_policy_delegate_; + std::unique_ptr<extensions::Dispatcher> extension_dispatcher_; + std::unique_ptr<extensions::ExtensionsGuestViewContainerDispatcher> guest_view_container_dispatcher_; + std::unique_ptr<extensions::ResourceRequestPolicyQt> resource_request_policy_; +}; + +} // namespace QtWebEngineCore + +#endif // EXTENSIONSRENDERERCLIENTQT_H diff --git a/src/core/renderer/extensions/renderer_permissions_policy_delegate_qt.cpp b/src/core/renderer/extensions/renderer_permissions_policy_delegate_qt.cpp new file mode 100644 index 000000000..39412b76c --- /dev/null +++ b/src/core/renderer/extensions/renderer_permissions_policy_delegate_qt.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 "renderer_permissions_policy_delegate_qt.h" + +#include "extensions/common/constants.h" +#include "extensions/common/extensions_client.h" +#include "extensions/common/manifest_constants.h" +#include "extensions/common/switches.h" +#include "extensions/renderer/dispatcher.h" + +namespace QtWebEngineCore { + +RendererPermissionsPolicyDelegateQt::RendererPermissionsPolicyDelegateQt(extensions::Dispatcher *dispatcher) + : m_dispatcher(dispatcher) +{ + extensions::PermissionsData::SetPolicyDelegate(this); +} + +RendererPermissionsPolicyDelegateQt::~RendererPermissionsPolicyDelegateQt() +{ + extensions::PermissionsData::SetPolicyDelegate(nullptr); +} + +bool RendererPermissionsPolicyDelegateQt::IsRestrictedUrl(const GURL &, std::string *) +{ + return false; +} + +} // namespace QtWebEngineCore diff --git a/src/core/renderer/extensions/renderer_permissions_policy_delegate_qt.h b/src/core/renderer/extensions/renderer_permissions_policy_delegate_qt.h new file mode 100644 index 000000000..e2af47657 --- /dev/null +++ b/src/core/renderer/extensions/renderer_permissions_policy_delegate_qt.h @@ -0,0 +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$ +** +****************************************************************************/ + +#ifndef RENDERERPERMISSIONSPOLICYDELEGATEQT_H +#define RENDERERPERMISSIONSPOLICYDELEGATEQT_H + +#include "base/macros.h" +#include "extensions/common/permissions/permissions_data.h" + +namespace extensions { +class Dispatcher; +} + +namespace QtWebEngineCore { + +class RendererPermissionsPolicyDelegateQt : public extensions::PermissionsData::PolicyDelegate +{ +public: + explicit RendererPermissionsPolicyDelegateQt(extensions::Dispatcher *dispatcher); + ~RendererPermissionsPolicyDelegateQt() override; + + bool IsRestrictedUrl(const GURL &, std::string *) override; + +private: + extensions::Dispatcher *m_dispatcher; + + DISALLOW_COPY_AND_ASSIGN(RendererPermissionsPolicyDelegateQt); +}; + +} // namespace QtWebEngineCore + +#endif // RENDERERPERMISSIONSPOLICYDELEGATEQT_H diff --git a/src/core/renderer/extensions/resource_request_policy_qt.cpp b/src/core/renderer/extensions/resource_request_policy_qt.cpp new file mode 100644 index 000000000..dc5a90120 --- /dev/null +++ b/src/core/renderer/extensions/resource_request_policy_qt.cpp @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// based on chrome/renderer/extensions/resource_request_policy.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 "resource_request_policy_qt.h" + +#include "base/strings/stringprintf.h" +#include "chrome/common/url_constants.h" +#include "extensions/common/constants.h" +#include "extensions/common/manifest_handlers/web_accessible_resources_info.h" +#include "extensions/common/manifest_handlers/webview_info.h" +#include "extensions/renderer/dispatcher.h" +#include "third_party/blink/public/web/web_console_message.h" +#include "third_party/blink/public/web/web_document.h" +#include "third_party/blink/public/web/web_local_frame.h" + +namespace extensions { +ResourceRequestPolicyQt::ResourceRequestPolicyQt(Dispatcher *dispatcher) + : m_dispatcher(dispatcher) +{ +} + +void ResourceRequestPolicyQt::OnExtensionLoaded(const Extension &extension) +{ + if (WebAccessibleResourcesInfo::HasWebAccessibleResources(&extension) + || WebviewInfo::HasWebviewAccessibleResources(extension, m_dispatcher->webview_partition_id()) +// // Hosted app icons are accessible. +// // TODO(devlin): Should we incorporate this into +// // WebAccessibleResourcesInfo? +// || (extension.is_hosted_app() && !IconsInfo::GetIcons(&extension).empty()) + ) { + m_web_accessible_ids.insert(extension.id()); + } +} + +void ResourceRequestPolicyQt::OnExtensionUnloaded(const ExtensionId &extension_id) +{ + m_web_accessible_ids.erase(extension_id); +} + +// Returns true if the chrome-extension:// |resource_url| can be requested +// from |frame_url|. In some cases this decision is made based upon how +// this request was generated. Web triggered transitions are more restrictive +// than those triggered through UI. +bool ResourceRequestPolicyQt::CanRequestResource(const GURL &resource_url, + blink::WebLocalFrame *frame, + ui::PageTransition transition_type) +{ + CHECK(resource_url.SchemeIs(kExtensionScheme)); + + GURL frame_url = frame->GetDocument().Url(); + + // The page_origin may be GURL("null") for unique origins like data URLs, + // but this is ok for the checks below. We only care if it matches the + // current extension or has a devtools scheme. + GURL page_origin = url::Origin(frame->Top()->GetSecurityOrigin()).GetURL(); + + GURL extension_origin = resource_url.GetOrigin(); + + // We always allow loads in the following cases, regardless of web accessible + // resources: + + // Empty urls (needed for some edge cases when we have empty urls). + if (frame_url.is_empty()) + return true; + + // Extensions requesting their own resources (frame_url check is for images, + // page_url check is for iframes). + // TODO(devlin): We should be checking the ancestor chain, not just the + // top-level frame. Additionally, we should be checking the security origin + // of the frame, to account for about:blank subframes being scripted by an + // extension parent (though we'll still need the frame origin check for + // sandboxed frames). + if (frame_url.GetOrigin() == extension_origin || page_origin == extension_origin) + return true; + + if (!ui::PageTransitionIsWebTriggerable(transition_type)) + return true; + + // Unreachable web page error page (to allow showing the icon of the + // unreachable app on this page). + if (frame_url == content::kUnreachableWebDataURL) + return true; + + bool is_dev_tools = page_origin.SchemeIs(content::kChromeDevToolsScheme); + // Note: we check |web_accessible_ids_| (rather than first looking up the + // extension in the registry and checking that) to be more resistant against + // timing attacks. This way, determining access for an extension that isn't + // installed takes the same amount of time as determining access for an + // extension with no web accessible resources. We aren't worried about any + // extensions with web accessible resources, since those are inherently + // identifiable. + if (!is_dev_tools && !m_web_accessible_ids.count(extension_origin.host())) + return false; + + const Extension* extension = RendererExtensionRegistry::Get()->GetExtensionOrAppByURL(resource_url); + if (is_dev_tools) { + // Allow the load in the case of a non-existent extension. We'll just get a + // 404 from the browser process. + // TODO(devlin): Can this happen? Does devtools potentially make requests + // to non-existent extensions? + if (!extension) + return true; +// // Devtools (chrome-extension:// URLs are loaded into frames of devtools to +// // support the devtools extension APIs). +// if (!chrome_manifest_urls::GetDevToolsPage(extension).is_empty()) +// return true; + } + + DCHECK(extension); + + // Disallow loading of packaged resources for hosted apps. We don't allow + // hybrid hosted/packaged apps. The one exception is access to icons, since + // some extensions want to be able to do things like create their own + // launchers. + base::StringPiece resource_root_relative_path = + resource_url.path_piece().empty() ? base::StringPiece() + : resource_url.path_piece().substr(1); + if (extension->is_hosted_app() /*&& !IconsInfo::GetIcons(extension).ContainsPath(resource_root_relative_path)*/) { + LOG(ERROR) << "Denying load of " << resource_url.spec() << " from " + << "hosted app."; + return false; + } + + // Disallow loading of extension resources which are not explicitly listed + // as web or WebView accessible if the manifest version is 2 or greater. + if (!WebAccessibleResourcesInfo::IsResourceWebAccessible(extension, resource_url.path()) && + !WebviewInfo::IsResourceWebviewAccessible(extension, m_dispatcher->webview_partition_id(), resource_url.path())) + { + std::string message = base::StringPrintf( + "Denying load of %s. Resources must be listed in the " + "web_accessible_resources manifest key in order to be loaded by " + "pages outside the extension.", + resource_url.spec().c_str()); + frame->AddMessageToConsole(blink::WebConsoleMessage(blink::WebConsoleMessage::kLevelError, blink::WebString::FromUTF8(message))); + return false; + } + + return true; +} + +} // namespace extensions diff --git a/src/core/renderer/extensions/resource_request_policy_qt.h b/src/core/renderer/extensions/resource_request_policy_qt.h new file mode 100644 index 000000000..e6d4e79bb --- /dev/null +++ b/src/core/renderer/extensions/resource_request_policy_qt.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** 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 RESOURCEREQUESTPOLICYQT_H +#define RESOURCEREQUESTPOLICYQT_H + +#include <set> + +#include "base/macros.h" +#include "extensions/common/extension_id.h" +#include "ui/base/page_transition_types.h" + +class GURL; + +namespace blink { +class WebLocalFrame; +} + +namespace extensions { + +class Dispatcher; +class Extension; + +// Encapsulates the policy for when chrome-extension:// and +// chrome-extension-resource:// URLs can be requested. +class ResourceRequestPolicyQt +{ +public: + explicit ResourceRequestPolicyQt(Dispatcher *dispatcher); + + void OnExtensionLoaded(const Extension &extension); + void OnExtensionUnloaded(const ExtensionId &extension); + + // Returns true if the chrome-extension:// |resource_url| can be requested + // from |frame_url|. In some cases this decision is made based upon how + // this request was generated. Web triggered transitions are more restrictive + // than those triggered through UI. + bool CanRequestResource(const GURL &resource_url, + blink::WebLocalFrame *frame, + ui::PageTransition transition_type); + +private: + Dispatcher *m_dispatcher; + + // The set of extension IDs with any potentially web- or webview-accessible + // resources. + std::set<ExtensionId> m_web_accessible_ids; + + DISALLOW_COPY_AND_ASSIGN(ResourceRequestPolicyQt); +}; +} // namespace extensions + +#endif // RESOURCEREQUESTPOLICYQT_H diff --git a/src/core/renderer/pepper/pepper_renderer_host_factory_qt.cpp b/src/core/renderer/pepper/pepper_renderer_host_factory_qt.cpp index 4acf69043..33c744f13 100644 --- a/src/core/renderer/pepper/pepper_renderer_host_factory_qt.cpp +++ b/src/core/renderer/pepper/pepper_renderer_host_factory_qt.cpp @@ -44,9 +44,13 @@ #include "pepper_renderer_host_factory_qt.h" #include "pepper_flash_renderer_host_qt.h" +#include "qtwebenginecoreglobal_p.h" #include "base/memory/ptr_util.h" #include "chrome/renderer/pepper/pepper_flash_font_file_host.h" +#if QT_CONFIG(webengine_printing_and_pdf) +#include "components/pdf/renderer/pepper_pdf_host.h" +#endif // QT_CONFIG(webengine_printing_and_pdf) #include "content/public/renderer/renderer_ppapi_host.h" #include "ppapi/host/ppapi_host.h" #include "ppapi/host/resource_host.h" @@ -100,7 +104,7 @@ std::unique_ptr<ppapi::host::ResourceHost> PepperRendererHostFactoryQt::CreateRe // We should either rename PPB_FlashFont_File to PPB_FontFile_Private or get // rid of its use in PDF if possible. if (host_->GetPpapiHost()->permissions().HasPermission(ppapi::PERMISSION_FLASH) - || host_->GetPpapiHost()->permissions().HasPermission(ppapi::PERMISSION_PRIVATE)) { + || host_->GetPpapiHost()->permissions().HasPermission(ppapi::PERMISSION_PDF)) { switch (message.type()) { case PpapiHostMsg_FlashFontFile_Create::ID: { ppapi::proxy::SerializedFontDescription description; @@ -115,14 +119,14 @@ std::unique_ptr<ppapi::host::ResourceHost> PepperRendererHostFactoryQt::CreateRe } } - if (host_->GetPpapiHost()->permissions().HasPermission(ppapi::PERMISSION_PRIVATE)) { +#if QT_CONFIG(webengine_printing_and_pdf) + if (host_->GetPpapiHost()->permissions().HasPermission(ppapi::PERMISSION_PDF)) { switch (message.type()) { case PpapiHostMsg_PDF_Create::ID: - // Not implemented - break; + return std::make_unique<pdf::PepperPDFHost>(host_, instance, resource); } } - +#endif // QT_CONFIG(webengine_printing_and_pdf) return nullptr; } diff --git a/src/core/renderer/print_web_view_helper_delegate_qt.cpp b/src/core/renderer/print_web_view_helper_delegate_qt.cpp index e693cf096..67cdd6b66 100644 --- a/src/core/renderer/print_web_view_helper_delegate_qt.cpp +++ b/src/core/renderer/print_web_view_helper_delegate_qt.cpp @@ -41,8 +41,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE.Chromium file. -#include "print_web_view_helper_delegate_qt.h" +#include "content/public/renderer/render_frame.h" +#include "content/public/renderer/render_view.h" +#include "extensions/common/constants.h" +#include "third_party/blink/public/web/web_document.h" #include "third_party/blink/public/web/web_element.h" +#include "third_party/blink/public/web/web_local_frame.h" + +#include "print_web_view_helper_delegate_qt.h" #include "web_engine_library_info.h" namespace QtWebEngineCore { @@ -58,6 +64,15 @@ bool PrintWebViewHelperDelegateQt::CancelPrerender(content::RenderFrame *) blink::WebElement PrintWebViewHelperDelegateQt::GetPdfElement(blink::WebLocalFrame* frame) { + GURL url = frame->GetDocument().Url(); + if (url.SchemeIs(extensions::kExtensionScheme) && url.host() == extension_misc::kPdfExtensionId) + { + // <object> with id="plugin" is created in + // chrome/browser/resources/pdf/pdf.js. + auto plugin_element = frame->GetDocument().GetElementById("plugin"); + CHECK(!plugin_element.IsNull()); + return plugin_element; + } return blink::WebElement(); } diff --git a/src/core/renderer/render_frame_observer_qt.h b/src/core/renderer/render_frame_observer_qt.h index bca45bd8e..4c05422bb 100644 --- a/src/core/renderer/render_frame_observer_qt.h +++ b/src/core/renderer/render_frame_observer_qt.h @@ -44,6 +44,8 @@ #include "base/compiler_specific.h" #include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer_tracker.h" +#include "ppapi/buildflags/buildflags.h" +#include "services/service_manager/public/cpp/binder_registry.h" namespace content { class RenderFrame; @@ -67,10 +69,13 @@ public: bool isFrameDetached() const; + service_manager::BinderRegistry* registry() { return ®istry_; } + private: DISALLOW_COPY_AND_ASSIGN(RenderFrameObserverQt); bool m_isFrameDetached; + service_manager::BinderRegistry registry_; }; } // namespace QtWebEngineCore |