diff options
Diffstat (limited to 'src/core/renderer_host')
16 files changed, 303 insertions, 1339 deletions
diff --git a/src/core/renderer_host/pepper/pepper_flash_browser_host_qt.cpp b/src/core/renderer_host/pepper/pepper_flash_browser_host_qt.cpp deleted file mode 100644 index d54a9cdf2..000000000 --- a/src/core/renderer_host/pepper/pepper_flash_browser_host_qt.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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$ -** -****************************************************************************/ - -// This is based on chrome/browser/renderer_host/pepper/pepper_flash_browser_host.cc: -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.Chromium file. - -#include "pepper_flash_browser_host_qt.h" - -#include "base/time/time.h" -#include "content/public/browser/browser_context.h" -#include "content/public/browser/browser_ppapi_host.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/render_process_host.h" -#include "ipc/ipc_message_macros.h" -#include "ppapi/c/pp_errors.h" -#include "ppapi/c/private/ppb_flash.h" -#include "ppapi/host/dispatch_host_message.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/resource_message_params.h" -#include "ppapi/shared_impl/time_conversion.h" -#include "qtwebenginecoreglobal_p.h" -#include "url/gurl.h" - -#if defined(OS_WIN) -#include <windows.h> -#elif defined(OS_MACOSX) -#include <CoreServices/CoreServices.h> -#endif - -using content::BrowserPpapiHost; -using content::BrowserThread; -using content::RenderProcessHost; - -namespace QtWebEngineCore { - -PepperFlashBrowserHostQt::PepperFlashBrowserHostQt(BrowserPpapiHost* host, - PP_Instance instance, - PP_Resource resource) - : ResourceHost(host->GetPpapiHost(), instance, resource), - host_(host), - weak_factory_(this) -{ - int unused; - host->GetRenderFrameIDsForInstance(instance, &render_process_id_, &unused); -} - -PepperFlashBrowserHostQt::~PepperFlashBrowserHostQt() {} - -int32_t PepperFlashBrowserHostQt::OnResourceMessageReceived( - const IPC::Message& msg, - ppapi::host::HostMessageContext* context) -{ - PPAPI_BEGIN_MESSAGE_MAP(PepperFlashBrowserHostQt, msg) - PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_UpdateActivity, - OnUpdateActivity) - PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_Flash_GetLocalTimeZoneOffset, - OnGetLocalTimeZoneOffset) - PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_Flash_GetLocalDataRestrictions, - OnGetLocalDataRestrictions) - PPAPI_END_MESSAGE_MAP() - return PP_ERROR_FAILED; -} - -int32_t PepperFlashBrowserHostQt::OnUpdateActivity(ppapi::host::HostMessageContext* host_context) -{ -#if defined(OS_WIN) - // Reading then writing back the same value to the screensaver timeout system - // setting resets the countdown which prevents the screensaver from turning - // on "for a while". As long as the plugin pings us with this message faster - // than the screensaver timeout, it won't go on. - int value = 0; - if (SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &value, 0)) - SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, value, NULL, 0); -#elif defined(OS_MACOSX) - UpdateSystemActivity(OverallAct); -#endif - return PP_OK; -} - -int32_t PepperFlashBrowserHostQt::OnGetLocalTimeZoneOffset( - ppapi::host::HostMessageContext* host_context, - const base::Time& t) -{ - // The reason for this processing being in the browser process is that on - // Linux, the localtime calls require filesystem access prohibited by the - // sandbox. - host_context->reply_msg = PpapiPluginMsg_Flash_GetLocalTimeZoneOffsetReply( - ppapi::PPGetLocalTimeZoneOffset(t)); - return PP_OK; -} - -int32_t PepperFlashBrowserHostQt::OnGetLocalDataRestrictions( - ppapi::host::HostMessageContext* context) -{ - QT_NOT_YET_IMPLEMENTED - return PP_OK; -} - -} // namespace QtWebEngineCore diff --git a/src/core/renderer_host/pepper/pepper_flash_browser_host_qt.h b/src/core/renderer_host/pepper/pepper_flash_browser_host_qt.h deleted file mode 100644 index 5d1107dfb..000000000 --- a/src/core/renderer_host/pepper/pepper_flash_browser_host_qt.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 PEPPER_FLASH_BROWSER_HOST_QT_H -#define PEPPER_FLASH_BROWSER_HOST_QT_H - -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" -#include "ppapi/host/host_message_context.h" -#include "ppapi/host/resource_host.h" - -namespace base { -class Time; -} - -namespace content { -class BrowserPpapiHost; -class ResourceContext; -} - -class GURL; - -namespace QtWebEngineCore { - -class PepperFlashBrowserHostQt : public ppapi::host::ResourceHost { -public: - PepperFlashBrowserHostQt(content::BrowserPpapiHost* host, - PP_Instance instance, - PP_Resource resource); - ~PepperFlashBrowserHostQt() override; - - // ppapi::host::ResourceHost override. - int32_t OnResourceMessageReceived( - const IPC::Message& msg, - ppapi::host::HostMessageContext* context) override; - -private: - int32_t OnUpdateActivity(ppapi::host::HostMessageContext* host_context); - int32_t OnGetLocalTimeZoneOffset( - ppapi::host::HostMessageContext* host_context, - const base::Time& t); - int32_t OnGetLocalDataRestrictions(ppapi::host::HostMessageContext* context); - - void GetLocalDataRestrictions(ppapi::host::ReplyMessageContext reply_context, - const GURL& document_url, - const GURL& plugin_url); - - content::BrowserPpapiHost* host_; - int render_process_id_; - base::WeakPtrFactory<PepperFlashBrowserHostQt> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(PepperFlashBrowserHostQt); -}; - -} // namespace QtWebEngineCore - -#endif // PEPPER_FLASH_BROWSER_HOST_QT_H diff --git a/src/core/renderer_host/pepper/pepper_host_factory_qt.cpp b/src/core/renderer_host/pepper/pepper_host_factory_qt.cpp deleted file mode 100644 index 00ab4963b..000000000 --- a/src/core/renderer_host/pepper/pepper_host_factory_qt.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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$ -** -****************************************************************************/ - -// This is based on chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.cc: -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.Chromium file. - -#include "pepper_host_factory_qt.h" - -#include "base/memory/ptr_util.h" -#include "build/build_config.h" -#include "chrome/browser/renderer_host/pepper/pepper_flash_clipboard_message_filter.h" -#include "content/public/browser/browser_ppapi_host.h" -#include "ppapi/host/message_filter_host.h" -#include "ppapi/host/ppapi_host.h" -#include "ppapi/host/resource_host.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/shared_impl/ppapi_permissions.h" - -#include "pepper_flash_browser_host_qt.h" -#include "pepper_isolated_file_system_message_filter.h" - -using ppapi::host::MessageFilterHost; -using ppapi::host::ResourceMessageFilter; - -namespace QtWebEngineCore { - -PepperHostFactoryQt::PepperHostFactoryQt(content::BrowserPpapiHost* host) - : host_(host) -{ -} - -PepperHostFactoryQt::~PepperHostFactoryQt() {} - -std::unique_ptr<ppapi::host::ResourceHost> PepperHostFactoryQt::CreateResourceHost(ppapi::host::PpapiHost* host, - PP_Resource resource, - PP_Instance instance, - const IPC::Message& message) -{ - DCHECK(host == host_->GetPpapiHost()); - - - if (!host_->IsValidInstance(instance)) - return nullptr; - - // Flash interfaces. - if (host_->GetPpapiHost()->permissions().HasPermission(ppapi::PERMISSION_FLASH)) { - switch (message.type()) { - case PpapiHostMsg_Flash_Create::ID: - return base::WrapUnique(new PepperFlashBrowserHostQt(host_, instance, resource)); - case PpapiHostMsg_FlashClipboard_Create::ID: { - scoped_refptr<ResourceMessageFilter> clipboard_filter(new PepperFlashClipboardMessageFilter); - return base::WrapUnique(new MessageFilterHost( - host_->GetPpapiHost(), instance, resource, clipboard_filter)); - } - } - } - - // Permissions for the following interfaces will be checked at the - // time of the corresponding instance's methods calls (because - // permission check can be performed only on the UI - // thread). Currently these interfaces are available only for - // whitelisted apps which may not have access to the other private - // interfaces. - if (message.type() == PpapiHostMsg_IsolatedFileSystem_Create::ID) { - PepperIsolatedFileSystemMessageFilter* isolated_fs_filter = PepperIsolatedFileSystemMessageFilter::Create(instance, host_); - if (!isolated_fs_filter) - return nullptr; - return base::WrapUnique( - new MessageFilterHost(host_->GetPpapiHost(), instance, resource, isolated_fs_filter)); - } - - return nullptr; -} - -} // namespace QtWebEngineCore diff --git a/src/core/renderer_host/pepper/pepper_host_factory_qt.h b/src/core/renderer_host/pepper/pepper_host_factory_qt.h deleted file mode 100644 index 0446cf9e3..000000000 --- a/src/core/renderer_host/pepper/pepper_host_factory_qt.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 PEPPER_HOST_FACTORY_QT_H -#define PEPPER_HOST_FACTORY_QT_H - -#include "base/compiler_specific.h" -#include "ppapi/host/host_factory.h" -#include "ppapi/host/resource_host.h" -#include "ppapi/host/ppapi_host.h" - -namespace content { -class BrowserPpapiHost; -} // namespace content - -namespace QtWebEngineCore { - -class PepperHostFactoryQt final : public ppapi::host::HostFactory { -public: - // Non-owning pointer to the filter must outlive this class. - explicit PepperHostFactoryQt(content::BrowserPpapiHost* host); - ~PepperHostFactoryQt() override; - - virtual std::unique_ptr<ppapi::host::ResourceHost> CreateResourceHost( - ppapi::host::PpapiHost* host, - PP_Resource resource, - PP_Instance instance, - const IPC::Message& message) override; -private: - // Non-owning pointer. - content::BrowserPpapiHost* host_; - - DISALLOW_COPY_AND_ASSIGN(PepperHostFactoryQt); -}; -} // namespace QtWebEngineCore - -#endif // PEPPER_HOST_FACTORY_QT_H diff --git a/src/core/renderer_host/pepper/pepper_isolated_file_system_message_filter.cpp b/src/core/renderer_host/pepper/pepper_isolated_file_system_message_filter.cpp deleted file mode 100644 index 5d7c3973f..000000000 --- a/src/core/renderer_host/pepper/pepper_isolated_file_system_message_filter.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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$ -** -****************************************************************************/ - -// This is based on chrome/browser/renderer_host/pepper/pepper_isolated_file_system_message_filter.cc: -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.Chromium file. - -#include "pepper_isolated_file_system_message_filter.h" - -#include "base/macros.h" -#include "base/task/post_task.h" -#include "chrome/common/chrome_switches.h" -#include "content/public/browser/browser_ppapi_host.h" -#include "content/public/browser/browser_task_traits.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/child_process_security_policy.h" -#include "content/public/browser/render_view_host.h" -#include "ppapi/c/pp_errors.h" -#include "ppapi/host/dispatch_host_message.h" -#include "ppapi/host/host_message_context.h" -#include "ppapi/host/ppapi_host.h" -#include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/shared_impl/file_system_util.h" -#include "storage/browser/fileapi/isolated_context.h" - -namespace QtWebEngineCore { - -// static -PepperIsolatedFileSystemMessageFilter* PepperIsolatedFileSystemMessageFilter::Create(PP_Instance instance, content::BrowserPpapiHost *host) -{ - int render_process_id; - int unused_render_frame_id; - if (!host->GetRenderFrameIDsForInstance(instance, &render_process_id, &unused_render_frame_id)) - return nullptr; - return new PepperIsolatedFileSystemMessageFilter(render_process_id, host->GetPpapiHost()); -} - -PepperIsolatedFileSystemMessageFilter::PepperIsolatedFileSystemMessageFilter(int render_process_id, - ppapi::host::PpapiHost *ppapi_host) - : m_render_process_id(render_process_id), - m_ppapi_host(ppapi_host) -{} - -PepperIsolatedFileSystemMessageFilter::~PepperIsolatedFileSystemMessageFilter() -{} - -scoped_refptr<base::TaskRunner> PepperIsolatedFileSystemMessageFilter::OverrideTaskRunnerForMessage(const IPC::Message &) -{ - // In order to reach ExtensionSystem, we need to get ProfileManager first. - // ProfileManager lives in UI thread, so we need to do this in UI thread. - return base::CreateSingleThreadTaskRunnerWithTraits({content::BrowserThread::UI}); -} - -int32_t PepperIsolatedFileSystemMessageFilter::OnResourceMessageReceived(const IPC::Message& msg, ppapi::host::HostMessageContext *context) -{ - PPAPI_BEGIN_MESSAGE_MAP(PepperIsolatedFileSystemMessageFilter, msg) - PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_IsolatedFileSystem_BrowserOpen, OnOpenFileSystem) - PPAPI_END_MESSAGE_MAP() - return PP_ERROR_FAILED; -} - -int32_t PepperIsolatedFileSystemMessageFilter::OnOpenFileSystem(ppapi::host::HostMessageContext *context, - PP_IsolatedFileSystemType_Private type) -{ - switch (type) { - case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_INVALID: - break; - case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_CRX: - return PP_ERROR_NOTSUPPORTED; - case PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_PLUGINPRIVATE: - return OpenPluginPrivateFileSystem(context); - } - NOTREACHED(); - context->reply_msg = PpapiPluginMsg_IsolatedFileSystem_BrowserOpenReply(std::string()); - return PP_ERROR_FAILED; -} - -int32_t PepperIsolatedFileSystemMessageFilter::OpenPluginPrivateFileSystem(ppapi::host::HostMessageContext *context) -{ - DCHECK(m_ppapi_host); - // Only plugins with private permission can open the filesystem. - if (!m_ppapi_host->permissions().HasPermission(ppapi::PERMISSION_PRIVATE)) - return PP_ERROR_NOACCESS; - - const std::string& root_name = ppapi::IsolatedFileSystemTypeToRootName(PP_ISOLATEDFILESYSTEMTYPE_PRIVATE_PLUGINPRIVATE); - const std::string& fsid = - storage::IsolatedContext::GetInstance()->RegisterFileSystemForVirtualPath( - storage::kFileSystemTypePluginPrivate, root_name, base::FilePath()); - - // Grant full access of isolated filesystem to renderer process. - content::ChildProcessSecurityPolicy* policy = content::ChildProcessSecurityPolicy::GetInstance(); - policy->GrantCreateReadWriteFileSystem(m_render_process_id, fsid); - - context->reply_msg = PpapiPluginMsg_IsolatedFileSystem_BrowserOpenReply(fsid); - return PP_OK; -} - -} // namespace chrome diff --git a/src/core/renderer_host/pepper/pepper_isolated_file_system_message_filter.h b/src/core/renderer_host/pepper/pepper_isolated_file_system_message_filter.h deleted file mode 100644 index 750f7cea0..000000000 --- a/src/core/renderer_host/pepper/pepper_isolated_file_system_message_filter.h +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 PEPPER_ISOLATED_FILE_SYSTEM_MESSAGE_FILTER_H -#define PEPPER_ISOLATED_FILE_SYSTEM_MESSAGE_FILTER_H - -#include "base/macros.h" -#include "ppapi/c/pp_instance.h" -#include "ppapi/c/pp_resource.h" -#include "ppapi/c/private/ppb_isolated_file_system_private.h" -#include "ppapi/host/resource_host.h" -#include "ppapi/host/resource_message_filter.h" - -namespace content { -class BrowserPpapiHost; -} - -namespace ppapi { -namespace host { -struct HostMessageContext; -} // namespace host -} // namespace ppapi - -namespace QtWebEngineCore { - -class PepperIsolatedFileSystemMessageFilter : public ppapi::host::ResourceMessageFilter { -public: - static PepperIsolatedFileSystemMessageFilter *Create(PP_Instance instance, content::BrowserPpapiHost *host); - - // ppapi::host::ResourceMessageFilter implementation. - scoped_refptr<base::TaskRunner> OverrideTaskRunnerForMessage(const IPC::Message &msg) override; - int32_t OnResourceMessageReceived(const IPC::Message &msg, ppapi::host::HostMessageContext *context) override; - -private: - PepperIsolatedFileSystemMessageFilter(int render_process_id, ppapi::host::PpapiHost *ppapi_host); - - ~PepperIsolatedFileSystemMessageFilter() override; - - - int32_t OnOpenFileSystem(ppapi::host::HostMessageContext *context, PP_IsolatedFileSystemType_Private type); - int32_t OpenPluginPrivateFileSystem(ppapi::host::HostMessageContext *context); - - const int m_render_process_id; - - // Not owned by this object. - ppapi::host::PpapiHost* m_ppapi_host; - - DISALLOW_COPY_AND_ASSIGN(PepperIsolatedFileSystemMessageFilter); -}; - -} // namespace QtWebEngineCore - -#endif // PEPPER_ISOLATED_FILE_SYSTEM_MESSAGE_FILTER_H diff --git a/src/core/renderer_host/render_view_observer_host_qt.cpp b/src/core/renderer_host/render_view_observer_host_qt.cpp deleted file mode 100644 index c097e102d..000000000 --- a/src/core/renderer_host/render_view_observer_host_qt.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 "render_view_observer_host_qt.h" - -#include "common/qt_messages.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/web_contents.h" - -#include "render_widget_host_view_qt.h" -#include "type_conversion.h" -#include "web_contents_adapter_client.h" - -namespace QtWebEngineCore { - -RenderViewObserverHostQt::RenderViewObserverHostQt(content::WebContents *webContents, WebContentsAdapterClient *adapterClient) - : content::WebContentsObserver(webContents) - , m_adapterClient(adapterClient) -{ -} - -void RenderViewObserverHostQt::fetchDocumentMarkup(quint64 requestId) -{ - web_contents()->GetRenderViewHost()->Send( - new RenderViewObserverQt_FetchDocumentMarkup( - web_contents()->GetRenderViewHost()->GetRoutingID(), requestId)); -} - -void RenderViewObserverHostQt::fetchDocumentInnerText(quint64 requestId) -{ - web_contents()->GetRenderViewHost()->Send( - new RenderViewObserverQt_FetchDocumentInnerText( - web_contents()->GetRenderViewHost()->GetRoutingID(), requestId)); -} - -bool RenderViewObserverHostQt::OnMessageReceived(const IPC::Message& message) -{ - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(RenderViewObserverHostQt, message) - IPC_MESSAGE_HANDLER(RenderViewObserverHostQt_DidFetchDocumentMarkup, - onDidFetchDocumentMarkup) - IPC_MESSAGE_HANDLER(RenderViewObserverHostQt_DidFetchDocumentInnerText, - onDidFetchDocumentInnerText) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; - -} - -void RenderViewObserverHostQt::onDidFetchDocumentMarkup(quint64 requestId, const base::string16& markup) -{ - m_adapterClient->didFetchDocumentMarkup(requestId, toQt(markup)); -} - -void RenderViewObserverHostQt::onDidFetchDocumentInnerText(quint64 requestId, const base::string16& innerText) -{ - m_adapterClient->didFetchDocumentInnerText(requestId, toQt(innerText)); -} - -} // namespace QtWebEngineCore diff --git a/src/core/renderer_host/render_view_observer_host_qt.h b/src/core/renderer_host/render_view_observer_host_qt.h deleted file mode 100644 index a08263e07..000000000 --- a/src/core/renderer_host/render_view_observer_host_qt.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 RENDER_VIEW_OBSERVER_HOST_QT_H -#define RENDER_VIEW_OBSERVER_HOST_QT_H - -#include "content/public/browser/web_contents_observer.h" - -#include <QtGlobal> - -namespace content { - class WebContents; -} - -namespace QtWebEngineCore { - -class WebContentsAdapterClient; - -class RenderViewObserverHostQt : public content::WebContentsObserver -{ -public: - RenderViewObserverHostQt(content::WebContents*, WebContentsAdapterClient *adapterClient); - void fetchDocumentMarkup(quint64 requestId); - void fetchDocumentInnerText(quint64 requestId); - -private: - bool OnMessageReceived(const IPC::Message& message) override; - void onDidFetchDocumentMarkup(quint64 requestId, const base::string16& markup); - void onDidFetchDocumentInnerText(quint64 requestId, const base::string16& innerText); - - WebContentsAdapterClient *m_adapterClient; -}; - -} // namespace QtWebEngineCore - -#endif // RENDER_VIEW_OBSERVER_HOST_QT_H diff --git a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp b/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp deleted file mode 100644 index eba835cd7..000000000 --- a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.Chromium file. - -#include "resource_dispatcher_host_delegate_qt.h" - -#include "base/bind.h" -#include "base/guid.h" -#include "base/strings/stringprintf.h" -#include "base/task/post_task.h" -#include "content/public/browser/browser_context.h" -#include "content/public/browser/browser_task_traits.h" -#include "content/public/browser/browser_thread.h" -#include "content/public/browser/download_manager.h" -#include "content/public/browser/download_request_utils.h" -#include "content/public/browser/navigation_controller.h" - -#include "content/public/browser/render_frame_host.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/resource_dispatcher_host.h" -#include "content/public/browser/resource_request_info.h" -#include "content/public/browser/stream_info.h" -#include "content/public/browser/web_contents.h" - -#include "extensions/extension_system_qt.h" -#include "extensions/browser/info_map.h" -#include "extensions/common/constants.h" -#include "extensions/common/extension.h" -#include "extensions/common/manifest_handlers/mime_types_handler.h" - -#include "net/base/escape.h" -#include "net/url_request/url_request.h" - -#include "profile_io_data_qt.h" -#include "type_conversion.h" -#include "web_contents_delegate_qt.h" -#include "web_engine_settings.h" - -namespace QtWebEngineCore { - -void OnPdfStreamIntercepted( - const GURL& original_url, - std::string extension_id, - int frame_tree_node_id, - const content::ResourceRequestInfo::WebContentsGetter& - web_contents_getter) { - content::WebContents* web_contents = web_contents_getter.Run(); - if (!web_contents) - return; - - WebContentsDelegateQt *contentsDelegate = static_cast<WebContentsDelegateQt*>(web_contents->GetDelegate()); - if (!contentsDelegate) - return; - - WebEngineSettings *settings = contentsDelegate->webEngineSettings(); - if (!settings->testAttribute(WebEngineSettings::PdfViewerEnabled) - || !settings->testAttribute(WebEngineSettings::PluginsEnabled)) { - // If the applications has been set up to always download PDF files to open them in an - // external viewer, trigger the download. - std::unique_ptr<download::DownloadUrlParameters> params( - content::DownloadRequestUtils::CreateDownloadForWebContentsMainFrame( - web_contents, original_url, NO_TRAFFIC_ANNOTATION_YET)); - content::BrowserContext::GetDownloadManager(web_contents->GetBrowserContext()) - ->DownloadUrl(std::move(params)); - return; - } - - // The URL passes the original pdf resource url, that will be requested - // by the pdf viewer extension page. - content::NavigationController::LoadURLParams params( - GURL(base::StringPrintf("%s://%s/index.html?%s", extensions::kExtensionScheme, - extension_id.c_str(), - original_url.spec().c_str()))); - - params.frame_tree_node_id = frame_tree_node_id; - web_contents->GetController().LoadURLWithParams(params); -} - -bool ResourceDispatcherHostDelegateQt::ShouldInterceptResourceAsStream(net::URLRequest *request, - const std::string &mime_type, - GURL *origin, - std::string *payload) -{ - content::ResourceRequestInfo* info = - content::ResourceRequestInfo::ForRequest(request); - - int render_process_host_id = -1; - int render_frame_id = -1; - if (!content::ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_host_id, &render_frame_id)) - return false; - - std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist(); - - extensions::ExtensionSystemQt *extensionSystem = ProfileIODataQt::FromResourceContext(info->GetContext())->GetExtensionSystem(); - if (!extensionSystem) - return false; - - const scoped_refptr<const extensions::InfoMap> extension_info_map(extensionSystem->info_map()); - - for (const std::string &extension_id : whitelist) { - const extensions::Extension *extension = extension_info_map->extensions().GetByID(extension_id); - if (!extension) - continue; - - MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); - if (!handler) - continue; - if (handler->CanHandleMIMEType(mime_type)) { - StreamTargetInfo target_info; - *origin = extensions::Extension::GetBaseURLFromExtensionId(extension_id); - target_info.extension_id = extension_id; - target_info.view_id = base::GenerateGUID(); - *payload = target_info.view_id; - stream_target_info_[request] = target_info; - return true; - } - } - return false; -} - -// Informs the delegate that a Stream was created. The Stream can be read from -// the blob URL of the Stream, but can only be read once. -void ResourceDispatcherHostDelegateQt::OnStreamCreated(net::URLRequest *request, - std::unique_ptr<content::StreamInfo> stream) -{ - content::ResourceRequestInfo *info = content::ResourceRequestInfo::ForRequest(request); - std::map<net::URLRequest *, StreamTargetInfo>::iterator ix = stream_target_info_.find(request); - CHECK(ix != stream_target_info_.end()); - int render_frame_id = -1; - int render_process_id = -1; - if (!content::ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_id, &render_frame_id)) { - stream_target_info_.erase(request); - request->Cancel(); - return; - } - - base::PostTaskWithTraits( - FROM_HERE, {content::BrowserThread::UI}, - base::BindOnce(&OnPdfStreamIntercepted, - request->url(), ix->second.extension_id, - info->GetFrameTreeNodeId(), info->GetWebContentsGetterForRequest() - ) - ); - stream_target_info_.erase(request); -} - -} // namespace QtWebEngineCore diff --git a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.h b/src/core/renderer_host/resource_dispatcher_host_delegate_qt.h deleted file mode 100644 index 3039fd03e..000000000 --- a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H -#define RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H - -#include "content/public/browser/resource_dispatcher_host_delegate.h" -#include "extensions/buildflags/buildflags.h" - -#include "web_contents_adapter_client.h" - -namespace QtWebEngineCore { - -class ResourceDispatcherHostDelegateQt : public content::ResourceDispatcherHostDelegate { -public: - // If the stream will be rendered in a BrowserPlugin, |payload| will contain - // the data that should be given to the old ResourceHandler to forward to the - // renderer process. - bool ShouldInterceptResourceAsStream(net::URLRequest *request, - const std::string &mime_type, - GURL *origin, - std::string *payload) override; - - // Informs the delegate that a Stream was created. The Stream can be read from - // the blob URL of the Stream, but can only be read once. - void OnStreamCreated(net::URLRequest *request, - std::unique_ptr<content::StreamInfo> stream) override; -private: -#if BUILDFLAG(ENABLE_EXTENSIONS) - struct StreamTargetInfo { - std::string extension_id; - std::string view_id; - }; - std::map<net::URLRequest *, StreamTargetInfo> stream_target_info_; -#endif - -}; - -} // namespace QtWebEngineCore - -#endif // RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H diff --git a/src/core/renderer_host/user_resource_controller_host.cpp b/src/core/renderer_host/user_resource_controller_host.cpp index ed4d736f2..f2a00fc72 100644 --- a/src/core/renderer_host/user_resource_controller_host.cpp +++ b/src/core/renderer_host/user_resource_controller_host.cpp @@ -1,92 +1,67 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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) 2016 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 "user_resource_controller_host.h" -#include "common/qt_messages.h" #include "type_conversion.h" #include "web_contents_adapter.h" + #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host_observer.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_observer.h" +#include "ipc/ipc_channel_proxy.h" +#include "qtwebengine/userscript/userscript.mojom.h" +#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" namespace QtWebEngineCore { -class UserResourceControllerHost::WebContentsObserverHelper : public content::WebContentsObserver { +class UserResourceControllerHost::WebContentsObserverHelper : public content::WebContentsObserver +{ public: WebContentsObserverHelper(UserResourceControllerHost *, content::WebContents *); // WebContentsObserver overrides: void RenderFrameCreated(content::RenderFrameHost *renderFrameHost) override; - void RenderFrameHostChanged(content::RenderFrameHost *oldHost, - content::RenderFrameHost *newHost) override; + void RenderFrameHostChanged(content::RenderFrameHost *oldHost, content::RenderFrameHost *newHost) override; + void RenderFrameDeleted(content::RenderFrameHost *render_frame_host) override; void WebContentsDestroyed() override; private: UserResourceControllerHost *m_controllerHost; }; -UserResourceControllerHost::WebContentsObserverHelper::WebContentsObserverHelper(UserResourceControllerHost *controller, content::WebContents *contents) - : content::WebContentsObserver(contents) - , m_controllerHost(controller) +UserResourceControllerHost::WebContentsObserverHelper::WebContentsObserverHelper(UserResourceControllerHost *controller, + content::WebContents *contents) + : content::WebContentsObserver(contents) + , m_controllerHost(controller) { } -void UserResourceControllerHost::WebContentsObserverHelper::RenderFrameCreated( - content::RenderFrameHost *renderFrameHost) +void UserResourceControllerHost::WebContentsObserverHelper::RenderFrameCreated(content::RenderFrameHost *renderFrameHost) { content::WebContents *contents = web_contents(); + auto &remote = m_controllerHost->GetUserResourceControllerRenderFrame(renderFrameHost); const QList<UserScript> scripts = m_controllerHost->m_perContentsScripts.value(contents); for (const UserScript &script : scripts) - renderFrameHost->Send(new RenderFrameObserverHelper_AddScript( - renderFrameHost->GetRoutingID(), script.data())); + remote->AddScript(script.data()); } -void UserResourceControllerHost::WebContentsObserverHelper::RenderFrameHostChanged( - content::RenderFrameHost *oldHost, - content::RenderFrameHost *newHost) +void UserResourceControllerHost::WebContentsObserverHelper::RenderFrameHostChanged(content::RenderFrameHost *oldHost, + content::RenderFrameHost *newHost) { - if (oldHost) - oldHost->Send(new RenderFrameObserverHelper_ClearScripts(oldHost->GetRoutingID())); + if (oldHost) { + auto &remote = m_controllerHost->GetUserResourceControllerRenderFrame(oldHost); + remote->ClearScripts(); + } +} + +void UserResourceControllerHost::WebContentsObserverHelper::RenderFrameDeleted( + content::RenderFrameHost *render_frame_host) +{ + m_controllerHost->m_renderFrames.erase(render_frame_host); } void UserResourceControllerHost::WebContentsObserverHelper::WebContentsDestroyed() @@ -95,10 +70,12 @@ void UserResourceControllerHost::WebContentsObserverHelper::WebContentsDestroyed delete this; } -class UserResourceControllerHost::RenderProcessObserverHelper : public content::RenderProcessHostObserver { +class UserResourceControllerHost::RenderProcessObserverHelper : public content::RenderProcessHostObserver +{ public: RenderProcessObserverHelper(UserResourceControllerHost *); void RenderProcessHostDestroyed(content::RenderProcessHost *) override; + private: UserResourceControllerHost *m_controllerHost; }; @@ -111,20 +88,19 @@ UserResourceControllerHost::RenderProcessObserverHelper::RenderProcessObserverHe void UserResourceControllerHost::RenderProcessObserverHelper::RenderProcessHostDestroyed(content::RenderProcessHost *renderer) { Q_ASSERT(m_controllerHost); + delete m_controllerHost->m_observedProcesses[renderer]; m_controllerHost->m_observedProcesses.remove(renderer); } void UserResourceControllerHost::addUserScript(const UserScript &script, WebContentsAdapter *adapter) { - if (script.isNull()) - return; // Global scripts should be dispatched to all our render processes. const bool isProfileWideScript = !adapter; if (isProfileWideScript) { if (!m_profileWideScripts.contains(script)) { m_profileWideScripts.append(script); - for (content::RenderProcessHost *renderer : qAsConst(m_observedProcesses)) - renderer->Send(new UserResourceController_AddScript(script.data())); + for (auto controller : m_observedProcesses.values()) + (*controller)->AddScript(script.data()); } } else { content::WebContents *contents = adapter->webContents(); @@ -141,36 +117,20 @@ void UserResourceControllerHost::addUserScript(const UserScript &script, WebCont m_perContentsScripts.insert(contents, currentScripts); } } - contents->GetRenderViewHost()->Send( - new RenderFrameObserverHelper_AddScript( - contents->GetRenderViewHost()->GetMainFrame()->GetRoutingID(), - script.data())); + GetUserResourceControllerRenderFrame(contents->GetPrimaryMainFrame()) + ->AddScript(script.data()); } } -bool UserResourceControllerHost::containsUserScript(const UserScript &script, WebContentsAdapter *adapter) -{ - if (script.isNull()) - return false; - // Global scripts should be dispatched to all our render processes. - const bool isProfileWideScript = !adapter; - if (isProfileWideScript) - return m_profileWideScripts.contains(script); - return m_perContentsScripts.value(adapter->webContents()).contains(script); -} - bool UserResourceControllerHost::removeUserScript(const UserScript &script, WebContentsAdapter *adapter) { - if (script.isNull()) - return false; const bool isProfileWideScript = !adapter; if (isProfileWideScript) { - QList<UserScript>::iterator it - = std::find(m_profileWideScripts.begin(), m_profileWideScripts.end(), script); + QList<UserScript>::iterator it = std::find(m_profileWideScripts.begin(), m_profileWideScripts.end(), script); if (it == m_profileWideScripts.end()) return false; - for (content::RenderProcessHost *renderer : qAsConst(m_observedProcesses)) - renderer->Send(new UserResourceController_RemoveScript((*it).data())); + for (auto controller : m_observedProcesses.values()) + (*controller)->RemoveScript((*it).data()); m_profileWideScripts.erase(it); } else { content::WebContents *contents = adapter->webContents(); @@ -180,10 +140,8 @@ bool UserResourceControllerHost::removeUserScript(const UserScript &script, WebC QList<UserScript>::iterator it = std::find(list.begin(), list.end(), script); if (it == list.end()) return false; - contents->GetRenderViewHost()->Send( - new RenderFrameObserverHelper_RemoveScript( - contents->GetMainFrame()->GetRoutingID(), - (*it).data())); + GetUserResourceControllerRenderFrame(contents->GetPrimaryMainFrame()) + ->RemoveScript((*it).data()); list.erase(it); } return true; @@ -194,24 +152,18 @@ void UserResourceControllerHost::clearAllScripts(WebContentsAdapter *adapter) const bool isProfileWideScript = !adapter; if (isProfileWideScript) { m_profileWideScripts.clear(); - for (content::RenderProcessHost *renderer : qAsConst(m_observedProcesses)) - renderer->Send(new UserResourceController_ClearScripts); + for (auto controller : m_observedProcesses.values()) + (*controller)->ClearScripts(); } else { content::WebContents *contents = adapter->webContents(); m_perContentsScripts.remove(contents); - contents->GetRenderViewHost()->Send( - new RenderFrameObserverHelper_ClearScripts(contents->GetMainFrame()->GetRoutingID())); + mojo::AssociatedRemote<qtwebengine::mojom::UserResourceControllerRenderFrame> + userResourceController; + GetUserResourceControllerRenderFrame(contents->GetPrimaryMainFrame()) + ->ClearScripts(); } } -const QList<UserScript> UserResourceControllerHost::registeredScripts(WebContentsAdapter *adapter) const -{ - const bool isProfileWideScript = !adapter; - if (isProfileWideScript) - return m_profileWideScripts; - return m_perContentsScripts.value(adapter->webContents()); -} - void UserResourceControllerHost::reserve(WebContentsAdapter *adapter, int count) { const bool isProfileWideScript = !adapter; @@ -223,15 +175,18 @@ void UserResourceControllerHost::reserve(WebContentsAdapter *adapter, int count) void UserResourceControllerHost::renderProcessStartedWithHost(content::RenderProcessHost *renderer) { - if (m_observedProcesses.contains(renderer)) + if (m_observedProcesses.keys().contains(renderer)) return; if (m_renderProcessObserver.isNull()) m_renderProcessObserver.reset(new RenderProcessObserverHelper(this)); renderer->AddObserver(m_renderProcessObserver.data()); - m_observedProcesses.insert(renderer); - for (const UserScript &script : qAsConst(m_profileWideScripts)) - renderer->Send(new UserResourceController_AddScript(script.data())); + auto userResourceController = new UserResourceControllerRemote; + renderer->GetChannel()->GetRemoteAssociatedInterface(userResourceController); + m_observedProcesses.insert(renderer, userResourceController); + for (const UserScript &script : std::as_const(m_profileWideScripts)) { + (*userResourceController)->AddScript(script.data()); + } } void UserResourceControllerHost::webContentsDestroyed(content::WebContents *contents) @@ -245,8 +200,26 @@ UserResourceControllerHost::UserResourceControllerHost() UserResourceControllerHost::~UserResourceControllerHost() { - for (content::RenderProcessHost *renderer : qAsConst(m_observedProcesses)) + for (content::RenderProcessHost *renderer : m_observedProcesses.keys()) { renderer->RemoveObserver(m_renderProcessObserver.data()); + delete m_observedProcesses[renderer]; + } +} + +const UserResourceControllerRenderFrameRemote & +UserResourceControllerHost::GetUserResourceControllerRenderFrame(content::RenderFrameHost *rfh) +{ + auto it = m_renderFrames.find(rfh); + if (it == m_renderFrames.end()) { + UserResourceControllerRenderFrameRemote remote; + rfh->GetRemoteAssociatedInterfaces()->GetInterface(remote.BindNewEndpointAndPassReceiver()); + it = m_renderFrames.insert(std::make_pair(rfh, std::move(remote))).first; + } else if (it->second.is_bound() && !it->second.is_connected()) { + it->second.reset(); + rfh->GetRemoteAssociatedInterfaces()->GetInterface(&it->second); + } + + return it->second; } } // namespace diff --git a/src/core/renderer_host/user_resource_controller_host.h b/src/core/renderer_host/user_resource_controller_host.h index 16a73f5fb..eb4404879 100644 --- a/src/core/renderer_host/user_resource_controller_host.h +++ b/src/core/renderer_host/user_resource_controller_host.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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) 2016 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 // // W A R N I N G @@ -53,31 +17,47 @@ #include "qtwebenginecoreglobal_p.h" -#include <QtCore/QSet> +#include <QtCore/QHash> #include <QtCore/QScopedPointer> +#include <map> #include "user_script.h" namespace content { class RenderProcessHost; class WebContents; +class RenderFrameHost; +} + +namespace mojo { +template <typename Type> +class AssociatedRemote; +} + +namespace qtwebengine { +namespace mojom { +class UserResourceController; +class UserResourceControllerRenderFrame; +} } namespace QtWebEngineCore { +class UserScript; +using UserResourceControllerRemote = mojo::AssociatedRemote<qtwebengine::mojom::UserResourceController>; +using UserResourceControllerRenderFrameRemote = mojo::AssociatedRemote<qtwebengine::mojom::UserResourceControllerRenderFrame>; class WebContentsAdapter; -class Q_WEBENGINECORE_PRIVATE_EXPORT UserResourceControllerHost { +class Q_WEBENGINECORE_EXPORT UserResourceControllerHost +{ public: UserResourceControllerHost(); ~UserResourceControllerHost(); void addUserScript(const UserScript &script, WebContentsAdapter *adapter); - bool containsUserScript(const UserScript &script, WebContentsAdapter *adapter); bool removeUserScript(const UserScript &script, WebContentsAdapter *adapter); void clearAllScripts(WebContentsAdapter *adapter); void reserve(WebContentsAdapter *adapter, int count); - const QList<UserScript> registeredScripts(WebContentsAdapter *adapter) const; void renderProcessStartedWithHost(content::RenderProcessHost *renderer); @@ -87,12 +67,15 @@ private: class RenderProcessObserverHelper; void webContentsDestroyed(content::WebContents *); + const UserResourceControllerRenderFrameRemote & + GetUserResourceControllerRenderFrame(content::RenderFrameHost *rfh); QList<UserScript> m_profileWideScripts; typedef QHash<content::WebContents *, QList<UserScript>> ContentsScriptsMap; ContentsScriptsMap m_perContentsScripts; - QSet<content::RenderProcessHost *> m_observedProcesses; + QHash<content::RenderProcessHost *, UserResourceControllerRemote *> m_observedProcesses; QScopedPointer<RenderProcessObserverHelper> m_renderProcessObserver; + std::map<content::RenderFrameHost *, UserResourceControllerRenderFrameRemote> m_renderFrames; }; } // namespace diff --git a/src/core/renderer_host/web_channel_ipc_transport_host.cpp b/src/core/renderer_host/web_channel_ipc_transport_host.cpp index e1929e4cd..0824ed56d 100644 --- a/src/core/renderer_host/web_channel_ipc_transport_host.cpp +++ b/src/core/renderer_host/web_channel_ipc_transport_host.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 #include "web_channel_ipc_transport_host.h" @@ -46,40 +10,29 @@ #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" #include "services/service_manager/public/cpp/interface_provider.h" #include "qtwebengine/browser/qtwebchannel.mojom.h" -#include "common/qt_messages.h" #include <QJsonDocument> #include <QJsonObject> #include <QLoggingCategory> -#include <QtCore/private/qjson_p.h> - namespace QtWebEngineCore { -Q_LOGGING_CATEGORY(log, "qt.webengine.webchanneltransport"); +Q_LOGGING_CATEGORY(log, "qt.webengine.webchanneltransport") inline QDebug operator<<(QDebug stream, content::RenderFrameHost *frame) { return stream << "frame " << frame->GetRoutingID() << " in process " << frame->GetProcess()->GetID(); } -template <class T> -inline QDebug operator<<(QDebug stream, const base::Optional<T> &opt) -{ - if (opt) - return stream << *opt; - else - return stream << "nullopt"; -} - WebChannelIPCTransportHost::WebChannelIPCTransportHost(content::WebContents *contents, uint worldId, QObject *parent) : QWebChannelAbstractTransport(parent) , content::WebContentsObserver(contents) , m_worldId(worldId) - , m_binding(contents, this) + , m_receiver(contents, this) { - for (content::RenderFrameHost *frame : contents->GetAllFrames()) - setWorldId(frame, worldId); + contents->ForEachRenderFrameHost([this, worldId](content::RenderFrameHost *frame) { + setWorldId(frame, worldId); + }); } WebChannelIPCTransportHost::~WebChannelIPCTransportHost() @@ -95,21 +48,20 @@ uint WebChannelIPCTransportHost::worldId() const void WebChannelIPCTransportHost::sendMessage(const QJsonObject &message) { QJsonDocument doc(message); - int size = 0; - const char *rawData = doc.rawData(&size); - content::RenderFrameHost *frame = web_contents()->GetMainFrame(); - qtwebchannel::mojom::WebChannelTransportRenderAssociatedPtr webChannelTransport; - frame->GetRemoteAssociatedInterfaces()->GetInterface(&webChannelTransport); + QByteArray json = doc.toJson(QJsonDocument::Compact); + content::RenderFrameHost *frame = web_contents()->GetPrimaryMainFrame(); qCDebug(log).nospace() << "sending webchannel message to " << frame << ": " << doc; - webChannelTransport->DispatchWebChannelMessage(std::vector<uint8_t>(rawData, rawData + size), m_worldId); + GetWebChannelIPCTransportRemote(frame)->DispatchWebChannelMessage( + std::vector<uint8_t>(json.begin(), json.end()), m_worldId); } void WebChannelIPCTransportHost::setWorldId(uint32_t worldId) { if (m_worldId == worldId) return; - for (content::RenderFrameHost *frame : web_contents()->GetAllFrames()) - setWorldId(frame, worldId); + web_contents()->ForEachRenderFrameHost([this, worldId](content::RenderFrameHost *frame) { + setWorldId(frame, worldId); + }); m_worldId = worldId; } @@ -118,36 +70,28 @@ void WebChannelIPCTransportHost::setWorldId(content::RenderFrameHost *frame, uin if (!frame->IsRenderFrameLive()) return; qCDebug(log).nospace() << "sending setWorldId(" << worldId << ") message to " << frame; - qtwebchannel::mojom::WebChannelTransportRenderAssociatedPtr webChannelTransport; - frame->GetRemoteAssociatedInterfaces()->GetInterface(&webChannelTransport); - webChannelTransport->SetWorldId(worldId); + GetWebChannelIPCTransportRemote(frame)->SetWorldId(worldId); } void WebChannelIPCTransportHost::resetWorldId() { - for (content::RenderFrameHost *frame : web_contents()->GetAllFrames()) { + web_contents()->ForEachRenderFrameHost([this] (content::RenderFrameHost *frame) { if (!frame->IsRenderFrameLive()) return; - qtwebchannel::mojom::WebChannelTransportRenderAssociatedPtr webChannelTransport; - frame->GetRemoteAssociatedInterfaces()->GetInterface(&webChannelTransport); - webChannelTransport->ResetWorldId(); - } + GetWebChannelIPCTransportRemote(frame)->ResetWorldId(); + }); } -void WebChannelIPCTransportHost::DispatchWebChannelMessage(const std::vector<uint8_t> &binaryJson) +void WebChannelIPCTransportHost::DispatchWebChannelMessage(const std::vector<uint8_t> &json) { - content::RenderFrameHost *frame = web_contents()->GetMainFrame(); + content::RenderFrameHost *frame = web_contents()->GetPrimaryMainFrame(); - if (m_binding.GetCurrentTargetFrame() != frame) { + if (m_receiver.GetCurrentTargetFrame() != frame) { return; } - QJsonDocument doc; - // QJsonDocument::fromRawData does not check the length before it starts - // parsing the QJsonPrivate::Header and QJsonPrivate::Base structures. - if (binaryJson.size() >= sizeof(QJsonPrivate::Header) + sizeof(QJsonPrivate::Base)) - doc = QJsonDocument::fromRawData(reinterpret_cast<const char *>(binaryJson.data()), - binaryJson.size()); + QJsonDocument doc = QJsonDocument::fromJson( + QByteArray(reinterpret_cast<const char *>(json.data()), json.size())); if (!doc.isObject()) { qCCritical(log).nospace() << "received invalid webchannel message from " << frame; @@ -163,4 +107,33 @@ void WebChannelIPCTransportHost::RenderFrameCreated(content::RenderFrameHost *fr setWorldId(frame, m_worldId); } +void WebChannelIPCTransportHost::RenderFrameDeleted(content::RenderFrameHost *rfh) +{ + m_renderFrames.erase(rfh); +} + +void WebChannelIPCTransportHost::BindReceiver( + mojo::PendingAssociatedReceiver<qtwebchannel::mojom::WebChannelTransportHost> receiver, + content::RenderFrameHost *rfh) +{ + m_receiver.Bind(rfh, std::move(receiver)); +} + + +const mojo::AssociatedRemote<qtwebchannel::mojom::WebChannelTransportRender> & +WebChannelIPCTransportHost::GetWebChannelIPCTransportRemote(content::RenderFrameHost *rfh) +{ + auto it = m_renderFrames.find(rfh); + if (it == m_renderFrames.end()) { + mojo::AssociatedRemote<qtwebchannel::mojom::WebChannelTransportRender> remote; + rfh->GetRemoteAssociatedInterfaces()->GetInterface(remote.BindNewEndpointAndPassReceiver()); + it = m_renderFrames.insert(std::make_pair(rfh, std::move(remote))).first; + } else if (it->second.is_bound() && !it->second.is_connected()) { + it->second.reset(); + rfh->GetRemoteAssociatedInterfaces()->GetInterface(&it->second); + } + + return it->second; +} + } // namespace QtWebEngineCore diff --git a/src/core/renderer_host/web_channel_ipc_transport_host.h b/src/core/renderer_host/web_channel_ipc_transport_host.h index 94891f25f..9e003c222 100644 --- a/src/core/renderer_host/web_channel_ipc_transport_host.h +++ b/src/core/renderer_host/web_channel_ipc_transport_host.h @@ -1,61 +1,27 @@ -/**************************************************************************** -** -** 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 #ifndef WEB_CHANNEL_IPC_TRANSPORT_H #define WEB_CHANNEL_IPC_TRANSPORT_H #include "qtwebenginecoreglobal.h" +#include "content/public/browser/render_frame_host_receiver_set.h" #include "content/public/browser/web_contents_observer.h" -#include "services/service_manager/public/cpp/binder_registry.h" -#include "content/public/browser/web_contents_binding_set.h" #include "qtwebengine/browser/qtwebchannel.mojom.h" #include <QWebChannelAbstractTransport> +#include <map> QT_FORWARD_DECLARE_CLASS(QString) namespace QtWebEngineCore { -class WebChannelIPCTransportHost : public QWebChannelAbstractTransport +class WebChannelIPCTransportHost + : public QWebChannelAbstractTransport , private content::WebContentsObserver - , qtwebchannel::mojom::WebChannelTransportHost { + , qtwebchannel::mojom::WebChannelTransportHost +{ public: WebChannelIPCTransportHost(content::WebContents *webContents, uint32_t worldId = 0, QObject *parent = nullptr); ~WebChannelIPCTransportHost() override; @@ -66,21 +32,31 @@ public: // QWebChannelAbstractTransport void sendMessage(const QJsonObject &message) override; + void BindReceiver( + mojo::PendingAssociatedReceiver<qtwebchannel::mojom::WebChannelTransportHost> receiver, + content::RenderFrameHost *rfh); + private: void setWorldId(content::RenderFrameHost *frame, uint32_t worldId); void resetWorldId(); - void onWebChannelMessage(const std::vector<char> &message); + + const mojo::AssociatedRemote<qtwebchannel::mojom::WebChannelTransportRender> & + GetWebChannelIPCTransportRemote(content::RenderFrameHost *rfh); // WebContentsObserver void RenderFrameCreated(content::RenderFrameHost *frame) override; + void RenderFrameDeleted(content::RenderFrameHost *render_frame_host) override; // qtwebchannel::mojom::WebChannelTransportHost - void DispatchWebChannelMessage(const std::vector<uint8_t> &binaryJson) override; + void DispatchWebChannelMessage(const std::vector<uint8_t> &json) override; // Empty only during construction/destruction. Synchronized to all the // WebChannelIPCTransports/RenderFrames in the observed WebContents. uint32_t m_worldId; - content::WebContentsFrameBindingSet<qtwebchannel::mojom::WebChannelTransportHost> m_binding; + content::RenderFrameHostReceiverSet<qtwebchannel::mojom::WebChannelTransportHost> m_receiver; + std::map<content::RenderFrameHost *, + mojo::AssociatedRemote<qtwebchannel::mojom::WebChannelTransportRender>> + m_renderFrames; }; } // namespace diff --git a/src/core/renderer_host/web_engine_page_host.cpp b/src/core/renderer_host/web_engine_page_host.cpp new file mode 100644 index 000000000..ea9b363ea --- /dev/null +++ b/src/core/renderer_host/web_engine_page_host.cpp @@ -0,0 +1,76 @@ +// Copyright (C) 2016 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 "web_engine_page_host.h" + +#include "qtwebengine/browser/qtwebenginepage.mojom.h" +#include "content/public/browser/web_contents.h" + +#include "render_widget_host_view_qt.h" +#include "type_conversion.h" +#include "web_contents_adapter_client.h" +#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" + +namespace QtWebEngineCore { + +WebEnginePageHost::WebEnginePageHost(content::WebContents *webContents, + WebContentsAdapterClient *adapterClient) + : content::WebContentsObserver(webContents), m_adapterClient(adapterClient) +{ +} + +void WebEnginePageHost::FetchDocumentMarkup(uint64_t requestId) +{ + auto &remote = GetWebEnginePageRenderFrame(web_contents()->GetPrimaryMainFrame()); + remote->FetchDocumentMarkup( + requestId, + base::BindOnce(&WebEnginePageHost::OnDidFetchDocumentMarkup, base::Unretained(this))); +} + +void WebEnginePageHost::FetchDocumentInnerText(uint64_t requestId) +{ + auto &remote = GetWebEnginePageRenderFrame(web_contents()->GetPrimaryMainFrame()); + remote->FetchDocumentInnerText(requestId, + base::BindOnce(&WebEnginePageHost::OnDidFetchDocumentInnerText, + base::Unretained(this))); +} + +void WebEnginePageHost::OnDidFetchDocumentMarkup(uint64_t requestId, const std::string &markup) +{ + m_adapterClient->didFetchDocumentMarkup(requestId, toQt(markup)); +} + +void WebEnginePageHost::OnDidFetchDocumentInnerText(uint64_t requestId, + const std::string &innerText) +{ + m_adapterClient->didFetchDocumentInnerText(requestId, toQt(innerText)); +} + +void WebEnginePageHost::RenderFrameDeleted(content::RenderFrameHost *render_frame) +{ + m_renderFrames.erase(render_frame); +} + +void WebEnginePageHost::SetBackgroundColor(uint32_t color) +{ + auto &remote = GetWebEnginePageRenderFrame(web_contents()->GetPrimaryMainFrame()); + remote->SetBackgroundColor(color); +} + +const WebEnginePageRenderFrameRemote & +WebEnginePageHost::GetWebEnginePageRenderFrame(content::RenderFrameHost *rfh) +{ + auto it = m_renderFrames.find(rfh); + if (it == m_renderFrames.end()) { + WebEnginePageRenderFrameRemote remote; + rfh->GetRemoteAssociatedInterfaces()->GetInterface(remote.BindNewEndpointAndPassReceiver()); + it = m_renderFrames.insert(std::make_pair(rfh, std::move(remote))).first; + } else if (it->second.is_bound() && !it->second.is_connected()) { + it->second.reset(); + rfh->GetRemoteAssociatedInterfaces()->GetInterface(&it->second); + } + + return it->second; +} + +} // namespace QtWebEngineCore diff --git a/src/core/renderer_host/web_engine_page_host.h b/src/core/renderer_host/web_engine_page_host.h new file mode 100644 index 000000000..20b9145b2 --- /dev/null +++ b/src/core/renderer_host/web_engine_page_host.h @@ -0,0 +1,54 @@ +// Copyright (C) 2016 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 WEB_ENGINE_PAGE_HOST_H +#define WEB_ENGINE_PAGE_HOST_H + +#include "content/public/browser/web_contents_observer.h" + +#include <QtGlobal> + +namespace content { +class WebContents; +} + +namespace mojo { +template<typename Type> +class AssociatedRemote; +} + +namespace qtwebenginepage { +namespace mojom { +class WebEnginePageRenderFrame; +} +} + +namespace QtWebEngineCore { + +using WebEnginePageRenderFrameRemote = mojo::AssociatedRemote<qtwebenginepage::mojom::WebEnginePageRenderFrame>; + +class WebContentsAdapterClient; + +class WebEnginePageHost : public content::WebContentsObserver +{ +public: + WebEnginePageHost(content::WebContents *, WebContentsAdapterClient *adapterClient); + void FetchDocumentMarkup(uint64_t requestId); + void FetchDocumentInnerText(uint64_t requestId); + void RenderFrameDeleted(content::RenderFrameHost *render_frame) override; + void SetBackgroundColor(uint32_t color); + +private: + void OnDidFetchDocumentMarkup(uint64_t requestId, const std::string &markup); + void OnDidFetchDocumentInnerText(uint64_t requestId, const std::string &innerText); + const WebEnginePageRenderFrameRemote & + GetWebEnginePageRenderFrame(content::RenderFrameHost *rfh); + +private: + WebContentsAdapterClient *m_adapterClient; + std::map<content::RenderFrameHost *, WebEnginePageRenderFrameRemote> m_renderFrames; +}; + +} // namespace QtWebEngineCore + +#endif // WEB_ENGINE_PAGE_HOST_H |