diff options
Diffstat (limited to 'src/core/extensions')
17 files changed, 2271 insertions, 0 deletions
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_ |