summaryrefslogtreecommitdiffstats
path: root/src/core/common
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/common
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/common')
-rw-r--r--src/core/common/extensions/api/qtwebengine_extensions_features.gni25
-rw-r--r--src/core/common/extensions/extensions_api_provider_qt.cpp105
-rw-r--r--src/core/common/extensions/extensions_api_provider_qt.h75
-rw-r--r--src/core/common/extensions/extensions_client_qt.cpp190
-rw-r--r--src/core/common/extensions/extensions_client_qt.h148
5 files changed, 543 insertions, 0 deletions
diff --git a/src/core/common/extensions/api/qtwebengine_extensions_features.gni b/src/core/common/extensions/api/qtwebengine_extensions_features.gni
new file mode 100644
index 000000000..ed7e713c6
--- /dev/null
+++ b/src/core/common/extensions/api/qtwebengine_extensions_features.gni
@@ -0,0 +1,25 @@
+import("//tools/json_schema_compiler/json_features.gni")
+
+json_features("qt_api_features") {
+ feature_type = "APIFeature"
+ method_name = "AddQtAPIFeatures"
+ sources = [
+ "//extensions/common/api/_webengine_api_features.json"
+ ]
+}
+
+json_features("qt_permission_features") {
+ feature_type = "PermissionFeature"
+ method_name = "AddQtPermissionFeatures"
+ sources = [
+ "//extensions/common/api/_permission_features.json"
+ ]
+}
+
+group("qtwebengine_extensions_features") {
+ public_deps = [
+ ":qt_api_features",
+ ":qt_permission_features",
+ "//extensions/common/api:extensions_features",
+ ]
+}
diff --git a/src/core/common/extensions/extensions_api_provider_qt.cpp b/src/core/common/extensions/extensions_api_provider_qt.cpp
new file mode 100644
index 000000000..aa746133e
--- /dev/null
+++ b/src/core/common/extensions/extensions_api_provider_qt.cpp
@@ -0,0 +1,105 @@
+/****************************************************************************
+**
+** 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_api_provider_qt.h"
+
+#include "chrome/grit/common_resources.h"
+
+#include "extensions/common/api/api_features.h"
+#include "extensions/common/api/behavior_features.h"
+#include "extensions/common/api/generated_schemas.h"
+#include "extensions/common/api/manifest_features.h"
+#include "extensions/common/api/permission_features.h"
+#include "extensions/common/common_manifest_handlers.h"
+#include "extensions/common/features/feature_provider.h"
+#include "extensions/common/features/json_feature_provider_source.h"
+#include "extensions/common/permissions/permissions_info.h"
+#include "extensions/grit/extensions_resources.h"
+
+#include "qt_api_features.h"
+//#include "qt_behavior_features.h"
+#include "qt_permission_features.h"
+//#include "qt_manifest_features.h"
+
+
+namespace extensions {
+
+ExtensionsAPIProviderQt::ExtensionsAPIProviderQt()
+{
+
+}
+
+void ExtensionsAPIProviderQt::RegisterManifestHandlers()
+{
+ RegisterCommonManifestHandlers();
+}
+
+void ExtensionsAPIProviderQt::AddAPIFeatures(FeatureProvider *provider)
+{
+ AddCoreAPIFeatures(provider);
+ AddQtAPIFeatures(provider);
+}
+
+void ExtensionsAPIProviderQt::AddAPIJSONSources(JSONFeatureProviderSource *json_source)
+{
+ json_source->LoadJSON(IDR_EXTENSION_API_FEATURES);
+ json_source->LoadJSON(IDR_CHROME_EXTENSION_API_FEATURES);
+}
+
+void ExtensionsAPIProviderQt::AddPermissionFeatures(FeatureProvider *provider)
+{
+ AddQtPermissionFeatures(provider);
+}
+
+bool ExtensionsAPIProviderQt::IsAPISchemaGenerated(const std::string &name)
+{
+ return api::GeneratedSchemas::IsGenerated(name);
+}
+
+base::StringPiece ExtensionsAPIProviderQt::GetAPISchema(const std::string &name)
+{
+ return api::GeneratedSchemas::Get(name);
+}
+
+void ExtensionsAPIProviderQt::RegisterPermissions(PermissionsInfo* permissions_info)
+{
+
+}
+
+}
diff --git a/src/core/common/extensions/extensions_api_provider_qt.h b/src/core/common/extensions/extensions_api_provider_qt.h
new file mode 100644
index 000000000..8b85e5de2
--- /dev/null
+++ b/src/core/common/extensions/extensions_api_provider_qt.h
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** 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 EXTENSIONS_API_PROVIDER_QT_H
+#define EXTENSIONS_API_PROVIDER_QT_H
+
+#include "extensions/common/extensions_api_provider.h"
+
+#include "base/macros.h"
+
+namespace extensions {
+
+class ExtensionsAPIProviderQt : public ExtensionsAPIProvider
+{
+public:
+ ExtensionsAPIProviderQt();
+
+ void RegisterManifestHandlers() override;
+ void AddAPIFeatures(FeatureProvider *provider) override;
+ void AddAPIJSONSources(JSONFeatureProviderSource* json_source) override;
+ void AddPermissionFeatures(FeatureProvider* provider) override;
+
+ bool IsAPISchemaGenerated(const std::string& name) override;
+ base::StringPiece GetAPISchema(const std::string& name) override;
+
+
+ // Adds feature definitions to the given |provider| of the specified type.
+ void AddManifestFeatures(FeatureProvider* provider) override { }
+ void AddBehaviorFeatures(FeatureProvider* provider) override { }
+
+
+ // Registers permissions for any associated API features.
+ void RegisterPermissions(PermissionsInfo* permissions_info) override;
+
+DISALLOW_COPY_AND_ASSIGN(ExtensionsAPIProviderQt);
+};
+
+}
+
+#endif // EXTENSIONS_API_PROVIDER_QT_H
diff --git a/src/core/common/extensions/extensions_client_qt.cpp b/src/core/common/extensions/extensions_client_qt.cpp
new file mode 100644
index 000000000..6c6200eb0
--- /dev/null
+++ b/src/core/common/extensions/extensions_client_qt.cpp
@@ -0,0 +1,190 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+// Portions copyright 2013 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_client_qt.h"
+
+#include "extensions/common/alias.h"
+#include "extensions/common/core_extensions_api_provider.h"
+#include "extensions/common/extension_urls.h"
+
+#include "extensions/common/features/simple_feature.h"
+#include "extensions/common/permissions/permissions_info.h"
+
+#include "extensions_api_provider_qt.h"
+
+
+namespace extensions {
+
+template<class FeatureClass> SimpleFeature *CreateFeature()
+{
+ return new FeatureClass;
+}
+
+static base::LazyInstance<ExtensionsClientQt>::Leaky g_client = LAZY_INSTANCE_INITIALIZER;
+
+ExtensionsClientQt *ExtensionsClientQt::GetInstance()
+{
+ return g_client.Pointer();
+}
+
+ExtensionsClientQt::ExtensionsClientQt() : ExtensionsClient()
+{
+ AddAPIProvider(std::make_unique<CoreExtensionsAPIProvider>());
+ AddAPIProvider(std::make_unique<ExtensionsAPIProviderQt>());
+}
+
+// Initializes global state. Not done in the constructor because unit tests
+// can create additional ExtensionsClients because the utility thread runs
+// in-process.
+void ExtensionsClientQt::Initialize()
+{
+}
+
+void ExtensionsClientQt::InitializeWebStoreUrls(base::CommandLine *command_line)
+{
+}
+
+// Returns the global PermissionMessageProvider to use to provide permission
+// warning strings.
+const PermissionMessageProvider &ExtensionsClientQt::GetPermissionMessageProvider() const
+{
+ return permission_message_provider_;
+}
+
+// Returns the application name. For example, "Chromium" or "app_shell".
+const std::string ExtensionsClientQt::GetProductName()
+{
+ return "Qt WebEngine"; // return Qt WebEngine for now, consider returning the application name if possible.
+}
+
+// Takes the list of all hosts and filters out those with special
+// permission strings. Adds the regular hosts to |new_hosts|,
+// and adds any additional permissions to |permissions|.
+// TODO(sashab): Split this function in two: One to filter out ignored host
+// permissions, and one to get permissions for the given hosts.
+void ExtensionsClientQt::FilterHostPermissions(const URLPatternSet &hosts,
+ URLPatternSet *new_hosts,
+ PermissionIDSet *permissions) const
+{
+}
+
+// Replaces the scripting whitelist with |whitelist|. Used in the renderer{}
+// only used for testing in the browser process.
+void ExtensionsClientQt::SetScriptingWhitelist(const ExtensionsClient::ScriptingWhitelist &whitelist)
+{
+ scripting_whitelist_ = whitelist;
+}
+
+// Return the whitelist of extensions that can run content scripts on
+// any origin.
+const ExtensionsClient::ScriptingWhitelist &ExtensionsClientQt::GetScriptingWhitelist() const
+{
+ return scripting_whitelist_;
+}
+
+// Get the set of chrome:// hosts that |extension| can run content scripts on.
+URLPatternSet ExtensionsClientQt::GetPermittedChromeSchemeHosts(const Extension *extension,
+ const APIPermissionSet &api_permissions) const
+{
+ return URLPatternSet();
+}
+
+// Returns false if content scripts are forbidden from running on |url|.
+bool ExtensionsClientQt::IsScriptableURL(const GURL &url, std::string *error) const
+{
+ return true;
+}
+
+// Determines if certain fatal extensions errors should be surpressed
+// (i.e., only logged) or allowed (i.e., logged before crashing).
+bool ExtensionsClientQt::ShouldSuppressFatalErrors() const
+{
+ return true;
+}
+
+// Records that a fatal error was caught and suppressed. It is expected that
+// embedders will only do so if ShouldSuppressFatalErrors at some point
+// returned true.
+void ExtensionsClientQt::RecordDidSuppressFatalError()
+{
+}
+
+// Returns the base webstore URL prefix.
+const GURL &ExtensionsClientQt::GetWebstoreBaseURL() const
+{
+ if (base_url_.is_empty())
+ base_url_ = GURL(extension_urls::kChromeWebstoreBaseURL);
+ return base_url_;
+}
+
+// Returns the URL to use for update manifest queries.
+const GURL &ExtensionsClientQt::GetWebstoreUpdateURL() const
+{
+ if (update_url_.is_empty())
+ update_url_ = GURL(extension_urls::GetWebstoreUpdateUrl());
+ return update_url_;
+}
+
+// Returns a flag indicating whether or not a given URL is a valid
+// extension blacklist URL.
+bool ExtensionsClientQt::IsBlacklistUpdateURL(const GURL &url) const
+{
+ return true;
+}
+
+// Returns the set of file paths corresponding to any images within an
+// extension's contents that may be displayed directly within the browser UI
+// or WebUI, such as icons or theme images. This set of paths is used by the
+// extension unpacker to determine which assets should be transcoded safely
+// within the utility sandbox.
+//
+// The default implementation returns the images used as icons for the
+// extension itself, so implementors of ExtensionsClient overriding this may
+// want to call the base class version and then add additional paths to that
+// result.
+std::set<base::FilePath> ExtensionsClientQt::GetBrowserImagePaths(const Extension *extension)
+{
+ return ExtensionsClient::GetBrowserImagePaths(extension);
+}
+
+} // namespace extensions
diff --git a/src/core/common/extensions/extensions_client_qt.h b/src/core/common/extensions/extensions_client_qt.h
new file mode 100644
index 000000000..657487277
--- /dev/null
+++ b/src/core/common/extensions/extensions_client_qt.h
@@ -0,0 +1,148 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+// Portions copyright 2013 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 EXTENSIONS_CLIENT_QT_H
+#define EXTENSIONS_CLIENT_QT_H
+
+#include "extensions/common/extensions_client.h"
+
+#include "base/compiler_specific.h"
+#include "base/lazy_instance.h"
+#include "base/macros.h"
+#include "chrome/common/extensions/permissions/chrome_permission_message_provider.h"
+#include "extensions/common/features/feature_provider.h"
+#include "extensions/common/features/json_feature_provider_source.h"
+#include "extensions/common/permissions/extensions_api_permissions.h"
+#include "url/gurl.h"
+
+namespace extensions {
+
+// Sets up global state for the extensions system. Should be Set() once in each
+// process. This should be implemented by the client of the extensions system.
+class ExtensionsClientQt : public ExtensionsClient
+{
+public:
+ ExtensionsClientQt();
+ virtual ~ExtensionsClientQt() {}
+
+ // Initializes global state. Not done in the constructor because unit tests
+ // can create additional ExtensionsClients because the utility thread runs
+ // in-process.
+ void Initialize() override;
+ void InitializeWebStoreUrls(base::CommandLine *command_line) override;
+
+ // Returns the global PermissionMessageProvider to use to provide permission
+ // warning strings.
+ const PermissionMessageProvider &GetPermissionMessageProvider() const override;
+
+ // Returns the application name. For example, "Chromium" or "app_shell".
+ const std::string GetProductName() override;
+
+ // Takes the list of all hosts and filters out those with special
+ // permission strings. Adds the regular hosts to |new_hosts|,
+ // and adds any additional permissions to |permissions|.
+ // TODO(sashab): Split this function in two: One to filter out ignored host
+ // permissions, and one to get permissions for the given hosts.
+ void FilterHostPermissions(const URLPatternSet &hosts,
+ URLPatternSet *new_hosts,
+ PermissionIDSet *permissions) const override;
+
+ // Replaces the scripting whitelist with |whitelist|. Used in the renderer;
+ // only used for testing in the browser process.
+ void SetScriptingWhitelist(const ScriptingWhitelist &whitelist) override;
+
+ // Return the whitelist of extensions that can run content scripts on
+ // any origin.
+ const ScriptingWhitelist &GetScriptingWhitelist() const override;
+
+ // Get the set of chrome:// hosts that |extension| can run content scripts on.
+ URLPatternSet GetPermittedChromeSchemeHosts(const Extension *extension,
+ const APIPermissionSet &api_permissions) const override;
+
+ // Returns false if content scripts are forbidden from running on |url|.
+ bool IsScriptableURL(const GURL &url, std::string *error) const override;
+
+ // Determines if certain fatal extensions errors should be surpressed
+ // (i.e., only logged) or allowed (i.e., logged before crashing).
+ bool ShouldSuppressFatalErrors() const override;
+
+ // Records that a fatal error was caught and suppressed. It is expected that
+ // embedders will only do so if ShouldSuppressFatalErrors at some point
+ // returned true.
+ void RecordDidSuppressFatalError() override;
+
+ // Returns the base webstore URL prefix.
+ const GURL &GetWebstoreBaseURL() const override;
+
+ // Returns the URL to use for update manifest queries.
+ const GURL &GetWebstoreUpdateURL() const override;
+
+ // Returns a flag indicating whether or not a given URL is a valid
+ // extension blacklist URL.
+ bool IsBlacklistUpdateURL(const GURL &url) const override;
+
+ // Returns the set of file paths corresponding to any images within an
+ // extension's contents that may be displayed directly within the browser UI
+ // or WebUI, such as icons or theme images. This set of paths is used by the
+ // extension unpacker to determine which assets should be transcoded safely
+ // within the utility sandbox.
+ //
+ // The default implementation returns the images used as icons for the
+ // extension itself, so implementors of ExtensionsClient overriding this may
+ // want to call the base class version and then add additional paths to that
+ // result.
+ std::set<base::FilePath> GetBrowserImagePaths(const Extension *extension) override;
+ // Get the LazyInstance for ChromeExtensionsClient.
+ static ExtensionsClientQt *GetInstance();
+
+private:
+ ScriptingWhitelist scripting_whitelist_;
+ const ChromePermissionMessageProvider permission_message_provider_;
+ mutable GURL update_url_;
+ mutable GURL base_url_;
+ DISALLOW_COPY_AND_ASSIGN(ExtensionsClientQt);
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_CLIENT_QT_H