diff options
Diffstat (limited to 'src/core/extensions')
25 files changed, 518 insertions, 1108 deletions
diff --git a/src/core/extensions/component_extension_resource_manager_qt.cpp b/src/core/extensions/component_extension_resource_manager_qt.cpp index 2b6a24541..428f673d3 100644 --- a/src/core/extensions/component_extension_resource_manager_qt.cpp +++ b/src/core/extensions/component_extension_resource_manager_qt.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // based on chrome/browser/extensions/chrome_component_extension_resource_manager.cc: // Copyright 2014 The Chromium Authors. All rights reserved. @@ -45,7 +9,7 @@ #include "component_extension_resource_manager_qt.h" #include "base/check.h" -#include "base/logging.h" +#include "base/containers/contains.h" #include "base/path_service.h" #include "base/stl_util.h" #include "base/values.h" @@ -73,12 +37,12 @@ ComponentExtensionResourceManagerQt::ComponentExtensionResourceManagerQt() AddComponentResourceEntries(kPdfResources, kPdfResourcesSize); #endif #if BUILDFLAG(ENABLE_PDF) - base::Value dict(base::Value::Type::DICTIONARY); + base::Value::Dict dict; pdf_extension_util::AddStrings(pdf_extension_util::PdfViewerContext::kPdfViewer, &dict); - pdf_extension_util::AddAdditionalData(&dict); + pdf_extension_util::AddAdditionalData(/*enable_annotations=*/true, &dict); ui::TemplateReplacements pdf_viewer_replacements; - ui::TemplateReplacementsFromDictionaryValue(base::Value::AsDictionaryValue(dict), &pdf_viewer_replacements); + ui::TemplateReplacementsFromDictionaryValue(dict, &pdf_viewer_replacements); template_replacements_[extension_misc::kPdfExtensionId] = std::move(pdf_viewer_replacements); #endif } diff --git a/src/core/extensions/component_extension_resource_manager_qt.h b/src/core/extensions/component_extension_resource_manager_qt.h index b029a7f71..4da18890e 100644 --- a/src/core/extensions/component_extension_resource_manager_qt.h +++ b/src/core/extensions/component_extension_resource_manager_qt.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be @@ -47,7 +11,6 @@ #include <map> #include "base/files/file_path.h" -#include "base/macros.h" #include "extensions/browser/component_extension_resource_manager.h" #include "ui/base/webui/resource_path.h" @@ -74,8 +37,6 @@ private: // A map from an extension ID to its i18n template replacements. std::map<std::string, ui::TemplateReplacements> template_replacements_; - - DISALLOW_COPY_AND_ASSIGN(ComponentExtensionResourceManagerQt); }; } // namespace extensions diff --git a/src/core/extensions/extension_host_delegate_qt.cpp b/src/core/extensions/extension_host_delegate_qt.cpp index 4db1aeb71..16133a598 100644 --- a/src/core/extensions/extension_host_delegate_qt.cpp +++ b/src/core/extensions/extension_host_delegate_qt.cpp @@ -1,48 +1,22 @@ -/**************************************************************************** -** -** Copyright (C) 2020 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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "extension_host_delegate_qt.h" + +#include "desktop_media_controller.h" +#include "desktop_media_controller_p.h" #include "extension_web_contents_observer_qt.h" #include "media_capture_devices_dispatcher.h" #include "extension_system_qt.h" +#include "web_contents_view_qt.h" +#include "base/functional/callback.h" +#include "content/browser/web_contents/web_contents_impl.h" #include "extensions/browser/extension_host.h" +#include "third_party/blink/public/mojom/mediastream/media_stream.mojom-shared.h" +#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h" + +using namespace QtWebEngineCore; namespace extensions { @@ -69,32 +43,52 @@ content::JavaScriptDialogManager *ExtensionHostDelegateQt::GetJavaScriptDialogMa void ExtensionHostDelegateQt::CreateTab(std::unique_ptr<content::WebContents> web_contents, const std::string &extension_id, WindowOpenDisposition disposition, - const gfx::Rect &initial_rect, + const blink::mojom::WindowFeatures &features, bool user_gesture) { Q_UNUSED(web_contents); Q_UNUSED(extension_id); Q_UNUSED(disposition); - Q_UNUSED(initial_rect); + Q_UNUSED(features); Q_UNUSED(user_gesture); Q_UNREACHABLE(); } +static void processMediaAccessRequest(content::WebContents *webContents, + const content::MediaStreamRequest &request, + content::MediaResponseCallback callback, + content::DesktopMediaID id) +{ + MediaCaptureDevicesDispatcher::GetInstance()->processMediaAccessRequest( + webContents, request, std::move(callback), id); +} + void ExtensionHostDelegateQt::ProcessMediaAccessRequest(content::WebContents *web_contents, const content::MediaStreamRequest &request, content::MediaResponseCallback callback, const Extension *extension) { Q_UNUSED(extension); - - QtWebEngineCore::MediaCaptureDevicesDispatcher::GetInstance()->processMediaAccessRequest(web_contents, request, std::move(callback)); + base::OnceCallback<void(content::DesktopMediaID)> cb = base::BindOnce( + &processMediaAccessRequest, web_contents, std::move(request), std::move(callback)); + + // ownership is taken by the request + auto *controller = new DesktopMediaController(new DesktopMediaControllerPrivate(std::move(cb))); + base::WeakPtr<content::WebContents> webContents = web_contents->GetWeakPtr(); + QObject::connect(controller, &DesktopMediaController::mediaListsInitialized, [controller, webContents]() { + if (webContents) { + auto *client = WebContentsViewQt::from(static_cast<content::WebContentsImpl *>(webContents.get())->GetView())->client(); + client->desktopMediaRequested(controller); + } else { + controller->deleteLater(); + } + }); } -bool ExtensionHostDelegateQt::CheckMediaAccessPermission(content::RenderFrameHost *render_frame_host, - const GURL &security_origin, - blink::mojom::MediaStreamType type, - const Extension *extension) +bool ExtensionHostDelegateQt::CheckMediaAccessPermission( + content::RenderFrameHost *render_frame_host, const url::Origin &security_origin, + blink::mojom::MediaStreamType type, const Extension *extension) { Q_UNUSED(render_frame_host); Q_UNUSED(security_origin); @@ -105,13 +99,9 @@ bool ExtensionHostDelegateQt::CheckMediaAccessPermission(content::RenderFrameHos return false; } -content::PictureInPictureResult ExtensionHostDelegateQt::EnterPictureInPicture(content::WebContents *web_contents, - const viz::SurfaceId &surface_id, - const gfx::Size &natural_size) +content::PictureInPictureResult ExtensionHostDelegateQt::EnterPictureInPicture(content::WebContents *web_contents) { Q_UNUSED(web_contents); - Q_UNUSED(surface_id); - Q_UNUSED(natural_size); Q_UNREACHABLE(); return content::PictureInPictureResult::kNotSupported; diff --git a/src/core/extensions/extension_host_delegate_qt.h b/src/core/extensions/extension_host_delegate_qt.h index 04ffb9d16..38b5d4a2f 100644 --- a/src/core/extensions/extension_host_delegate_qt.h +++ b/src/core/extensions/extension_host_delegate_qt.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef EXTENSION_HOST_DELEGATE_QT_H #define EXTENSION_HOST_DELEGATE_QT_H @@ -56,19 +20,17 @@ public: void CreateTab(std::unique_ptr<content::WebContents> web_contents, const std::string &extension_id, WindowOpenDisposition disposition, - const gfx::Rect &initial_rect, + const blink::mojom::WindowFeatures &features, bool user_gesture) override; void ProcessMediaAccessRequest(content::WebContents *web_contents, const content::MediaStreamRequest &request, content::MediaResponseCallback callback, const Extension *extension) override; bool CheckMediaAccessPermission(content::RenderFrameHost *render_frame_host, - const GURL &security_origin, + const url::Origin &security_origin, blink::mojom::MediaStreamType type, const Extension *extension) override; - content::PictureInPictureResult EnterPictureInPicture(content::WebContents *web_contents, - const viz::SurfaceId &surface_id, - const gfx::Size &natural_size) override; + content::PictureInPictureResult EnterPictureInPicture(content::WebContents *web_contents) override; void ExitPictureInPicture() override; }; diff --git a/src/core/extensions/extension_system_factory_qt.cpp b/src/core/extensions/extension_system_factory_qt.cpp index b63b41a86..63d88fcaf 100644 --- a/src/core/extensions/extension_system_factory_qt.cpp +++ b/src/core/extensions/extension_system_factory_qt.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be diff --git a/src/core/extensions/extension_system_factory_qt.h b/src/core/extensions/extension_system_factory_qt.h index 6e840b6d6..b6f6acc5d 100644 --- a/src/core/extensions/extension_system_factory_qt.h +++ b/src/core/extensions/extension_system_factory_qt.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be @@ -44,7 +8,6 @@ #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" @@ -73,8 +36,6 @@ private: 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 diff --git a/src/core/extensions/extension_system_qt.cpp b/src/core/extensions/extension_system_qt.cpp index 99b56786b..b9f11646d 100644 --- a/src/core/extensions/extension_system_qt.cpp +++ b/src/core/extensions/extension_system_qt.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be @@ -47,7 +11,7 @@ #include "base/base_paths.h" #include "base/base_switches.h" -#include "base/bind.h" +#include "base/functional/bind.h" #include "base/command_line.h" #include "base/files/file_path.h" #include "base/files/file_util.h" @@ -57,20 +21,21 @@ #include "base/path_service.h" #include "base/strings/string_tokenizer.h" #include "base/strings/utf_string_conversions.h" -#include "base/task/post_task.h" #include "base/time/time.h" #include "base/trace_event/trace_event.h" #include "build/build_config.h" #include "chrome/common/buildflags.h" #include "components/crx_file/id_util.h" +#include "components/value_store/value_store_factory.h" +#include "components/value_store/value_store_factory_impl.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_service.h" -#include "content/public/browser/plugin_service.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/url_data_source.h" #include "content/public/common/webplugininfo.h" +#include "extensions/browser/app_sorting.h" #include "extensions/browser/content_verifier.h" #include "extensions/browser/content_verifier_delegate.h" #include "extensions/browser/extension_pref_store.h" @@ -78,51 +43,53 @@ #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/service_worker_manager.h" +#include "extensions/browser/task_queue_util.h" #include "extensions/browser/user_script_manager.h" -#include "extensions/browser/value_store/value_store_factory_impl.h" #include "extensions/common/constants.h" #include "extensions/common/manifest_constants.h" #include "extensions/common/manifest_handlers/mime_types_handler.h" #include "extensions/common/manifest_url_handlers.h" #include "net/base/mime_util.h" +#include "pdf/buildflags.h" +#include "ppapi/buildflags/buildflags.h" #include "qtwebengine/grit/qt_webengine_resources.h" #include "ui/base/resource/resource_bundle.h" +#if BUILDFLAG(ENABLE_PLUGINS) +#include "content/public/browser/plugin_service.h" +#endif + using content::BrowserThread; namespace extensions { namespace { -std::string GenerateId(const base::DictionaryValue *manifest, const base::FilePath &path) +std::string GenerateId(const base::Value::Dict &manifest, const base::FilePath &path) { - std::string raw_key; + const std::string *raw_key; std::string id_input; - CHECK(manifest->GetString(manifest_keys::kPublicKey, &raw_key)); - CHECK(Extension::ParsePEMKeyBytes(raw_key, &id_input)); + CHECK(raw_key = manifest.FindString(manifest_keys::kPublicKey)); + CHECK(Extension::ParsePEMKeyBytes(*raw_key, &id_input)); std::string id = crx_file::id_util::GenerateId(id_input); return id; } // Implementation based on ComponentLoader::ParseManifest. -std::unique_ptr<base::DictionaryValue> ParseManifest(const std::string &manifest_contents) +absl::optional<base::Value::Dict> ParseManifest(base::StringPiece manifest_contents) { JSONStringValueDeserializer deserializer(manifest_contents); - std::unique_ptr<base::Value> manifest(deserializer.Deserialize(NULL, NULL)); + std::unique_ptr<base::Value> manifest = deserializer.Deserialize(nullptr, nullptr); if (!manifest.get() || !manifest->is_dict()) { LOG(ERROR) << "Failed to parse extension manifest."; - return NULL; + return absl::nullopt; } - // Transfer ownership to the caller. - return base::DictionaryValue::From(std::move(manifest)); + + return std::move(*manifest).TakeDict(); } } // namespace @@ -161,38 +128,25 @@ public: void Shutdown() override {} }; -void ExtensionSystemQt::LoadExtension(std::string extension_id, std::unique_ptr<base::DictionaryValue> manifest, const base::FilePath &directory) +void ExtensionSystemQt::LoadExtension(std::string extension_id, const base::Value::Dict &manifest, const base::FilePath &directory) { int flags = Extension::REQUIRE_KEY; std::string error; + scoped_refptr<const Extension> extension = Extension::Create( directory, - Manifest::COMPONENT, - *manifest, + mojom::ManifestLocation::kComponent, + manifest, flags, &error); if (!extension.get()) LOG(ERROR) << error; - base::PostTask(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) { @@ -202,11 +156,7 @@ void ExtensionSystemQt::NotifyExtensionLoaded(const Extension *extension) // that the request context doesn't yet know about. The profile is responsible // for ensuring its URLRequestContexts appropriately discover the loaded // extension. - RegisterExtensionWithRequestContexts( - extension, - base::Bind(&ExtensionSystemQt::OnExtensionRegisteredWithRequestContexts, - weak_ptr_factory_.GetWeakPtr(), - base::WrapRefCounted(extension))); + ActivateTaskQueueForExtension(browser_context_, extension); // Tell renderers about the loaded extension. renderer_helper_->OnExtensionLoaded(*extension); @@ -220,10 +170,13 @@ void ExtensionSystemQt::NotifyExtensionLoaded(const Extension *extension) // know about it. extension_registry_->TriggerOnLoaded(extension); +#if BUILDFLAG(ENABLE_PLUGINS) // Register plugins included with the extension. // Implementation based on PluginManager::OnExtensionLoaded. + bool plugins_changed = false; const MimeTypesHandler *handler = MimeTypesHandler::GetHandler(extension); if (handler && handler->HasPlugin()) { + plugins_changed = true; content::WebPluginInfo info; info.type = content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN; info.name = base::UTF8ToUTF16(extension->name()); @@ -245,6 +198,13 @@ void ExtensionSystemQt::NotifyExtensionLoaded(const Extension *extension) plugin_service->RefreshPlugins(); plugin_service->RegisterInternalPlugin(info, true); } + if (plugins_changed) + content::PluginService::GetInstance()->PurgePluginListCache(browser_context_, false); +#endif // BUILDFLAG(ENABLE_PLUGINS) + + extension_registry_->AddReady(extension); + if (extension_registry_->enabled_extensions().Contains(extension->id())) + extension_registry_->TriggerOnReady(extension); } bool ExtensionSystemQt::FinishDelayedInstallationIfReady(const std::string &extension_id, bool install_immediately) @@ -269,11 +229,6 @@ ExtensionService *ExtensionSystemQt::extension_service() return nullptr; } -RuntimeData *ExtensionSystemQt::runtime_data() -{ - return runtime_data_.get(); -} - ManagementPolicy *ExtensionSystemQt::management_policy() { return nullptr; @@ -294,16 +249,14 @@ StateStore *ExtensionSystemQt::rules_store() return nullptr; } -scoped_refptr<ValueStoreFactory> ExtensionSystemQt::store_factory() +StateStore *ExtensionSystemQt::dynamic_user_scripts_store() { - return store_factory_; + return nullptr; } -InfoMap *ExtensionSystemQt::info_map() +scoped_refptr<value_store::ValueStoreFactory> ExtensionSystemQt::store_factory() { - if (!info_map_.get()) - info_map_ = new InfoMap; - return info_map_.get(); + return store_factory_; } QuotaService *ExtensionSystemQt::quota_service() @@ -313,7 +266,7 @@ QuotaService *ExtensionSystemQt::quota_service() AppSorting *ExtensionSystemQt::app_sorting() { - return app_sorting_.get(); + return nullptr; } ContentVerifier *ExtensionSystemQt::content_verifier() @@ -326,7 +279,7 @@ ContentVerifier *ExtensionSystemQt::content_verifier() ExtensionSystemQt::ExtensionSystemQt(content::BrowserContext *browserContext) : browser_context_(browserContext) - , store_factory_(new ValueStoreFactoryImpl(browserContext->GetPath())) + , store_factory_(new value_store::ValueStoreFactoryImpl(browserContext->GetPath())) , extension_registry_(ExtensionRegistry::Get(browserContext)) , renderer_helper_(extensions::RendererStartupHelperFactory::GetForBrowserContext(browserContext)) , initialized_(false) @@ -345,13 +298,9 @@ void ExtensionSystemQt::Init(bool extensions_enabled) initialized_ = true; - service_worker_manager_.reset(new ServiceWorkerManager(browser_context_)); - runtime_data_.reset(new RuntimeData(extension_registry_)); - quota_service_.reset(new QuotaService); - app_sorting_.reset(new NullAppSorting); - - user_script_manager_ = - std::make_unique<UserScriptManager>(browser_context_); + service_worker_manager_ = std::make_unique<ServiceWorkerManager>(browser_context_); + user_script_manager_ = std::make_unique<UserScriptManager>(browser_context_); + quota_service_ = std::make_unique<QuotaService>(); // Make the chrome://extension-icon/ resource available. // content::URLDataSource::Add(browser_context_, new ExtensionIconSource(browser_context_)); @@ -360,27 +309,31 @@ void ExtensionSystemQt::Init(bool extensions_enabled) // Inform the rest of the extensions system to start. ready_.Signal(); +#if BUILDFLAG(ENABLE_PDF) { - std::string pdf_manifest = ui::ResourceBundle::GetSharedInstance().GetRawDataResource(IDR_PDF_MANIFEST).as_string(); + std::string pdf_manifest = ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(IDR_PDF_MANIFEST); base::ReplaceFirstSubstringAfterOffset(&pdf_manifest, 0, "<NAME>", "chromium-pdf"); - std::unique_ptr<base::DictionaryValue> pdfManifestDict = ParseManifest(pdf_manifest); + auto pdfManifestDict = ParseManifest(pdf_manifest); + CHECK(pdfManifestDict); base::FilePath path; base::PathService::Get(base::DIR_QT_LIBRARY_DATA, &path); path = path.Append(base::FilePath(FILE_PATH_LITERAL("pdf"))); - std::string id = GenerateId(pdfManifestDict.get(), path); - LoadExtension(id, std::move(pdfManifestDict), path); + std::string id = GenerateId(pdfManifestDict.value(), path); + LoadExtension(id, pdfManifestDict.value(), path); } +#endif // BUILDFLAG(ENABLE_PDF) #if BUILDFLAG(ENABLE_HANGOUT_SERVICES_EXTENSION) { - std::string hangout_manifest = ui::ResourceBundle::GetSharedInstance().GetRawDataResource(IDR_HANGOUT_SERVICES_MANIFEST).as_string(); - std::unique_ptr<base::DictionaryValue> hangoutManifestDict = ParseManifest(hangout_manifest); + std::string hangout_manifest = ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(IDR_HANGOUT_SERVICES_MANIFEST); + auto hangoutManifestDict = ParseManifest(hangout_manifest); + CHECK(hangoutManifestDict); base::FilePath path; base::PathService::Get(base::DIR_QT_LIBRARY_DATA, &path); path = path.Append(base::FilePath(FILE_PATH_LITERAL("hangout_services"))); - std::string id = GenerateId(hangoutManifestDict.get(), path); - LoadExtension(id, std::move(hangoutManifestDict), path); + std::string id = GenerateId(hangoutManifestDict.value(), path); + LoadExtension(id, hangoutManifestDict.value(), path); } #endif // BUILDFLAG(ENABLE_HANGOUT_SERVICES_EXTENSION) } @@ -390,8 +343,6 @@ 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); } @@ -401,30 +352,6 @@ std::unique_ptr<ExtensionSet> ExtensionSystemQt::GetDependentExtensions(const Ex return base::WrapUnique(new ExtensionSet()); } -void ExtensionSystemQt::RegisterExtensionWithRequestContexts(const Extension *extension, - base::OnceClosure callback) -{ - base::Time install_time = base::Time::Now(); - - bool incognito_enabled = false; - bool notifications_disabled = false; - - base::PostTaskAndReply( - FROM_HERE, {BrowserThread::IO}, - base::Bind(&InfoMap::AddExtension, info_map(), - base::RetainedRef(extension), install_time, incognito_enabled, - notifications_disabled), - std::move(callback)); -} - -void ExtensionSystemQt::UnregisterExtensionWithRequestContexts(const std::string &extension_id, - const UnloadedExtensionReason reason) -{ - base::PostTask( - FROM_HERE, {BrowserThread::IO}, - base::Bind(&InfoMap::RemoveExtension, info_map(), extension_id, reason)); -} - bool ExtensionSystemQt::is_ready() const { return ready_.is_signaled(); diff --git a/src/core/extensions/extension_system_qt.h b/src/core/extensions/extension_system_qt.h index 2ae92581a..c213671a7 100644 --- a/src/core/extensions/extension_system_qt.h +++ b/src/core/extensions/extension_system_qt.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be @@ -50,12 +14,15 @@ #include <string> #include "base/one_shot_event.h" -#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" +namespace value_store { +class ValueStoreFactory; +} + namespace extensions { class ExtensionRegistry; @@ -63,8 +30,6 @@ 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 @@ -86,23 +51,16 @@ public: // ExtensionSystem implementation: void InitForRegularProfile(bool extensions_enabled) override; ExtensionService *extension_service() override; - RuntimeData *runtime_data() override; ManagementPolicy *management_policy() override; ServiceWorkerManager *service_worker_manager() override; UserScriptManager *user_script_manager() override; StateStore *state_store() override; StateStore *rules_store() override; - scoped_refptr<ValueStoreFactory> store_factory() override; - InfoMap *info_map() override; + StateStore *dynamic_user_scripts_store() override; + scoped_refptr<value_store::ValueStoreFactory> store_factory() override; QuotaService *quota_service() override; AppSorting *app_sorting() override; - void RegisterExtensionWithRequestContexts(const Extension *extension, - base::OnceClosure 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; @@ -113,37 +71,28 @@ public: const base::OneShotEvent &ready() const override { return ready_; } bool is_ready() const override; - void PerformActionBasedOnOmahaAttributes(const std::string &, const base::Value &) override { /* fixme? */} + void PerformActionBasedOnOmahaAttributes(const std::string &, const base::Value::Dict &) override { /* fixme? */} 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_; + void LoadExtension(std::string extension_id, const base::Value::Dict &manifest, const base::FilePath &directory); + // The services that are shared between normal and incognito profiles. 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<UserScriptManager> user_script_manager_; - // For verifying the contents of extensions read from disk. scoped_refptr<ContentVerifier> content_verifier_; base::OneShotEvent ready_; content::BrowserContext *browser_context_; - scoped_refptr<ValueStoreFactory> store_factory_; + scoped_refptr<value_store::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 diff --git a/src/core/extensions/extension_web_contents_observer_qt.cpp b/src/core/extensions/extension_web_contents_observer_qt.cpp index 0959806f6..a33954a20 100644 --- a/src/core/extensions/extension_web_contents_observer_qt.cpp +++ b/src/core/extensions/extension_web_contents_observer_qt.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be @@ -43,14 +7,13 @@ #include "extension_web_contents_observer_qt.h" -#include "components/guest_view/browser/guest_view_base.h" +#include "content/browser/renderer_host/render_frame_host_impl.h" #include "content/public/browser/child_process_security_policy.h" -#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" -#include "content/public/common/url_constants.h" #include "extensions/browser/extension_registry.h" #include "extensions/common/manifest.h" +#include "third_party/blink/public/common/chrome_debug_urls.h" #include "render_widget_host_view_qt.h" @@ -58,6 +21,7 @@ namespace extensions { ExtensionWebContentsObserverQt::ExtensionWebContentsObserverQt(content::WebContents *web_contents) : ExtensionWebContentsObserver(web_contents) + , content::WebContentsUserData<ExtensionWebContentsObserverQt>(*web_contents) { } @@ -77,6 +41,8 @@ void ExtensionWebContentsObserverQt::CreateForWebContents(content::WebContents * void ExtensionWebContentsObserverQt::RenderFrameCreated(content::RenderFrameHost *render_frame_host) { ExtensionWebContentsObserver::RenderFrameCreated(render_frame_host); + QtWebEngineCore::RenderWidgetHostViewQt::registerInputEventObserver(web_contents(), + render_frame_host); const Extension *extension = GetExtensionFromFrame(render_frame_host, false); if (!extension) @@ -86,19 +52,9 @@ void ExtensionWebContentsObserverQt::RenderFrameCreated(content::RenderFrameHost auto *policy = content::ChildProcessSecurityPolicy::GetInstance(); if (extension->is_extension() && Manifest::IsComponentLocation(extension->location())) - policy->GrantRequestOrigin(process_id, url::Origin::Create(GURL(content::kChromeUIResourcesURL))); + policy->GrantRequestOrigin(process_id, url::Origin::Create(GURL(blink::kChromeUIResourcesURL))); } -void ExtensionWebContentsObserverQt::RenderViewReady() -{ - if (web_contents()->IsInnerWebContentsForGuest()) { - content::RenderWidgetHost *render_widget_host = web_contents()->GetRenderViewHost()->GetWidget(); - content::WebContents *parent_web_contents = guest_view::GuestViewBase::GetTopLevelWebContents(web_contents()); - QtWebEngineCore::RenderWidgetHostViewQt *parent_rwhv = static_cast<QtWebEngineCore::RenderWidgetHostViewQt *>(parent_web_contents->GetRenderWidgetHostView()); - parent_rwhv->setGuest(static_cast<content::RenderWidgetHostImpl *>(render_widget_host)); - } -} - -WEB_CONTENTS_USER_DATA_KEY_IMPL(ExtensionWebContentsObserverQt) +WEB_CONTENTS_USER_DATA_KEY_IMPL(ExtensionWebContentsObserverQt); } // namespace extensions diff --git a/src/core/extensions/extension_web_contents_observer_qt.h b/src/core/extensions/extension_web_contents_observer_qt.h index 346e94d4a..ff50b28e2 100644 --- a/src/core/extensions/extension_web_contents_observer_qt.h +++ b/src/core/extensions/extension_web_contents_observer_qt.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be @@ -61,12 +25,10 @@ public: // content::WebContentsObserver overrides. void RenderFrameCreated(content::RenderFrameHost *render_frame_host) override; - void RenderViewReady() override; private: friend class content::WebContentsUserData<ExtensionWebContentsObserverQt>; WEB_CONTENTS_USER_DATA_KEY_DECL(); - DISALLOW_COPY_AND_ASSIGN(ExtensionWebContentsObserverQt); }; } // namespace extensions diff --git a/src/core/extensions/extensions_api_client_qt.cpp b/src/core/extensions/extensions_api_client_qt.cpp index 925fd10da..678c252cc 100644 --- a/src/core/extensions/extensions_api_client_qt.cpp +++ b/src/core/extensions/extensions_api_client_qt.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Portions copyright 2015 The Chromium Embedded Framework Authors. // Portions copyright 2014 The Chromium Authors. All rights reserved. @@ -43,15 +7,21 @@ // found in the LICENSE file. #include "extensions_api_client_qt.h" +#include "file_system_delegate_qt.h" #include "messaging_delegate_qt.h" #include <memory> -#include "components/pdf/browser/pdf_web_contents_helper.h" + #include "extension_web_contents_observer_qt.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 "mime_handler_view_guest_delegate_qt.h" +#include "pdf/buildflags.h" +#include "printing/buildflags/buildflags.h" + +#if BUILDFLAG(ENABLE_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) #include "printing/print_view_manager_qt.h" +#endif namespace extensions { @@ -66,9 +36,16 @@ AppViewGuestDelegate *ExtensionsAPIClientQt::CreateAppViewGuestDelegate() const return nullptr; } -std::unique_ptr<guest_view::GuestViewManagerDelegate> ExtensionsAPIClientQt::CreateGuestViewManagerDelegate(content::BrowserContext *context) const +FileSystemDelegate *ExtensionsAPIClientQt::GetFileSystemDelegate() +{ + if (!m_fileSystemDelegate) + m_fileSystemDelegate = std::make_unique<FileSystemDelegateQt>(); + return m_fileSystemDelegate.get(); +} + +std::unique_ptr<guest_view::GuestViewManagerDelegate> ExtensionsAPIClientQt::CreateGuestViewManagerDelegate() const { - return std::make_unique<extensions::ExtensionsGuestViewManagerDelegate>(context); + return std::make_unique<extensions::ExtensionsGuestViewManagerDelegate>(); } std::unique_ptr<MimeHandlerViewGuestDelegate> ExtensionsAPIClientQt::CreateMimeHandlerViewGuestDelegate(MimeHandlerViewGuest *guest) const @@ -79,7 +56,9 @@ std::unique_ptr<MimeHandlerViewGuestDelegate> ExtensionsAPIClientQt::CreateMimeH void ExtensionsAPIClientQt::AttachWebContentsHelpers(content::WebContents *web_contents) const { // PrefsTabHelper::CreateForWebContents(web_contents); +#if BUILDFLAG(ENABLE_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) QtWebEngineCore::PrintViewManagerQt::CreateForWebContents(web_contents); +#endif ExtensionWebContentsObserverQt::CreateForWebContents(web_contents); } diff --git a/src/core/extensions/extensions_api_client_qt.h b/src/core/extensions/extensions_api_client_qt.h index b1b6356e8..e7838138c 100644 --- a/src/core/extensions/extensions_api_client_qt.h +++ b/src/core/extensions/extensions_api_client_qt.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Portions copyright 2015 The Chromium Embedded Framework Authors. // Portions copyright 2014 The Chromium Authors. All rights reserved. @@ -49,6 +13,7 @@ namespace extensions { +class FileSystemDelegate; class MessagingDelegate; class ExtensionsAPIClientQt : public ExtensionsAPIClient @@ -58,14 +23,16 @@ public: // ExtensionsAPIClient implementation. AppViewGuestDelegate *CreateAppViewGuestDelegate() const override; + FileSystemDelegate *GetFileSystemDelegate() override; std::unique_ptr<guest_view::GuestViewManagerDelegate> - CreateGuestViewManagerDelegate(content::BrowserContext *context) const override; + CreateGuestViewManagerDelegate() const override; std::unique_ptr<MimeHandlerViewGuestDelegate> CreateMimeHandlerViewGuestDelegate(MimeHandlerViewGuest *guest) const override; void AttachWebContentsHelpers(content::WebContents *web_contents) const override; MessagingDelegate *GetMessagingDelegate() override; private: + std::unique_ptr<FileSystemDelegate> m_fileSystemDelegate; std::unique_ptr<MessagingDelegate> m_messagingDelegate; }; diff --git a/src/core/extensions/extensions_browser_client_qt.cpp b/src/core/extensions/extensions_browser_client_qt.cpp index 406facc5c..36151cee5 100644 --- a/src/core/extensions/extensions_browser_client_qt.cpp +++ b/src/core/extensions/extensions_browser_client_qt.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Portions copyright 2015 The Chromium Embedded Framework Authors. // Portions copyright 2014 The Chromium Authors. All rights reserved. @@ -49,15 +13,15 @@ #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" #include "base/path_service.h" -#include "base/task/post_task.h" +#include "base/task/thread_pool.h" #include "base/memory/ref_counted_memory.h" #include "chrome/browser/extensions/api/generated_api_registration.h" #include "chrome/browser/profiles/profile.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/render_frame_host.h" +#include "extensions/browser/api/core_extensions_browser_api_provider.h" #include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/api/runtime/runtime_api_delegate.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" @@ -67,6 +31,7 @@ #include "extensions/common/file_util.h" #include "net/base/mime_util.h" #include "qtwebengine/browser/extensions/api/generated_api_registration.h" +#include "services/network/public/cpp/resource_request.h" #include "services/network/public/mojom/url_loader.mojom.h" #include "services/network/public/mojom/url_response_head.mojom.h" #include "third_party/zlib/google/compression_utils.h" @@ -114,7 +79,7 @@ scoped_refptr<base::RefCountedMemory> GetResource(int resource_id, const std::st base::StringPiece input(reinterpret_cast<const char *>(bytes->front()), bytes->size()); std::string temp_str = ui::ReplaceTemplateExpressions(input, *replacements); DCHECK(!temp_str.empty()); - return base::RefCountedString::TakeString(&temp_str); + return base::MakeRefCounted<base::RefCountedString>(std::move(temp_str)); } return bytes; } @@ -128,12 +93,12 @@ public: mojo::PendingReceiver<network::mojom::URLLoader> loader, mojo::PendingRemote<network::mojom::URLLoaderClient> client_info, const base::FilePath &filename, int resource_id, - const std::string &content_security_policy, bool send_cors_header) + scoped_refptr<net::HttpResponseHeaders> headers) { // Owns itself. Will live as long as its URLLoader and URLLoaderClientPtr // bindings are alive - essentially until either the client gives up or all // file data has been sent to it. - auto *bundle_loader = new ResourceBundleFileLoader(content_security_policy, send_cors_header); + auto *bundle_loader = new ResourceBundleFileLoader(std::move(headers)); bundle_loader->Start(request, std::move(loader), std::move(client_info), filename, resource_id); } @@ -141,7 +106,7 @@ public: void FollowRedirect(const std::vector<std::string> &removed_headers, const net::HttpRequestHeaders &modified_headers, const net::HttpRequestHeaders &modified_cors_exempt_headers, - const base::Optional<GURL> &new_url) override + const absl::optional<GURL> &new_url) override { NOTREACHED() << "No redirects for local file loads."; } @@ -152,9 +117,9 @@ public: void ResumeReadingBodyFromNet() override {} private: - ResourceBundleFileLoader(const std::string &content_security_policy, bool send_cors_header) + ResourceBundleFileLoader(scoped_refptr<net::HttpResponseHeaders> headers) + : response_headers_(std::move(headers)) { - response_headers_ = extensions::BuildHttpHeaders(content_security_policy, send_cors_header, base::Time()); } ~ResourceBundleFileLoader() override = default; @@ -172,8 +137,8 @@ private: auto data = GetResource(resource_id, request.url.host()); std::string *read_mime_type = new std::string; - base::PostTaskAndReplyWithResult( - FROM_HERE, { base::ThreadPool(), base::MayBlock() }, + base::ThreadPool::PostTaskAndReplyWithResult( + FROM_HERE, { base::MayBlock() }, base::BindOnce(&net::GetMimeTypeFromFile, filename, base::Unretained(read_mime_type)), base::BindOnce(&ResourceBundleFileLoader::OnMimeTypeRead, weak_factory_.GetWeakPtr(), std::move(data), base::Owned(read_mime_type))); @@ -201,8 +166,7 @@ private: if (!head->mime_type.empty()) { head->headers->AddHeader(net::HttpRequestHeaders::kContentType, head->mime_type.c_str()); } - client_->OnReceiveResponse(std::move(head)); - client_->OnStartLoadingResponseBody(std::move(consumer_handle)); + client_->OnReceiveResponse(std::move(head), std::move(consumer_handle), absl::nullopt); uint32_t write_size = data->size(); MojoResult result = producer_handle->WriteData(data->front(), &write_size, MOJO_WRITE_DATA_FLAG_NONE); @@ -243,8 +207,6 @@ private: mojo::Remote<network::mojom::URLLoaderClient> client_; scoped_refptr<net::HttpResponseHeaders> response_headers_; base::WeakPtrFactory<ResourceBundleFileLoader> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(ResourceBundleFileLoader); }; } // namespace @@ -264,8 +226,6 @@ public: api::ChromeGeneratedFunctionRegistry::RegisterAll(registry); } -private: - DISALLOW_COPY_AND_ASSIGN(ChromeExtensionsBrowserAPIProvider); }; class QtWebEngineExtensionsBrowserAPIProvider : public ExtensionsBrowserAPIProvider @@ -279,9 +239,6 @@ public: // Generated APIs from QtWebEngine. api::QtWebEngineGeneratedFunctionRegistry::RegisterAll(registry); } - -private: - DISALLOW_COPY_AND_ASSIGN(QtWebEngineExtensionsBrowserAPIProvider); }; ExtensionsBrowserClientQt::ExtensionsBrowserClientQt() @@ -307,7 +264,7 @@ bool ExtensionsBrowserClientQt::AreExtensionsDisabled(const base::CommandLine &c return false; } -bool ExtensionsBrowserClientQt::IsValidContext(BrowserContext *context) +bool ExtensionsBrowserClientQt::IsValidContext(void *) { return true; } @@ -334,6 +291,30 @@ BrowserContext *ExtensionsBrowserClientQt::GetOriginalContext(BrowserContext *co return context; } +content::BrowserContext* ExtensionsBrowserClientQt::GetContextRedirectedToOriginal(content::BrowserContext *context, bool) +{ + // like in ShellExtensionsBrowserClient: + return context; +} + +content::BrowserContext* ExtensionsBrowserClientQt::GetContextOwnInstance(content::BrowserContext *context, bool) +{ + // like in ShellExtensionsBrowserClient: + return context; +} + +content::BrowserContext* ExtensionsBrowserClientQt::GetContextForOriginalOnly(content::BrowserContext *context, bool) +{ + // like in ShellExtensionsBrowserClient: + return context; +} + +bool ExtensionsBrowserClientQt::AreExtensionsDisabledForContext(content::BrowserContext*) +{ + // like in ShellExtensionsBrowserClient: + return false; +} + bool ExtensionsBrowserClientQt::IsGuestSession(BrowserContext *context) const { return context->IsOffTheRecord(); @@ -387,12 +368,11 @@ void ExtensionsBrowserClientQt::LoadResourceFromResourceBundle(const network::Re mojo::PendingReceiver<network::mojom::URLLoader> loader, const base::FilePath &resource_relative_path, int resource_id, - const std::string &content_security_policy, - mojo::PendingRemote<network::mojom::URLLoaderClient> client, - bool send_cors_header) + scoped_refptr<net::HttpResponseHeaders> headers, + mojo::PendingRemote<network::mojom::URLLoaderClient> client) { ResourceBundleFileLoader::CreateAndStart(request, std::move(loader), std::move(client), resource_relative_path, - resource_id, content_security_policy, send_cors_header); + resource_id, headers); } @@ -490,7 +470,8 @@ const ComponentExtensionResourceManager *ExtensionsBrowserClientQt::GetComponent void ExtensionsBrowserClientQt::BroadcastEventToRenderers(events::HistogramValue histogram_value, const std::string &event_name, - std::unique_ptr<base::ListValue> args, bool dispatch_to_off_the_record_profiles) + base::Value::List args, + bool dispatch_to_off_the_record_profiles) { NOTIMPLEMENTED(); // TODO : do the event routing @@ -543,7 +524,6 @@ ExtensionWebContentsObserver *ExtensionsBrowserClientQt::GetExtensionWebContents KioskDelegate *ExtensionsBrowserClientQt::GetKioskDelegate() { - NOTREACHED(); return nullptr; } @@ -557,4 +537,15 @@ void ExtensionsBrowserClientQt::SetAPIClientForTest(ExtensionsAPIClient *api_cli api_client_.reset(api_client); } +media_device_salt::MediaDeviceSaltService *ExtensionsBrowserClientQt::GetMediaDeviceSaltService(content::BrowserContext *context) +{ + // Not needed for QWE + return nullptr; +} +mojo::PendingRemote<network::mojom::URLLoaderFactory> +ExtensionsBrowserClientQt::GetControlledFrameEmbedderURLLoader( + int frame_tree_node_id, content::BrowserContext *browser_context) +{ + return mojo::PendingRemote<network::mojom::URLLoaderFactory>(); +} } // namespace extensions diff --git a/src/core/extensions/extensions_browser_client_qt.h b/src/core/extensions/extensions_browser_client_qt.h index 7c00adcad..34a846311 100644 --- a/src/core/extensions/extensions_browser_client_qt.h +++ b/src/core/extensions/extensions_browser_client_qt.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Portions copyright 2015 The Chromium Embedded Framework Authors. // Portions copyright 2014 The Chromium Authors. All rights reserved. @@ -45,7 +9,6 @@ #ifndef EXTENSIONS_BROWSER_CLIENT_QT_H_ #define EXTENSIONS_BROWSER_CLIENT_QT_H_ -#include "base/compiler_specific.h" #include "extensions/browser/extensions_browser_client.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_remote.h" @@ -66,12 +29,15 @@ public: bool IsShuttingDown() override; bool AreExtensionsDisabled(const base::CommandLine &command_line, content::BrowserContext *context) override; - bool IsValidContext(content::BrowserContext *context) override; + bool IsValidContext(void*) 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; + content::BrowserContext *GetContextRedirectedToOriginal(content::BrowserContext*, bool) override; + content::BrowserContext *GetContextOwnInstance(content::BrowserContext*, bool) override; + content::BrowserContext *GetContextForOriginalOnly(content::BrowserContext*, bool) 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; @@ -102,7 +68,7 @@ public: GetComponentExtensionResourceManager() override; void BroadcastEventToRenderers(events::HistogramValue histogram_value, const std::string &event_name, - std::unique_ptr<base::ListValue> args, + base::Value::List args, bool dispatch_to_off_the_record_profiles) override; ExtensionCache *GetExtensionCache() override; bool IsBackgroundUpdateAllowed() override; @@ -127,9 +93,8 @@ public: mojo::PendingReceiver<network::mojom::URLLoader> loader, const base::FilePath &resource_relative_path, int resource_id, - const std::string &content_security_policy, - mojo::PendingRemote<network::mojom::URLLoaderClient> client, - bool send_cors_header) override; + scoped_refptr<net::HttpResponseHeaders> headers, + mojo::PendingRemote<network::mojom::URLLoaderClient> client) override; // Returns the locale used by the application. std::string GetApplicationLocale() override; @@ -139,6 +104,14 @@ public: // Sets the API client. void SetAPIClientForTest(ExtensionsAPIClient *api_client); + bool AreExtensionsDisabledForContext(content::BrowserContext*) override; + + media_device_salt::MediaDeviceSaltService *GetMediaDeviceSaltService(content::BrowserContext *context) override; + + mojo::PendingRemote<network::mojom::URLLoaderFactory> + GetControlledFrameEmbedderURLLoader(int frame_tree_node_id, + content::BrowserContext *browser_context) override; + private: // Support for extension APIs. std::unique_ptr<ExtensionsAPIClient> api_client_; @@ -147,8 +120,6 @@ private: std::unique_ptr<ComponentExtensionResourceManager> resource_manager_; //scoped_refptr<EventRouterForwarder> event_router_forwarder_; - - DISALLOW_COPY_AND_ASSIGN(ExtensionsBrowserClientQt); }; } // namespace extensions diff --git a/src/core/extensions/file_system_delegate_qt.cpp b/src/core/extensions/file_system_delegate_qt.cpp new file mode 100644 index 000000000..6c5b33919 --- /dev/null +++ b/src/core/extensions/file_system_delegate_qt.cpp @@ -0,0 +1,131 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "file_system_delegate_qt.h" + +#include "select_file_dialog_factory_qt.h" +#include "type_conversion.h" + +#include "base/files/file_path.h" +#include "base/files/file_path.h" +#include "base/functional/callback.h" +#include "base/functional/callback.h" +#include "base/memory/ref_counted.h" +#include "content/public/browser/web_contents.h" +#include "content/public/browser/web_contents.h" +#include "extensions/browser/api/file_system/file_system_delegate.h" +#include "extensions/browser/extension_function.h" +#include "ui/shell_dialogs/selected_file_info.h" + +#include <QStandardPaths> + +namespace extensions { + +FileEntryPickerQt::FileEntryPickerQt( + content::WebContents *web_contents, + const base::FilePath &suggested_name, + const ui::SelectFileDialog::FileTypeInfo *file_type_info, + ui::SelectFileDialog::Type picker_type, + FileSystemDelegate::FilesSelectedCallback files_selected_callback, + base::OnceClosure file_selection_canceled_callback) + : m_filesSelectedCallback(std::move(files_selected_callback)) + , m_fileSelectionCanceledCallback(std::move(file_selection_canceled_callback)) +{ + const GURL caller = web_contents->GetPrimaryMainFrame()->GetLastCommittedURL(); + m_selectFileDialog = ui::SelectFileDialog::Create( + this, std::make_unique<QtWebEngineCore::SelectFilePolicyQt>(web_contents)); + m_selectFileDialog->SelectFile( + picker_type, std::u16string(), suggested_name, file_type_info, 0, + base::FilePath::StringType(), nullptr, nullptr, &caller); +} + +FileEntryPickerQt::~FileEntryPickerQt() = default; + +void FileEntryPickerQt::FileSelected(const ui::SelectedFileInfo &file, int index, void *params) +{ + MultiFilesSelected({ file }, params); +} + +void FileEntryPickerQt::MultiFilesSelected(const std::vector<ui::SelectedFileInfo> &files, + void *params) +{ + Q_UNUSED(params); + std::vector<base::FilePath> paths; + for (const auto &file : files) { + paths.push_back(file.file_path); + } + std::move(m_filesSelectedCallback).Run(paths); + delete this; +} + +void FileEntryPickerQt::FileSelectionCanceled(void *params) +{ + std::move(m_fileSelectionCanceledCallback).Run(); + delete this; +} + +FileSystemDelegateQt::FileSystemDelegateQt() +{ +} + +base::FilePath FileSystemDelegateQt::GetDefaultDirectory() +{ + return QtWebEngineCore::toFilePath( + QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)); +} + +base::FilePath FileSystemDelegateQt::GetManagedSaveAsDirectory( + content::BrowserContext *browser_context, + const Extension &extension) +{ + Q_UNUSED(browser_context); + Q_UNUSED(extension); + return base::FilePath(); +} + +bool FileSystemDelegateQt::ShowSelectFileDialog( + scoped_refptr<ExtensionFunction> extension_function, + ui::SelectFileDialog::Type type, + const base::FilePath &default_path, + const ui::SelectFileDialog::FileTypeInfo *file_type_info, + FileSystemDelegate::FilesSelectedCallback files_selected_callback, + base::OnceClosure file_selection_canceled_callback) +{ + content::WebContents *web_contents = extension_function->GetSenderWebContents(); + if (!web_contents) + return false; + + new FileEntryPickerQt(web_contents, default_path, file_type_info, type, + std::move(files_selected_callback), + std::move(file_selection_canceled_callback)); + return true; +} + +void FileSystemDelegateQt::ConfirmSensitiveDirectoryAccess( + bool has_write_permission, + const std::u16string &app_name, + content::WebContents *web_contents, + base::OnceClosure on_accept, + base::OnceClosure on_cancel) +{ + Q_UNUSED(has_write_permission); + Q_UNUSED(app_name); + Q_UNUSED(web_contents); + Q_UNUSED(on_accept); + std::move(on_cancel).Run(); +} + +int FileSystemDelegateQt::GetDescriptionIdForAcceptType(const std::string &accept_type) +{ + Q_UNUSED(accept_type); + return 0; +} + +SavedFilesServiceInterface *FileSystemDelegateQt::GetSavedFilesService( + content::BrowserContext *browser_context) +{ + Q_UNUSED(browser_context); + return nullptr; +} + +} // namespace extensions diff --git a/src/core/extensions/file_system_delegate_qt.h b/src/core/extensions/file_system_delegate_qt.h new file mode 100644 index 000000000..01b56fa56 --- /dev/null +++ b/src/core/extensions/file_system_delegate_qt.h @@ -0,0 +1,84 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef FILE_SYSTEM_DELEGATE_QT_H +#define FILE_SYSTEM_DELEGATE_QT_H + +#include "extensions/browser/api/file_system/file_system_delegate.h" + +#include "base/files/file_path.h" +#include "base/functional/callback.h" +#include "base/memory/ref_counted.h" +#include "extensions/browser/extension_function.h" +#include "ui/shell_dialogs/select_file_dialog.h" + +#include <memory> +#include <vector> + +namespace content { +class BrowserContext; +} // namespace content + +namespace ui { +struct SelectedFileInfo; +} + +namespace extensions { + +class FileEntryPickerQt : public ui::SelectFileDialog::Listener { +public: + FileEntryPickerQt( + content::WebContents *web_contents, + const base::FilePath &suggested_name, + const ui::SelectFileDialog::FileTypeInfo *file_type_info, + ui::SelectFileDialog::Type picker_type, + FileSystemDelegate::FilesSelectedCallback files_selected_callback, + base::OnceClosure file_selection_canceled_callback); + + FileEntryPickerQt(const FileEntryPickerQt &) = delete; + FileEntryPickerQt &operator=(const FileEntryPickerQt &) = delete; + +private: + ~FileEntryPickerQt() override; + + // ui::SelectFileDialog::Listener implementation. + void FileSelected(const ui::SelectedFileInfo &file, int index, void *params) override; + void MultiFilesSelected(const std::vector<ui::SelectedFileInfo> &files, void *params) override; + void FileSelectionCanceled(void *params) override; + + FileSystemDelegate::FilesSelectedCallback m_filesSelectedCallback; + base::OnceClosure m_fileSelectionCanceledCallback; + scoped_refptr<ui::SelectFileDialog> m_selectFileDialog; +}; + +class FileSystemDelegateQt : public FileSystemDelegate +{ +public: + FileSystemDelegateQt(); + + // FileSystemDelegate implementation + virtual base::FilePath GetDefaultDirectory() override; + virtual base::FilePath GetManagedSaveAsDirectory( + content::BrowserContext *browser_context, + const Extension &extension) override; + virtual bool ShowSelectFileDialog( + scoped_refptr<ExtensionFunction> extension_function, + ui::SelectFileDialog::Type type, + const base::FilePath &default_path, + const ui::SelectFileDialog::FileTypeInfo *file_types, + FileSystemDelegate::FilesSelectedCallback files_selected_callback, + base::OnceClosure file_selection_canceled_callback) override; + virtual void ConfirmSensitiveDirectoryAccess( + bool has_write_permission, + const std::u16string &app_name, + content::WebContents *web_contents, + base::OnceClosure on_accept, + base::OnceClosure on_cancel) override; + virtual int GetDescriptionIdForAcceptType(const std::string &accept_type) override; + virtual SavedFilesServiceInterface *GetSavedFilesService( + content::BrowserContext *browser_context) override; +}; + +} // namespace extensions + +#endif // FILE_SYSTEM_DELEGATE_QT_H diff --git a/src/core/extensions/messaging_delegate_qt.cpp b/src/core/extensions/messaging_delegate_qt.cpp index c666daa09..b0089aea2 100644 --- a/src/core/extensions/messaging_delegate_qt.cpp +++ b/src/core/extensions/messaging_delegate_qt.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "messaging_delegate_qt.h" @@ -47,10 +11,10 @@ MessagingDelegateQt::MessagingDelegateQt() { } -std::unique_ptr<base::DictionaryValue> MessagingDelegateQt::MaybeGetTabInfo(content::WebContents *web_contents) +absl::optional<base::Value::Dict> MessagingDelegateQt::MaybeGetTabInfo(content::WebContents *web_contents) { Q_UNUSED(web_contents); - return nullptr; + return absl::nullopt; } } // namespace extensions diff --git a/src/core/extensions/messaging_delegate_qt.h b/src/core/extensions/messaging_delegate_qt.h index 44bfdc2d5..c3c6244f5 100644 --- a/src/core/extensions/messaging_delegate_qt.h +++ b/src/core/extensions/messaging_delegate_qt.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 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) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef MESSAGING_DELEGATE_QT_H #define MESSAGING_DELEGATE_QT_H @@ -58,7 +22,7 @@ public: MessagingDelegateQt(); // MessagingDelegate implementation. - std::unique_ptr<base::DictionaryValue> MaybeGetTabInfo(content::WebContents *web_contents) override; + absl::optional<base::Value::Dict> MaybeGetTabInfo(content::WebContents *web_contents) override; }; } // namespace extensions diff --git a/src/core/extensions/mime_handler_view_guest_delegate_qt.cpp b/src/core/extensions/mime_handler_view_guest_delegate_qt.cpp index 16a747929..fcea708b0 100644 --- a/src/core/extensions/mime_handler_view_guest_delegate_qt.cpp +++ b/src/core/extensions/mime_handler_view_guest_delegate_qt.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Portions copyright 2015 The Chromium Embedded Framework Authors. // Portions copyright 2014 The Chromium Authors. All rights reserved. @@ -70,8 +34,9 @@ MimeHandlerViewGuestDelegateQt::~MimeHandlerViewGuestDelegateQt() delete m_contextMenuRequest; } -bool MimeHandlerViewGuestDelegateQt::HandleContextMenu(content::WebContents *web_contents, const content::ContextMenuParams ¶ms) +bool MimeHandlerViewGuestDelegateQt::HandleContextMenu(content::RenderFrameHost &render_frame_host, const content::ContextMenuParams ¶ms) { + content::WebContents *web_contents = content::WebContents::FromRenderFrameHost(&render_frame_host); content::WebContents *parent_web_contents = guest_view::GuestViewBase::GetTopLevelWebContents(web_contents); if (auto rwhv = static_cast<QtWebEngineCore::RenderWidgetHostViewQt *>(parent_web_contents->GetRenderWidgetHostView())) { if (rwhv->getTouchSelectionControllerClient()->handleContextMenu(params)) diff --git a/src/core/extensions/mime_handler_view_guest_delegate_qt.h b/src/core/extensions/mime_handler_view_guest_delegate_qt.h index c9b822aa1..bdb3c840b 100644 --- a/src/core/extensions/mime_handler_view_guest_delegate_qt.h +++ b/src/core/extensions/mime_handler_view_guest_delegate_qt.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Portions copyright 2015 The Chromium Embedded Framework Authors. // Portions copyright 2014 The Chromium Authors. All rights reserved. @@ -65,12 +29,11 @@ public: explicit MimeHandlerViewGuestDelegateQt(MimeHandlerViewGuest *guest); ~MimeHandlerViewGuestDelegateQt() override; - bool HandleContextMenu(content::WebContents *web_contents, + bool HandleContextMenu(content::RenderFrameHost &render_frame_host, const content::ContextMenuParams ¶ms) override; private: QWebEngineContextMenuRequest *m_contextMenuRequest; - DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewGuestDelegateQt); }; } // namespace extensions diff --git a/src/core/extensions/pdf_iframe_navigation_throttle_qt.cpp b/src/core/extensions/pdf_iframe_navigation_throttle_qt.cpp index 7c2fe75f0..a494e2f49 100644 --- a/src/core/extensions/pdf_iframe_navigation_throttle_qt.cpp +++ b/src/core/extensions/pdf_iframe_navigation_throttle_qt.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // based on //chrome/browser/plugins/pdf_iframe_navigation_throttle.cc // Copyright 2017 The Chromium Authors. All rights reserved. @@ -45,6 +9,7 @@ #include "extensions/pdf_iframe_navigation_throttle_qt.h" +#include "base/task/sequenced_task_runner.h" #include "chrome/grit/renderer_resources.h" #include "components/strings/grit/components_strings.h" #include "content/public/browser/download_utils.h" @@ -54,23 +19,25 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_user_data.h" #include "content/public/common/webplugininfo.h" -#include "net/base/escape.h" +#include "base/strings/escape.h" #include "net/http/http_response_headers.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/webui/jstemplate_builder.h" #include "ui/base/webui/web_ui_util.h" -namespace extensions { +#include "pdf_util_qt.h" + +#include <QtGlobal> -constexpr char kPDFMimeType[] = "application/pdf"; +namespace extensions { // Used to scope the posted navigation task to the lifetime of |web_contents|. class PdfWebContentsLifetimeHelper : public content::WebContentsUserData<PdfWebContentsLifetimeHelper> { public: explicit PdfWebContentsLifetimeHelper(content::WebContents *web_contents) - : web_contents_(web_contents) + : content::WebContentsUserData<PdfWebContentsLifetimeHelper>(*web_contents) {} base::WeakPtr<PdfWebContentsLifetimeHelper> GetWeakPtr() @@ -80,32 +47,37 @@ public: void NavigateIFrameToPlaceholder(const content::OpenURLParams &url_params) { - web_contents_->OpenURL(url_params); + GetWebContents().OpenURL(url_params); } private: friend class content::WebContentsUserData<PdfWebContentsLifetimeHelper>; - content::WebContents* const web_contents_; base::WeakPtrFactory<PdfWebContentsLifetimeHelper> weak_factory_{this}; WEB_CONTENTS_USER_DATA_KEY_DECL(); }; -WEB_CONTENTS_USER_DATA_KEY_IMPL(PdfWebContentsLifetimeHelper) +WEB_CONTENTS_USER_DATA_KEY_IMPL(PdfWebContentsLifetimeHelper); bool IsPDFPluginEnabled(content::NavigationHandle *navigation_handle, bool *is_stale) { content::WebContents *web_contents = navigation_handle->GetWebContents(); - int process_id = web_contents->GetMainFrame()->GetProcess()->GetID(); - int routing_id = web_contents->GetMainFrame()->GetRoutingID(); + Q_ASSERT(web_contents); + + if (web_contents->IsInnerWebContentsForGuest()) + web_contents = web_contents->GetOuterWebContents(); + + int process_id = web_contents->GetPrimaryMainFrame()->GetProcess()->GetID(); + int routing_id = web_contents->GetPrimaryMainFrame()->GetRoutingID(); content::WebPluginInfo plugin_info; // Will check WebEngineSettings by PluginServiceFilterQt return content::PluginService::GetInstance()->GetPluginInfo( - process_id, routing_id, navigation_handle->GetURL(), - web_contents->GetMainFrame()->GetLastCommittedOrigin(), kPDFMimeType, - false /* allow_wildcard */, is_stale, &plugin_info, - nullptr /* actual_mime_type */); + process_id, routing_id, + navigation_handle->GetWebContents()->GetBrowserContext(), + navigation_handle->GetURL(), + QtWebEngineCore::kPDFMimeType, false /* allow_wildcard */, + is_stale, &plugin_info, nullptr /* actual_mime_type */); } std::string GetPDFPlaceholderHTML(const GURL &pdf_url) @@ -113,12 +85,12 @@ std::string GetPDFPlaceholderHTML(const GURL &pdf_url) std::string template_html = ui::ResourceBundle::GetSharedInstance().LoadDataResourceString(IDR_PDF_PLUGIN_HTML); webui::AppendWebUiCssTextDefaults(&template_html); - base::DictionaryValue values; - values.SetString("fileName", pdf_url.ExtractFileName()); - values.SetString("open", l10n_util::GetStringUTF8(IDS_ACCNAME_OPEN)); - values.SetString("pdfUrl", pdf_url.spec()); + base::Value::Dict values; + values.Set("fileName", pdf_url.ExtractFileName()); + values.Set("open", l10n_util::GetStringUTF8(IDS_ACCNAME_OPEN)); + values.Set("pdfUrl", pdf_url.spec()); - return webui::GetI18nTemplateHtml(template_html, &values); + return webui::GetI18nTemplateHtml(template_html, std::move(values)); } // static @@ -147,12 +119,15 @@ content::NavigationThrottle::ThrottleCheckResult PDFIFrameNavigationThrottleQt:: std::string mime_type; response_headers->GetMimeType(&mime_type); - if (mime_type != kPDFMimeType) + if (mime_type != QtWebEngineCore::kPDFMimeType) return content::NavigationThrottle::PROCEED; // We MUST download responses marked as attachments rather than showing // a placeholder. - if (content::download_utils::MustDownload(navigation_handle()->GetURL(), response_headers, mime_type)) + if (content::download_utils::MustDownload(navigation_handle()->GetWebContents() + ? navigation_handle()->GetWebContents()->GetBrowserContext() + : nullptr, + navigation_handle()->GetURL(), response_headers, mime_type)) return content::NavigationThrottle::PROCEED; bool is_stale = false; @@ -195,7 +170,7 @@ void PDFIFrameNavigationThrottleQt::LoadPlaceholderHTML() { // Prepare the params to navigate to the placeholder. std::string html = GetPDFPlaceholderHTML(navigation_handle()->GetURL()); - GURL data_url("data:text/html," + net::EscapePath(html)); + GURL data_url("data:text/html," + base::EscapePath(html)); content::OpenURLParams params = content::OpenURLParams::FromNavigationHandle(navigation_handle()); params.url = data_url; params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; @@ -210,7 +185,7 @@ void PDFIFrameNavigationThrottleQt::LoadPlaceholderHTML() PdfWebContentsLifetimeHelper::CreateForWebContents(web_contents); PdfWebContentsLifetimeHelper *helper = PdfWebContentsLifetimeHelper::FromWebContents(web_contents); - base::SequencedTaskRunnerHandle::Get()->PostTask( + base::SequencedTaskRunner::GetCurrentDefault()->PostTask( FROM_HERE, base::BindOnce(&PdfWebContentsLifetimeHelper::NavigateIFrameToPlaceholder, helper->GetWeakPtr(), std::move(params))); diff --git a/src/core/extensions/pdf_iframe_navigation_throttle_qt.h b/src/core/extensions/pdf_iframe_navigation_throttle_qt.h index 37f5bf1d6..fdc168aec 100644 --- a/src/core/extensions/pdf_iframe_navigation_throttle_qt.h +++ b/src/core/extensions/pdf_iframe_navigation_throttle_qt.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // based on //chrome/browser/plugins/pdf_iframe_navigation_throttle.h // Copyright 2017 The Chromium Authors. All rights reserved. diff --git a/src/core/extensions/pdf_web_contents_helper_client_qt.h b/src/core/extensions/pdf_web_contents_helper_client_qt.h deleted file mode 100644 index 9a37375b3..000000000 --- a/src/core/extensions/pdf_web_contents_helper_client_qt.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef PDF_WEB_CONTENTS_HELPER_CLIENT_QT_H_ -#define PDF_WEB_CONTENTS_HELPER_CLIENT_QT_H_ - -#include "base/macros.h" -#include "components/pdf/browser/pdf_web_contents_helper_client.h" - -namespace extensions { - -class PDFWebContentsHelperClientQt : public pdf::PDFWebContentsHelperClient -{ -public: - PDFWebContentsHelperClientQt(); - ~PDFWebContentsHelperClientQt() override; - -private: - // pdf::PDFWebContentsHelperClient: - void UpdateContentRestrictions(content::WebContents *contents, int content_restrictions) override; - void OnPDFHasUnsupportedFeature(content::WebContents *contents) override; - void OnSaveURL(content::WebContents *contents) override; - - DISALLOW_COPY_AND_ASSIGN(PDFWebContentsHelperClientQt); -}; - -} // namespace extensions - -#endif // PDF_WEB_CONTENTS_HELPER_CLIENT_QT_H_ diff --git a/src/core/extensions/plugin_service_filter_qt.cpp b/src/core/extensions/plugin_service_filter_qt.cpp index 778f803c3..1f6c606bc 100644 --- a/src/core/extensions/plugin_service_filter_qt.cpp +++ b/src/core/extensions/plugin_service_filter_qt.cpp @@ -1,46 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2021 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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "extensions/plugin_service_filter_qt.h" -#include "content/public/browser/render_frame_host.h" -#include "content/public/browser/web_contents.h" +#include "content/public/browser/render_process_host.h" #include "web_contents_delegate_qt.h" #include "web_engine_settings.h" @@ -50,16 +13,17 @@ using namespace QtWebEngineCore; namespace extensions { // static -PluginServiceFilterQt *PluginServiceFilterQt::GetInstance() { +PluginServiceFilterQt *PluginServiceFilterQt::GetInstance() +{ return base::Singleton<PluginServiceFilterQt>::get(); } -bool PluginServiceFilterQt::IsPluginAvailable(int render_process_id, - int render_frame_id, - const GURL &url, - const url::Origin &main_frame_origin, - content::WebPluginInfo *plugin) +bool PluginServiceFilterQt::IsPluginAvailable(int render_process_id, int render_frame_id, + content::BrowserContext *browser_context, + const content::WebPluginInfo &plugin) { + Q_UNUSED(plugin); + Q_UNUSED(browser_context); content::RenderFrameHost *frame_host = content::RenderFrameHost::FromID(render_process_id, render_frame_id); content::WebContents *web_contents = content::WebContents::FromRenderFrameHost(frame_host); if (!web_contents) { diff --git a/src/core/extensions/plugin_service_filter_qt.h b/src/core/extensions/plugin_service_filter_qt.h index ea5f082f2..d171edfde 100644 --- a/src/core/extensions/plugin_service_filter_qt.h +++ b/src/core/extensions/plugin_service_filter_qt.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef PLUGIN_SERVICE_FILTER_QT #define PLUGIN_SERVICE_FILTER_QT @@ -50,11 +14,9 @@ class PluginServiceFilterQt : public content::PluginServiceFilter { public: static PluginServiceFilterQt* GetInstance(); - bool IsPluginAvailable(int render_process_id, - int render_frame_id, - const GURL &url, - const url::Origin &main_frame_origin, - content::WebPluginInfo *plugin) override; + bool IsPluginAvailable(int render_process_id, int render_frame_id, + content::BrowserContext *browser_context, + const content::WebPluginInfo &plugin) override; bool CanLoadPlugin(int render_process_id, const base::FilePath &path) override; |