summaryrefslogtreecommitdiffstats
path: root/src/core/renderer/extensions
diff options
context:
space:
mode:
authorMichael BrĂ¼ning <michael.bruning@qt.io>2019-01-22 18:03:00 +0100
committerMichael BrĂ¼ning <michael.bruning@qt.io>2019-02-01 10:26:00 +0000
commite3968360b4f1b7b0603b97d50244b18c92207f21 (patch)
treed326be003ca43991bacc8685a07a051f4e46c898 /src/core/renderer/extensions
parent3bff0bae7e0c660fc25c5c46dedaf9cb89563a58 (diff)
Add extension system and PDF viewer to Qt WebEngine
Adds the Chromium extensiuon system to Qt WebEngine. Currently, it only exposes internal APIs to the internal PDF viewer extension. To load a PDF, simply navigate to it. This feature can be configured via the webengine-extensions flag and is turned on by default. Needs patch in Chromium 71-based to build. Adaptations to 71-based from 69-based include: * Flag out update installation, add crx file dependency * Move PostTask over to 71-based implementation * Move extensions API providers to 71-based implementaion * Don't use custom guest view and mime handler view delegates * Adapt the URLRequestResourceBundleJob to match new interface * Move extension system initialization to end of profile constructor Change-Id: I4fa5149057291bb5847f048534c11820cd7ff58c Fixes: QTBUG-50556 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/renderer/extensions')
-rw-r--r--src/core/renderer/extensions/extensions_dispatcher_delegate_qt.cpp52
-rw-r--r--src/core/renderer/extensions/extensions_dispatcher_delegate_qt.h60
-rw-r--r--src/core/renderer/extensions/extensions_renderer_client_qt.cpp203
-rw-r--r--src/core/renderer/extensions/extensions_renderer_client_qt.h135
-rw-r--r--src/core/renderer/extensions/renderer_permissions_policy_delegate_qt.cpp66
-rw-r--r--src/core/renderer/extensions/renderer_permissions_policy_delegate_qt.h68
-rw-r--r--src/core/renderer/extensions/resource_request_policy_qt.cpp182
-rw-r--r--src/core/renderer/extensions/resource_request_policy_qt.h89
8 files changed, 855 insertions, 0 deletions
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 &params)
+{
+ 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 &params);
+ 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