diff options
Diffstat (limited to 'src/core/extensions')
9 files changed, 220 insertions, 18 deletions
diff --git a/src/core/extensions/extension_system_qt.cpp b/src/core/extensions/extension_system_qt.cpp index 9c080e9aa..285b27729 100644 --- a/src/core/extensions/extension_system_qt.cpp +++ b/src/core/extensions/extension_system_qt.cpp @@ -223,11 +223,12 @@ void ExtensionSystemQt::NotifyExtensionLoaded(const Extension *extension) // Register plugins included with the extension. // Implementation based on PluginManager::OnExtensionLoaded. const MimeTypesHandler *handler = MimeTypesHandler::GetHandler(extension); - if (handler && !handler->handler_url().empty()) { + if (handler && handler->HasPlugin()) { content::WebPluginInfo info; info.type = content::WebPluginInfo::PLUGIN_TYPE_BROWSER_PLUGIN; info.name = base::UTF8ToUTF16(extension->name()); - info.path = base::FilePath::FromUTF8Unsafe(extension->url().spec()); + info.path = handler->GetPluginPath(); + info.background_color = handler->GetBackgroundColor(); for (std::set<std::string>::const_iterator mime_type = handler->mime_type_set().begin(); mime_type != handler->mime_type_set().end(); ++mime_type) { content::WebPluginMimeType mime_type_info; diff --git a/src/core/extensions/extension_web_contents_observer_qt.cpp b/src/core/extensions/extension_web_contents_observer_qt.cpp index 5b1514bb4..e336f70b4 100644 --- a/src/core/extensions/extension_web_contents_observer_qt.cpp +++ b/src/core/extensions/extension_web_contents_observer_qt.cpp @@ -43,13 +43,17 @@ #include "extension_web_contents_observer_qt.h" +#include "components/guest_view/browser/guest_view_base.h" #include "content/public/browser/child_process_security_policy.h" -#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_frame_host.h" +#include "content/public/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 "render_widget_host_view_qt.h" + namespace extensions { ExtensionWebContentsObserverQt::ExtensionWebContentsObserverQt(content::WebContents *web_contents) @@ -85,6 +89,16 @@ void ExtensionWebContentsObserverQt::RenderFrameCreated(content::RenderFrameHost policy->GrantRequestOrigin(process_id, url::Origin::Create(GURL(content::kChromeUIResourcesURL))); } +void ExtensionWebContentsObserverQt::RenderViewCreated(content::RenderViewHost *render_view_host) +{ + if (web_contents()->IsInnerWebContentsForGuest()) { + content::RenderWidgetHost *render_widget_host = render_view_host->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) } // 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 658966b31..c0269e4f5 100644 --- a/src/core/extensions/extension_web_contents_observer_qt.h +++ b/src/core/extensions/extension_web_contents_observer_qt.h @@ -61,6 +61,7 @@ public: // content::WebContentsObserver overrides. void RenderFrameCreated(content::RenderFrameHost *render_frame_host) override; + void RenderViewCreated(content::RenderViewHost *render_view_host) override; private: friend class content::WebContentsUserData<ExtensionWebContentsObserverQt>; diff --git a/src/core/extensions/extensions_api_client_qt.cpp b/src/core/extensions/extensions_api_client_qt.cpp index 81d9efde2..925fd10da 100644 --- a/src/core/extensions/extensions_api_client_qt.cpp +++ b/src/core/extensions/extensions_api_client_qt.cpp @@ -47,9 +47,10 @@ #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 "extension_web_contents_observer_qt.h" +#include "mime_handler_view_guest_delegate_qt.h" #include "printing/print_view_manager_qt.h" namespace extensions { @@ -67,12 +68,12 @@ AppViewGuestDelegate *ExtensionsAPIClientQt::CreateAppViewGuestDelegate() const std::unique_ptr<guest_view::GuestViewManagerDelegate> ExtensionsAPIClientQt::CreateGuestViewManagerDelegate(content::BrowserContext *context) const { - return std::make_unique<guest_view::GuestViewManagerDelegate>(); + return std::make_unique<extensions::ExtensionsGuestViewManagerDelegate>(context); } std::unique_ptr<MimeHandlerViewGuestDelegate> ExtensionsAPIClientQt::CreateMimeHandlerViewGuestDelegate(MimeHandlerViewGuest *guest) const { - return std::make_unique<MimeHandlerViewGuestDelegate>(); + return std::make_unique<MimeHandlerViewGuestDelegateQt>(guest); } void ExtensionsAPIClientQt::AttachWebContentsHelpers(content::WebContents *web_contents) const diff --git a/src/core/extensions/extensions_browser_client_qt.cpp b/src/core/extensions/extensions_browser_client_qt.cpp index 6bcf37d85..501252823 100644 --- a/src/core/extensions/extensions_browser_client_qt.cpp +++ b/src/core/extensions/extensions_browser_client_qt.cpp @@ -335,7 +335,7 @@ BrowserContext *ExtensionsBrowserClientQt::GetOriginalContext(BrowserContext *co bool ExtensionsBrowserClientQt::IsGuestSession(BrowserContext *context) const { - return false; + return context->IsOffTheRecord(); } bool ExtensionsBrowserClientQt::IsExtensionIncognitoEnabled(const std::string &extension_id, 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 58f4f209a..16a747929 100644 --- a/src/core/extensions/mime_handler_view_guest_delegate_qt.cpp +++ b/src/core/extensions/mime_handler_view_guest_delegate_qt.cpp @@ -44,33 +44,44 @@ #include "mime_handler_view_guest_delegate_qt.h" -#include "content/browser/browser_plugin/browser_plugin_guest.h" -#include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/context_menu_params.h" #include "content/public/browser/web_contents.h" #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h" +#include "profile_adapter.h" +#include "qwebenginecontextmenurequest.h" +#include "qwebenginecontextmenurequest_p.h" +#include "render_widget_host_view_qt.h" +#include "touch_selection_controller_client_qt.h" +#include "web_contents_adapter.h" +#include "web_contents_adapter_client.h" +#include "web_contents_view_qt.h" + namespace extensions { MimeHandlerViewGuestDelegateQt::MimeHandlerViewGuestDelegateQt(MimeHandlerViewGuest *) : MimeHandlerViewGuestDelegate() + , m_contextMenuRequest(new QWebEngineContextMenuRequest(new QWebEngineContextMenuRequestPrivate)) { } MimeHandlerViewGuestDelegateQt::~MimeHandlerViewGuestDelegateQt() { + delete m_contextMenuRequest; } bool MimeHandlerViewGuestDelegateQt::HandleContextMenu(content::WebContents *web_contents, const content::ContextMenuParams ¶ms) { - content::ContextMenuParams new_params = params; - - gfx::Point guest_coordinates = - static_cast<content::WebContentsImpl *>(web_contents)->GetBrowserPluginGuest()->GetScreenCoordinates(gfx::Point()); + 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)) + return true; - // Adjust (x,y) position for offset from guest to embedder. - new_params.x += guest_coordinates.x(); - new_params.y += guest_coordinates.y(); + QtWebEngineCore::WebContentsAdapterClient *adapterClient = rwhv->adapterClient(); + QtWebEngineCore::WebContentsViewQt::update(m_contextMenuRequest, params, adapterClient->profileAdapter()->isSpellCheckEnabled()); + adapterClient->contextMenuRequested(m_contextMenuRequest); + return true; + } return false; } 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 6cd80689c..c9b822aa1 100644 --- a/src/core/extensions/mime_handler_view_guest_delegate_qt.h +++ b/src/core/extensions/mime_handler_view_guest_delegate_qt.h @@ -46,8 +46,11 @@ #define MIME_HANDLER_VIEW_GUEST_DELEGATE_QT_H_ #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h" -#include "content/browser/web_contents/web_contents_view.h" -#include "content/public/browser/web_contents.h" +#include "api/qtwebenginecoreglobal_p.h" + +QT_BEGIN_NAMESPACE +class QWebEngineContextMenuRequest; +QT_END_NAMESPACE namespace content { struct ContextMenuParams; @@ -66,6 +69,7 @@ public: const content::ContextMenuParams ¶ms) override; private: + QWebEngineContextMenuRequest *m_contextMenuRequest; DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewGuestDelegateQt); }; diff --git a/src/core/extensions/plugin_service_filter_qt.cpp b/src/core/extensions/plugin_service_filter_qt.cpp new file mode 100644 index 000000000..94cf5cb27 --- /dev/null +++ b/src/core/extensions/plugin_service_filter_qt.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "extensions/plugin_service_filter_qt.h" + +#include "content/public/browser/render_frame_host.h" +#include "content/public/browser/web_contents.h" + +#include "web_contents_delegate_qt.h" + +using namespace QtWebEngineCore; + +namespace extensions { + +// static +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) +{ + 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) { + // Availability checked somewhere before/during WebContents initialization. Let it load and enable + // all the plugins at this phase. This information will be queried again when receiving the response + // for the requested content. Postponing our decision and enabling/blocking there makes WebEngineSettings + // modifiable in runtime without reconstructing WebContents. + return true; + } + + if (web_contents->IsInnerWebContentsForGuest()) + web_contents = web_contents->GetOuterWebContents(); + + if (auto *delegate = static_cast<WebContentsDelegateQt *>(web_contents->GetDelegate())) { + const WebEngineSettings *settings = delegate->webEngineSettings(); + if (!settings->testAttribute(QWebEngineSettings::PdfViewerEnabled) + || !settings->testAttribute(QWebEngineSettings::PluginsEnabled)) + return false; + } + + return true; +} + +bool PluginServiceFilterQt::CanLoadPlugin(int render_process_id, + const base::FilePath &path) +{ + return true; +} + +PluginServiceFilterQt::PluginServiceFilterQt() +{ +} + +PluginServiceFilterQt::~PluginServiceFilterQt() +{ +} + +} // namespace extensions diff --git a/src/core/extensions/plugin_service_filter_qt.h b/src/core/extensions/plugin_service_filter_qt.h new file mode 100644 index 000000000..ea5f082f2 --- /dev/null +++ b/src/core/extensions/plugin_service_filter_qt.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef PLUGIN_SERVICE_FILTER_QT +#define PLUGIN_SERVICE_FILTER_QT + +#include "content/public/browser/plugin_service_filter.h" + +#include "base/memory/singleton.h" + +namespace extensions { + +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 CanLoadPlugin(int render_process_id, + const base::FilePath &path) override; + +private: + friend struct base::DefaultSingletonTraits<PluginServiceFilterQt>; + + PluginServiceFilterQt(); + ~PluginServiceFilterQt(); +}; + +} // namespace extensions + +#endif // PLUGIN_SERVICE_FILTER_QT |