From aeadc50e2c2efdde82e246a82f0b7983d1801805 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 23 Sep 2016 11:12:41 +0200 Subject: Cleanup directory structure The src/core/renderer directory is meant to contain files that would be in the renderer process and the chrome/renderer subdirectory in chromium, but a few classes from the browser process and the renderer_host dir has snuck in. This patch cleans up the structure so that classes in the browser that serves as host classes for renderer classes goes in renderer_host. Change-Id: I9333b1322e2246d4da9b4e8cfe6be604f6d996bf Reviewed-by: Peter Varga --- src/core/authentication_dialog_controller_p.h | 3 +- src/core/browser_context_adapter.cpp | 3 +- src/core/content_browser_client_qt.cpp | 6 +- src/core/core_gyp_generator.pro | 24 +-- .../pepper/pepper_flash_browser_host_qt.cpp | 137 ------------ .../renderer/pepper/pepper_flash_browser_host_qt.h | 93 -------- .../renderer/pepper/pepper_host_factory_qt.cpp | 113 ---------- src/core/renderer/pepper/pepper_host_factory_qt.h | 73 ------- .../pepper_isolated_file_system_message_filter.cpp | 133 ------------ .../pepper_isolated_file_system_message_filter.h | 89 -------- .../pepper/pepper_flash_browser_host_qt.cpp | 137 ++++++++++++ .../pepper/pepper_flash_browser_host_qt.h | 93 ++++++++ .../pepper/pepper_host_factory_qt.cpp | 113 ++++++++++ .../renderer_host/pepper/pepper_host_factory_qt.h | 73 +++++++ .../pepper_isolated_file_system_message_filter.cpp | 133 ++++++++++++ .../pepper_isolated_file_system_message_filter.h | 89 ++++++++ .../resource_dispatcher_host_delegate_qt.cpp | 175 +++++++++++++++ .../resource_dispatcher_host_delegate_qt.h | 102 +++++++++ .../user_resource_controller_host.cpp | 239 +++++++++++++++++++++ .../renderer_host/user_resource_controller_host.h | 90 ++++++++ .../web_channel_ipc_transport_host.cpp | 105 +++++++++ .../renderer_host/web_channel_ipc_transport_host.h | 78 +++++++ src/core/resource_dispatcher_host_delegate_qt.cpp | 175 --------------- src/core/resource_dispatcher_host_delegate_qt.h | 102 --------- src/core/user_resource_controller_host.cpp | 239 --------------------- src/core/user_resource_controller_host.h | 90 -------- src/core/web_channel_ipc_transport_host.cpp | 105 --------- src/core/web_channel_ipc_transport_host.h | 78 ------- src/core/web_contents_adapter.cpp | 2 +- 29 files changed, 1447 insertions(+), 1445 deletions(-) delete mode 100644 src/core/renderer/pepper/pepper_flash_browser_host_qt.cpp delete mode 100644 src/core/renderer/pepper/pepper_flash_browser_host_qt.h delete mode 100644 src/core/renderer/pepper/pepper_host_factory_qt.cpp delete mode 100644 src/core/renderer/pepper/pepper_host_factory_qt.h delete mode 100644 src/core/renderer/pepper/pepper_isolated_file_system_message_filter.cpp delete mode 100644 src/core/renderer/pepper/pepper_isolated_file_system_message_filter.h create mode 100644 src/core/renderer_host/pepper/pepper_flash_browser_host_qt.cpp create mode 100644 src/core/renderer_host/pepper/pepper_flash_browser_host_qt.h create mode 100644 src/core/renderer_host/pepper/pepper_host_factory_qt.cpp create mode 100644 src/core/renderer_host/pepper/pepper_host_factory_qt.h create mode 100644 src/core/renderer_host/pepper/pepper_isolated_file_system_message_filter.cpp create mode 100644 src/core/renderer_host/pepper/pepper_isolated_file_system_message_filter.h create mode 100644 src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp create mode 100644 src/core/renderer_host/resource_dispatcher_host_delegate_qt.h create mode 100644 src/core/renderer_host/user_resource_controller_host.cpp create mode 100644 src/core/renderer_host/user_resource_controller_host.h create mode 100644 src/core/renderer_host/web_channel_ipc_transport_host.cpp create mode 100644 src/core/renderer_host/web_channel_ipc_transport_host.h delete mode 100644 src/core/resource_dispatcher_host_delegate_qt.cpp delete mode 100644 src/core/resource_dispatcher_host_delegate_qt.h delete mode 100644 src/core/user_resource_controller_host.cpp delete mode 100644 src/core/user_resource_controller_host.h delete mode 100644 src/core/web_channel_ipc_transport_host.cpp delete mode 100644 src/core/web_channel_ipc_transport_host.h (limited to 'src/core') diff --git a/src/core/authentication_dialog_controller_p.h b/src/core/authentication_dialog_controller_p.h index 2acc588e1..af5d92530 100644 --- a/src/core/authentication_dialog_controller_p.h +++ b/src/core/authentication_dialog_controller_p.h @@ -41,7 +41,8 @@ #define AUTHENTICATION_DIALOG_CONTROLLER_P_H #include "base/memory/ref_counted.h" -#include "resource_dispatcher_host_delegate_qt.h" + +#include "renderer_host/resource_dispatcher_host_delegate_qt.h" namespace QtWebEngineCore { diff --git a/src/core/browser_context_adapter.cpp b/src/core/browser_context_adapter.cpp index cf7987fa7..86808e177 100644 --- a/src/core/browser_context_adapter.cpp +++ b/src/core/browser_context_adapter.cpp @@ -41,6 +41,7 @@ #include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/browser_thread.h" + #include "browser_context_qt.h" #include "content_client_qt.h" #include "download_manager_delegate_qt.h" @@ -49,7 +50,7 @@ #include "web_engine_context.h" #include "web_engine_visited_links_manager.h" #include "url_request_context_getter_qt.h" -#include "user_resource_controller_host.h" +#include "renderer_host/user_resource_controller_host.h" #include "net/proxy/proxy_service.h" diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp index 5131d8229..a2453070e 100644 --- a/src/core/content_browser_client_qt.cpp +++ b/src/core/content_browser_client_qt.cpp @@ -81,8 +81,8 @@ #if defined(ENABLE_BASIC_PRINTING) #include "printing_message_filter_qt.h" #endif // defined(ENABLE_BASIC_PRINTING) -#include "resource_dispatcher_host_delegate_qt.h" -#include "user_resource_controller_host.h" +#include "renderer_host/resource_dispatcher_host_delegate_qt.h" +#include "renderer_host/user_resource_controller_host.h" #include "web_contents_delegate_qt.h" #include "web_engine_context.h" #include "web_engine_library_info.h" @@ -95,7 +95,7 @@ #if defined(ENABLE_PLUGINS) #include "content/public/browser/browser_ppapi_host.h" #include "ppapi/host/ppapi_host.h" -#include "renderer/pepper/pepper_host_factory_qt.h" +#include "renderer_host/pepper/pepper_host_factory_qt.h" #endif #include diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro index 1f745a3f5..f5b9f870c 100644 --- a/src/core/core_gyp_generator.pro +++ b/src/core/core_gyp_generator.pro @@ -81,18 +81,20 @@ SOURCES = \ render_view_observer_host_qt.cpp \ render_widget_host_view_qt.cpp \ renderer/content_renderer_client_qt.cpp \ - renderer/pepper/pepper_flash_browser_host_qt.cpp \ renderer/pepper/pepper_flash_renderer_host_qt.cpp \ - renderer/pepper/pepper_host_factory_qt.cpp \ - renderer/pepper/pepper_isolated_file_system_message_filter.cpp \ renderer/pepper/pepper_renderer_host_factory_qt.cpp \ renderer/render_frame_observer_qt.cpp \ renderer/render_view_observer_qt.cpp \ renderer/user_resource_controller.cpp \ renderer/web_channel_ipc_transport.cpp \ + renderer_host/pepper/pepper_flash_browser_host_qt.cpp \ + renderer_host/pepper/pepper_host_factory_qt.cpp \ + renderer_host/pepper/pepper_isolated_file_system_message_filter.cpp \ + renderer_host/resource_dispatcher_host_delegate_qt.cpp \ + renderer_host/user_resource_controller_host.cpp \ + renderer_host/web_channel_ipc_transport_host.cpp \ resource_bundle_qt.cpp \ resource_context_qt.cpp \ - resource_dispatcher_host_delegate_qt.cpp \ ssl_host_state_delegate_qt.cpp \ stream_video_node.cpp \ surface_factory_qt.cpp \ @@ -101,9 +103,7 @@ SOURCES = \ url_request_custom_job.cpp \ url_request_custom_job_delegate.cpp \ url_request_qrc_job_qt.cpp \ - user_resource_controller_host.cpp \ user_script.cpp \ - web_channel_ipc_transport_host.cpp \ web_contents_adapter.cpp \ web_contents_delegate_qt.cpp \ web_contents_view_qt.cpp \ @@ -164,17 +164,19 @@ HEADERS = \ render_widget_host_view_qt.h \ render_widget_host_view_qt_delegate.h \ renderer/content_renderer_client_qt.h \ - renderer/pepper/pepper_flash_browser_host_qt.h \ renderer/pepper/pepper_flash_renderer_host_qt.h \ - renderer/pepper/pepper_host_factory_qt.h \ - renderer/pepper/pepper_isolated_file_system_message_filter.h \ renderer/pepper/pepper_renderer_host_factory_qt.h \ renderer/render_frame_observer_qt.h \ renderer/render_view_observer_qt.h \ renderer/user_resource_controller.h \ renderer/web_channel_ipc_transport.h \ + renderer_host/pepper/pepper_flash_browser_host_qt.h \ + renderer_host/pepper/pepper_host_factory_qt.h \ + renderer_host/pepper/pepper_isolated_file_system_message_filter.h \ + renderer_host/resource_dispatcher_host_delegate_qt.h \ + renderer_host/user_resource_controller_host.h \ + renderer_host/web_channel_ipc_transport_host.h \ resource_context_qt.h \ - resource_dispatcher_host_delegate_qt.h \ ssl_host_state_delegate_qt.h \ stream_video_node.h \ surface_factory_qt.h \ @@ -183,9 +185,7 @@ HEADERS = \ url_request_custom_job.h \ url_request_custom_job_delegate.h \ url_request_qrc_job_qt.h \ - user_resource_controller_host.h \ user_script.h \ - web_channel_ipc_transport_host.h \ web_contents_adapter.h \ web_contents_adapter_client.h \ web_contents_adapter_p.h \ diff --git a/src/core/renderer/pepper/pepper_flash_browser_host_qt.cpp b/src/core/renderer/pepper/pepper_flash_browser_host_qt.cpp deleted file mode 100644 index 4427a67f2..000000000 --- a/src/core/renderer/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 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 -#elif defined(OS_MACOSX) -#include -#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/pepper/pepper_flash_browser_host_qt.h b/src/core/renderer/pepper/pepper_flash_browser_host_qt.h deleted file mode 100644 index 5d1107dfb..000000000 --- a/src/core/renderer/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 weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(PepperFlashBrowserHostQt); -}; - -} // namespace QtWebEngineCore - -#endif // PEPPER_FLASH_BROWSER_HOST_QT_H diff --git a/src/core/renderer/pepper/pepper_host_factory_qt.cpp b/src/core/renderer/pepper/pepper_host_factory_qt.cpp deleted file mode 100644 index 4a25e7756..000000000 --- a/src/core/renderer/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 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 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 clipboard_filter(new chrome::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/pepper/pepper_host_factory_qt.h b/src/core/renderer/pepper/pepper_host_factory_qt.h deleted file mode 100644 index 0446cf9e3..000000000 --- a/src/core/renderer/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 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/pepper/pepper_isolated_file_system_message_filter.cpp b/src/core/renderer/pepper/pepper_isolated_file_system_message_filter.cpp deleted file mode 100644 index 7e8b2fdda..000000000 --- a/src/core/renderer/pepper/pepper_isolated_file_system_message_filter.cpp +++ /dev/null @@ -1,133 +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 file. - -#include "pepper_isolated_file_system_message_filter.h" - -#include "base/macros.h" -#include "chrome/common/chrome_switches.h" -#include "content/public/browser/browser_ppapi_host.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 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 content::BrowserThread::GetMessageLoopProxyForThread(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/pepper/pepper_isolated_file_system_message_filter.h b/src/core/renderer/pepper/pepper_isolated_file_system_message_filter.h deleted file mode 100644 index 750f7cea0..000000000 --- a/src/core/renderer/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 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/pepper/pepper_flash_browser_host_qt.cpp b/src/core/renderer_host/pepper/pepper_flash_browser_host_qt.cpp new file mode 100644 index 000000000..4427a67f2 --- /dev/null +++ b/src/core/renderer_host/pepper/pepper_flash_browser_host_qt.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** 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 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 +#elif defined(OS_MACOSX) +#include +#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 new file mode 100644 index 000000000..5d1107dfb --- /dev/null +++ b/src/core/renderer_host/pepper/pepper_flash_browser_host_qt.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** 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 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 new file mode 100644 index 000000000..4a25e7756 --- /dev/null +++ b/src/core/renderer_host/pepper/pepper_host_factory_qt.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 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 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 clipboard_filter(new chrome::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 new file mode 100644 index 000000000..0446cf9e3 --- /dev/null +++ b/src/core/renderer_host/pepper/pepper_host_factory_qt.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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 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 new file mode 100644 index 000000000..7e8b2fdda --- /dev/null +++ b/src/core/renderer_host/pepper/pepper_isolated_file_system_message_filter.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** 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 file. + +#include "pepper_isolated_file_system_message_filter.h" + +#include "base/macros.h" +#include "chrome/common/chrome_switches.h" +#include "content/public/browser/browser_ppapi_host.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 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 content::BrowserThread::GetMessageLoopProxyForThread(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 new file mode 100644 index 000000000..750f7cea0 --- /dev/null +++ b/src/core/renderer_host/pepper/pepper_isolated_file_system_message_filter.h @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** 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 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/resource_dispatcher_host_delegate_qt.cpp b/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp new file mode 100644 index 000000000..16a4e7265 --- /dev/null +++ b/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** 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 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 file. + +#include "resource_dispatcher_host_delegate_qt.h" + +#include "content/public/browser/browser_thread.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 "net/url_request/url_request.h" + +#include "authentication_dialog_controller.h" +#include "authentication_dialog_controller_p.h" +#include "type_conversion.h" +#include "web_contents_view_qt.h" + +namespace QtWebEngineCore { + +ResourceDispatcherHostLoginDelegateQt::ResourceDispatcherHostLoginDelegateQt(net::AuthChallengeInfo *authInfo, net::URLRequest *request) + : m_authInfo(authInfo) + , m_request(request) +{ + Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); + content::ResourceRequestInfo::GetRenderFrameForRequest(request, &m_renderProcessId, &m_renderFrameId); + + content::BrowserThread::PostTask( + content::BrowserThread::UI, FROM_HERE, + base::Bind(&ResourceDispatcherHostLoginDelegateQt::triggerDialog, this)); +} + +ResourceDispatcherHostLoginDelegateQt::~ResourceDispatcherHostLoginDelegateQt() +{ + Q_ASSERT(m_dialogController.isNull()); + // We must have called ClearLoginDelegateForRequest if we didn't receive an OnRequestCancelled. + Q_ASSERT(!m_request); +} + +void ResourceDispatcherHostLoginDelegateQt::OnRequestCancelled() +{ + destroy(); +} + +QUrl ResourceDispatcherHostLoginDelegateQt::url() const +{ + return toQt(m_request->url()); +} + +QString ResourceDispatcherHostLoginDelegateQt::realm() const +{ + return QString::fromStdString(m_authInfo->realm); +} + +QString ResourceDispatcherHostLoginDelegateQt::host() const +{ + return QString::fromStdString(m_authInfo->challenger.host()); +} + +bool ResourceDispatcherHostLoginDelegateQt::isProxy() const +{ + return m_authInfo->is_proxy; +} + +void ResourceDispatcherHostLoginDelegateQt::triggerDialog() +{ + Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + content::RenderFrameHost *renderFrameHost = content::RenderFrameHost::FromID(m_renderProcessId, m_renderFrameId); + if (!renderFrameHost) + return; + content::RenderViewHost *renderViewHost = renderFrameHost->GetRenderViewHost(); + content::WebContentsImpl *webContents = static_cast(content::WebContents::FromRenderViewHost(renderViewHost)); + WebContentsAdapterClient *client = WebContentsViewQt::from(webContents->GetView())->client(); + + AuthenticationDialogControllerPrivate *dialogControllerData = new AuthenticationDialogControllerPrivate(this); + m_dialogController.reset(new AuthenticationDialogController(dialogControllerData)); + client->authenticationRequired(m_dialogController); +} + +void ResourceDispatcherHostLoginDelegateQt::sendAuthToRequester(bool success, const QString &user, const QString &password) +{ + Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); + if (!m_request) + return; + + if (success) + m_request->SetAuth(net::AuthCredentials(toString16(user), toString16(password))); + else + m_request->CancelAuth(); + content::ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(m_request); + + destroy(); +} + +void ResourceDispatcherHostLoginDelegateQt::destroy() +{ + m_dialogController.reset(); + m_request = 0; +} + +static void LaunchURL(const GURL& url, int render_process_id, + const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, + ui::PageTransition page_transition, bool is_main_frame) +{ + Q_UNUSED(render_process_id); + Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + content::WebContents* webContents = web_contents_getter.Run(); + if (!webContents) + return; + WebContentsDelegateQt *contentsDelegate = static_cast(webContents->GetDelegate()); + contentsDelegate->launchExternalURL(toQt(url), page_transition, is_main_frame); +} + +bool ResourceDispatcherHostDelegateQt::HandleExternalProtocol(const GURL& url, int child_id, + const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, + bool is_main_frame, ui::PageTransition page_transition, bool has_user_gesture, + content::ResourceContext* /*resource_context*/) +{ + Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); + // We don't want to launch external applications unless it is based on a user action + if (!has_user_gesture) + return false; + + content::BrowserThread::PostTask( + content::BrowserThread::UI, + FROM_HERE, + base::Bind(&LaunchURL, url, child_id, web_contents_getter, page_transition, is_main_frame)); + return true; +} + +content::ResourceDispatcherHostLoginDelegate *ResourceDispatcherHostDelegateQt::CreateLoginDelegate(net::AuthChallengeInfo *authInfo, net::URLRequest *request) +{ + // ResourceDispatcherHostLoginDelegateQt is ref-counted and will be released after we called ClearLoginDelegateForRequest. + return new ResourceDispatcherHostLoginDelegateQt(authInfo, 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 new file mode 100644 index 000000000..a8a65cfb7 --- /dev/null +++ b/src/core/renderer_host/resource_dispatcher_host_delegate_qt.h @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** 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 RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H +#define RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H + +#include "content/public/browser/resource_dispatcher_host_delegate.h" +#include "content/public/browser/resource_dispatcher_host_login_delegate.h" + +#include "web_contents_adapter_client.h" + +namespace QtWebEngineCore { + +class AuthenticationDialogController; + +class ResourceDispatcherHostLoginDelegateQt : public content::ResourceDispatcherHostLoginDelegate { +public: + ResourceDispatcherHostLoginDelegateQt(net::AuthChallengeInfo *authInfo, net::URLRequest *request); + ~ResourceDispatcherHostLoginDelegateQt(); + + // ResourceDispatcherHostLoginDelegate implementation + virtual void OnRequestCancelled(); + + QUrl url() const; + QString realm() const; + QString host() const; + bool isProxy() const; + + void sendAuthToRequester(bool success, const QString &user, const QString &password); + +private: + void triggerDialog(); + void destroy(); + + QUrl m_url; + QString m_realm; + bool m_isProxy; + QString m_host; + + int m_renderProcessId; + int m_renderFrameId; + + net::AuthChallengeInfo *m_authInfo; + + // The request that wants login data. + // Must only be accessed on the IO thread. + net::URLRequest *m_request; + + // This member is used to keep authentication dialog controller alive until + // authorization is sent or cancelled. + QSharedPointer m_dialogController; +}; + +class ResourceDispatcherHostDelegateQt : public content::ResourceDispatcherHostDelegate { +public: + bool HandleExternalProtocol(const GURL& url, int child_id, + const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, + bool is_main_frame, ui::PageTransition page_transition, bool has_user_gesture, + content::ResourceContext* resource_context) override; + + virtual content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(net::AuthChallengeInfo *authInfo, net::URLRequest *request) Q_DECL_OVERRIDE; +}; + +} // 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 new file mode 100644 index 000000000..9d2ba8eb8 --- /dev/null +++ b/src/core/renderer_host/user_resource_controller_host.cpp @@ -0,0 +1,239 @@ +/**************************************************************************** +** +** 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 "user_resource_controller_host.h" + +#include "common/qt_messages.h" +#include "type_conversion.h" +#include "web_contents_adapter.h" +#include "web_contents_adapter_p.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/web_contents.h" +#include "content/public/browser/web_contents_observer.h" + +namespace QtWebEngineCore { + +class UserResourceControllerHost::WebContentsObserverHelper : public content::WebContentsObserver { +public: + WebContentsObserverHelper(UserResourceControllerHost *, content::WebContents *); + + // WebContentsObserver overrides: + void RenderViewCreated(content::RenderViewHost *renderViewHost) override; + void RenderViewHostChanged(content::RenderViewHost *oldHost, content::RenderViewHost *newHost) override; + void WebContentsDestroyed() override; + +private: + UserResourceControllerHost *m_controllerHost; +}; + +UserResourceControllerHost::WebContentsObserverHelper::WebContentsObserverHelper(UserResourceControllerHost *controller, content::WebContents *contents) + : content::WebContentsObserver(contents) + , m_controllerHost(controller) +{ +} + +void UserResourceControllerHost::WebContentsObserverHelper::RenderViewCreated(content::RenderViewHost *renderViewHost) +{ + content::WebContents *contents = web_contents(); + Q_FOREACH (const UserScript &script, m_controllerHost->m_perContentsScripts.value(contents)) + renderViewHost->Send(new RenderViewObserverHelper_AddScript(renderViewHost->GetRoutingID(), script.data())); +} + +void UserResourceControllerHost::WebContentsObserverHelper::RenderViewHostChanged(content::RenderViewHost *oldHost, + content::RenderViewHost *newHost) +{ + if (oldHost) + oldHost->Send(new RenderViewObserverHelper_ClearScripts(oldHost->GetRoutingID())); + + content::WebContents *contents = web_contents(); + Q_FOREACH (const UserScript &script, m_controllerHost->m_perContentsScripts.value(contents)) + newHost->Send(new RenderViewObserverHelper_AddScript(newHost->GetRoutingID(), script.data())); +} + +void UserResourceControllerHost::WebContentsObserverHelper::WebContentsDestroyed() +{ + m_controllerHost->webContentsDestroyed(web_contents()); + delete this; +} + +class UserResourceControllerHost::RenderProcessObserverHelper : public content::RenderProcessHostObserver { +public: + RenderProcessObserverHelper(UserResourceControllerHost *); + virtual void RenderProcessHostDestroyed(content::RenderProcessHost *) Q_DECL_OVERRIDE; +private: + UserResourceControllerHost *m_controllerHost; +}; + +UserResourceControllerHost::RenderProcessObserverHelper::RenderProcessObserverHelper(UserResourceControllerHost *controller) + : m_controllerHost(controller) +{ +} + +void UserResourceControllerHost::RenderProcessObserverHelper::RenderProcessHostDestroyed(content::RenderProcessHost *renderer) +{ + Q_ASSERT(m_controllerHost); + 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. + if (!adapter) { + if (!m_profileWideScripts.contains(script)) { + m_profileWideScripts.append(script); + Q_FOREACH (content::RenderProcessHost *renderer, m_observedProcesses) + renderer->Send(new UserResourceController_AddScript(script.data())); + } + } else { + content::WebContents *contents = adapter->webContents(); + ContentsScriptsMap::iterator it = m_perContentsScripts.find(contents); + if (it == m_perContentsScripts.end()) { + // We need to keep track of RenderView/RenderViewHost changes for a given contents + // in order to make sure the scripts stay in sync + new WebContentsObserverHelper(this, contents); + it = m_perContentsScripts.insert(contents, (QList() << script)); + } else { + QList currentScripts = it.value(); + if (!currentScripts.contains(script)) { + currentScripts.append(script); + m_perContentsScripts.insert(contents, currentScripts); + } + } + contents->Send(new RenderViewObserverHelper_AddScript(contents->GetRoutingID(), 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. + if (!adapter) + 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; + if (!adapter) { + QList::iterator it + = std::find(m_profileWideScripts.begin(), m_profileWideScripts.end(), script); + if (it == m_profileWideScripts.end()) + return false; + Q_FOREACH (content::RenderProcessHost *renderer, m_observedProcesses) + renderer->Send(new UserResourceController_RemoveScript((*it).data())); + m_profileWideScripts.erase(it); + } else { + content::WebContents *contents = adapter->webContents(); + if (!m_perContentsScripts.contains(contents)) + return false; + QList &list(m_perContentsScripts[contents]); + QList::iterator it = std::find(list.begin(), list.end(), script); + if (it == list.end()) + return false; + contents->Send(new RenderViewObserverHelper_RemoveScript(contents->GetRoutingID(), (*it).data())); + list.erase(it); + } + return true; +} + +void UserResourceControllerHost::clearAllScripts(WebContentsAdapter *adapter) +{ + if (!adapter) { + m_profileWideScripts.clear(); + Q_FOREACH (content::RenderProcessHost *renderer, m_observedProcesses) + renderer->Send(new UserResourceController_ClearScripts); + } else { + content::WebContents *contents = adapter->webContents(); + m_perContentsScripts.remove(contents); + contents->Send(new RenderViewObserverHelper_ClearScripts(contents->GetRoutingID())); + } +} + +const QList UserResourceControllerHost::registeredScripts(WebContentsAdapter *adapter) const +{ + if (!adapter) + return m_profileWideScripts; + return m_perContentsScripts.value(adapter->webContents()); +} + +void UserResourceControllerHost::reserve(WebContentsAdapter *adapter, int count) +{ + if (!adapter) + m_profileWideScripts.reserve(count); + else + m_perContentsScripts[adapter->webContents()].reserve(count); +} + +void UserResourceControllerHost::renderProcessStartedWithHost(content::RenderProcessHost *renderer) +{ + if (m_observedProcesses.contains(renderer)) + return; + + if (m_renderProcessObserver.isNull()) + m_renderProcessObserver.reset(new RenderProcessObserverHelper(this)); + renderer->AddObserver(m_renderProcessObserver.data()); + m_observedProcesses.insert(renderer); + Q_FOREACH (const UserScript &script, m_profileWideScripts) + renderer->Send(new UserResourceController_AddScript(script.data())); +} + +void UserResourceControllerHost::webContentsDestroyed(content::WebContents *contents) +{ + m_perContentsScripts.remove(contents); +} + +UserResourceControllerHost::UserResourceControllerHost() +{ +} + +UserResourceControllerHost::~UserResourceControllerHost() +{ + Q_FOREACH (content::RenderProcessHost *renderer, m_observedProcesses) + renderer->RemoveObserver(m_renderProcessObserver.data()); +} + +} // namespace diff --git a/src/core/renderer_host/user_resource_controller_host.h b/src/core/renderer_host/user_resource_controller_host.h new file mode 100644 index 000000000..8e6e1e3bf --- /dev/null +++ b/src/core/renderer_host/user_resource_controller_host.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 USER_RESOURCE_CONTROLLER_HOST_H +#define USER_RESOURCE_CONTROLLER_HOST_H + +#include "qtwebenginecoreglobal.h" + +#include +#include +#include "user_script.h" + +namespace content { +class RenderProcessHost; +class WebContents; +} + +namespace QtWebEngineCore { + +class WebContentsAdapter; +class WebContentsAdapterPrivate; + +class QWEBENGINE_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 registeredScripts(WebContentsAdapter *adapter) const; + + void renderProcessStartedWithHost(content::RenderProcessHost *renderer); + +private: + Q_DISABLE_COPY(UserResourceControllerHost) + class WebContentsObserverHelper; + class RenderProcessObserverHelper; + + void webContentsDestroyed(content::WebContents *); + + QList m_profileWideScripts; + typedef QHash> ContentsScriptsMap; + ContentsScriptsMap m_perContentsScripts; + QSet m_observedProcesses; + QScopedPointer m_renderProcessObserver; +}; + +} // namespace + +#endif // USER_RESOURCE_CONTROLLER_HOST_H diff --git a/src/core/renderer_host/web_channel_ipc_transport_host.cpp b/src/core/renderer_host/web_channel_ipc_transport_host.cpp new file mode 100644 index 000000000..aef16f0a0 --- /dev/null +++ b/src/core/renderer_host/web_channel_ipc_transport_host.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** 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 "web_channel_ipc_transport_host.h" + +#include "base/strings/string16.h" + +#include "common/qt_messages.h" +#include "type_conversion.h" + +#include +#include + +namespace QtWebEngineCore { + +WebChannelIPCTransportHost::WebChannelIPCTransportHost(content::WebContents *contents, uint worldId, QObject *parent) + : QWebChannelAbstractTransport(parent) + , content::WebContentsObserver(contents) + , m_worldId(worldId) +{ + Send(new WebChannelIPCTransport_Install(routing_id(), m_worldId)); +} + +WebChannelIPCTransportHost::~WebChannelIPCTransportHost() +{ +} + +void WebChannelIPCTransportHost::RenderViewHostChanged(content::RenderViewHost *, content::RenderViewHost *) +{ + // This means that we were moved into a different RenderView, possibly in a different + // render process and that we lost our WebChannelIPCTransport object and its state. + Send(new WebChannelIPCTransport_Install(routing_id(), m_worldId)); +} + +void WebChannelIPCTransportHost::setWorldId(uint worldId) +{ + if (worldId == m_worldId) + return; + Send(new WebChannelIPCTransport_Uninstall(routing_id(), m_worldId)); + m_worldId = worldId; + Send(new WebChannelIPCTransport_Install(routing_id(), m_worldId)); +} + +void WebChannelIPCTransportHost::sendMessage(const QJsonObject &message) +{ + QJsonDocument doc(message); + int size = 0; + const char *rawData = doc.rawData(&size); + Send(new WebChannelIPCTransport_Message(routing_id(), std::vector(rawData, rawData + size), m_worldId)); +} + +void WebChannelIPCTransportHost::onWebChannelMessage(const std::vector &message) +{ + QJsonDocument doc = QJsonDocument::fromRawData(message.data(), message.size(), QJsonDocument::BypassValidation); + Q_ASSERT(doc.isObject()); + Q_EMIT messageReceived(doc.object(), this); +} + +bool WebChannelIPCTransportHost::OnMessageReceived(const IPC::Message &message) +{ + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(WebChannelIPCTransportHost, message) + IPC_MESSAGE_HANDLER(WebChannelIPCTransportHost_SendMessage, onWebChannelMessage) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +} // namespace diff --git a/src/core/renderer_host/web_channel_ipc_transport_host.h b/src/core/renderer_host/web_channel_ipc_transport_host.h new file mode 100644 index 000000000..75b40477e --- /dev/null +++ b/src/core/renderer_host/web_channel_ipc_transport_host.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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 WEB_CHANNEL_IPC_TRANSPORT_H +#define WEB_CHANNEL_IPC_TRANSPORT_H + + +#include +#include "content/public/browser/web_contents_observer.h" + +#include "qtwebenginecoreglobal.h" +#include + +QT_FORWARD_DECLARE_CLASS(QString) + +namespace QtWebEngineCore { + +class WebChannelIPCTransportHost : public QWebChannelAbstractTransport + , public content::WebContentsObserver +{ +public: + WebChannelIPCTransportHost(content::WebContents *, uint worldId = 0, QObject *parent = 0); + virtual ~WebChannelIPCTransportHost(); + + // WebContentsObserver + virtual void RenderViewHostChanged(content::RenderViewHost* old_host, content::RenderViewHost* new_host) Q_DECL_OVERRIDE; + + // QWebChannelAbstractTransport + void sendMessage(const QJsonObject &message) Q_DECL_OVERRIDE; + + void setWorldId(uint worldId); + uint worldId() const { return m_worldId; } + +private: + bool OnMessageReceived(const IPC::Message& message) Q_DECL_OVERRIDE; + void onWebChannelMessage(const std::vector &message); + uint m_worldId; +}; + +} // namespace + +#endif // WEB_CHANNEL_IPC_TRANSPORT_H diff --git a/src/core/resource_dispatcher_host_delegate_qt.cpp b/src/core/resource_dispatcher_host_delegate_qt.cpp deleted file mode 100644 index 16a4e7265..000000000 --- a/src/core/resource_dispatcher_host_delegate_qt.cpp +++ /dev/null @@ -1,175 +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$ -** -****************************************************************************/ - -// 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 file. - -#include "resource_dispatcher_host_delegate_qt.h" - -#include "content/public/browser/browser_thread.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 "net/url_request/url_request.h" - -#include "authentication_dialog_controller.h" -#include "authentication_dialog_controller_p.h" -#include "type_conversion.h" -#include "web_contents_view_qt.h" - -namespace QtWebEngineCore { - -ResourceDispatcherHostLoginDelegateQt::ResourceDispatcherHostLoginDelegateQt(net::AuthChallengeInfo *authInfo, net::URLRequest *request) - : m_authInfo(authInfo) - , m_request(request) -{ - Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - content::ResourceRequestInfo::GetRenderFrameForRequest(request, &m_renderProcessId, &m_renderFrameId); - - content::BrowserThread::PostTask( - content::BrowserThread::UI, FROM_HERE, - base::Bind(&ResourceDispatcherHostLoginDelegateQt::triggerDialog, this)); -} - -ResourceDispatcherHostLoginDelegateQt::~ResourceDispatcherHostLoginDelegateQt() -{ - Q_ASSERT(m_dialogController.isNull()); - // We must have called ClearLoginDelegateForRequest if we didn't receive an OnRequestCancelled. - Q_ASSERT(!m_request); -} - -void ResourceDispatcherHostLoginDelegateQt::OnRequestCancelled() -{ - destroy(); -} - -QUrl ResourceDispatcherHostLoginDelegateQt::url() const -{ - return toQt(m_request->url()); -} - -QString ResourceDispatcherHostLoginDelegateQt::realm() const -{ - return QString::fromStdString(m_authInfo->realm); -} - -QString ResourceDispatcherHostLoginDelegateQt::host() const -{ - return QString::fromStdString(m_authInfo->challenger.host()); -} - -bool ResourceDispatcherHostLoginDelegateQt::isProxy() const -{ - return m_authInfo->is_proxy; -} - -void ResourceDispatcherHostLoginDelegateQt::triggerDialog() -{ - Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - content::RenderFrameHost *renderFrameHost = content::RenderFrameHost::FromID(m_renderProcessId, m_renderFrameId); - if (!renderFrameHost) - return; - content::RenderViewHost *renderViewHost = renderFrameHost->GetRenderViewHost(); - content::WebContentsImpl *webContents = static_cast(content::WebContents::FromRenderViewHost(renderViewHost)); - WebContentsAdapterClient *client = WebContentsViewQt::from(webContents->GetView())->client(); - - AuthenticationDialogControllerPrivate *dialogControllerData = new AuthenticationDialogControllerPrivate(this); - m_dialogController.reset(new AuthenticationDialogController(dialogControllerData)); - client->authenticationRequired(m_dialogController); -} - -void ResourceDispatcherHostLoginDelegateQt::sendAuthToRequester(bool success, const QString &user, const QString &password) -{ - Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - if (!m_request) - return; - - if (success) - m_request->SetAuth(net::AuthCredentials(toString16(user), toString16(password))); - else - m_request->CancelAuth(); - content::ResourceDispatcherHost::Get()->ClearLoginDelegateForRequest(m_request); - - destroy(); -} - -void ResourceDispatcherHostLoginDelegateQt::destroy() -{ - m_dialogController.reset(); - m_request = 0; -} - -static void LaunchURL(const GURL& url, int render_process_id, - const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, - ui::PageTransition page_transition, bool is_main_frame) -{ - Q_UNUSED(render_process_id); - Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - content::WebContents* webContents = web_contents_getter.Run(); - if (!webContents) - return; - WebContentsDelegateQt *contentsDelegate = static_cast(webContents->GetDelegate()); - contentsDelegate->launchExternalURL(toQt(url), page_transition, is_main_frame); -} - -bool ResourceDispatcherHostDelegateQt::HandleExternalProtocol(const GURL& url, int child_id, - const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, - bool is_main_frame, ui::PageTransition page_transition, bool has_user_gesture, - content::ResourceContext* /*resource_context*/) -{ - Q_ASSERT(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - // We don't want to launch external applications unless it is based on a user action - if (!has_user_gesture) - return false; - - content::BrowserThread::PostTask( - content::BrowserThread::UI, - FROM_HERE, - base::Bind(&LaunchURL, url, child_id, web_contents_getter, page_transition, is_main_frame)); - return true; -} - -content::ResourceDispatcherHostLoginDelegate *ResourceDispatcherHostDelegateQt::CreateLoginDelegate(net::AuthChallengeInfo *authInfo, net::URLRequest *request) -{ - // ResourceDispatcherHostLoginDelegateQt is ref-counted and will be released after we called ClearLoginDelegateForRequest. - return new ResourceDispatcherHostLoginDelegateQt(authInfo, request); -} - -} // namespace QtWebEngineCore diff --git a/src/core/resource_dispatcher_host_delegate_qt.h b/src/core/resource_dispatcher_host_delegate_qt.h deleted file mode 100644 index a8a65cfb7..000000000 --- a/src/core/resource_dispatcher_host_delegate_qt.h +++ /dev/null @@ -1,102 +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 RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H -#define RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H - -#include "content/public/browser/resource_dispatcher_host_delegate.h" -#include "content/public/browser/resource_dispatcher_host_login_delegate.h" - -#include "web_contents_adapter_client.h" - -namespace QtWebEngineCore { - -class AuthenticationDialogController; - -class ResourceDispatcherHostLoginDelegateQt : public content::ResourceDispatcherHostLoginDelegate { -public: - ResourceDispatcherHostLoginDelegateQt(net::AuthChallengeInfo *authInfo, net::URLRequest *request); - ~ResourceDispatcherHostLoginDelegateQt(); - - // ResourceDispatcherHostLoginDelegate implementation - virtual void OnRequestCancelled(); - - QUrl url() const; - QString realm() const; - QString host() const; - bool isProxy() const; - - void sendAuthToRequester(bool success, const QString &user, const QString &password); - -private: - void triggerDialog(); - void destroy(); - - QUrl m_url; - QString m_realm; - bool m_isProxy; - QString m_host; - - int m_renderProcessId; - int m_renderFrameId; - - net::AuthChallengeInfo *m_authInfo; - - // The request that wants login data. - // Must only be accessed on the IO thread. - net::URLRequest *m_request; - - // This member is used to keep authentication dialog controller alive until - // authorization is sent or cancelled. - QSharedPointer m_dialogController; -}; - -class ResourceDispatcherHostDelegateQt : public content::ResourceDispatcherHostDelegate { -public: - bool HandleExternalProtocol(const GURL& url, int child_id, - const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, - bool is_main_frame, ui::PageTransition page_transition, bool has_user_gesture, - content::ResourceContext* resource_context) override; - - virtual content::ResourceDispatcherHostLoginDelegate* CreateLoginDelegate(net::AuthChallengeInfo *authInfo, net::URLRequest *request) Q_DECL_OVERRIDE; -}; - -} // namespace QtWebEngineCore - -#endif // RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H diff --git a/src/core/user_resource_controller_host.cpp b/src/core/user_resource_controller_host.cpp deleted file mode 100644 index 9d2ba8eb8..000000000 --- a/src/core/user_resource_controller_host.cpp +++ /dev/null @@ -1,239 +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 "user_resource_controller_host.h" - -#include "common/qt_messages.h" -#include "type_conversion.h" -#include "web_contents_adapter.h" -#include "web_contents_adapter_p.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/web_contents.h" -#include "content/public/browser/web_contents_observer.h" - -namespace QtWebEngineCore { - -class UserResourceControllerHost::WebContentsObserverHelper : public content::WebContentsObserver { -public: - WebContentsObserverHelper(UserResourceControllerHost *, content::WebContents *); - - // WebContentsObserver overrides: - void RenderViewCreated(content::RenderViewHost *renderViewHost) override; - void RenderViewHostChanged(content::RenderViewHost *oldHost, content::RenderViewHost *newHost) override; - void WebContentsDestroyed() override; - -private: - UserResourceControllerHost *m_controllerHost; -}; - -UserResourceControllerHost::WebContentsObserverHelper::WebContentsObserverHelper(UserResourceControllerHost *controller, content::WebContents *contents) - : content::WebContentsObserver(contents) - , m_controllerHost(controller) -{ -} - -void UserResourceControllerHost::WebContentsObserverHelper::RenderViewCreated(content::RenderViewHost *renderViewHost) -{ - content::WebContents *contents = web_contents(); - Q_FOREACH (const UserScript &script, m_controllerHost->m_perContentsScripts.value(contents)) - renderViewHost->Send(new RenderViewObserverHelper_AddScript(renderViewHost->GetRoutingID(), script.data())); -} - -void UserResourceControllerHost::WebContentsObserverHelper::RenderViewHostChanged(content::RenderViewHost *oldHost, - content::RenderViewHost *newHost) -{ - if (oldHost) - oldHost->Send(new RenderViewObserverHelper_ClearScripts(oldHost->GetRoutingID())); - - content::WebContents *contents = web_contents(); - Q_FOREACH (const UserScript &script, m_controllerHost->m_perContentsScripts.value(contents)) - newHost->Send(new RenderViewObserverHelper_AddScript(newHost->GetRoutingID(), script.data())); -} - -void UserResourceControllerHost::WebContentsObserverHelper::WebContentsDestroyed() -{ - m_controllerHost->webContentsDestroyed(web_contents()); - delete this; -} - -class UserResourceControllerHost::RenderProcessObserverHelper : public content::RenderProcessHostObserver { -public: - RenderProcessObserverHelper(UserResourceControllerHost *); - virtual void RenderProcessHostDestroyed(content::RenderProcessHost *) Q_DECL_OVERRIDE; -private: - UserResourceControllerHost *m_controllerHost; -}; - -UserResourceControllerHost::RenderProcessObserverHelper::RenderProcessObserverHelper(UserResourceControllerHost *controller) - : m_controllerHost(controller) -{ -} - -void UserResourceControllerHost::RenderProcessObserverHelper::RenderProcessHostDestroyed(content::RenderProcessHost *renderer) -{ - Q_ASSERT(m_controllerHost); - 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. - if (!adapter) { - if (!m_profileWideScripts.contains(script)) { - m_profileWideScripts.append(script); - Q_FOREACH (content::RenderProcessHost *renderer, m_observedProcesses) - renderer->Send(new UserResourceController_AddScript(script.data())); - } - } else { - content::WebContents *contents = adapter->webContents(); - ContentsScriptsMap::iterator it = m_perContentsScripts.find(contents); - if (it == m_perContentsScripts.end()) { - // We need to keep track of RenderView/RenderViewHost changes for a given contents - // in order to make sure the scripts stay in sync - new WebContentsObserverHelper(this, contents); - it = m_perContentsScripts.insert(contents, (QList() << script)); - } else { - QList currentScripts = it.value(); - if (!currentScripts.contains(script)) { - currentScripts.append(script); - m_perContentsScripts.insert(contents, currentScripts); - } - } - contents->Send(new RenderViewObserverHelper_AddScript(contents->GetRoutingID(), 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. - if (!adapter) - 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; - if (!adapter) { - QList::iterator it - = std::find(m_profileWideScripts.begin(), m_profileWideScripts.end(), script); - if (it == m_profileWideScripts.end()) - return false; - Q_FOREACH (content::RenderProcessHost *renderer, m_observedProcesses) - renderer->Send(new UserResourceController_RemoveScript((*it).data())); - m_profileWideScripts.erase(it); - } else { - content::WebContents *contents = adapter->webContents(); - if (!m_perContentsScripts.contains(contents)) - return false; - QList &list(m_perContentsScripts[contents]); - QList::iterator it = std::find(list.begin(), list.end(), script); - if (it == list.end()) - return false; - contents->Send(new RenderViewObserverHelper_RemoveScript(contents->GetRoutingID(), (*it).data())); - list.erase(it); - } - return true; -} - -void UserResourceControllerHost::clearAllScripts(WebContentsAdapter *adapter) -{ - if (!adapter) { - m_profileWideScripts.clear(); - Q_FOREACH (content::RenderProcessHost *renderer, m_observedProcesses) - renderer->Send(new UserResourceController_ClearScripts); - } else { - content::WebContents *contents = adapter->webContents(); - m_perContentsScripts.remove(contents); - contents->Send(new RenderViewObserverHelper_ClearScripts(contents->GetRoutingID())); - } -} - -const QList UserResourceControllerHost::registeredScripts(WebContentsAdapter *adapter) const -{ - if (!adapter) - return m_profileWideScripts; - return m_perContentsScripts.value(adapter->webContents()); -} - -void UserResourceControllerHost::reserve(WebContentsAdapter *adapter, int count) -{ - if (!adapter) - m_profileWideScripts.reserve(count); - else - m_perContentsScripts[adapter->webContents()].reserve(count); -} - -void UserResourceControllerHost::renderProcessStartedWithHost(content::RenderProcessHost *renderer) -{ - if (m_observedProcesses.contains(renderer)) - return; - - if (m_renderProcessObserver.isNull()) - m_renderProcessObserver.reset(new RenderProcessObserverHelper(this)); - renderer->AddObserver(m_renderProcessObserver.data()); - m_observedProcesses.insert(renderer); - Q_FOREACH (const UserScript &script, m_profileWideScripts) - renderer->Send(new UserResourceController_AddScript(script.data())); -} - -void UserResourceControllerHost::webContentsDestroyed(content::WebContents *contents) -{ - m_perContentsScripts.remove(contents); -} - -UserResourceControllerHost::UserResourceControllerHost() -{ -} - -UserResourceControllerHost::~UserResourceControllerHost() -{ - Q_FOREACH (content::RenderProcessHost *renderer, m_observedProcesses) - renderer->RemoveObserver(m_renderProcessObserver.data()); -} - -} // namespace diff --git a/src/core/user_resource_controller_host.h b/src/core/user_resource_controller_host.h deleted file mode 100644 index 8e6e1e3bf..000000000 --- a/src/core/user_resource_controller_host.h +++ /dev/null @@ -1,90 +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 USER_RESOURCE_CONTROLLER_HOST_H -#define USER_RESOURCE_CONTROLLER_HOST_H - -#include "qtwebenginecoreglobal.h" - -#include -#include -#include "user_script.h" - -namespace content { -class RenderProcessHost; -class WebContents; -} - -namespace QtWebEngineCore { - -class WebContentsAdapter; -class WebContentsAdapterPrivate; - -class QWEBENGINE_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 registeredScripts(WebContentsAdapter *adapter) const; - - void renderProcessStartedWithHost(content::RenderProcessHost *renderer); - -private: - Q_DISABLE_COPY(UserResourceControllerHost) - class WebContentsObserverHelper; - class RenderProcessObserverHelper; - - void webContentsDestroyed(content::WebContents *); - - QList m_profileWideScripts; - typedef QHash> ContentsScriptsMap; - ContentsScriptsMap m_perContentsScripts; - QSet m_observedProcesses; - QScopedPointer m_renderProcessObserver; -}; - -} // namespace - -#endif // USER_RESOURCE_CONTROLLER_HOST_H diff --git a/src/core/web_channel_ipc_transport_host.cpp b/src/core/web_channel_ipc_transport_host.cpp deleted file mode 100644 index aef16f0a0..000000000 --- a/src/core/web_channel_ipc_transport_host.cpp +++ /dev/null @@ -1,105 +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 "web_channel_ipc_transport_host.h" - -#include "base/strings/string16.h" - -#include "common/qt_messages.h" -#include "type_conversion.h" - -#include -#include - -namespace QtWebEngineCore { - -WebChannelIPCTransportHost::WebChannelIPCTransportHost(content::WebContents *contents, uint worldId, QObject *parent) - : QWebChannelAbstractTransport(parent) - , content::WebContentsObserver(contents) - , m_worldId(worldId) -{ - Send(new WebChannelIPCTransport_Install(routing_id(), m_worldId)); -} - -WebChannelIPCTransportHost::~WebChannelIPCTransportHost() -{ -} - -void WebChannelIPCTransportHost::RenderViewHostChanged(content::RenderViewHost *, content::RenderViewHost *) -{ - // This means that we were moved into a different RenderView, possibly in a different - // render process and that we lost our WebChannelIPCTransport object and its state. - Send(new WebChannelIPCTransport_Install(routing_id(), m_worldId)); -} - -void WebChannelIPCTransportHost::setWorldId(uint worldId) -{ - if (worldId == m_worldId) - return; - Send(new WebChannelIPCTransport_Uninstall(routing_id(), m_worldId)); - m_worldId = worldId; - Send(new WebChannelIPCTransport_Install(routing_id(), m_worldId)); -} - -void WebChannelIPCTransportHost::sendMessage(const QJsonObject &message) -{ - QJsonDocument doc(message); - int size = 0; - const char *rawData = doc.rawData(&size); - Send(new WebChannelIPCTransport_Message(routing_id(), std::vector(rawData, rawData + size), m_worldId)); -} - -void WebChannelIPCTransportHost::onWebChannelMessage(const std::vector &message) -{ - QJsonDocument doc = QJsonDocument::fromRawData(message.data(), message.size(), QJsonDocument::BypassValidation); - Q_ASSERT(doc.isObject()); - Q_EMIT messageReceived(doc.object(), this); -} - -bool WebChannelIPCTransportHost::OnMessageReceived(const IPC::Message &message) -{ - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(WebChannelIPCTransportHost, message) - IPC_MESSAGE_HANDLER(WebChannelIPCTransportHost_SendMessage, onWebChannelMessage) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -} // namespace diff --git a/src/core/web_channel_ipc_transport_host.h b/src/core/web_channel_ipc_transport_host.h deleted file mode 100644 index 75b40477e..000000000 --- a/src/core/web_channel_ipc_transport_host.h +++ /dev/null @@ -1,78 +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 WEB_CHANNEL_IPC_TRANSPORT_H -#define WEB_CHANNEL_IPC_TRANSPORT_H - - -#include -#include "content/public/browser/web_contents_observer.h" - -#include "qtwebenginecoreglobal.h" -#include - -QT_FORWARD_DECLARE_CLASS(QString) - -namespace QtWebEngineCore { - -class WebChannelIPCTransportHost : public QWebChannelAbstractTransport - , public content::WebContentsObserver -{ -public: - WebChannelIPCTransportHost(content::WebContents *, uint worldId = 0, QObject *parent = 0); - virtual ~WebChannelIPCTransportHost(); - - // WebContentsObserver - virtual void RenderViewHostChanged(content::RenderViewHost* old_host, content::RenderViewHost* new_host) Q_DECL_OVERRIDE; - - // QWebChannelAbstractTransport - void sendMessage(const QJsonObject &message) Q_DECL_OVERRIDE; - - void setWorldId(uint worldId); - uint worldId() const { return m_worldId; } - -private: - bool OnMessageReceived(const IPC::Message& message) Q_DECL_OVERRIDE; - void onWebChannelMessage(const std::vector &message); - uint m_worldId; -}; - -} // namespace - -#endif // WEB_CHANNEL_IPC_TRANSPORT_H diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 6cbfe2867..c8d93b3f0 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -53,9 +53,9 @@ #include "pdfium_printing_wrapper_qt.h" #include "print_view_manager_qt.h" #include "qwebenginecallback_p.h" +#include "renderer_host/web_channel_ipc_transport_host.h" #include "render_view_observer_host_qt.h" #include "type_conversion.h" -#include "web_channel_ipc_transport_host.h" #include "web_contents_adapter_client.h" #include "web_contents_view_qt.h" #include "web_engine_context.h" -- cgit v1.2.3