diff options
author | Michael BrĂ¼ning <michael.bruning@qt.io> | 2019-02-05 14:50:22 +0100 |
---|---|---|
committer | Michael BrĂ¼ning <michael.bruning@qt.io> | 2019-02-05 16:56:24 +0100 |
commit | 7aa06a1614b7ca6508d96ee2e8ef0f4c49038a6f (patch) | |
tree | 4331533a6c0fa7a843c831d66e62472a7f8a4d30 /src | |
parent | 5e92adf5f85c4ec8340d5b7e92166a5e4f8e9883 (diff) | |
parent | f17f815878d1d3f02f464347d2807555cab00a88 (diff) |
Merge remote-tracking branch 'origin/dev' into 5.13
Conflicts:
src/core/content_browser_client_qt.cpp
src/core/content_browser_client_qt.h
Change-Id: I3da791a82dab56fd7535ba1e4c0ab1d9ca74f547
Diffstat (limited to 'src')
72 files changed, 4475 insertions, 106 deletions
diff --git a/src/3rdparty b/src/3rdparty -Subproject c677809fe785df63fe97608cb5a949302b2f0c6 +Subproject 5a76a0a325a041dab3c93943c99835d3e929762 diff --git a/src/core/browser_main_parts_qt.cpp b/src/core/browser_main_parts_qt.cpp index cfe9ea8bb..e6c76fb4f 100644 --- a/src/core/browser_main_parts_qt.cpp +++ b/src/core/browser_main_parts_qt.cpp @@ -44,7 +44,16 @@ #include "base/threading/thread_restrictions.h" #include "content/public/browser/browser_main_parts.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/child_process_security_policy.h" #include "content/public/common/service_manager_connection.h" +#include "extensions/buildflags/buildflags.h" +#if BUILDFLAG(ENABLE_EXTENSIONS) +#include "extensions/common/constants.h" +#include "extensions/common/extensions_client.h" +#include "extensions/extensions_browser_client_qt.h" +#include "extensions/extension_system_factory_qt.h" +#include "common/extensions/extensions_client_qt.h" +#endif //BUILDFLAG(ENABLE_EXTENSIONS) #include "services/resource_coordinator/public/cpp/process_resource_coordinator.h" #include "services/resource_coordinator/public/cpp/resource_coordinator_features.h" #include "services/service_manager/public/cpp/connector.h" @@ -247,6 +256,9 @@ BrowserMainPartsQt::~BrowserMainPartsQt() = default; int BrowserMainPartsQt::PreEarlyInitialization() { +#if BUILDFLAG(ENABLE_EXTENSIONS) + content::ChildProcessSecurityPolicy::GetInstance()->RegisterWebSafeScheme(extensions::kExtensionScheme); +#endif //ENABLE_EXTENSIONS base::MessageLoop::InitMessagePumpForUIFactory(messagePumpFactory); return 0; } @@ -255,6 +267,15 @@ void BrowserMainPartsQt::PreMainMessageLoopStart() { } +void BrowserMainPartsQt::PreMainMessageLoopRun() +{ +#if BUILDFLAG(ENABLE_EXTENSIONS) + extensions::ExtensionsClient::Set(new extensions::ExtensionsClientQt()); + extensions::ExtensionsBrowserClient::Set(new extensions::ExtensionsBrowserClientQt()); + extensions::ExtensionSystemFactoryQt::GetInstance(); +#endif //ENABLE_EXTENSIONS +} + void BrowserMainPartsQt::PostMainMessageLoopRun() { // The ProfileQt's destructor uses the MessageLoop so it should be deleted diff --git a/src/core/browser_main_parts_qt.h b/src/core/browser_main_parts_qt.h index 04ca9483d..374220c3b 100644 --- a/src/core/browser_main_parts_qt.h +++ b/src/core/browser_main_parts_qt.h @@ -66,6 +66,7 @@ public: int PreEarlyInitialization() override; void PreMainMessageLoopStart() override; + void PreMainMessageLoopRun() override; void PostMainMessageLoopRun() override; int PreCreateThreads() override; void ServiceManagerConnectionStarted(content::ServiceManagerConnection *connection) override; 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 diff --git a/src/core/config/common.pri b/src/core/config/common.pri index be57942d2..57913423a 100644 --- a/src/core/config/common.pri +++ b/src/core/config/common.pri @@ -22,7 +22,10 @@ gn_args += \ use_custom_libcxx=false \ v8_use_external_startup_data=false \ toolkit_views=false \ - treat_warnings_as_errors=false + treat_warnings_as_errors=false \ + safe_browsing_mode=0 \ + optimize_webui=false \ + closure_compile=false !win32: gn_args += \ use_jumbo_build=true \ @@ -57,6 +60,12 @@ qtConfig(webengine-webrtc) { qtConfig(webengine-proprietary-codecs): gn_args += proprietary_codecs=true ffmpeg_branding=\"Chrome\" +qtConfig(webengine-extensions) { + gn_args += enable_extensions=true +} else { + gn_args += enable_extensions=false +} + precompile_header { gn_args += enable_precompiled_headers=true } else { diff --git a/src/core/configure.json b/src/core/configure.json index 755a525a8..f111247e4 100644 --- a/src/core/configure.json +++ b/src/core/configure.json @@ -20,6 +20,7 @@ "webengine-pulseaudio": "boolean", "webengine-spellchecker": "boolean", "webengine-native-spellchecker": "boolean", + "webengine-extensions": "boolean", "webengine-webrtc": "boolean", "webengine-geolocation": "boolean", "webengine-v8-snapshot": "boolean", @@ -36,6 +37,7 @@ "printing-and-pdf": { "type": "boolean", "name": "webengine-printing-and-pdf" }, "proprietary-codecs": { "type": "boolean", "name": "webengine-proprietary-codecs" }, "spellchecker": { "type": "boolean", "name": "webengine-spellchecker" }, + "extensions": { "type": "boolean", "name": "webengine-extensions" }, "webrtc": { "type": "boolean", "name": "webengine-webrtc" } } }, @@ -328,6 +330,10 @@ "webengine-arm-thumb" : { "label": "thumb instruction set", "type": "hasThumbFlag" + }, + "webengine-extensions-gcc-version" : { + "label": "GCC 6 or newer", + "type": "hasGcc6OrNewer" } }, @@ -548,6 +554,14 @@ "condition": "config.macos && features.webengine-spellchecker", "output": [ "publicFeature" ] }, + "webengine-extensions": { + "label": "Extensions", + "purpose": "Enables Chromium extensions within certain limits. Currently used for enabling the pdf viewer.", + "section": "WebEngine", + "condition": "features.webengine-printing-and-pdf && (tests.webengine-extensions-gcc-version || config.clang || !config.gcc)", + "autoDetect": "features.webengine-printing-and-pdf", + "output": [ "publicFeature" ] + }, "webengine-webrtc": { "label": "WebRTC", "purpose": "Provides WebRTC support.", @@ -727,6 +741,7 @@ "webengine-webchannel", "webengine-v8-snapshot", "webengine-kerberos", + "webengine-extensions", { "type": "feature", "args": "webengine-v8-snapshot-support", diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 095528244..3861d1c95 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -48,6 +48,7 @@ #if QT_CONFIG(webengine_spellchecker) #include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h" #endif +#include "components/guest_view/browser/guest_view_base.h" #include "components/network_hints/browser/network_hints_message_filter.h" #include "content/browser/renderer_host/render_view_host_delegate.h" #include "content/common/url_schemes.h" @@ -70,6 +71,7 @@ #include "content/public/common/service_names.mojom.h" #include "content/public/common/url_constants.h" #include "media/media_buildflags.h" +#include "extensions/buildflags/buildflags.h" #include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding_set.h" #include "printing/buildflags/buildflags.h" @@ -128,6 +130,16 @@ #include "location_provider_qt.h" #endif +#if BUILDFLAG(ENABLE_EXTENSIONS) +#include "extensions/extensions_browser_client_qt.h" +#include "extensions/browser/extension_message_filter.h" +#include "extensions/browser/guest_view/extensions_guest_view_message_filter.h" +#include "extensions/browser/io_thread_extension_message_filter.h" +#include "extensions/common/constants.h" +#include "common/extensions/extensions_client_qt.h" +#include "renderer_host/resource_dispatcher_host_delegate_qt.h" +#endif + #include <QGuiApplication> #include <QLocale> #ifndef QT_NO_OPENGL @@ -252,6 +264,11 @@ void ContentBrowserClientQt::RenderProcessWillLaunch(content::RenderProcessHost* #if QT_CONFIG(webengine_printing_and_pdf) host->AddFilter(new PrintingMessageFilterQt(host->GetID())); #endif +#if BUILDFLAG(ENABLE_EXTENSIONS) + host->AddFilter(new extensions::ExtensionMessageFilter(host->GetID(), host->GetBrowserContext())); + host->AddFilter(new extensions::IOThreadExtensionMessageFilter(host->GetID(), host->GetBrowserContext())); + host->AddFilter(new extensions::ExtensionsGuestViewMessageFilter(host->GetID(), host->GetBrowserContext())); +#endif //ENABLE_EXTENSIONS service_manager::mojom::ServicePtr service; *service_request = mojo::MakeRequest(&service); @@ -266,7 +283,11 @@ void ContentBrowserClientQt::RenderProcessWillLaunch(content::RenderProcessHost* void ContentBrowserClientQt::ResourceDispatcherHostCreated() { +#if BUILDFLAG(ENABLE_EXTENSIONS) + m_resourceDispatcherHostDelegate.reset(new ResourceDispatcherHostDelegateQt); +#else m_resourceDispatcherHostDelegate.reset(new content::ResourceDispatcherHostDelegate); +#endif content::ResourceDispatcherHost::Get()->SetDelegate(m_resourceDispatcherHostDelegate.get()); } @@ -285,6 +306,10 @@ content::MediaObserver *ContentBrowserClientQt::GetMediaObserver() void ContentBrowserClientQt::OverrideWebkitPrefs(content::RenderViewHost *rvh, content::WebPreferences *web_prefs) { if (content::WebContents *webContents = rvh->GetDelegate()->GetAsWebContents()) { +#if BUILDFLAG(ENABLE_EXTENSIONS) + if (guest_view::GuestViewBase::IsGuest(webContents)) + return; +#endif // BUILDFLAG(ENABLE_EXTENSIONS) WebContentsDelegateQt* delegate = static_cast<WebContentsDelegateQt*>(webContents->GetDelegate()); if (delegate) delegate->overrideWebPreferences(webContents, web_prefs); @@ -404,6 +429,11 @@ void ContentBrowserClientQt::GetAdditionalWebUISchemes(std::vector<std::string>* additional_schemes->push_back(content::kChromeDevToolsScheme); } +void ContentBrowserClientQt::GetAdditionalViewSourceSchemes(std::vector<std::string>* additional_schemes) +{ + additional_schemes->push_back(content::kChromeDevToolsScheme); +} + #if defined(Q_OS_LINUX) void ContentBrowserClientQt::GetAdditionalMappedFilesForChildProcess(const base::CommandLine& command_line, int child_process_id, content::PosixFileDescriptorInfo* mappings) { @@ -736,4 +766,13 @@ bool ContentBrowserClientQt::ShouldIsolateErrorPage(bool in_main_frame) return false; } +bool ContentBrowserClientQt::ShouldUseProcessPerSite(content::BrowserContext* browser_context, const GURL& effective_url) +{ +#if BUILDFLAG(ENABLE_EXTENSIONS) + if (effective_url.SchemeIs(extensions::kExtensionScheme)) + return true; +#endif + return ContentBrowserClient::ShouldUseProcessPerSite(browser_context, effective_url); +} + } // namespace QtWebEngineCore diff --git a/src/core/content_browser_client_qt.h b/src/core/content_browser_client_qt.h index 471443a81..fc938f882 100644 --- a/src/core/content_browser_client_qt.h +++ b/src/core/content_browser_client_qt.h @@ -112,6 +112,8 @@ public: std::string GetApplicationLocale() override; std::string GetAcceptLangs(content::BrowserContext* context) override; void AppendExtraCommandLineSwitches(base::CommandLine* command_line, int child_process_id) override; + + void GetAdditionalViewSourceSchemes(std::vector<std::string>* additional_schemes) override; void GetAdditionalWebUISchemes(std::vector<std::string>* additional_schemes) override; void BindInterfaceRequestFromFrame(content::RenderFrameHost* render_frame_host, @@ -174,6 +176,7 @@ public: std::unique_ptr<device::LocationProvider> OverrideSystemLocationProvider() override; #endif bool ShouldIsolateErrorPage(bool in_main_frame) override; + bool ShouldUseProcessPerSite(content::BrowserContext* browser_context, const GURL& effective_url) override; #if defined(Q_OS_LINUX) void GetAdditionalMappedFilesForChildProcess(const base::CommandLine& command_line, int child_process_id, content::PosixFileDescriptorInfo* mappings) override; diff --git a/src/core/content_client_qt.cpp b/src/core/content_client_qt.cpp index 41e3f7f6c..9065174b8 100644 --- a/src/core/content_client_qt.cpp +++ b/src/core/content_client_qt.cpp @@ -84,6 +84,14 @@ const char kWidevineCdmFileName[] = #endif #endif +#if QT_CONFIG(webengine_printing_and_pdf) +#include "pdf/pdf.h" +#include "pdf/pdf_ppapi.h" +const char kPdfPluginMimeType[] = "application/x-google-chrome-pdf"; +const char kPdfPluginPath[] = "internal-pdf-viewer/"; +const char kPdfPluginSrc[] = "src"; +#endif // QT_CONFIG(webengine_printing_and_pdf) + static QString webenginePluginsPath() { // Look for plugins in /plugins/webengine or application dir. @@ -98,7 +106,6 @@ static QString webenginePluginsPath() } #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) - #if defined(Q_OS_WIN) #include <shlobj.h> static QString getLocalAppDataDir() @@ -234,10 +241,30 @@ void AddPepperFlashFromCommandLine(std::vector<content::PepperPluginInfo>* plugi plugins->push_back(CreatePepperFlashInfo(base::FilePath(flash_path), flash_version)); } +void ComputeBuiltInPlugins(std::vector<content::PepperPluginInfo>* plugins) +{ +#if QT_CONFIG(webengine_printing_and_pdf) + content::PepperPluginInfo pdf_info; + pdf_info.is_internal = true; + pdf_info.is_out_of_process = true; + pdf_info.name = "Chromium PDF Viewer"; + pdf_info.description = "Portable Document Format"; + pdf_info.path = base::FilePath::FromUTF8Unsafe(kPdfPluginPath); + content::WebPluginMimeType pdf_mime_type(kPdfPluginMimeType, "pdf", "Portable Document Format"); + pdf_info.mime_types.push_back(pdf_mime_type); + pdf_info.internal_entry_points.get_interface = chrome_pdf::PPP_GetInterface; + pdf_info.internal_entry_points.initialize_module = chrome_pdf::PPP_InitializeModule; + pdf_info.internal_entry_points.shutdown_module = chrome_pdf::PPP_ShutdownModule; + pdf_info.permissions = ppapi::PERMISSION_PRIVATE | ppapi::PERMISSION_DEV | ppapi::PERMISSION_PDF; + plugins->push_back(pdf_info); +#endif // QT_CONFIG(webengine_printing_and_pdf) +} + namespace QtWebEngineCore { void ContentClientQt::AddPepperPlugins(std::vector<content::PepperPluginInfo>* plugins) { + ComputeBuiltInPlugins(plugins); AddPepperFlashFromSystem(plugins); AddPepperFlashFromCommandLine(plugins); } @@ -319,7 +346,6 @@ static bool IsWidevineAvailable(base::FilePath *cdm_path, } #endif // defined(WIDEVINE_CDM_AVAILABLE_NOT_COMPONENT) - void ContentClientQt::AddContentDecryptionModules(std::vector<content::CdmInfo> *cdms, std::vector<media::CdmHostFilePath> *cdm_host_file_paths) { @@ -375,6 +401,11 @@ void ContentClientQt::AddContentDecryptionModules(std::vector<content::CdmInfo> } } +void ContentClientQt::AddAdditionalSchemes(Schemes* schemes) +{ + schemes->standard_schemes.push_back("chrome-extension"); +} + std::string ContentClientQt::getUserAgent() { // Mention the Chromium version we're based on to get passed stupid UA-string-based feature detection (several WebRTC demos need this) diff --git a/src/core/content_client_qt.h b/src/core/content_client_qt.h index c3feded00..bee79986c 100644 --- a/src/core/content_client_qt.h +++ b/src/core/content_client_qt.h @@ -56,6 +56,7 @@ public: #endif void AddContentDecryptionModules(std::vector<content::CdmInfo> *cdms, std::vector<media::CdmHostFilePath> *cdm_host_file_paths) override; + void AddAdditionalSchemes(Schemes* schemes) override; base::StringPiece GetDataResource(int, ui::ScaleFactor) const override; base::RefCountedMemory* GetDataResourceBytes(int resource_id) const override; diff --git a/src/core/core_chromium.pri b/src/core/core_chromium.pri index 584439840..edf6806a3 100644 --- a/src/core/core_chromium.pri +++ b/src/core/core_chromium.pri @@ -310,3 +310,39 @@ qtConfig(webengine-webchannel) { SOURCES += renderer/web_channel_ipc_transport.cpp \ renderer_host/web_channel_ipc_transport_host.cpp } + +qtConfig(webengine-extensions) { + SOURCES += \ + common/extensions/extensions_api_provider_qt.cpp \ + common/extensions/extensions_client_qt.cpp \ + extensions/component_extension_resource_manager_qt.cpp \ + extensions/extension_system_qt.cpp \ + extensions/extension_system_factory_qt.cpp \ + extensions/extension_web_contents_observer_qt.cpp \ + extensions/extensions_api_client_qt.cpp \ + extensions/extensions_browser_api_provider_qt.cpp \ + extensions/extensions_browser_client_qt.cpp \ + extensions/mime_handler_view_guest_delegate_qt.cpp \ + renderer/extensions/extensions_dispatcher_delegate_qt.cpp \ + renderer/extensions/extensions_renderer_client_qt.cpp \ + renderer/extensions/renderer_permissions_policy_delegate_qt.cpp \ + renderer/extensions/resource_request_policy_qt.cpp \ + renderer_host/resource_dispatcher_host_delegate_qt.cpp + + HEADERS += \ + common/extensions/extensions_api_provider_qt.h \ + common/extensions/extensions_client_qt.h \ + extensions/component_extension_resource_manager_qt.h \ + extensions/extension_system_qt.h \ + extensions/extension_system_factory_qt.h \ + extensions/extension_web_contents_observer_qt.h \ + extensions/extensions_api_client_qt.h \ + extensions/extensions_browser_api_provider_qt.h \ + extensions/extensions_browser_client_qt.h \ + extensions/mime_handler_view_guest_delegate_qt.h \ + renderer/extensions/extensions_dispatcher_delegate_qt.h \ + renderer/extensions/extensions_renderer_client_qt.h \ + renderer/extensions/renderer_permissions_policy_delegate_qt.h \ + renderer/extensions/resource_request_policy_qt.h \ + renderer_host/resource_dispatcher_host_delegate_qt.h +} diff --git a/src/core/core_gn_config.pri b/src/core/core_gn_config.pri index 9b0145dfc..b76cdc81a 100644 --- a/src/core/core_gn_config.pri +++ b/src/core/core_gn_config.pri @@ -1,11 +1,19 @@ +include($$QTWEBENGINE_OUT_ROOT/src/core/qtwebenginecore-config.pri) +QT_FOR_CONFIG += webenginecore webenginecore-private + CONFIG = gn_generator $$CONFIG GN_SRC_DIR = $$PWD GN_FILE = $$OUT_PWD/$$getConfigDir()/BUILD.gn GN_FIND_MOCABLES_SCRIPT = $$shell_path($$QTWEBENGINE_ROOT/tools/scripts/gn_find_mocables.py) GN_RUN_BINARY_SCRIPT = $$shell_path($$QTWEBENGINE_ROOT/tools/scripts/gn_run_binary.py) GN_IMPORTS = $$PWD/qtwebengine.gni -GN_INCLUDES = $$PWD/qtwebengine_sources.gni $$PWD/qtwebengine_resources.gni +qtConfig (webengine-extensions) { + GN_INCLUDES += $$PWD/qtwebengine_sources.gni $$PWD/qtwebengine_resources.gni $$PWD/common/extensions/api/qtwebengine_extensions_features.gni +} else { + GN_INCLUDES = $$PWD/qtwebengine_sources.gni $$PWD/qtwebengine_resources.gni +} GN_CORE_INCLUDE_DIRS = $$PWD/service GN_CREATE_PRI = true QMAKE_INTERNAL_INCLUDED_FILES = $$GN_IMPORTS $$GN_INCLUDES $$GN_FILE + diff --git a/src/core/extensions/component_extension_resource_manager_qt.cpp b/src/core/extensions/component_extension_resource_manager_qt.cpp new file mode 100644 index 000000000..d8326400e --- /dev/null +++ b/src/core/extensions/component_extension_resource_manager_qt.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** 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/browser/extensions/chrome_component_extension_resource_manager.cc: +// Copyright 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 "component_extension_resource_manager_qt.h" + +#include "base/logging.h" +#include "base/path_service.h" +#include "chrome/grit/component_extension_resources_map.h" + +namespace extensions { + +ComponentExtensionResourceManagerQt::ComponentExtensionResourceManagerQt() +{ + AddComponentResourceEntries(kComponentExtensionResources, + kComponentExtensionResourcesSize); +} + +ComponentExtensionResourceManagerQt::~ComponentExtensionResourceManagerQt() {} + +bool ComponentExtensionResourceManagerQt::IsComponentExtensionResource(const base::FilePath &extension_path, + const base::FilePath &resource_path, + int *resource_id) const +{ + base::FilePath directory_path = extension_path; + base::FilePath resources_dir; + base::FilePath relative_path; + if (!base::PathService::Get(base::DIR_QT_LIBRARY_DATA, &resources_dir) + || !resources_dir.AppendRelativePath(directory_path, &relative_path)) { + return false; + } + + relative_path = relative_path.Append(resource_path); + relative_path = relative_path.NormalizePathSeparators(); + + std::map<base::FilePath, int>::const_iterator entry = path_to_resource_id_.find(relative_path); + if (entry != path_to_resource_id_.end()) + *resource_id = entry->second; + + return entry != path_to_resource_id_.end(); +} + +void ComponentExtensionResourceManagerQt::AddComponentResourceEntries(const GritResourceMap *entries, size_t size) +{ + for (size_t i = 0; i < size; ++i) { + base::FilePath resource_path = base::FilePath().AppendASCII(entries[i].name); + resource_path = resource_path.NormalizePathSeparators(); + + DCHECK(path_to_resource_id_.find(resource_path) == path_to_resource_id_.end()); + path_to_resource_id_[resource_path] = entries[i].value; + } +} + +} // namespace extensions diff --git a/src/core/extensions/component_extension_resource_manager_qt.h b/src/core/extensions/component_extension_resource_manager_qt.h new file mode 100644 index 000000000..f12edf61e --- /dev/null +++ b/src/core/extensions/component_extension_resource_manager_qt.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// Copyright 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. + +#ifndef COMPONENT_EXTENSION_RESOURCE_MANAGER_QT_H_ +#define COMPONENT_EXTENSION_RESOURCE_MANAGER_QT_H_ + +#include <map> + +#include "base/files/file_path.h" +#include "extensions/browser/component_extension_resource_manager.h" + +struct GritResourceMap; + +namespace extensions { + +class ComponentExtensionResourceManagerQt : public ComponentExtensionResourceManager +{ +public: + ComponentExtensionResourceManagerQt(); + ~ComponentExtensionResourceManagerQt() override; + + // Overridden from ComponentExtensionResourceManager: + bool IsComponentExtensionResource(const base::FilePath &extension_path, + const base::FilePath &resource_path, + int *resource_id) const override; + +private: + void AddComponentResourceEntries(const GritResourceMap* entries, size_t size); + + // A map from a resource path to the resource ID. Used by + // IsComponentExtensionResource. + std::map<base::FilePath, int> path_to_resource_id_; + + DISALLOW_COPY_AND_ASSIGN(ComponentExtensionResourceManagerQt); +}; + +} // namespace extensions + +#endif // COMPONENT_EXTENSION_RESOURCE_MANAGER_QT_H_ diff --git a/src/core/extensions/extension_system_factory_qt.cpp b/src/core/extensions/extension_system_factory_qt.cpp new file mode 100644 index 000000000..41ba31214 --- /dev/null +++ b/src/core/extensions/extension_system_factory_qt.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// 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 "extension_system_factory_qt.h" + +#include "components/keyed_service/content/browser_context_dependency_manager.h" +#include "extensions/browser/declarative_user_script_manager_factory.h" +#include "extensions/browser/event_router_factory.h" +#include "extensions/browser/extension_prefs_factory.h" +#include "extensions/browser/extension_registry_factory.h" +#include "extensions/browser/extension_system.h" +#include "extensions/browser/extensions_browser_client.h" +#include "extensions/browser/process_manager_factory.h" +#include "extensions/browser/renderer_startup_helper.h" + +namespace extensions { + +// static +ExtensionSystem *ExtensionSystemFactoryQt::GetForBrowserContext(content::BrowserContext *context) +{ + return static_cast<ExtensionSystem *>(GetInstance()->GetServiceForBrowserContext(context, true)); +} + +// static +ExtensionSystemFactoryQt *ExtensionSystemFactoryQt::GetInstance() +{ + return base::Singleton<ExtensionSystemFactoryQt>::get(); +} + +ExtensionSystemFactoryQt::ExtensionSystemFactoryQt() + : ExtensionSystemProvider("ExtensionSystem", BrowserContextDependencyManager::GetInstance()) +{ + DCHECK(ExtensionsBrowserClient::Get()) << "ExtensionSystemFactory must be initialized after BrowserProcess"; + DependsOn(ExtensionPrefsFactory::GetInstance()); + DependsOn(ExtensionRegistryFactory::GetInstance()); +} + +ExtensionSystemFactoryQt::~ExtensionSystemFactoryQt() +{ +} + +KeyedService *ExtensionSystemFactoryQt::BuildServiceInstanceFor(content::BrowserContext *context) const +{ + return new ExtensionSystemQt(context); +} + +content::BrowserContext *ExtensionSystemFactoryQt::GetBrowserContextToUse(content::BrowserContext *context) const +{ + // Separate instance in incognito. + return context; +} + +bool ExtensionSystemFactoryQt::ServiceIsCreatedWithBrowserContext() const +{ + return true; +} + +} // namespace extensions diff --git a/src/core/extensions/extension_system_factory_qt.h b/src/core/extensions/extension_system_factory_qt.h new file mode 100644 index 000000000..6e840b6d6 --- /dev/null +++ b/src/core/extensions/extension_system_factory_qt.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef EXTENSION_SYSTEM_FACTORY_QT_H_ +#define EXTENSION_SYSTEM_FACTORY_QT_H_ + +#include "base/macros.h" +#include "base/memory/singleton.h" +#include "components/keyed_service/content/browser_context_keyed_service_factory.h" +#include "extensions/browser/extension_system_provider.h" +#include "extension_system_qt.h" + +namespace extensions { +class ExtensionSystem; + +// BrowserContextKeyedServiceFactory for ExtensionSystemImpl. +// TODO(yoz): Rename to ExtensionSystemImplFactory. +class ExtensionSystemFactoryQt : public ExtensionSystemProvider +{ +public: + // ExtensionSystem provider implementation: + ExtensionSystem *GetForBrowserContext(content::BrowserContext *context) override; + + static ExtensionSystemFactoryQt *GetInstance(); + +private: + friend struct base::DefaultSingletonTraits<ExtensionSystemFactoryQt>; + + ExtensionSystemFactoryQt(); + ~ExtensionSystemFactoryQt() override; + + // BrowserContextKeyedServiceFactory implementation: + KeyedService *BuildServiceInstanceFor(content::BrowserContext *context) const override; + content::BrowserContext *GetBrowserContextToUse(content::BrowserContext *context) const override; + bool ServiceIsCreatedWithBrowserContext() const override; + + DISALLOW_COPY_AND_ASSIGN(ExtensionSystemFactoryQt); +}; + +} // namespace extensions + +#endif // EXTENSION_SYSTEM_FACTORY_QT_H_ diff --git a/src/core/extensions/extension_system_qt.cpp b/src/core/extensions/extension_system_qt.cpp new file mode 100644 index 000000000..4ca407421 --- /dev/null +++ b/src/core/extensions/extension_system_qt.cpp @@ -0,0 +1,447 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// Copyright 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 "extension_system_qt.h" + +#include <algorithm> + +#include "base/base_paths.h" +#include "base/base_switches.h" +#include "base/bind.h" +#include "base/command_line.h" +#include "base/files/file_path.h" +#include "base/files/file_util.h" +#include "base/json/json_string_value_serializer.h" +#include "base/memory/ptr_util.h" +#include "base/memory/weak_ptr.h" +#include "base/path_service.h" +#include "base/strings/string_tokenizer.h" +#include "base/strings/utf_string_conversions.h" +#include "base/task/post_task.h" +#include "base/time/time.h" +#include "base/trace_event/trace_event.h" +#include "build/build_config.h" +#include "components/crx_file/id_util.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/notification_service.h" +#include "content/public/browser/plugin_service.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/url_data_source.h" +#include "content/public/common/webplugininfo.h" +#include "extensions/browser/content_verifier.h" +#include "extensions/browser/content_verifier_delegate.h" +#include "extensions/browser/extension_pref_store.h" +#include "extensions/browser/extension_pref_value_map.h" +#include "extensions/browser/extension_pref_value_map_factory.h" +#include "extensions/browser/extension_prefs.h" +#include "extensions/browser/extension_registry.h" +#include "extensions/browser/info_map.h" +#include "extensions/browser/notification_types.h" +#include "extensions/browser/null_app_sorting.h" +#include "extensions/browser/quota_service.h" +#include "extensions/browser/renderer_startup_helper.h" +#include "extensions/browser/runtime_data.h" +#include "extensions/browser/shared_user_script_master.h" +#include "extensions/browser/service_worker_manager.h" +#include "extensions/browser/value_store/value_store_factory_impl.h" +#include "extensions/common/constants.h" +#include "extensions/common/extension_messages.h" +#include "extensions/common/manifest_constants.h" +#include "extensions/common/manifest_handlers/mime_types_handler.h" +#include "extensions/common/manifest_url_handlers.h" +#include "ui/base/resource/resource_bundle.h" +#include "chrome/grit/component_extension_resources.h" +#include "chrome/grit/browser_resources.h" +#include "net/base/mime_util.h" + +using content::BrowserThread; + +namespace extensions { + +namespace { + +std::string GenerateId(const base::DictionaryValue *manifest, + const base::FilePath &path) +{ + std::string raw_key; + std::string id_input; + CHECK(manifest->GetString(manifest_keys::kPublicKey, &raw_key)); + CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input)); + std::string id = crx_file::id_util::GenerateId(id_input); + return id; +} + +// Implementation based on ComponentLoader::ParseManifest. +std::unique_ptr<base::DictionaryValue> ParseManifest(const std::string &manifest_contents) +{ + JSONStringValueDeserializer deserializer(manifest_contents); + std::unique_ptr<base::Value> manifest(deserializer.Deserialize(NULL, NULL)); + + if (!manifest.get() || !manifest->is_dict()) { + LOG(ERROR) << "Failed to parse extension manifest."; + return NULL; + } + // Transfer ownership to the caller. + return base::DictionaryValue::From(std::move(manifest)); +} + +} // namespace + +// Dummy Content Verifier Delegate. Added to prevent crashes. +class ContentVerifierDelegateQt + : public ContentVerifierDelegate { + public: + ~ContentVerifierDelegateQt() override {} + + // This should return what verification mode is appropriate for the given + // extension, if any. + Mode ShouldBeVerified(const Extension& extension) override { + return NONE; + } + + // Should return the public key to use for validating signatures via the two + // out parameters. + ContentVerifierKey GetPublicKey() override { + return ContentVerifierKey(); + } + // This should return a URL that can be used to fetch the + // verified_contents.json containing signatures for the given extension + // id/version pair. + GURL GetSignatureFetchUrl(const std::string& extension_id, + const base::Version& version) override { + return GURL(); + } + + // This should return the set of file paths for images used within the + // browser process. (These may get transcoded during the install process). + std::set<base::FilePath> GetBrowserImagePaths( + const extensions::Extension* extension) override { + return std::set<base::FilePath>(); + } + + // Called when the content verifier detects that a read of a file inside + // an extension did not match its expected hash. + void VerifyFailed(const std::string& extension_id, + ContentVerifyJob::FailureReason reason) override { + + } + + // Called when ExtensionSystem is shutting down. + void Shutdown() override { + + } +}; + +void ExtensionSystemQt::LoadExtension(std::string extension_id, std::unique_ptr<base::DictionaryValue> manifest, const base::FilePath &directory) +{ + int flags = Extension::REQUIRE_KEY; + std::string error; + scoped_refptr<const Extension> extension = Extension::Create( + directory, + Manifest::COMPONENT, + *manifest, + flags, + &error); + if (!extension.get()) + LOG(ERROR) << error; + + base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::IO}, + base::Bind(&InfoMap::AddExtension, + base::Unretained(info_map()), + base::RetainedRef(extension), + base::Time::Now(), + true, + false)); + extension_registry_->AddEnabled(extension.get()); + + NotifyExtensionLoaded(extension.get()); +} + +void ExtensionSystemQt::OnExtensionRegisteredWithRequestContexts(scoped_refptr<const extensions::Extension> extension) +{ + extension_registry_->AddReady(extension); + if (extension_registry_->enabled_extensions().Contains(extension->id())) + extension_registry_->TriggerOnReady(extension.get()); +} + +// Implementation based on ExtensionService::NotifyExtensionLoaded. +void ExtensionSystemQt::NotifyExtensionLoaded(const Extension *extension) +{ + // The URLRequestContexts need to be first to know that the extension + // was loaded, otherwise a race can arise where a renderer that is created + // for the extension may try to load an extension URL with an extension id + // that the request context doesn't yet know about. The profile is responsible + // for ensuring its URLRequestContexts appropriately discover the loaded + // extension. + RegisterExtensionWithRequestContexts( + extension, + base::Bind(&ExtensionSystemQt::OnExtensionRegisteredWithRequestContexts, + weak_ptr_factory_.GetWeakPtr(), + base::WrapRefCounted(extension))); + + // Tell renderers about the loaded extension. + renderer_helper_->OnExtensionLoaded(*extension); + + // Tell subsystems that use the ExtensionRegistryObserver::OnExtensionLoaded + // about the new extension. + // + // NOTE: It is important that this happen after notifying the renderers about + // the new extensions so that if we navigate to an extension URL in + // ExtensionRegistryObserver::OnExtensionLoaded the renderer is guaranteed to + // know about it. + extension_registry_->TriggerOnLoaded(extension); + + // Register plugins included with the extension. + // Implementation based on PluginManager::OnExtensionLoaded. + const MimeTypesHandler *handler = MimeTypesHandler::GetHandler(extension); + if (handler && !handler->handler_url().empty()) { + content::WebPluginInfo info; + info.type = content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN; + info.name = base::UTF8ToUTF16(extension->name()); + info.path = base::FilePath::FromUTF8Unsafe(extension->url().spec()); + for (std::set<std::string>::const_iterator mime_type = handler->mime_type_set().begin(); + mime_type != handler->mime_type_set().end(); ++mime_type) { + content::WebPluginMimeType mime_type_info; + mime_type_info.mime_type = *mime_type; + base::FilePath::StringType file_extension; + if (net::GetPreferredExtensionForMimeType(*mime_type, &file_extension)) { + mime_type_info.file_extensions.push_back( + base::FilePath(file_extension).AsUTF8Unsafe()); + } + info.mime_types.push_back(mime_type_info); + } + content::PluginService *plugin_service = + content::PluginService::GetInstance(); + plugin_service->RefreshPlugins(); + plugin_service->RegisterInternalPlugin(info, true); + } +} + +bool ExtensionSystemQt::FinishDelayedInstallationIfReady(const std::string &extension_id, bool install_immediately) +{ + // TODO mibrunin + return false; +} + +void ExtensionSystemQt::Shutdown() +{ + if (content_verifier_.get()) + content_verifier_->Shutdown(); +} + +ServiceWorkerManager *ExtensionSystemQt::service_worker_manager() +{ + return service_worker_manager_.get(); +} + +ExtensionService *ExtensionSystemQt::extension_service() +{ + return nullptr; +} + +RuntimeData *ExtensionSystemQt::runtime_data() +{ + return runtime_data_.get(); +} + +ManagementPolicy *ExtensionSystemQt::management_policy() +{ + return nullptr; +} + +SharedUserScriptMaster *ExtensionSystemQt::shared_user_script_master() +{ + return shared_user_script_master_.get(); +} + +StateStore *ExtensionSystemQt::state_store() +{ + return nullptr; +} + +StateStore *ExtensionSystemQt::rules_store() +{ + return nullptr; +} + +scoped_refptr<ValueStoreFactory> ExtensionSystemQt::store_factory() +{ + return store_factory_; +} + +InfoMap *ExtensionSystemQt::info_map() +{ + if (!info_map_.get()) + info_map_ = new InfoMap; + return info_map_.get(); +} + +QuotaService *ExtensionSystemQt::quota_service() +{ + return quota_service_.get(); +} + +AppSorting *ExtensionSystemQt::app_sorting() +{ + return app_sorting_.get(); +} + +ContentVerifier *ExtensionSystemQt::content_verifier() +{ + if (!content_verifier_.get()) { + content_verifier_ = new ContentVerifier(browser_context_, std::make_unique<ContentVerifierDelegateQt>()); + } + return content_verifier_.get(); +} + +ExtensionSystemQt::ExtensionSystemQt(content::BrowserContext *browserContext) + : browser_context_(browserContext) + , store_factory_(new ValueStoreFactoryImpl(browserContext->GetPath())) + , extension_registry_(ExtensionRegistry::Get(browserContext)) + , renderer_helper_(extensions::RendererStartupHelperFactory::GetForBrowserContext(browserContext)) + , initialized_(false) + , weak_ptr_factory_(this) +{ +} + +ExtensionSystemQt::~ExtensionSystemQt() +{ +} + +void ExtensionSystemQt::Init(bool extensions_enabled) +{ + if (initialized_) + return; + + initialized_ = true; + + service_worker_manager_.reset(new ServiceWorkerManager(browser_context_)); + runtime_data_.reset(new RuntimeData(extension_registry_)); + quota_service_.reset(new QuotaService); + app_sorting_.reset(new NullAppSorting); + + shared_user_script_master_ = + std::make_unique<SharedUserScriptMaster>(browser_context_); + + // Make the chrome://extension-icon/ resource available. + // content::URLDataSource::Add(browser_context_, new ExtensionIconSource(browser_context_)); + + if (extensions_enabled) { + // Inform the rest of the extensions system to start. + ready_.Signal(); + content::NotificationService::current()->Notify( + NOTIFICATION_EXTENSIONS_READY_DEPRECATED, + content::Source<content::BrowserContext>(browser_context_), + content::NotificationService::NoDetails()); + + std::string pdf_manifest = ui::ResourceBundle::GetSharedInstance().GetRawDataResource(IDR_PDF_MANIFEST).as_string(); + base::ReplaceFirstSubstringAfterOffset(&pdf_manifest, 0, "<NAME>", "chromium-pdf"); + + std::unique_ptr<base::DictionaryValue> pdfManifestDict = ParseManifest(pdf_manifest); + base::FilePath path; + base::PathService::Get(base::DIR_QT_LIBRARY_DATA, &path); + path = path.Append(base::FilePath(FILE_PATH_LITERAL("pdf"))); + std::string id = GenerateId(pdfManifestDict.get(), path); + LoadExtension(id, std::move(pdfManifestDict), path); + } +} + +void ExtensionSystemQt::InitForRegularProfile(bool extensions_enabled) +{ + if (initialized_) + return; // Already initialized. + // The InfoMap needs to be created before the ProcessManager. + info_map(); + + Init(extensions_enabled); +} + +void ExtensionSystemQt::InitForIncognitoProfile() +{ + NOTIMPLEMENTED(); +} + +std::unique_ptr<ExtensionSet> ExtensionSystemQt::GetDependentExtensions(const Extension *extension) +{ + return base::WrapUnique(new ExtensionSet()); +} + +#if !defined(TOOLKIT_QT) +void ExtensionSystemQt::InstallUpdate(const std::string &extension_id, + const std::string &public_key, + const base::FilePath &unpacked_dir, + bool install_immediately, + InstallUpdateCallback install_update_callback) +{ + NOTREACHED() << "Not yet implemented"; + base::DeleteFile(unpacked_dir, true /* recursive */); + std::move(install_update_callback).Run(CrxInstallError(CrxInstallErrorType::DECLINED, CrxInstallErrorDetail::DISALLOWED_BY_POLICY)); +} +#endif + +void ExtensionSystemQt::RegisterExtensionWithRequestContexts(const Extension *extension, + const base::Closure &callback) +{ + base::Time install_time = base::Time::Now(); + + bool incognito_enabled = false; + bool notifications_disabled = false; + + base::PostTaskWithTraitsAndReply( + FROM_HERE, {BrowserThread::IO}, + base::Bind(&InfoMap::AddExtension, info_map(), + base::RetainedRef(extension), install_time, incognito_enabled, + notifications_disabled), + callback); +} + +void ExtensionSystemQt::UnregisterExtensionWithRequestContexts(const std::string &extension_id, + const UnloadedExtensionReason reason) +{ + base::PostTaskWithTraits( + FROM_HERE, {BrowserThread::IO}, + base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); +} +} // namespace extensions diff --git a/src/core/extensions/extension_system_qt.h b/src/core/extensions/extension_system_qt.h new file mode 100644 index 000000000..0ebe1d044 --- /dev/null +++ b/src/core/extensions/extension_system_qt.h @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// Copyright 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. + +// Large parts of this file are based on the source code from the file +// chrome/browser/extensions/extension_system_impl.h from the Chromium sources. + +#ifndef EXTENSION_SYSTEM_QT_H +#define EXTENSION_SYSTEM_QT_H + +#include <string> + +#include "base/macros.h" +#include "base/memory/weak_ptr.h" +#include "build/build_config.h" +#include "extensions/browser/extension_system.h" +#include "extensions/common/extension_set.h" +#include "extensions/common/one_shot_event.h" + +namespace extensions { + +class ExtensionRegistry; +class InfoMap; +class RendererStartupHelper; +class ServiceWorkerManager; +class StateStoreNotificationObserver; +class ValueStoreFactory; +class ValueStoreFactoryImpl; + +// The ExtensionSystem for ProfileImpl and OffTheRecordProfileImpl. +// Implementation details: non-shared services are owned by +// ExtensionSystemImpl, a KeyedService with separate incognito +// instances. A private Shared class (also a KeyedService, +// but with a shared instance for incognito) keeps the common services. +class ExtensionSystemQt : public ExtensionSystem +{ +public: + explicit ExtensionSystemQt(content::BrowserContext *browserContext); + ~ExtensionSystemQt() override; + + // Initializes the extension system. + void Initialize(); + + // KeyedService implementation: + void Shutdown() override; + + // ExtensionSystem implementation: + void InitForRegularProfile(bool extensions_enabled) override; + void InitForIncognitoProfile() override; + ExtensionService *extension_service() override; + RuntimeData *runtime_data() override; + ManagementPolicy *management_policy() override; + ServiceWorkerManager *service_worker_manager() override; + SharedUserScriptMaster *shared_user_script_master() override; + StateStore* state_store() override; + StateStore* rules_store() override; + scoped_refptr<ValueStoreFactory> store_factory() override; + InfoMap *info_map() override; + QuotaService *quota_service() override; + AppSorting *app_sorting() override; + + void RegisterExtensionWithRequestContexts(const Extension *extension, + const base::Closure &callback) override; + + void UnregisterExtensionWithRequestContexts(const std::string &extension_id, + const UnloadedExtensionReason reason) override; + + ContentVerifier *content_verifier() override; + std::unique_ptr<ExtensionSet> GetDependentExtensions(const Extension *extension) override; + +#if !defined(TOOLKIT_QT) + void InstallUpdate(const std::string &extension_id, + const std::string &public_key, + const base::FilePath &unpacked_dir, + bool install_immediately, + InstallUpdateCallback install_update_callback) override; +#endif // TOOLKIT_QT + //friend class ExtensionSystemSharedFactory; + + bool FinishDelayedInstallationIfReady(const std::string &extension_id, bool install_immediately) override; + + void Init(bool extensions_enabled); + + const OneShotEvent &ready() const override { return ready_; } + +private: + void OnExtensionRegisteredWithRequestContexts(scoped_refptr<const extensions::Extension> extension); + + void NotifyExtensionLoaded(const Extension *extension); + void LoadExtension(std::string extension_id, std::unique_ptr<base::DictionaryValue> manifest, const base::FilePath &directory); + // The services that are shared between normal and incognito profiles. + + // Data to be accessed on the IO thread. Must outlive process_manager_. + scoped_refptr<InfoMap> info_map_; + + std::unique_ptr<ServiceWorkerManager> service_worker_manager_; + std::unique_ptr<RuntimeData> runtime_data_; + std::unique_ptr<QuotaService> quota_service_; + std::unique_ptr<AppSorting> app_sorting_; + std::unique_ptr<SharedUserScriptMaster> shared_user_script_master_; + + + // For verifying the contents of extensions read from disk. + scoped_refptr<ContentVerifier> content_verifier_; + OneShotEvent ready_; + + content::BrowserContext *browser_context_; + scoped_refptr<ValueStoreFactory> store_factory_; + ExtensionRegistry *extension_registry_; + extensions::RendererStartupHelper *renderer_helper_; + bool initialized_; + + base::WeakPtrFactory<ExtensionSystemQt> weak_ptr_factory_; + DISALLOW_COPY_AND_ASSIGN(ExtensionSystemQt); +}; + +} // namespace extensions + +#endif // EXTENSION_SYSTEM_QT_H diff --git a/src/core/extensions/extension_web_contents_observer_qt.cpp b/src/core/extensions/extension_web_contents_observer_qt.cpp new file mode 100644 index 000000000..1eb2298ca --- /dev/null +++ b/src/core/extensions/extension_web_contents_observer_qt.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// Copyright 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 "extension_web_contents_observer_qt.h" + +#include "content/public/browser/child_process_security_policy.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/render_frame_host.h" +#include "content/public/common/url_constants.h" +#include "extensions/browser/extension_registry.h" +#include "extensions/common/manifest.h" + +namespace extensions { + +ExtensionWebContentsObserverQt::ExtensionWebContentsObserverQt(content::WebContents *web_contents) + : ExtensionWebContentsObserver(web_contents) +{ +} + +ExtensionWebContentsObserverQt::~ExtensionWebContentsObserverQt() +{ +} + +// static +void ExtensionWebContentsObserverQt::CreateForWebContents(content::WebContents *web_contents) +{ + content::WebContentsUserData<ExtensionWebContentsObserverQt>::CreateForWebContents(web_contents); + + // Initialize this instance if necessary. + FromWebContents(web_contents)->Initialize(); +} + +std::string ExtensionWebContentsObserverQt::GetExtensionIdFromFrame(content::RenderFrameHost *render_frame_host) const +{ + const GURL &site = render_frame_host->GetSiteInstance()->GetSiteURL(); + if (!site.SchemeIs(kExtensionScheme)) + return std::string(); + + return site.host(); +} + +const Extension *ExtensionWebContentsObserverQt::GetExtensionFromFrame(content::RenderFrameHost *render_frame_host, bool verify_url) const +{ + std::string extension_id = GetExtensionIdFromFrame(render_frame_host); + if (extension_id.empty()) + return nullptr; + + content::BrowserContext *browser_context = + render_frame_host->GetProcess()->GetBrowserContext(); + const Extension *extension = ExtensionRegistry::Get(browser_context) + ->enabled_extensions() + .GetByID(extension_id); + if (!extension) + return nullptr; + + if (verify_url) { + const url::Origin &origin(render_frame_host->GetLastCommittedOrigin()); + // Without site isolation, this check is needed to eliminate non-extension + // schemes. With site isolation, this is still needed to exclude sandboxed + // extension frames with a unique origin. + const GURL site_url(render_frame_host->GetSiteInstance()->GetSiteURL()); + if (origin.opaque() || site_url != content::SiteInstance::GetSiteForURL(browser_context, origin.GetURL())) + return nullptr; + } + + return extension; +} + +void ExtensionWebContentsObserverQt::RenderFrameCreated(content::RenderFrameHost *render_frame_host) +{ + ExtensionWebContentsObserver::RenderFrameCreated(render_frame_host); + + const Extension *extension = GetExtensionFromFrame(render_frame_host, false); + if (!extension) + return; + + int process_id = render_frame_host->GetProcess()->GetID(); + auto *policy = content::ChildProcessSecurityPolicy::GetInstance(); + + if (extension->is_extension() && Manifest::IsComponentLocation(extension->location())) + policy->GrantRequestOrigin(process_id, url::Origin::Create(GURL(content::kChromeUIResourcesURL))); +} + +} // namespace extensions diff --git a/src/core/extensions/extension_web_contents_observer_qt.h b/src/core/extensions/extension_web_contents_observer_qt.h new file mode 100644 index 000000000..043b9d4fa --- /dev/null +++ b/src/core/extensions/extension_web_contents_observer_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$ +** +****************************************************************************/ + +// Copyright 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. + +#ifndef EXTENSION_WEB_CONTENTS_OBSERVER_QT_H_ +#define EXTENSION_WEB_CONTENTS_OBSERVER_QT_H_ + +#include "content/public/browser/web_contents_user_data.h" +#include "extensions/browser/extension_web_contents_observer.h" + +namespace extensions { + +class ExtensionWebContentsObserverQt + : public ExtensionWebContentsObserver, + public content::WebContentsUserData<ExtensionWebContentsObserverQt> +{ +public: + explicit ExtensionWebContentsObserverQt(content::WebContents *web_contents); + ~ExtensionWebContentsObserverQt() override; + + static void CreateForWebContents(content::WebContents *web_contents); + + std::string GetExtensionIdFromFrame(content::RenderFrameHost *) const; + const Extension *GetExtensionFromFrame(content::RenderFrameHost *, bool) const; + + // content::WebContentsObserver overrides. + void RenderFrameCreated(content::RenderFrameHost *render_frame_host) override; + +private: + friend class content::WebContentsUserData<ExtensionWebContentsObserverQt>; + DISALLOW_COPY_AND_ASSIGN(ExtensionWebContentsObserverQt); +}; + +} // namespace extensions + +#endif // EXTENSION_WEB_CONTENTS_OBSERVER_QT_H_ diff --git a/src/core/extensions/extensions_api_client_qt.cpp b/src/core/extensions/extensions_api_client_qt.cpp new file mode 100644 index 000000000..731b79a63 --- /dev/null +++ b/src/core/extensions/extensions_api_client_qt.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Portions copyright 2015 The Chromium Embedded Framework Authors. +// Portions copyright 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_api_client_qt.h" + +#include <memory> +//#include "base/memory/ptr_util.h" +#include "extension_web_contents_observer_qt.h" +#include "components/pdf/browser/pdf_web_contents_helper.h" +#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" +#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h" +#include "printing/print_view_manager_qt.h" + +namespace extensions { + +ExtensionsAPIClientQt::ExtensionsAPIClientQt() +{ +} + +AppViewGuestDelegate *ExtensionsAPIClientQt::CreateAppViewGuestDelegate() const +{ + // TODO(extensions): Implement to support Apps. + NOTREACHED(); + return nullptr; +} + +std::unique_ptr<guest_view::GuestViewManagerDelegate> ExtensionsAPIClientQt::CreateGuestViewManagerDelegate(content::BrowserContext *context) const +{ + return std::make_unique<guest_view::GuestViewManagerDelegate>(); +} + +std::unique_ptr<MimeHandlerViewGuestDelegate> ExtensionsAPIClientQt::CreateMimeHandlerViewGuestDelegate(MimeHandlerViewGuest *guest) const +{ + return std::make_unique<MimeHandlerViewGuestDelegate>(); +} + +void ExtensionsAPIClientQt::AttachWebContentsHelpers(content::WebContents *web_contents) const +{ + // PrefsTabHelper::CreateForWebContents(web_contents); + QtWebEngineCore::PrintViewManagerQt::CreateForWebContents(web_contents); + ExtensionWebContentsObserverQt::CreateForWebContents(web_contents); +} + +} // namespace extensions diff --git a/src/core/extensions/extensions_api_client_qt.h b/src/core/extensions/extensions_api_client_qt.h new file mode 100644 index 000000000..2fa69f539 --- /dev/null +++ b/src/core/extensions/extensions_api_client_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$ +** +****************************************************************************/ + +// Portions copyright 2015 The Chromium Embedded Framework Authors. +// Portions copyright 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. + +#ifndef EXTENSIONS_API_CLIENT_QT_H_ +#define EXTENSIONS_API_CLIENT_QT_H_ + +#include "extensions/browser/api/extensions_api_client.h" + +namespace extensions { + +class ExtensionsAPIClientQt : public ExtensionsAPIClient +{ +public: + ExtensionsAPIClientQt(); + + // ExtensionsAPIClient implementation. + AppViewGuestDelegate *CreateAppViewGuestDelegate() const override; + std::unique_ptr<guest_view::GuestViewManagerDelegate> + CreateGuestViewManagerDelegate(content::BrowserContext *context) const override; + std::unique_ptr<MimeHandlerViewGuestDelegate> + CreateMimeHandlerViewGuestDelegate(MimeHandlerViewGuest *guest) const override; + void AttachWebContentsHelpers(content::WebContents *web_contents) const override; +}; + +} // namespace extensions + +#endif // EXTENSIONS_API_CLIENT_QT_H_ diff --git a/src/core/extensions/extensions_browser_api_provider_qt.cpp b/src/core/extensions/extensions_browser_api_provider_qt.cpp new file mode 100644 index 000000000..cc1932c64 --- /dev/null +++ b/src/core/extensions/extensions_browser_api_provider_qt.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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_browser_api_provider_qt.h" + +#include "extensions/browser/api/generated_api_registration.h" + +namespace extensions { +ExtensionsBrowserAPIProviderQt::ExtensionsBrowserAPIProviderQt() = + default; +ExtensionsBrowserAPIProviderQt::~ExtensionsBrowserAPIProviderQt() = + default; + +void ExtensionsBrowserAPIProviderQt::RegisterExtensionFunctions( + ExtensionFunctionRegistry* registry) { + api::GeneratedFunctionRegistry::RegisterAll(registry); +} + + +} + diff --git a/src/core/extensions/extensions_browser_api_provider_qt.h b/src/core/extensions/extensions_browser_api_provider_qt.h new file mode 100644 index 000000000..612df3825 --- /dev/null +++ b/src/core/extensions/extensions_browser_api_provider_qt.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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/browser/extensions_browser_api_provider.h" +#include "base/macros.h" + +namespace extensions { + +class ExtensionsBrowserAPIProviderQt : public ExtensionsBrowserAPIProvider { +public: + ExtensionsBrowserAPIProviderQt(); + ~ExtensionsBrowserAPIProviderQt() override; + + void RegisterExtensionFunctions(ExtensionFunctionRegistry *registry) override; + +private: + DISALLOW_COPY_AND_ASSIGN(ExtensionsBrowserAPIProviderQt); +}; + +} + +#endif // EXTENSIONS_API_PROVIDER_QT_H diff --git a/src/core/extensions/extensions_browser_client_qt.cpp b/src/core/extensions/extensions_browser_client_qt.cpp new file mode 100644 index 000000000..8bba4128f --- /dev/null +++ b/src/core/extensions/extensions_browser_client_qt.cpp @@ -0,0 +1,499 @@ +/**************************************************************************** +** +** 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 2015 The Chromium Embedded Framework Authors. +// Portions copyright 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_browser_client_qt.h" + +#include <utility> + +#include "base/files/file_path.h" +#include "base/memory/weak_ptr.h" +#include "base/path_service.h" +#include "base/strings/stringprintf.h" +#include "base/task/post_task.h" +#include "base/memory/ref_counted_memory.h" +#include "chrome/browser/profiles/profile.h" +#include "content/public/browser/browser_context.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/render_frame_host.h" +#include "extensions/browser/api/extensions_api_client.h" +#include "extensions/browser/api/runtime/runtime_api_delegate.h" +#include "extensions/browser/app_sorting.h" +#include "extensions/browser/core_extensions_browser_api_provider.h" +#include "extensions/browser/event_router.h" +#include "extensions/browser/extension_host_delegate.h" +#include "extensions/browser/extension_protocols.h" +#include "extensions/browser/mojo/interface_registration.h" +#include "extensions/browser/url_request_util.h" +#include "extensions/common/file_util.h" +#include "net/base/completion_once_callback.h" +#include "net/base/mime_util.h" +#include "net/url_request/url_request_simple_job.h" +#include "ui/base/resource/resource_bundle.h" + +#include "component_extension_resource_manager_qt.h" +#include "extension_system_factory_qt.h" +#include "extension_web_contents_observer_qt.h" +#include "extensions_api_client_qt.h" +#include "extensions_browser_api_provider_qt.h" +#include "extensions_browser_client_qt.h" +#include "web_engine_library_info.h" + +using content::BrowserContext; +using content::BrowserThread; + +namespace { + +// helpers based on implementation in chrome_url_request_util.cc: +// Copyright 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. + +void DetermineCharset(const std::string &mime_type, + const base::RefCountedMemory *data, + std::string *out_charset) +{ + if (base::StartsWith(mime_type, "text/", base::CompareCase::INSENSITIVE_ASCII)) { + // All of our HTML files should be UTF-8 and for other resource types + // (like images), charset doesn't matter. + DCHECK(base::IsStringUTF8(base::StringPiece(reinterpret_cast<const char*>(data->front()), data->size()))); + *out_charset = "utf-8"; + } +} + +// A request for an extension resource in a Chrome .pak file. These are used +// by component extensions. +class URLRequestResourceBundleJob : public net::URLRequestSimpleJob { +public: + URLRequestResourceBundleJob(net::URLRequest *request, + net::NetworkDelegate *network_delegate, + const base::FilePath &filename, + int resource_id, + const std::string &content_security_policy, + bool send_cors_header) + : net::URLRequestSimpleJob(request, network_delegate) + , filename_(filename) + , resource_id_(resource_id) + , weak_factory_(this) + { + // Leave cache headers out of resource bundle requests. + response_info_.headers = extensions::BuildHttpHeaders(content_security_policy, send_cors_header, base::Time()); + } + int GetRefCountedData(std::string* mime_type, + std::string* charset, + scoped_refptr<base::RefCountedMemory>* data, + net::CompletionOnceCallback callback) const override + { + const ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + *data = rb.LoadDataResourceBytes(resource_id_); + + // Add the Content-Length header now that we know the resource length. + response_info_.headers->AddHeader( + base::StringPrintf("%s: %s", net::HttpRequestHeaders::kContentLength, + base::NumberToString((*data)->size()).c_str())); + + std::string* read_mime_type = new std::string; + base::PostTaskWithTraitsAndReplyWithResult( + FROM_HERE, {base::MayBlock()}, + base::BindOnce(&net::GetMimeTypeFromFile, filename_, + base::Unretained(read_mime_type)), + base::BindOnce(&URLRequestResourceBundleJob::OnMimeTypeRead, + weak_factory_.GetWeakPtr(), mime_type, charset, *data, + base::Owned(read_mime_type), std::move(callback))); + + return net::ERR_IO_PENDING; + } + + void GetResponseInfo(net::HttpResponseInfo* info) override + { + *info = response_info_; + } + +private: + ~URLRequestResourceBundleJob() override {} + + void OnMimeTypeRead(std::string *out_mime_type, + std::string *charset, + scoped_refptr<base::RefCountedMemory> data, + std::string *read_mime_type, + net::CompletionOnceCallback callback, + bool read_result) + { + response_info_.headers->AddHeader( + base::StringPrintf("%s: %s", net::HttpRequestHeaders::kContentType, + read_mime_type->c_str())); + *out_mime_type = *read_mime_type; + DetermineCharset(*read_mime_type, data.get(), charset); + int result = read_result ? net::OK : net::ERR_INVALID_URL; + std::move(callback).Run(result); + } + + // We need the filename of the resource to determine the mime type. + base::FilePath filename_; + + // The resource bundle id to load. + int resource_id_; + + net::HttpResponseInfo response_info_; + + mutable base::WeakPtrFactory<URLRequestResourceBundleJob> weak_factory_; +}; + +} // namespace + +namespace extensions { + +ExtensionsBrowserClientQt::ExtensionsBrowserClientQt() + : api_client_(new ExtensionsAPIClientQt) + , resource_manager_(new ComponentExtensionResourceManagerQt) +{ + AddAPIProvider(std::make_unique<CoreExtensionsBrowserAPIProvider>()); + AddAPIProvider(std::make_unique<ExtensionsBrowserAPIProviderQt>()); +} + +ExtensionsBrowserClientQt::~ExtensionsBrowserClientQt() +{ +} + +bool ExtensionsBrowserClientQt::IsShuttingDown() +{ + return false; +} + +bool ExtensionsBrowserClientQt::AreExtensionsDisabled(const base::CommandLine &command_line, BrowserContext *context) +{ + return false; +} + +bool ExtensionsBrowserClientQt::IsValidContext(BrowserContext *context) +{ + return true; +} + +bool ExtensionsBrowserClientQt::IsSameContext(BrowserContext *first, + BrowserContext *second) +{ + return first == second; +} + +bool ExtensionsBrowserClientQt::HasOffTheRecordContext(BrowserContext *context) +{ + return false; +} + +BrowserContext *ExtensionsBrowserClientQt::GetOffTheRecordContext(BrowserContext *context) +{ + // TODO(extensions): Do we need to support this? + return nullptr; +} + +BrowserContext *ExtensionsBrowserClientQt::GetOriginalContext(BrowserContext *context) +{ + return context; +} + +bool ExtensionsBrowserClientQt::IsGuestSession(BrowserContext *context) const +{ + return false; +} + +bool ExtensionsBrowserClientQt::IsExtensionIncognitoEnabled(const std::string &extension_id, + content::BrowserContext *context) const +{ + return false; +} + +bool ExtensionsBrowserClientQt::CanExtensionCrossIncognito(const Extension *extension, + content::BrowserContext *context) const +{ + return false; +} + +net::URLRequestJob *ExtensionsBrowserClientQt::MaybeCreateResourceBundleRequestJob(net::URLRequest *request, + net::NetworkDelegate *network_delegate, + const base::FilePath &directory_path, + const std::string &content_security_policy, + bool send_cors_header) +{ + base::FilePath resources_path; + base::FilePath relative_path; + // Try to load extension resources from chrome resource file if + // directory_path is a descendant of resources_path. resources_path + // corresponds to src/chrome/browser/resources in source tree. + if (base::PathService::Get(base::DIR_QT_LIBRARY_DATA, &resources_path) && + // Since component extension resources are included in + // component_extension_resources.pak file in resources_path, calculate + // extension relative path against resources_path. + resources_path.AppendRelativePath(directory_path, &relative_path)) { + base::FilePath request_path = extensions::file_util::ExtensionURLToRelativeFilePath(request->url()); + int resource_id = 0; + if (GetComponentExtensionResourceManager()->IsComponentExtensionResource(directory_path, request_path, &resource_id)) { + relative_path = relative_path.Append(request_path); + relative_path = relative_path.NormalizePathSeparators(); + return new URLRequestResourceBundleJob(request, + network_delegate, + relative_path, + resource_id, + content_security_policy, + send_cors_header); + } + } + return nullptr; +} + +// Return the resource relative path and id for the given request. +base::FilePath ExtensionsBrowserClientQt::GetBundleResourcePath(const network::ResourceRequest &request, + const base::FilePath &extension_resources_path, + int *resource_id) const +{ + *resource_id = 0; + // |chrome_resources_path| corresponds to src/chrome/browser/resources in + // source tree. + base::FilePath resources_path; + if (!base::PathService::Get(base::DIR_QT_LIBRARY_DATA, &resources_path)) + return base::FilePath(); + + // Since component extension resources are included in + // component_extension_resources.pak file in |chrome_resources_path|, + // calculate the extension |request_relative_path| against + // |chrome_resources_path|. + if (!resources_path.IsParent(extension_resources_path)) + return base::FilePath(); + + const base::FilePath request_relative_path = + extensions::file_util::ExtensionURLToRelativeFilePath(request.url); + if (!ExtensionsBrowserClient::Get()->GetComponentExtensionResourceManager()->IsComponentExtensionResource( + extension_resources_path, request_relative_path, resource_id)) { + return base::FilePath(); + } + DCHECK_NE(0, *resource_id); + + return request_relative_path; +} + +// Creates and starts a URLLoader to load an extension resource from the +// embedder's resource bundle (.pak) files. Used for component extensions. +void ExtensionsBrowserClientQt::LoadResourceFromResourceBundle(const network::ResourceRequest &request, + network::mojom::URLLoaderRequest loader, + const base::FilePath &resource_relative_path, + int resource_id, + const std::string &content_security_policy, + network::mojom::URLLoaderClientPtr client, + bool send_cors_header) +{ + NOTIMPLEMENTED(); +} + + +bool ExtensionsBrowserClientQt::AllowCrossRendererResourceLoad(const GURL &url, + content::ResourceType resource_type, + ui::PageTransition page_transition, + int child_id, + bool is_incognito, + const Extension *extension, + const ExtensionSet &extensions, + const ProcessMap &process_map) +{ + + if (extension && extension->id() == extension_misc::kPdfExtensionId) + return true; + + bool allowed = false; + if (url_request_util::AllowCrossRendererResourceLoad(url, resource_type, + page_transition, child_id, + is_incognito, extension, extensions, + process_map, &allowed)) { + return allowed; + } + // Couldn't determine if resource is allowed. Block the load. + return false; +} + +PrefService *ExtensionsBrowserClientQt::GetPrefServiceForContext(BrowserContext *context) +{ + return static_cast<Profile *>(context)->GetPrefs(); +} + +void ExtensionsBrowserClientQt::GetEarlyExtensionPrefsObservers(content::BrowserContext *context, + std::vector<ExtensionPrefsObserver *> *observers) const +{ +} + +ProcessManagerDelegate *ExtensionsBrowserClientQt::GetProcessManagerDelegate() const +{ + return nullptr; +} + +std::unique_ptr<ExtensionHostDelegate> ExtensionsBrowserClientQt::CreateExtensionHostDelegate() +{ + // TODO(extensions): Implement to support Apps. + NOTREACHED(); + return std::unique_ptr<ExtensionHostDelegate>(); +} + +bool ExtensionsBrowserClientQt::DidVersionUpdate(BrowserContext *context) +{ + // TODO(jamescook): We might want to tell extensions when app_shell updates. + return false; +} + +void ExtensionsBrowserClientQt::PermitExternalProtocolHandler() +{ +} + +bool ExtensionsBrowserClientQt::IsRunningInForcedAppMode() +{ + return false; +} + +bool ExtensionsBrowserClientQt::IsLoggedInAsPublicAccount() +{ + return false; +} + +ExtensionSystemProvider *ExtensionsBrowserClientQt::GetExtensionSystemFactory() +{ + return ExtensionSystemFactoryQt::GetInstance(); +} + +// void ExtensionsBrowserClientQt::RegisterExtensionFunctions(ExtensionFunctionRegistry *registry) const +//{ +// // Register core extension-system APIs. +// api::GeneratedFunctionRegistry::RegisterAll(registry); +//} + +void ExtensionsBrowserClientQt::RegisterExtensionInterfaces(service_manager::BinderRegistryWithArgs<content::RenderFrameHost *> *registry, + content::RenderFrameHost *render_frame_host, + const Extension *extension) const +{ + RegisterInterfacesForExtension(registry, render_frame_host, extension); +} + +std::unique_ptr<RuntimeAPIDelegate> ExtensionsBrowserClientQt::CreateRuntimeAPIDelegate(content::BrowserContext *context) const +{ + // TODO(extensions): Implement to support Apps. + NOTREACHED(); + return std::unique_ptr<RuntimeAPIDelegate>(); +} + +const ComponentExtensionResourceManager *ExtensionsBrowserClientQt::GetComponentExtensionResourceManager() +{ + return resource_manager_.get(); +} + +void ExtensionsBrowserClientQt::BroadcastEventToRenderers(events::HistogramValue histogram_value, + const std::string &event_name, + std::unique_ptr<base::ListValue> args) +{ + NOTIMPLEMENTED(); + // TODO : do the event routing + // event_router_forwarder_->BroadcastEventToRenderers( + // histogram_value, event_name, std::move(args), GURL()); +} + +net::NetLog *ExtensionsBrowserClientQt::GetNetLog() +{ + return nullptr; +} + +ExtensionCache *ExtensionsBrowserClientQt::GetExtensionCache() +{ + // Only used by Chrome via ExtensionService. + NOTREACHED(); + return nullptr; +} + +bool ExtensionsBrowserClientQt::IsBackgroundUpdateAllowed() +{ + return true; +} + +bool ExtensionsBrowserClientQt::IsMinBrowserVersionSupported( + const std::string &min_version) +{ + return true; +} + +bool ExtensionsBrowserClientQt::IsLockScreenContext(content::BrowserContext *context) +{ + return false; +} + +// Returns the locale used by the application. +std::string ExtensionsBrowserClientQt::GetApplicationLocale() +{ + return WebEngineLibraryInfo::getApplicationLocale(); +} + +bool ExtensionsBrowserClientQt::IsAppModeForcedForApp(const ExtensionId &id) +{ + return false; +} + +bool ExtensionsBrowserClientQt::IsInDemoMode() +{ + return false; +} + +ExtensionWebContentsObserver *ExtensionsBrowserClientQt::GetExtensionWebContentsObserver(content::WebContents *web_contents) +{ + return ExtensionWebContentsObserverQt::FromWebContents(web_contents); +} + +KioskDelegate *ExtensionsBrowserClientQt::GetKioskDelegate() +{ + NOTREACHED(); + return nullptr; +} + +bool ExtensionsBrowserClientQt::IsScreensaverInDemoMode(const std::string& app_id) +{ + return false; +} + +void ExtensionsBrowserClientQt::SetAPIClientForTest(ExtensionsAPIClient *api_client) +{ + api_client_.reset(api_client); +} + +} // namespace extensions diff --git a/src/core/extensions/extensions_browser_client_qt.h b/src/core/extensions/extensions_browser_client_qt.h new file mode 100644 index 000000000..f766b96a7 --- /dev/null +++ b/src/core/extensions/extensions_browser_client_qt.h @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** 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 2015 The Chromium Embedded Framework Authors. +// Portions copyright 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. + +#ifndef EXTENSIONS_BROWSER_CLIENT_QT_H_ +#define EXTENSIONS_BROWSER_CLIENT_QT_H_ + +#include "base/compiler_specific.h" +#include "extensions/browser/extensions_browser_client.h" + +namespace extensions { + +class ExtensionsAPIClient; + +// An ExtensionsBrowserClient that supports a single content::BrowserContent +// with no related incognito context. +class ExtensionsBrowserClientQt : public ExtensionsBrowserClient +{ +public: + ExtensionsBrowserClientQt(); + ~ExtensionsBrowserClientQt() override; + + // ExtensionsBrowserClient overrides: + bool IsShuttingDown() override; + bool AreExtensionsDisabled(const base::CommandLine &command_line, + content::BrowserContext *context) override; + bool IsValidContext(content::BrowserContext *context) override; + bool IsSameContext(content::BrowserContext *first, + content::BrowserContext *second) override; + bool HasOffTheRecordContext(content::BrowserContext *context) override; + content::BrowserContext *GetOffTheRecordContext(content::BrowserContext *context) override; + content::BrowserContext *GetOriginalContext(content::BrowserContext *context) override; + bool IsGuestSession(content::BrowserContext *context) const override; + bool IsExtensionIncognitoEnabled(const std::string &extension_id, content::BrowserContext *context) const override; + bool CanExtensionCrossIncognito(const Extension *extension, content::BrowserContext *context) const override; + net::URLRequestJob *MaybeCreateResourceBundleRequestJob(net::URLRequest *request, + net::NetworkDelegate *network_delegate, + const base::FilePath &directory_path, + const std::string &content_security_policy, + bool send_cors_header) override; + bool AllowCrossRendererResourceLoad(const GURL &url, + content::ResourceType resource_type, + ui::PageTransition page_transition, + int child_id, + bool is_incognito, + const Extension *extension, + const ExtensionSet &extensions, + const ProcessMap &process_map) override; + PrefService *GetPrefServiceForContext(content::BrowserContext *context) override; + void GetEarlyExtensionPrefsObservers(content::BrowserContext *context, std::vector<ExtensionPrefsObserver *> *observers) const + override; + ProcessManagerDelegate *GetProcessManagerDelegate() const override; + std::unique_ptr<ExtensionHostDelegate> + CreateExtensionHostDelegate() override; + bool DidVersionUpdate(content::BrowserContext *context) override; + void PermitExternalProtocolHandler() override; + bool IsRunningInForcedAppMode() override; + bool IsLoggedInAsPublicAccount() override; + ExtensionSystemProvider *GetExtensionSystemFactory() override; +// void RegisterExtensionFunctions(ExtensionFunctionRegistry *registry) const; + std::unique_ptr<RuntimeAPIDelegate> CreateRuntimeAPIDelegate(content::BrowserContext *context) const override; + void RegisterExtensionInterfaces(service_manager::BinderRegistryWithArgs<content::RenderFrameHost *> *registry, + content::RenderFrameHost *render_frame_host, + const Extension *extension) const override; + const ComponentExtensionResourceManager * + GetComponentExtensionResourceManager() override; + void BroadcastEventToRenderers(events::HistogramValue histogram_value, + const std::string &event_name, + std::unique_ptr<base::ListValue> args) override; + net::NetLog *GetNetLog() override; + ExtensionCache *GetExtensionCache() override; + bool IsBackgroundUpdateAllowed() override; + bool IsMinBrowserVersionSupported(const std::string &min_version) override; + ExtensionWebContentsObserver *GetExtensionWebContentsObserver( + content::WebContents *web_contents) override; + KioskDelegate *GetKioskDelegate() override; + + // Whether the browser context is associated with Chrome OS lock screen. + bool IsLockScreenContext(content::BrowserContext *context) override; + + bool IsAppModeForcedForApp(const ExtensionId &id) override; + bool IsInDemoMode() override; + + // Return the resource relative path and id for the given request. + base::FilePath GetBundleResourcePath(const network::ResourceRequest &request, + const base::FilePath &extension_resources_path, + int *resource_id) const override; + + // Creates and starts a URLLoader to load an extension resource from the + // embedder's resource bundle (.pak) files. Used for component extensions. + void LoadResourceFromResourceBundle(const network::ResourceRequest &request, + network::mojom::URLLoaderRequest loader, + const base::FilePath &resource_relative_path, + int resource_id, + const std::string &content_security_policy, + network::mojom::URLLoaderClientPtr client, + bool send_cors_header) override; + + // Returns the locale used by the application. + std::string GetApplicationLocale() override; + + bool IsScreensaverInDemoMode(const std::string& app_id) override; + + // Sets the API client. + void SetAPIClientForTest(ExtensionsAPIClient *api_client); + +private: + // Support for extension APIs. + std::unique_ptr<ExtensionsAPIClient> api_client_; + + // Resource manager used to supply resources from pak files. + std::unique_ptr<ComponentExtensionResourceManager> resource_manager_; + + //scoped_refptr<EventRouterForwarder> event_router_forwarder_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionsBrowserClientQt); +}; + +} // namespace extensions + +#endif // EXTENSIONS_BROWSER_CLIENT_QT_H_ diff --git a/src/core/extensions/mime_handler_view_guest_delegate_qt.cpp b/src/core/extensions/mime_handler_view_guest_delegate_qt.cpp new file mode 100644 index 000000000..438b8a83e --- /dev/null +++ b/src/core/extensions/mime_handler_view_guest_delegate_qt.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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 2015 The Chromium Embedded Framework Authors. +// Portions copyright 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 "mime_handler_view_guest_delegate_qt.h" + +#include "content/browser/browser_plugin/browser_plugin_guest.h" +#include "content/browser/web_contents/web_contents_impl.h" +#include "content/public/browser/web_contents.h" +#include "content/public/common/context_menu_params.h" +#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h" + +namespace extensions { + +MimeHandlerViewGuestDelegateQt::MimeHandlerViewGuestDelegateQt(MimeHandlerViewGuest *guest) + : MimeHandlerViewGuestDelegate() +{ +} + +MimeHandlerViewGuestDelegateQt::~MimeHandlerViewGuestDelegateQt() +{ +} + +bool MimeHandlerViewGuestDelegateQt::HandleContextMenu(content::WebContents *web_contents, const content::ContextMenuParams ¶ms) +{ + content::ContextMenuParams new_params = params; + + gfx::Point guest_coordinates = + static_cast<content::WebContentsImpl *>(web_contents)->GetBrowserPluginGuest()->GetScreenCoordinates(gfx::Point()); + + // Adjust (x,y) position for offset from guest to embedder. + new_params.x += guest_coordinates.x(); + new_params.y += guest_coordinates.y(); + + return false; +} + +} // namespace extensions diff --git a/src/core/extensions/mime_handler_view_guest_delegate_qt.h b/src/core/extensions/mime_handler_view_guest_delegate_qt.h new file mode 100644 index 000000000..b679c7a38 --- /dev/null +++ b/src/core/extensions/mime_handler_view_guest_delegate_qt.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 2015 The Chromium Embedded Framework Authors. +// Portions copyright 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. + +#ifndef MIME_HANDLER_VIEW_GUEST_DELEGATE_QT_H_ +#define MIME_HANDLER_VIEW_GUEST_DELEGATE_QT_H_ + +#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h" +#include "content/browser/web_contents/web_contents_view.h" +#include "content/public/browser/web_contents.h" + +namespace content { +struct ContextMenuParams; +} + +namespace extensions { +class MimeHandlerViewGuest; + +class MimeHandlerViewGuestDelegateQt : public MimeHandlerViewGuestDelegate +{ +public: + explicit MimeHandlerViewGuestDelegateQt(MimeHandlerViewGuest *guest); + ~MimeHandlerViewGuestDelegateQt() override; + + bool HandleContextMenu(content::WebContents *web_contents, + const content::ContextMenuParams ¶ms) override; + +private: + MimeHandlerViewGuest *guest_; // Owns us. + + DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewGuestDelegateQt); +}; + +} // namespace extensions + +#endif // MIME_HANDLER_VIEW_GUEST_DELEGATE_QT_H_ diff --git a/src/core/extensions/pdf_web_contents_helper_client_qt.h b/src/core/extensions/pdf_web_contents_helper_client_qt.h new file mode 100644 index 000000000..a22feb138 --- /dev/null +++ b/src/core/extensions/pdf_web_contents_helper_client_qt.h @@ -0,0 +1,29 @@ +// Copyright 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. + +#ifndef PDF_WEB_CONTENTS_HELPER_CLIENT_QT_H_ +#define PDF_WEB_CONTENTS_HELPER_CLIENT_QT_H_ + +#include "base/macros.h" +#include "components/pdf/browser/pdf_web_contents_helper_client.h" + +namespace extensions { + +class PDFWebContentsHelperClientQt : public pdf::PDFWebContentsHelperClient { +public: + PDFWebContentsHelperClientQt(); + ~PDFWebContentsHelperClientQt() override; + +private: + // pdf::PDFWebContentsHelperClient: + void UpdateContentRestrictions(content::WebContents* contents, int content_restrictions) override; + void OnPDFHasUnsupportedFeature(content::WebContents* contents) override; + void OnSaveURL(content::WebContents* contents) override; + + DISALLOW_COPY_AND_ASSIGN(PDFWebContentsHelperClientQt); +}; + +} // namespace extensions + +#endif // PDF_WEB_CONTENTS_HELPER_CLIENT_QT_H_ diff --git a/src/core/login_delegate_qt.cpp b/src/core/login_delegate_qt.cpp index 31824ca71..5b407c094 100644 --- a/src/core/login_delegate_qt.cpp +++ b/src/core/login_delegate_qt.cpp @@ -50,10 +50,22 @@ #include "content/public/browser/render_view_host.h" #include "content/public/browser/resource_dispatcher_host.h" #include "content/public/browser/resource_request_info.h" +#include "content/public/browser/stream_info.h" +#include "extensions/buildflags/buildflags.h" +#if BUILDFLAG(ENABLE_EXTENSIONS) +#include "extensions/browser/info_map.h" +#include "extensions/common/extension.h" +#include "extensions/common/manifest_handlers/mime_types_handler.h" +#endif // BUILDFLAG(ENABLE_EXTENSIONS) + #include "net/url_request/url_request.h" #include "authentication_dialog_controller.h" #include "authentication_dialog_controller_p.h" +#if BUILDFLAG(ENABLE_EXTENSIONS) +#include "extensions/extension_system_qt.h" +#endif // BUILDFLAG(ENABLE_EXTENSIONS) +#include "resource_context_qt.h" #include "type_conversion.h" #include "web_contents_view_qt.h" diff --git a/src/core/profile_adapter.cpp b/src/core/profile_adapter.cpp index dfe701cc9..48a6906e9 100644 --- a/src/core/profile_adapter.cpp +++ b/src/core/profile_adapter.cpp @@ -58,6 +58,10 @@ #include "components/keyed_service/content/browser_context_dependency_manager.h" +#if BUILDFLAG(ENABLE_EXTENSIONS) +#include "extensions/browser/extension_system.h" +#endif + #include <QCoreApplication> #include <QDir> #include <QString> @@ -93,6 +97,10 @@ ProfileAdapter::ProfileAdapter(const QString &storageName): // fixme: this should not be here m_profile->m_profileIOData->initializeOnUIThread(); m_customUrlSchemeHandlers.insert(QByteArrayLiteral("qrc"), &m_qrcHandler); +#if BUILDFLAG(ENABLE_EXTENSIONS) + if (!storageName.isEmpty()) + extensions::ExtensionSystem::Get(m_profile.data())->InitForRegularProfile(true); +#endif } ProfileAdapter::~ProfileAdapter() diff --git a/src/core/profile_io_data_qt.cpp b/src/core/profile_io_data_qt.cpp index dc5b6624e..4815b8749 100644 --- a/src/core/profile_io_data_qt.cpp +++ b/src/core/profile_io_data_qt.cpp @@ -223,6 +223,13 @@ content::ResourceContext *ProfileIODataQt::resourceContext() return m_resourceContext.get(); } +#if BUILDFLAG(ENABLE_EXTENSIONS) +extensions::ExtensionSystemQt* ProfileIODataQt::GetExtensionSystem() +{ + return m_profile->GetExtensionSystem(); +} +#endif // BUILDFLAG(ENABLE_EXTENSIONS) + void ProfileIODataQt::initializeOnIOThread() { m_networkDelegate.reset(new NetworkDelegateQt(this)); diff --git a/src/core/profile_io_data_qt.h b/src/core/profile_io_data_qt.h index f3460935a..407d0d6f2 100644 --- a/src/core/profile_io_data_qt.h +++ b/src/core/profile_io_data_qt.h @@ -43,6 +43,7 @@ #include "profile_adapter.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" +#include "extensions/buildflags/buildflags.h" #include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h" #include <QtCore/QString> @@ -61,6 +62,10 @@ class URLRequestJobFactoryImpl; class TransportSecurityPersister; } +namespace extensions { +class ExtensionSystemQt; +} + namespace QtWebEngineCore { class ProfileQt; @@ -78,6 +83,10 @@ public: QPointer<ProfileAdapter> profileAdapter(); content::ResourceContext *resourceContext(); net::URLRequestContext *urlRequestContext(); +#if BUILDFLAG(ENABLE_EXTENSIONS) + extensions::ExtensionSystemQt* GetExtensionSystem(); +#endif // BUILDFLAG(ENABLE_EXTENSIONS) + void initializeOnIOThread(); void initializeOnUIThread(); // runs on ui thread void shutdownOnUIThread(); // runs on ui thread diff --git a/src/core/profile_qt.cpp b/src/core/profile_qt.cpp index d98bb5c9c..0ede1df55 100644 --- a/src/core/profile_qt.cpp +++ b/src/core/profile_qt.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** 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. @@ -71,11 +71,24 @@ #include "components/spellcheck/browser/pref_names.h" #endif +#if BUILDFLAG(ENABLE_EXTENSIONS) +#include "components/guest_view/browser/guest_view_manager.h" +#include "extensions/browser/extension_protocols.h" +#include "extensions/browser/pref_names.h" +#include "extensions/browser/process_manager.h" +#include "extensions/common/constants.h" + +#include "extensions/extension_system_qt.h" +#endif + namespace QtWebEngineCore { ProfileQt::ProfileQt(ProfileAdapter *profileAdapter) : m_profileIOData(new ProfileIODataQt(this)), m_profileAdapter(profileAdapter) +#if BUILDFLAG(ENABLE_EXTENSIONS) + , m_extensionSystem(nullptr) +#endif // BUILDFLAG(ENABLE_EXTENSIONS) { PrefServiceFactory factory; factory.set_user_prefs(new InMemoryPrefStore); @@ -94,6 +107,23 @@ ProfileQt::ProfileQt(ProfileAdapter *profileAdapter) #endif // QT_CONFIG(webengine_spellchecker) registry->RegisterBooleanPref(prefs::kShowInternalAccessibilityTree, false); +#if BUILDFLAG(ENABLE_EXTENSIONS) + registry->RegisterDictionaryPref(extensions::pref_names::kExtensions); + registry->RegisterListPref(extensions::pref_names::kInstallAllowList); + registry->RegisterListPref(extensions::pref_names::kInstallDenyList); + registry->RegisterDictionaryPref(extensions::pref_names::kInstallForceList); + registry->RegisterDictionaryPref(extensions::pref_names::kInstallLoginScreenAppList); + registry->RegisterListPref(extensions::pref_names::kAllowedTypes); + registry->RegisterBooleanPref(extensions::pref_names::kStorageGarbageCollect, false); + registry->RegisterInt64Pref(extensions::pref_names::kLastUpdateCheck, 0); + registry->RegisterInt64Pref(extensions::pref_names::kNextUpdateCheck, 0); + registry->RegisterListPref(extensions::pref_names::kAllowedInstallSites); + registry->RegisterStringPref(extensions::pref_names::kLastChromeVersion, std::string()); + registry->RegisterListPref(extensions::pref_names::kNativeMessagingBlacklist); + registry->RegisterListPref(extensions::pref_names::kNativeMessagingWhitelist); + registry->RegisterBooleanPref(extensions::pref_names::kNativeMessagingUserLevelHosts, true); +#endif // BUILDFLAG(ENABLE_EXTENSIONS) + m_prefService = factory.Create(registry); user_prefs::UserPrefs::Set(this, m_prefService.get()); @@ -102,6 +132,11 @@ ProfileQt::ProfileQt(ProfileAdapter *profileAdapter) // ProfileQt object is allocated at the same address as a previously // destroyed one. Needs to be called after WebEngineContext initialization. BrowserContextDependencyManager::GetInstance()->MarkBrowserContextLive(this); + +#if BUILDFLAG(ENABLE_EXTENSIONS) + m_extensionSystem = static_cast<extensions::ExtensionSystemQt*>(extensions::ExtensionSystem::Get(this)); + m_extensionSystem->InitForRegularProfile(true); +#endif } ProfileQt::~ProfileQt() @@ -168,7 +203,9 @@ content::DownloadManagerDelegate *ProfileQt::GetDownloadManagerDelegate() content::BrowserPluginGuestManager *ProfileQt::GetGuestManager() { - return nullptr; +#if BUILDFLAG(ENABLE_EXTENSIONS) + return guest_view::GuestViewManager::FromBrowserContext(this); +#endif } storage::SpecialStoragePolicy *ProfileQt::GetSpecialStoragePolicy() @@ -222,6 +259,12 @@ net::URLRequestContextGetter *ProfileQt::CreateRequestContext( { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK(!m_urlRequestContextGetter.get()); +#if BUILDFLAG(ENABLE_EXTENSIONS) + extensions::InfoMap* extension_info_map = GetExtensionSystem()->info_map(); + (*protocol_handlers)[extensions::kExtensionScheme] = + extensions::CreateExtensionProtocolHandler(IsOffTheRecord(),extension_info_map); +#endif + m_profileIOData->setRequestContextData(protocol_handlers, std::move(request_interceptors)); m_profileIOData->updateStorageSettings(); m_urlRequestContextGetter = new URLRequestContextGetterQt(m_profileIOData.get()); @@ -278,4 +321,12 @@ bool ProfileQt::isSpellCheckEnabled() const return m_prefService->GetBoolean(spellcheck::prefs::kSpellCheckEnable); } #endif // QT_CONFIG(webengine_spellchecker) + +#if BUILDFLAG(ENABLE_EXTENSIONS) +extensions::ExtensionSystemQt* ProfileQt::GetExtensionSystem() +{ + return m_extensionSystem; +} +#endif // BUILDFLAG(ENABLE_EXTENSIONS) + } // namespace QtWebEngineCore diff --git a/src/core/profile_qt.h b/src/core/profile_qt.h index 8641646b1..41eeeecf5 100644 --- a/src/core/profile_qt.h +++ b/src/core/profile_qt.h @@ -43,6 +43,7 @@ #include "chrome/browser/profiles/profile.h" #include "content/public/browser/content_browser_client.h" #include "content/public/browser/resource_context.h" +#include "extensions/buildflags/buildflags.h" #include "net/url_request/url_request_context.h" #include "profile_io_data_qt.h" #include <QtGlobal> @@ -53,6 +54,10 @@ QT_END_NAMESPACE class InMemoryPrefStore; class PrefService; +namespace extensions { +class ExtensionSystemQt; +} + namespace QtWebEngineCore { class ProfileAdapter; @@ -99,6 +104,7 @@ public: PrefService *GetPrefs() override; const PrefService *GetPrefs() const override; net::URLRequestContextGetter *GetRequestContext() override; + void Initialize(); ProfileAdapter *profileAdapter() { return m_profileAdapter; } @@ -109,6 +115,9 @@ public: void setSpellCheckEnabled(bool enabled); bool isSpellCheckEnabled() const; #endif +#if BUILDFLAG(ENABLE_EXTENSIONS) + extensions::ExtensionSystemQt* GetExtensionSystem(); +#endif // defined(ENABLE_EXTENSIONS) private: friend class ContentBrowserClientQt; @@ -120,6 +129,10 @@ private: std::unique_ptr<ProfileIODataQt> m_profileIOData; ProfileAdapter *m_profileAdapter; friend class ProfileAdapter; +#if BUILDFLAG(ENABLE_EXTENSIONS) + extensions::ExtensionSystemQt *m_extensionSystem; +#endif //ENABLE_EXTENSIONS + friend class BrowserContextAdapter; DISALLOW_COPY_AND_ASSIGN(ProfileQt); }; diff --git a/src/core/qtwebengine.gni b/src/core/qtwebengine.gni index 0bb8f0cdb..7c0ca763e 100644 --- a/src/core/qtwebengine.gni +++ b/src/core/qtwebengine.gni @@ -1,5 +1,6 @@ import("//build/config/ui.gni") import("//media/media_options.gni") +import("//extensions/buildflags/buildflags.gni") import("//third_party/widevine/cdm/widevine.gni") chromium_version = exec_script("//build/util/version.py", [ "-f", rebase_path("//chrome/VERSION"), @@ -38,7 +39,7 @@ deps = [ "//ui/gl", "//qtwebengine/browser:interfaces", ":qtwebengine_sources", - ":qtwebengine_resources" + ":qtwebengine_resources", ] if (enable_webrtc) { @@ -59,6 +60,12 @@ if (use_ozone) { ] } +if (enable_extensions) { + deps += [ + ":qtwebengine_extensions_features" + ] +} + data_deps = [ "//qtwebengine/browser:service_manifests" ] defines = [ diff --git a/src/core/qtwebengine_resources.gni b/src/core/qtwebengine_resources.gni index 6e8c3c6eb..283235f66 100644 --- a/src/core/qtwebengine_resources.gni +++ b/src/core/qtwebengine_resources.gni @@ -1,10 +1,14 @@ import("//tools/grit/repack.gni") import("//build/config/locales.gni") import("//chrome/chrome_repack_locales.gni") +import("//extensions/buildflags/buildflags.gni") group("qtwebengine_resources") { deps = [ "//chrome/app:generated_resources", + "//chrome/browser:resources", + "//chrome/browser/resources:component_extension_resources", + "//chrome/common:resources", "//components/resources:components_resources", ":qtwebengine_repack_resources", ":qtwebengine_repack_resources_100", @@ -17,6 +21,8 @@ group("qtwebengine_resources") { repack("qtwebengine_repack_resources") { sources = [ "$root_gen_dir/qtwebengine/qt_webengine_resources.pak", + "$root_gen_dir/chrome/browser_resources.pak", + "$root_gen_dir/chrome/common_resources.pak", "$root_gen_dir/chrome/quota_internals_resources.pak", "$root_gen_dir/chrome/task_scheduler_internals_resources.pak", "$root_gen_dir/components/components_resources.pak", @@ -31,6 +37,8 @@ repack("qtwebengine_repack_resources") { "//qtwebengine/browser:qt_webengine_resources", "//chrome/browser/resources:quota_internals_resources", "//chrome/browser/resources:task_scheduler_internals_resources", + "//chrome/browser:resources_grit", + "//chrome/common:resources_grit", "//components/resources:components_resources_grit", "//content:resources_grit", "//mojo/public/js:resources", @@ -38,6 +46,20 @@ repack("qtwebengine_repack_resources") { "//third_party/blink/public:resources_grit", "//ui/resources:webui_resources_grd_grit", ] + + if (enable_extensions) { + sources += [ + "$root_gen_dir/chrome/component_extension_resources.pak", + "$root_gen_dir/extensions/extensions_renderer_resources.pak", + "$root_gen_dir/extensions/extensions_resources.pak", + ] + deps += [ + "//chrome/browser/resources:component_extension_resources_grit", + "//extensions:extensions_renderer_resources_grit", + "//extensions:extensions_resources_grd_grit", + ] + } + } repack("qtwebengine_repack_resources_100") { @@ -56,6 +78,14 @@ repack("qtwebengine_repack_resources_100") { "//third_party/blink/public:scaled_resources_100_percent", "//ui/resources:ui_resources_grd_grit" ] + if (enable_extensions) { + sources += [ + "$root_gen_dir/extensions/extensions_browser_resources_100_percent.pak" + ] + deps += [ + "//extensions:extensions_browser_resources_grit" + ] + } } repack("qtwebengine_repack_resources_200") { @@ -74,6 +104,14 @@ repack("qtwebengine_repack_resources_200") { "//third_party/blink/public:scaled_resources_200_percent", "//ui/resources:ui_resources_grd_grit" ] + if (enable_extensions) { + sources += [ + "$root_gen_dir/extensions/extensions_browser_resources_200_percent.pak" + ] + deps += [ + "//extensions:extensions_browser_resources_grit" + ] + } } repack("qtwebengine_repack_resources_devtools") { diff --git a/src/core/qtwebengine_sources.gni b/src/core/qtwebengine_sources.gni index aa9d12480..58df7096b 100644 --- a/src/core/qtwebengine_sources.gni +++ b/src/core/qtwebengine_sources.gni @@ -1,9 +1,11 @@ import("//build/config/features.gni") import("//build/config/ui.gni") +import("//chrome/common/features.gni") import("//components/spellcheck/spellcheck_build_features.gni") import("//pdf/features.gni") import("//ppapi/buildflags/buildflags.gni") import("//printing/buildflags/buildflags.gni") +import("//extensions/buildflags/buildflags.gni") source_set("qtwebengine_spellcheck_sources") { include_dirs = core_include_dirs @@ -40,12 +42,14 @@ source_set("qtwebengine_sources") { "//skia:skia_config", "//third_party/boringssl:external_config", ] + deps = [ "//chrome/common:buildflags", "//components/nacl/common:buildflags", "//extensions/buildflags:buildflags", "//third_party/blink/public/mojom:mojom_platform", ] + sources = [ "//chrome/browser/accessibility/accessibility_ui.cc", "//chrome/browser/accessibility/accessibility_ui.h", @@ -80,12 +84,47 @@ source_set("qtwebengine_sources") { "//chrome/common/url_constants.h", "//chrome/common/webui_url_constants.cc", "//chrome/common/webui_url_constants.h", - "//extensions/common/constants.cc", - "//extensions/common/constants.h", - "//extensions/common/url_pattern.cc", - "//extensions/common/url_pattern.h", + "//components/prefs/in_memory_pref_store.cc", + "//components/prefs/in_memory_pref_store.h", ] + if (enable_extensions) { + deps += [ + ":qtwebengine_extensions_features", + "//chrome/browser/resources:component_extension_resources_grit", + "//chrome/common/extensions/api", + "//chrome/common/extensions/api:extensions_features", + "//components/crx_file", + "//components/crx_file:crx_creator", + "//components/spellcheck:buildflags", + "//extensions/buildflags:buildflags", + "//extensions/common", + "//extensions/common/api", + "//extensions/common:core_api_provider", + "//extensions/browser", + "//extensions/browser/api", + "//extensions/browser:core_api_provider", + "//extensions/renderer", + "//extensions:extensions_resources", + "//extensions/strings", + ] + sources += [ + "//chrome/common/extensions/permissions/chrome_api_permissions.cc", + "//chrome/common/extensions/permissions/chrome_api_permissions.h", + "//chrome/common/extensions/permissions/chrome_permission_message_provider.cc", + "//chrome/common/extensions/permissions/chrome_permission_message_provider.h", + "//chrome/common/extensions/permissions/chrome_permission_message_rules.cc", + "//chrome/common/extensions/permissions/chrome_permission_message_rules.h", + ] + } else { + sources += [ + "//extensions/common/constants.cc", + "//extensions/common/constants.h", + "//extensions/common/url_pattern.cc", + "//extensions/common/url_pattern.h", + ] + } + if (is_linux) { sources += [ "//chrome/browser/ui/webui/sandbox_internals_ui.cc", @@ -131,6 +170,8 @@ source_set("qtwebengine_sources") { deps += [ "//pdf", "//pdf:buildflags", + "//components/pdf/browser:browser", + "//components/pdf/renderer:renderer", "//components/printing/browser", "//components/printing/renderer", ] diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index ac7357f0e..0217bed59 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -188,14 +188,13 @@ static inline bool isCommonTextEditShortcut(const QKeyEvent *ke) static uint32_t s_eventId = 0; class MotionEventQt : public ui::MotionEvent { public: - MotionEventQt(const QList<QTouchEvent::TouchPoint> &touchPoints, const base::TimeTicks &eventTime, Action action, const Qt::KeyboardModifiers modifiers, float dpiScale, int index = -1) + MotionEventQt(const QList<QTouchEvent::TouchPoint> &touchPoints, const base::TimeTicks &eventTime, Action action, const Qt::KeyboardModifiers modifiers, int index = -1) : touchPoints(touchPoints) , eventTime(eventTime) , action(action) , eventId(++s_eventId) , flags(flagsFromModifiers(modifiers)) , index(index) - , dpiScale(dpiScale) { // ACTION_DOWN and ACTION_UP must be accesssed through pointer_index 0 Q_ASSERT((action != Action::DOWN && action != Action::UP) || index == 0); @@ -206,8 +205,8 @@ public: int GetActionIndex() const override { return index; } size_t GetPointerCount() const override { return touchPoints.size(); } int GetPointerId(size_t pointer_index) const override { return touchPoints.at(pointer_index).id(); } - float GetX(size_t pointer_index) const override { return touchPoints.at(pointer_index).pos().x() / dpiScale; } - float GetY(size_t pointer_index) const override { return touchPoints.at(pointer_index).pos().y() / dpiScale; } + float GetX(size_t pointer_index) const override { return touchPoints.at(pointer_index).pos().x(); } + float GetY(size_t pointer_index) const override { return touchPoints.at(pointer_index).pos().y(); } float GetRawX(size_t pointer_index) const override { return touchPoints.at(pointer_index).screenPos().x(); } float GetRawY(size_t pointer_index) const override { return touchPoints.at(pointer_index).screenPos().y(); } float GetTouchMajor(size_t pointer_index) const override @@ -247,7 +246,6 @@ private: const uint32_t eventId; int flags; int index; - float dpiScale; }; RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost *widget) @@ -434,9 +432,8 @@ bool RenderWidgetHostViewQt::IsShowing() gfx::Rect RenderWidgetHostViewQt::GetViewBounds() const { QRectF p = m_delegate->contentsRect(); - float s = dpiScale(); - gfx::Point p1(floor(p.x() / s), floor(p.y() / s)); - gfx::Point p2(ceil(p.right() /s), ceil(p.bottom() / s)); + gfx::Point p1(floor(p.x()), floor(p.y())); + gfx::Point p2(ceil(p.right()), ceil(p.bottom())); return gfx::BoundingRect(p1, p2); } @@ -681,11 +678,6 @@ void RenderWidgetHostViewQt::SubmitCompositorFrame(const viz::LocalSurfaceId &lo if (frame_token) OnFrameTokenChangedForView(frame_token); - // Support experimental.viewport.devicePixelRatio, see GetScreenInfo implementation below. - float dpiScale = this->dpiScale(); - if (dpiScale != 0 && dpiScale != 1) - frame.metadata.device_scale_factor /= dpiScale; - m_compositor->submitFrame( std::move(frame), base::BindOnce(&RenderWidgetHostViewQtDelegate::update, base::Unretained(m_delegate.get()))); @@ -714,9 +706,6 @@ void RenderWidgetHostViewQt::GetScreenInfo(content::ScreenInfo *results) const if (!window) return; GetScreenInfoFromNativeWindow(window, results); - - // Support experimental.viewport.devicePixelRatio - results->device_scale_factor *= dpiScale(); } gfx::Rect RenderWidgetHostViewQt::GetBoundsInRootWindow() @@ -1182,11 +1171,6 @@ QList<QTouchEvent::TouchPoint> RenderWidgetHostViewQt::mapTouchPointIds(const QL return outputPoints; } -float RenderWidgetHostViewQt::dpiScale() const -{ - return m_adapterClient ? m_adapterClient->dpiScale() : 1.0; -} - bool RenderWidgetHostViewQt::IsPopup() const { return widget_type_ == content::WidgetType::kPopup; @@ -1414,7 +1398,7 @@ void RenderWidgetHostViewQt::handleWheelEvent(QWheelEvent *ev) { if (!m_wheelAckPending) { Q_ASSERT(m_pendingWheelEvents.isEmpty()); - blink::WebMouseWheelEvent webEvent = WebEventFactory::toWebWheelEvent(ev, dpiScale()); + blink::WebMouseWheelEvent webEvent = WebEventFactory::toWebWheelEvent(ev); m_wheelAckPending = (webEvent.phase != blink::WebMouseWheelEvent::kPhaseEnded); m_mouseWheelPhaseHandler.AddPhaseIfNeededAndScheduleEndEvent(webEvent, false); host()->ForwardWheelEvent(webEvent); @@ -1422,10 +1406,10 @@ void RenderWidgetHostViewQt::handleWheelEvent(QWheelEvent *ev) } if (!m_pendingWheelEvents.isEmpty()) { // Try to combine with this wheel event with the last pending one. - if (WebEventFactory::coalesceWebWheelEvent(m_pendingWheelEvents.last(), ev, dpiScale())) + if (WebEventFactory::coalesceWebWheelEvent(m_pendingWheelEvents.last(), ev)) return; } - m_pendingWheelEvents.append(WebEventFactory::toWebWheelEvent(ev, dpiScale())); + m_pendingWheelEvents.append(WebEventFactory::toWebWheelEvent(ev)); } void RenderWidgetHostViewQt::WheelEventAck(const blink::WebMouseWheelEvent &event, content::InputEventAckState /*ack_result*/) @@ -1460,9 +1444,7 @@ void RenderWidgetHostViewQt::handleGestureEvent(QNativeGestureEvent *ev) const Qt::NativeGestureType type = ev->gestureType(); // These are the only supported gestures by Chromium so far. if (type == Qt::ZoomNativeGesture || type == Qt::SmartZoomNativeGesture) { - host()->ForwardGestureEvent(WebEventFactory::toWebGestureEvent( - ev, - static_cast<double>(dpiScale()))); + host()->ForwardGestureEvent(WebEventFactory::toWebGestureEvent(ev)); } } #endif @@ -1508,7 +1490,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) break; } - MotionEventQt motionEvent(touchPoints, eventTimestamp, action, ev->modifiers(), dpiScale(), 0); + MotionEventQt motionEvent(touchPoints, eventTimestamp, action, ev->modifiers(), 0); if (m_touchSelectionController->WillHandleTouchEvent(motionEvent)) { ev->accept(); return; @@ -1539,8 +1521,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) if (touchPoints.isEmpty()) touchPoints = m_previousTouchPoints; clearPreviousTouchMotionState(); - MotionEventQt cancelEvent(touchPoints, eventTimestamp, ui::MotionEvent::Action::CANCEL, - ev->modifiers(), dpiScale()); + MotionEventQt cancelEvent(touchPoints, eventTimestamp, ui::MotionEvent::Action::CANCEL, ev->modifiers()); processMotionEvent(cancelEvent); return; } @@ -1593,8 +1574,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev) continue; } - MotionEventQt motionEvent(touchPoints, eventTimestamp, action, ev->modifiers(), dpiScale(), - i); + MotionEventQt motionEvent(touchPoints, eventTimestamp, action, ev->modifiers(), i); processMotionEvent(motionEvent); } } @@ -1611,7 +1591,7 @@ void RenderWidgetHostViewQt::handlePointerEvent(T *event) { // Currently WebMouseEvent is a subclass of WebPointerProperties, so basically // tablet events are mouse events with extra properties. - blink::WebMouseEvent webEvent = WebEventFactory::toWebMouseEvent(event, dpiScale()); + blink::WebMouseEvent webEvent = WebEventFactory::toWebMouseEvent(event); if ((webEvent.GetType() == blink::WebInputEvent::kMouseDown || webEvent.GetType() == blink::WebInputEvent::kMouseUp) && webEvent.button == blink::WebMouseEvent::Button::kNoButton) { // Blink can only handle the 3 main mouse-buttons and may assert when processing mouse-down for no button. @@ -1657,7 +1637,7 @@ void RenderWidgetHostViewQt::handlePointerEvent(T *event) void RenderWidgetHostViewQt::handleHoverEvent(QHoverEvent *ev) { - host()->ForwardMouseEvent(WebEventFactory::toWebMouseEvent(ev, dpiScale())); + host()->ForwardMouseEvent(WebEventFactory::toWebMouseEvent(ev)); } void RenderWidgetHostViewQt::handleFocusEvent(QFocusEvent *ev) diff --git a/src/core/render_widget_host_view_qt.h b/src/core/render_widget_host_view_qt.h index b9efc996f..f7bd82f03 100644 --- a/src/core/render_widget_host_view_qt.h +++ b/src/core/render_widget_host_view_qt.h @@ -234,7 +234,6 @@ private: void processMotionEvent(const ui::MotionEvent &motionEvent); void clearPreviousTouchMotionState(); QList<QTouchEvent::TouchPoint> mapTouchPointIds(const QList<QTouchEvent::TouchPoint> &inputPoints); - float dpiScale() const; void updateNeedsBeginFramesInternal(); bool IsPopup() const; 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 diff --git a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp b/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp new file mode 100644 index 000000000..0583060c6 --- /dev/null +++ b/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// 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.Chromium file. + +#include "resource_dispatcher_host_delegate_qt.h" + +#include "base/bind.h" +#include "base/guid.h" +#include "base/strings/stringprintf.h" +#include "base/task/post_task.h" +#include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/navigation_controller.h" + +#include "content/public/browser/render_frame_host.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/browser/resource_dispatcher_host.h" +#include "content/public/browser/resource_request_info.h" +#include "content/public/browser/stream_info.h" +#include "content/public/browser/web_contents.h" + +#include "extensions/extension_system_qt.h" +#include "extensions/browser/info_map.h" +#include "extensions/common/constants.h" +#include "extensions/common/extension.h" +#include "extensions/common/manifest_handlers/mime_types_handler.h" + +#include "net/base/escape.h" +#include "net/url_request/url_request.h" + +#include "resource_context_qt.h" +#include "type_conversion.h" + +namespace QtWebEngineCore { + +void OnPdfStreamIntercepted( + const GURL& original_url, + std::string extension_id, + int frame_tree_node_id, + const content::ResourceRequestInfo::WebContentsGetter& + web_contents_getter) { + content::WebContents* web_contents = web_contents_getter.Run(); + if (!web_contents) + return; + + // The URL passes the original pdf resource url, that will be requested + // by the pdf viewer extension page. + content::NavigationController::LoadURLParams params( + GURL(base::StringPrintf("%s://%s/index.html?%s", extensions::kExtensionScheme, + extension_id.c_str(), + net::EscapeUrlEncodedData(original_url.spec(), false).c_str()))); + + params.frame_tree_node_id = frame_tree_node_id; + web_contents->GetController().LoadURLWithParams(params); +} + +bool ResourceDispatcherHostDelegateQt::ShouldInterceptResourceAsStream(net::URLRequest *request, + const std::string &mime_type, + GURL *origin, + std::string *payload) +{ + const content::ResourceRequestInfo* info = + content::ResourceRequestInfo::ForRequest(request); + + int render_process_host_id = -1; + int render_frame_id = -1; + if (!content::ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_host_id, &render_frame_id)) { + return false; + } + + ResourceContextQt *context = static_cast<ResourceContextQt *>(info->GetContext()); + std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); + + extensions::ExtensionSystemQt *extensionSystem = context->GetExtensionSystem(); + if (!extensionSystem) + return false; + + const scoped_refptr<const extensions::InfoMap> extension_info_map(extensionSystem->info_map()); + + for (const std::string &extension_id : whitelist) { + const extensions::Extension *extension = extension_info_map->extensions().GetByID(extension_id); + if (!extension) + continue; + + MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); + if (!handler) + continue; + if (handler->CanHandleMIMEType(mime_type)) { + StreamTargetInfo target_info; + *origin = extensions::Extension::GetBaseURLFromExtensionId(extension_id); + target_info.extension_id = extension_id; + target_info.view_id = base::GenerateGUID(); + *payload = target_info.view_id; + stream_target_info_[request] = target_info; + return true; + } + } + return false; +} + +// Informs the delegate that a Stream was created. The Stream can be read from +// the blob URL of the Stream, but can only be read once. +void ResourceDispatcherHostDelegateQt::OnStreamCreated(net::URLRequest *request, + std::unique_ptr<content::StreamInfo> stream) +{ + const content::ResourceRequestInfo *info = content::ResourceRequestInfo::ForRequest(request); + std::map<net::URLRequest *, StreamTargetInfo>::iterator ix = stream_target_info_.find(request); + CHECK(ix != stream_target_info_.end()); + int render_frame_id = -1; + int render_process_id = -1; + if (!content::ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_id, &render_frame_id)) { + stream_target_info_.erase(request); + request->Cancel(); + return; + } + + base::PostTaskWithTraits( + FROM_HERE, {content::BrowserThread::UI}, + base::BindOnce(&OnPdfStreamIntercepted, + request->url(), ix->second.extension_id, + info->GetFrameTreeNodeId(), info->GetWebContentsGetterForRequest() + ) + ); + stream_target_info_.erase(request); +} + +} // namespace QtWebEngineCore diff --git a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.h b/src/core/renderer_host/resource_dispatcher_host_delegate_qt.h new file mode 100644 index 000000000..3039fd03e --- /dev/null +++ b/src/core/renderer_host/resource_dispatcher_host_delegate_qt.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H +#define RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H + +#include "content/public/browser/resource_dispatcher_host_delegate.h" +#include "extensions/buildflags/buildflags.h" + +#include "web_contents_adapter_client.h" + +namespace QtWebEngineCore { + +class ResourceDispatcherHostDelegateQt : public content::ResourceDispatcherHostDelegate { +public: + // If the stream will be rendered in a BrowserPlugin, |payload| will contain + // the data that should be given to the old ResourceHandler to forward to the + // renderer process. + bool ShouldInterceptResourceAsStream(net::URLRequest *request, + const std::string &mime_type, + GURL *origin, + std::string *payload) override; + + // Informs the delegate that a Stream was created. The Stream can be read from + // the blob URL of the Stream, but can only be read once. + void OnStreamCreated(net::URLRequest *request, + std::unique_ptr<content::StreamInfo> stream) override; +private: +#if BUILDFLAG(ENABLE_EXTENSIONS) + struct StreamTargetInfo { + std::string extension_id; + std::string view_id; + }; + std::map<net::URLRequest *, StreamTargetInfo> stream_target_info_; +#endif + +}; + +} // namespace QtWebEngineCore + +#endif // RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H diff --git a/src/core/resource_context_qt.cpp b/src/core/resource_context_qt.cpp index 6dfa5064e..78be72107 100644 --- a/src/core/resource_context_qt.cpp +++ b/src/core/resource_context_qt.cpp @@ -64,4 +64,11 @@ net::URLRequestContext* ResourceContextQt::GetRequestContext() return m_io_data->urlRequestContext(); } +#if BUILDFLAG(ENABLE_EXTENSIONS) +extensions::ExtensionSystemQt* ResourceContextQt::GetExtensionSystem() +{ + return m_io_data->GetExtensionSystem(); +} +#endif // BUILDFLAG(ENABLE_EXTENSIONS) + } // namespace QtWebEngineCore diff --git a/src/core/resource_context_qt.h b/src/core/resource_context_qt.h index 6a5e7a74e..08359c79c 100644 --- a/src/core/resource_context_qt.h +++ b/src/core/resource_context_qt.h @@ -42,6 +42,20 @@ #include "content/public/browser/resource_context.h" +#include "extensions/buildflags/buildflags.h" + +namespace net { +class URLRequestContextGetter; +} + +#if BUILDFLAG(ENABLE_EXTENSIONS) +namespace extensions { +class ExtensionSystemQt; +} +#endif // BUILDFLAG(ENABLE_EXTENSIONS) + +class GURL; + namespace QtWebEngineCore { class ProfileIODataQt; @@ -51,6 +65,9 @@ class ResourceContextQt : public content::ResourceContext public: ResourceContextQt(ProfileIODataQt *io_data); net::URLRequestContext *GetRequestContext() override; +#if BUILDFLAG(ENABLE_EXTENSIONS) + extensions::ExtensionSystemQt* GetExtensionSystem(); +#endif // BUILDFLAG(ENABLE_EXTENSIONS) private: ProfileIODataQt* m_io_data; DISALLOW_COPY_AND_ASSIGN(ResourceContextQt); diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 68bbc3daa..0c884d265 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -84,6 +84,9 @@ #include "content/public/common/url_constants.h" #include "content/public/common/web_preferences.h" #include "content/public/common/webrtc_ip_handling_policy.h" +#include "extensions/buildflags/buildflags.h" +#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h" +//#include "third_party/blink/public/web/web_find_options.h" #include "third_party/blink/public/web/web_media_player_action.h" #include "printing/buildflags/buildflags.h" #include "ui/base/clipboard/clipboard.h" @@ -95,6 +98,10 @@ #include <QtWebChannel/QWebChannel> #endif +#if BUILDFLAG(ENABLE_EXTENSIONS) +#include "extensions/extension_web_contents_observer_qt.h" +#endif + #include <QDir> #include <QGuiApplication> #include <QPageLayout> @@ -507,6 +514,9 @@ void WebContentsAdapter::initialize(content::SiteInstance *site) #if QT_CONFIG(webengine_printing_and_pdf) PrintViewManagerQt::CreateForWebContents(webContents()); #endif +#if BUILDFLAG(ENABLE_EXTENSIONS) + extensions::ExtensionWebContentsObserverQt::CreateForWebContents(webContents()); +#endif // Create an instance of WebEngineVisitedLinksManager to catch the first // content::NOTIFICATION_RENDERER_PROCESS_CREATED event. This event will @@ -1275,16 +1285,6 @@ void WebContentsAdapter::grantMouseLockPermission(bool granted) m_webContents->GotResponseToLockMouseRequest(granted); } -void WebContentsAdapter::dpiScaleChanged() -{ - CHECK_INITIALIZED(); - content::RenderWidgetHostImpl* impl = NULL; - if (m_webContents->GetRenderViewHost()) - impl = content::RenderWidgetHostImpl::From(m_webContents->GetRenderViewHost()->GetWidget()); - if (impl) - impl->NotifyScreenInfoChanged(); -} - void WebContentsAdapter::setBackgroundColor(const QColor &color) { CHECK_INITIALIZED(); diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h index e8e5359be..b4a01fb17 100644 --- a/src/core/web_contents_adapter.h +++ b/src/core/web_contents_adapter.h @@ -184,7 +184,6 @@ public: void runGeolocationRequestCallback(const QUrl &securityOrigin, bool allowed); void grantMouseLockPermission(bool granted); - void dpiScaleChanged(); void setBackgroundColor(const QColor &color); QAccessibleInterface *browserAccessible(); ProfileQt* profile(); diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index 4a36e77f9..f4937f0d4 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -424,7 +424,6 @@ public: virtual void selectionChanged() = 0; virtual void recentlyAudibleChanged(bool recentlyAudible) = 0; virtual QRectF viewportRect() const = 0; - virtual qreal dpiScale() const = 0; virtual QColor backgroundColor() const = 0; virtual void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) = 0; virtual void loadCommitted() = 0; diff --git a/src/core/web_contents_view_qt.cpp b/src/core/web_contents_view_qt.cpp index 648e0fd8f..550a98a52 100644 --- a/src/core/web_contents_view_qt.cpp +++ b/src/core/web_contents_view_qt.cpp @@ -239,7 +239,7 @@ void WebContentsViewQt::StartDragging(const content::DropData &drop_data, QPixmap pixmap; QPoint hotspot; - pixmap = QPixmap::fromImage(toQImage(image.GetRepresentation(m_client->dpiScale()))); + pixmap = QPixmap::fromImage(toQImage(image.GetRepresentation(1.0))); if (!pixmap.isNull()) { hotspot.setX(image_offset.x()); hotspot.setY(image_offset.y()); diff --git a/src/core/web_engine_context.cpp b/src/core/web_engine_context.cpp index 90b1bffa5..63a1637fe 100644 --- a/src/core/web_engine_context.cpp +++ b/src/core/web_engine_context.cpp @@ -51,6 +51,7 @@ #include "cc/base/switches.h" #if QT_CONFIG(webengine_printing_and_pdf) #include "chrome/browser/printing/print_job_manager.h" +#include "components/printing/browser/features.h" #endif #include "components/viz/common/features.h" #include "components/web_cache/browser/web_cache_manager.h" @@ -457,6 +458,10 @@ WebEngineContext::WebEngineContext() appendToFeatureSwitch(parsedCommandLine, switches::kDisableFeatures, features::kBackgroundFetch.name); +#if QT_CONFIG(webengine_printing_and_pdf) + appendToFeatureSwitch(parsedCommandLine, switches::kDisableFeatures, printing::features::kUsePdfCompositorServiceForPrint.name); +#endif + if (useEmbeddedSwitches) { // embedded switches are based on the switches for Android, see content/browser/android/content_startup_flags.cc appendToFeatureSwitch(parsedCommandLine, switches::kEnableFeatures, features::kOverlayScrollbar.name); diff --git a/src/core/web_event_factory.cpp b/src/core/web_event_factory.cpp index 339a3ef0e..b97696030 100644 --- a/src/core/web_event_factory.cpp +++ b/src/core/web_event_factory.cpp @@ -1354,10 +1354,10 @@ static WebPointerProperties::PointerType pointerTypeForTabletEvent(const QTablet } #endif -WebMouseEvent WebEventFactory::toWebMouseEvent(QMouseEvent *ev, double dpiScale) +WebMouseEvent WebEventFactory::toWebMouseEvent(QMouseEvent *ev) { WebMouseEvent webKitEvent(webEventTypeForEvent(ev), - WebFloatPoint(ev->x() / dpiScale, ev->y() / dpiScale), + WebFloatPoint(ev->x(), ev->y()), WebFloatPoint(ev->globalX(), ev->globalY()), mouseButtonForEvent<QMouseEvent>(ev), 0, @@ -1369,14 +1369,14 @@ WebMouseEvent WebEventFactory::toWebMouseEvent(QMouseEvent *ev, double dpiScale) return webKitEvent; } -WebMouseEvent WebEventFactory::toWebMouseEvent(QHoverEvent *ev, double dpiScale) +WebMouseEvent WebEventFactory::toWebMouseEvent(QHoverEvent *ev) { WebMouseEvent webKitEvent; webKitEvent.SetTimeStamp(base::TimeTicks::Now()); webKitEvent.SetModifiers(modifiersForEvent(ev)); webKitEvent.SetType(webEventTypeForEvent(ev)); - webKitEvent.SetPositionInWidget(ev->pos().x() / dpiScale, ev->pos().y() / dpiScale); + webKitEvent.SetPositionInWidget(ev->pos().x(), ev->pos().y()); webKitEvent.movement_x = ev->pos().x() - ev->oldPos().x(); webKitEvent.movement_y = ev->pos().y() - ev->oldPos().y(); webKitEvent.pointer_type = WebPointerProperties::PointerType::kMouse; @@ -1385,10 +1385,10 @@ WebMouseEvent WebEventFactory::toWebMouseEvent(QHoverEvent *ev, double dpiScale) } #if QT_CONFIG(tabletevent) -WebMouseEvent WebEventFactory::toWebMouseEvent(QTabletEvent *ev, double dpiScale) +WebMouseEvent WebEventFactory::toWebMouseEvent(QTabletEvent *ev) { WebMouseEvent webKitEvent(webEventTypeForEvent(ev), - WebFloatPoint(ev->x() / dpiScale, ev->y() / dpiScale), + WebFloatPoint(ev->x(), ev->y()), WebFloatPoint(ev->globalX(), ev->globalY()), mouseButtonForEvent<QTabletEvent>(ev), 0, @@ -1416,17 +1416,17 @@ WebMouseEvent WebEventFactory::toWebMouseEvent(QEvent *ev) } #ifndef QT_NO_GESTURES -WebGestureEvent WebEventFactory::toWebGestureEvent(QNativeGestureEvent *ev, double dpiScale) +WebGestureEvent WebEventFactory::toWebGestureEvent(QNativeGestureEvent *ev) { WebGestureEvent webKitEvent; webKitEvent.SetTimeStamp(base::TimeTicks::Now()); webKitEvent.SetModifiers(modifiersForEvent(ev)); - webKitEvent.SetPositionInWidget(WebFloatPoint(ev->localPos().x() / dpiScale, - ev->localPos().y() / dpiScale)); + webKitEvent.SetPositionInWidget(WebFloatPoint(ev->localPos().x(), + ev->localPos().y())); - webKitEvent.SetPositionInScreen(WebFloatPoint(ev->screenPos().x() / dpiScale, - ev->screenPos().y() / dpiScale)); + webKitEvent.SetPositionInScreen(WebFloatPoint(ev->screenPos().x(), + ev->screenPos().y())); webKitEvent.SetSourceDevice(blink::kWebGestureDeviceTouchpad); @@ -1484,13 +1484,13 @@ blink::WebMouseWheelEvent::Phase toBlinkPhase(QWheelEvent *ev) return blink::WebMouseWheelEvent::kPhaseNone; } -blink::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev, double dpiScale) +blink::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev) { WebMouseWheelEvent webEvent; webEvent.SetType(webEventTypeForEvent(ev)); webEvent.SetModifiers(modifiersForEvent(ev)); webEvent.SetTimeStamp(base::TimeTicks::Now()); - webEvent.SetPositionInWidget(ev->x() / dpiScale, ev->y() / dpiScale); + webEvent.SetPositionInWidget(ev->x(), ev->y()); webEvent.SetPositionInScreen(ev->globalX(), ev->globalY()); webEvent.wheel_ticks_x = static_cast<float>(ev->angleDelta().x()) / QWheelEvent::DefaultDeltasPerStep; @@ -1506,7 +1506,7 @@ blink::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev, doub return webEvent; } -bool WebEventFactory::coalesceWebWheelEvent(blink::WebMouseWheelEvent &webEvent, QWheelEvent *ev, double dpiScale) +bool WebEventFactory::coalesceWebWheelEvent(blink::WebMouseWheelEvent &webEvent, QWheelEvent *ev) { if (webEventTypeForEvent(ev) != webEvent.GetType()) return false; @@ -1520,7 +1520,7 @@ bool WebEventFactory::coalesceWebWheelEvent(blink::WebMouseWheelEvent &webEvent, #endif webEvent.SetTimeStamp(base::TimeTicks::Now()); - webEvent.SetPositionInWidget(ev->x() / dpiScale, ev->y() / dpiScale); + webEvent.SetPositionInWidget(ev->x(), ev->y()); webEvent.SetPositionInScreen(ev->globalX(), ev->globalY()); webEvent.wheel_ticks_x += static_cast<float>(ev->angleDelta().x()) / QWheelEvent::DefaultDeltasPerStep; diff --git a/src/core/web_event_factory.h b/src/core/web_event_factory.h index 4b22de7d7..526202cfb 100644 --- a/src/core/web_event_factory.h +++ b/src/core/web_event_factory.h @@ -66,17 +66,17 @@ QT_END_NAMESPACE class WebEventFactory { public: - static blink::WebMouseEvent toWebMouseEvent(QMouseEvent*, double dpiScale); - static blink::WebMouseEvent toWebMouseEvent(QHoverEvent*, double dpiScale); + static blink::WebMouseEvent toWebMouseEvent(QMouseEvent *); + static blink::WebMouseEvent toWebMouseEvent(QHoverEvent *); #ifndef QT_NO_TABLETEVENT - static blink::WebMouseEvent toWebMouseEvent(QTabletEvent*, double dpiScale); + static blink::WebMouseEvent toWebMouseEvent(QTabletEvent *); #endif static blink::WebMouseEvent toWebMouseEvent(QEvent *); #ifndef QT_NO_GESTURES - static blink::WebGestureEvent toWebGestureEvent(QNativeGestureEvent *, double dpiScale); + static blink::WebGestureEvent toWebGestureEvent(QNativeGestureEvent *); #endif - static blink::WebMouseWheelEvent toWebWheelEvent(QWheelEvent*, double dpiScale); - static bool coalesceWebWheelEvent(blink::WebMouseWheelEvent &, QWheelEvent*, double dpiScale); + static blink::WebMouseWheelEvent toWebWheelEvent(QWheelEvent *); + static bool coalesceWebWheelEvent(blink::WebMouseWheelEvent &, QWheelEvent *); static content::NativeWebKeyboardEvent toWebKeyboardEvent(QKeyEvent*); static bool getEditCommand(QKeyEvent *event, std::string *editCommand); }; diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 59431cadc..5e6a45924 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -128,7 +128,6 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate() , m_webChannel(0) , m_webChannelWorld(0) , m_isBeingAdopted(false) - , m_dpiScale(1.0) , m_backgroundColor(Qt::white) , m_zoomFactor(1.0) , m_ui2Enabled(false) @@ -415,11 +414,6 @@ QRectF QQuickWebEngineViewPrivate::viewportRect() const return QRectF(q->x(), q->y(), q->width(), q->height()); } -qreal QQuickWebEngineViewPrivate::dpiScale() const -{ - return m_dpiScale; -} - QColor QQuickWebEngineViewPrivate::backgroundColor() const { return m_backgroundColor; diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index 3c985cba1..4e8657651 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -109,7 +109,6 @@ public: void selectionChanged() override { } void recentlyAudibleChanged(bool recentlyAudible) override; QRectF viewportRect() const override; - qreal dpiScale() const override; QColor backgroundColor() const override; void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) override; void loadCommitted() override; @@ -218,7 +217,6 @@ public: private: QScopedPointer<QtWebEngineCore::UIDelegatesManager> m_uIDelegatesManager; QList<QQuickWebEngineScript *> m_userScripts; - qreal m_dpiScale; QColor m_backgroundColor; qreal m_zoomFactor; bool m_ui2Enabled; diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 5940319c3..22ef8fffe 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -267,11 +267,6 @@ QRectF QWebEnginePagePrivate::viewportRect() const return view ? view->rect() : QRectF(); } -qreal QWebEnginePagePrivate::dpiScale() const -{ - return 1.0; -} - QColor QWebEnginePagePrivate::backgroundColor() const { return m_backgroundColor; diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index e60438d97..bf2f43f80 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -100,7 +100,6 @@ public: void selectionChanged() override; void recentlyAudibleChanged(bool recentlyAudible) override; QRectF viewportRect() const override; - qreal dpiScale() const override; QColor backgroundColor() const override; void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) override; void loadCommitted() override { } |