diff options
Diffstat (limited to 'src/core/extensions/extension_system_qt.cpp')
-rw-r--r-- | src/core/extensions/extension_system_qt.cpp | 315 |
1 files changed, 114 insertions, 201 deletions
diff --git a/src/core/extensions/extension_system_qt.cpp b/src/core/extensions/extension_system_qt.cpp index 4ca407421..b9f11646d 100644 --- a/src/core/extensions/extension_system_qt.cpp +++ b/src/core/extensions/extension_system_qt.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** 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) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be @@ -47,7 +11,7 @@ #include "base/base_paths.h" #include "base/base_switches.h" -#include "base/bind.h" +#include "base/functional/bind.h" #include "base/command_line.h" #include "base/files/file_path.h" #include "base/files/file_util.h" @@ -57,19 +21,21 @@ #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 "chrome/common/buildflags.h" #include "components/crx_file/id_util.h" +#include "components/value_store/value_store_factory.h" +#include "components/value_store/value_store_factory_impl.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/app_sorting.h" #include "extensions/browser/content_verifier.h" #include "extensions/browser/content_verifier_delegate.h" #include "extensions/browser/extension_pref_store.h" @@ -77,24 +43,24 @@ #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/browser/task_queue_util.h" +#include "extensions/browser/user_script_manager.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" +#include "pdf/buildflags.h" +#include "ppapi/buildflags/buildflags.h" +#include "qtwebengine/grit/qt_webengine_resources.h" +#include "ui/base/resource/resource_bundle.h" + +#if BUILDFLAG(ENABLE_PLUGINS) +#include "content/public/browser/plugin_service.h" +#endif using content::BrowserThread; @@ -102,110 +68,85 @@ namespace extensions { namespace { -std::string GenerateId(const base::DictionaryValue *manifest, - const base::FilePath &path) +std::string GenerateId(const base::Value::Dict &manifest, const base::FilePath &path) { - std::string raw_key; + const std::string *raw_key; std::string id_input; - CHECK(manifest->GetString(manifest_keys::kPublicKey, &raw_key)); - CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input)); + CHECK(raw_key = manifest.FindString(manifest_keys::kPublicKey)); + 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) +absl::optional<base::Value::Dict> ParseManifest(base::StringPiece manifest_contents) { JSONStringValueDeserializer deserializer(manifest_contents); - std::unique_ptr<base::Value> manifest(deserializer.Deserialize(NULL, NULL)); + std::unique_ptr<base::Value> manifest = deserializer.Deserialize(nullptr, nullptr); if (!manifest.get() || !manifest->is_dict()) { LOG(ERROR) << "Failed to parse extension manifest."; - return NULL; + return absl::nullopt; } - // Transfer ownership to the caller. - return base::DictionaryValue::From(std::move(manifest)); + + return std::move(*manifest).TakeDict(); } } // 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; +class ContentVerifierDelegateQt : public ContentVerifierDelegate +{ +public: + ~ContentVerifierDelegateQt() override {} + + // This should return what verification mode is appropriate for the given + // extension, if any. + VerifierSourceType GetVerifierSourceType(const Extension &extension) override + { return VerifierSourceType::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>(); } - // 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 { - - } + // 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) +void ExtensionSystemQt::LoadExtension(std::string extension_id, const base::Value::Dict &manifest, const base::FilePath &directory) { int flags = Extension::REQUIRE_KEY; std::string error; + scoped_refptr<const Extension> extension = Extension::Create( directory, - Manifest::COMPONENT, - *manifest, + mojom::ManifestLocation::kComponent, + 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) { @@ -215,11 +156,7 @@ void ExtensionSystemQt::NotifyExtensionLoaded(const Extension *extension) // 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))); + ActivateTaskQueueForExtension(browser_context_, extension); // Tell renderers about the loaded extension. renderer_helper_->OnExtensionLoaded(*extension); @@ -233,14 +170,18 @@ void ExtensionSystemQt::NotifyExtensionLoaded(const Extension *extension) // know about it. extension_registry_->TriggerOnLoaded(extension); +#if BUILDFLAG(ENABLE_PLUGINS) // Register plugins included with the extension. // Implementation based on PluginManager::OnExtensionLoaded. + bool plugins_changed = false; const MimeTypesHandler *handler = MimeTypesHandler::GetHandler(extension); - if (handler && !handler->handler_url().empty()) { + if (handler && handler->HasPlugin()) { + plugins_changed = true; 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()); + info.path = handler->GetPluginPath(); + info.background_color = handler->GetBackgroundColor(); 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; @@ -257,6 +198,13 @@ void ExtensionSystemQt::NotifyExtensionLoaded(const Extension *extension) plugin_service->RefreshPlugins(); plugin_service->RegisterInternalPlugin(info, true); } + if (plugins_changed) + content::PluginService::GetInstance()->PurgePluginListCache(browser_context_, false); +#endif // BUILDFLAG(ENABLE_PLUGINS) + + extension_registry_->AddReady(extension); + if (extension_registry_->enabled_extensions().Contains(extension->id())) + extension_registry_->TriggerOnReady(extension); } bool ExtensionSystemQt::FinishDelayedInstallationIfReady(const std::string &extension_id, bool install_immediately) @@ -281,19 +229,14 @@ 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() +UserScriptManager *ExtensionSystemQt::user_script_manager() { - return shared_user_script_master_.get(); + return user_script_manager_.get(); } StateStore *ExtensionSystemQt::state_store() @@ -306,16 +249,14 @@ StateStore *ExtensionSystemQt::rules_store() return nullptr; } -scoped_refptr<ValueStoreFactory> ExtensionSystemQt::store_factory() +StateStore *ExtensionSystemQt::dynamic_user_scripts_store() { - return store_factory_; + return nullptr; } -InfoMap *ExtensionSystemQt::info_map() +scoped_refptr<value_store::ValueStoreFactory> ExtensionSystemQt::store_factory() { - if (!info_map_.get()) - info_map_ = new InfoMap; - return info_map_.get(); + return store_factory_; } QuotaService *ExtensionSystemQt::quota_service() @@ -325,7 +266,7 @@ QuotaService *ExtensionSystemQt::quota_service() AppSorting *ExtensionSystemQt::app_sorting() { - return app_sorting_.get(); + return nullptr; } ContentVerifier *ExtensionSystemQt::content_verifier() @@ -338,7 +279,7 @@ ContentVerifier *ExtensionSystemQt::content_verifier() ExtensionSystemQt::ExtensionSystemQt(content::BrowserContext *browserContext) : browser_context_(browserContext) - , store_factory_(new ValueStoreFactoryImpl(browserContext->GetPath())) + , store_factory_(new value_store::ValueStoreFactoryImpl(browserContext->GetPath())) , extension_registry_(ExtensionRegistry::Get(browserContext)) , renderer_helper_(extensions::RendererStartupHelperFactory::GetForBrowserContext(browserContext)) , initialized_(false) @@ -357,13 +298,9 @@ void ExtensionSystemQt::Init(bool extensions_enabled) 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_); + service_worker_manager_ = std::make_unique<ServiceWorkerManager>(browser_context_); + user_script_manager_ = std::make_unique<UserScriptManager>(browser_context_); + quota_service_ = std::make_unique<QuotaService>(); // Make the chrome://extension-icon/ resource available. // content::URLDataSource::Add(browser_context_, new ExtensionIconSource(browser_context_)); @@ -371,20 +308,34 @@ void ExtensionSystemQt::Init(bool extensions_enabled) 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); + +#if BUILDFLAG(ENABLE_PDF) + { + std::string pdf_manifest = ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(IDR_PDF_MANIFEST); + base::ReplaceFirstSubstringAfterOffset(&pdf_manifest, 0, "<NAME>", "chromium-pdf"); + + auto pdfManifestDict = ParseManifest(pdf_manifest); + CHECK(pdfManifestDict); + 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.value(), path); + LoadExtension(id, pdfManifestDict.value(), path); + } +#endif // BUILDFLAG(ENABLE_PDF) + +#if BUILDFLAG(ENABLE_HANGOUT_SERVICES_EXTENSION) + { + std::string hangout_manifest = ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(IDR_HANGOUT_SERVICES_MANIFEST); + auto hangoutManifestDict = ParseManifest(hangout_manifest); + CHECK(hangoutManifestDict); + base::FilePath path; + base::PathService::Get(base::DIR_QT_LIBRARY_DATA, &path); + path = path.Append(base::FilePath(FILE_PATH_LITERAL("hangout_services"))); + std::string id = GenerateId(hangoutManifestDict.value(), path); + LoadExtension(id, hangoutManifestDict.value(), path); + } +#endif // BUILDFLAG(ENABLE_HANGOUT_SERVICES_EXTENSION) } } @@ -392,56 +343,18 @@ 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) +bool ExtensionSystemQt::is_ready() const { - 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); + return ready_.is_signaled(); } -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 |