summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-12-02 15:16:28 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-12-17 14:34:34 +0100
commit09ce1e76716ca660ef6a9b39e4bb0015d03a0793 (patch)
tree994bd898f11544ffddc10330adc45c06f7b0fd9b /src/core
parentb8c6c4a8588374cd0e1830871134d44d0460e0e8 (diff)
Move pdf interception to URL loader
This should also work with network-service Change-Id: I1d38112b76f9a656cc50ffbb826db28b41cf2f85 Fixes: QTBUG-80462 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/content_browser_client_qt.cpp26
-rw-r--r--src/core/core_chromium.pri8
-rw-r--r--src/core/net/plugin_response_interceptor_url_loader_throttle.cpp (renamed from src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp)128
-rw-r--r--src/core/net/plugin_response_interceptor_url_loader_throttle.h (renamed from src/core/renderer_host/resource_dispatcher_host_delegate_qt.h)53
4 files changed, 87 insertions, 128 deletions
diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp
index 12d986bb7..e29a161ca 100644
--- a/src/core/content_browser_client_qt.cpp
+++ b/src/core/content_browser_client_qt.cpp
@@ -165,7 +165,7 @@
#include "extensions/browser/io_thread_extension_message_filter.h"
#include "extensions/common/constants.h"
#include "common/extensions/extensions_client_qt.h"
-#include "renderer_host/resource_dispatcher_host_delegate_qt.h"
+#include "net/plugin_response_interceptor_url_loader_throttle.h"
#endif
#if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS)
@@ -339,11 +339,7 @@ void ContentBrowserClientQt::RenderProcessWillLaunch(content::RenderProcessHost*
void ContentBrowserClientQt::ResourceDispatcherHostCreated()
{
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- m_resourceDispatcherHostDelegate.reset(new ResourceDispatcherHostDelegateQt);
-#else
m_resourceDispatcherHostDelegate.reset(new content::ResourceDispatcherHostDelegate);
-#endif
content::ResourceDispatcherHost::Get()->SetDelegate(m_resourceDispatcherHostDelegate.get());
}
@@ -870,27 +866,35 @@ private:
std::vector<std::unique_ptr<content::URLLoaderThrottle>>
ContentBrowserClientQt::CreateURLLoaderThrottlesOnIO(
- const network::ResourceRequest & /*request*/, content::ResourceContext *resource_context,
+ const network::ResourceRequest &request, content::ResourceContext *resource_context,
const base::RepeatingCallback<content::WebContents *()> & /*wc_getter*/,
- content::NavigationUIData * /*navigation_ui_data*/, int /*frame_tree_node_id*/)
+ content::NavigationUIData * /*navigation_ui_data*/, int frame_tree_node_id)
{
std::vector<std::unique_ptr<content::URLLoaderThrottle>> result;
ProfileIODataQt *ioData = ProfileIODataQt::FromResourceContext(resource_context);
result.push_back(std::make_unique<ProtocolHandlerThrottle<
scoped_refptr<ProtocolHandlerRegistry::IOThreadDelegate>>>(
- ioData->protocolHandlerRegistryIOThreadDelegate()));
+ ioData->protocolHandlerRegistryIOThreadDelegate()));
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+ result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
+ resource_context, request.resource_type, frame_tree_node_id));
+#endif
return result;
}
std::vector<std::unique_ptr<content::URLLoaderThrottle>>
ContentBrowserClientQt::CreateURLLoaderThrottles(
const network::ResourceRequest &request, content::BrowserContext *browser_context,
- const base::RepeatingCallback<content::WebContents *()> &wc_getter,
- content::NavigationUIData *navigation_ui_data, int frame_tree_node_id)
+ const base::RepeatingCallback<content::WebContents *()> & /*wc_getter*/,
+ content::NavigationUIData * /*navigation_ui_data*/, int frame_tree_node_id)
{
std::vector<std::unique_ptr<content::URLLoaderThrottle>> result;
result.push_back(std::make_unique<ProtocolHandlerThrottle<ProtocolHandlerRegistry *>>(
- ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
+ ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context)));
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+ result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>(
+ browser_context, request.resource_type, frame_tree_node_id));
+#endif
return result;
}
diff --git a/src/core/core_chromium.pri b/src/core/core_chromium.pri
index 09650d20a..000cffa50 100644
--- a/src/core/core_chromium.pri
+++ b/src/core/core_chromium.pri
@@ -349,11 +349,11 @@ qtConfig(webengine-extensions) {
extensions/extensions_browser_api_provider_qt.cpp \
extensions/extensions_browser_client_qt.cpp \
extensions/mime_handler_view_guest_delegate_qt.cpp \
+ net/plugin_response_interceptor_url_loader_throttle.cpp \
renderer/extensions/extensions_dispatcher_delegate_qt.cpp \
renderer/extensions/extensions_renderer_client_qt.cpp \
renderer/extensions/renderer_permissions_policy_delegate_qt.cpp \
- renderer/extensions/resource_request_policy_qt.cpp \
- renderer_host/resource_dispatcher_host_delegate_qt.cpp
+ renderer/extensions/resource_request_policy_qt.cpp
HEADERS += \
common/extensions/extensions_api_provider_qt.h \
@@ -366,9 +366,9 @@ qtConfig(webengine-extensions) {
extensions/extensions_browser_api_provider_qt.h \
extensions/extensions_browser_client_qt.h \
extensions/mime_handler_view_guest_delegate_qt.h \
+ net/plugin_response_interceptor_url_loader_throttle.h \
renderer/extensions/extensions_dispatcher_delegate_qt.h \
renderer/extensions/extensions_renderer_client_qt.h \
renderer/extensions/renderer_permissions_policy_delegate_qt.h \
- renderer/extensions/resource_request_policy_qt.h \
- renderer_host/resource_dispatcher_host_delegate_qt.h
+ renderer/extensions/resource_request_policy_qt.h
}
diff --git a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp b/src/core/net/plugin_response_interceptor_url_loader_throttle.cpp
index 59b0ca516..cfd011ade 100644
--- a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.cpp
+++ b/src/core/net/plugin_response_interceptor_url_loader_throttle.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2018 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -37,50 +37,32 @@
**
****************************************************************************/
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE.Chromium file.
-
-#include "resource_dispatcher_host_delegate_qt.h"
+#include "plugin_response_interceptor_url_loader_throttle.h"
#include "base/bind.h"
-#include "base/guid.h"
-#include "base/strings/stringprintf.h"
#include "base/task/post_task.h"
-#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/download_manager.h"
#include "content/public/browser/download_request_utils.h"
-#include "content/public/browser/navigation_controller.h"
-
-#include "content/public/browser/render_frame_host.h"
-#include "content/public/browser/render_view_host.h"
-#include "content/public/browser/resource_dispatcher_host.h"
-#include "content/public/browser/resource_request_info.h"
-#include "content/public/browser/stream_info.h"
-#include "content/public/browser/web_contents.h"
-
-#include "extensions/extension_system_qt.h"
-#include "extensions/browser/info_map.h"
+#include "content/public/browser/download_utils.h"
+#include "content/public/common/resource_type.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
-#include "extensions/common/manifest_handlers/mime_types_handler.h"
-
-#include "net/base/escape.h"
-#include "net/url_request/url_request.h"
+#include "extensions/extension_system_qt.h"
+#include "profile_adapter.h"
#include "profile_io_data_qt.h"
-#include "type_conversion.h"
+#include "profile_qt.h"
#include "web_contents_delegate_qt.h"
-#include "web_engine_settings.h"
+
+#include <string>
namespace QtWebEngineCore {
-void OnPdfStreamIntercepted(const GURL &original_url, std::string extension_id, int frame_tree_node_id,
- const content::ResourceRequestInfo::WebContentsGetter &web_contents_getter)
+void onPdfStreamIntercepted(const GURL &original_url, std::string extension_id, int frame_tree_node_id)
{
- content::WebContents *web_contents = web_contents_getter.Run();
+ content::WebContents *web_contents = content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
if (!web_contents)
return;
@@ -110,68 +92,44 @@ void OnPdfStreamIntercepted(const GURL &original_url, std::string extension_id,
web_contents->GetController().LoadURLWithParams(params);
}
-bool ResourceDispatcherHostDelegateQt::ShouldInterceptResourceAsStream(net::URLRequest *request,
- const std::string &mime_type,
- GURL *origin,
- std::string *payload)
-{
- content::ResourceRequestInfo *info = content::ResourceRequestInfo::ForRequest(request);
-
- int render_process_host_id = -1;
- int render_frame_id = -1;
- if (!content::ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_host_id, &render_frame_id))
- return false;
-
- std::vector<std::string> whitelist = MimeTypesHandler::GetMIMETypeWhitelist();
-
- extensions::ExtensionSystemQt *extensionSystem =
- ProfileIODataQt::FromResourceContext(info->GetContext())->GetExtensionSystem();
- if (!extensionSystem)
- return false;
-
- const scoped_refptr<const extensions::InfoMap> extension_info_map(extensionSystem->info_map());
-
- for (const std::string &extension_id : whitelist) {
- const extensions::Extension *extension = extension_info_map->extensions().GetByID(extension_id);
- if (!extension)
- continue;
-
- MimeTypesHandler *handler = MimeTypesHandler::GetHandler(extension);
- if (!handler)
- continue;
- if (handler->CanHandleMIMEType(mime_type)) {
- StreamTargetInfo target_info;
- *origin = extensions::Extension::GetBaseURLFromExtensionId(extension_id);
- target_info.extension_id = extension_id;
- target_info.view_id = base::GenerateGUID();
- *payload = target_info.view_id;
- stream_target_info_[request] = target_info;
- return true;
- }
- }
- return false;
-}
-// Informs the delegate that a Stream was created. The Stream can be read from
-// the blob URL of the Stream, but can only be read once.
-void ResourceDispatcherHostDelegateQt::OnStreamCreated(net::URLRequest *request, std::unique_ptr<content::StreamInfo> stream)
+PluginResponseInterceptorURLLoaderThrottle::PluginResponseInterceptorURLLoaderThrottle(
+ content::ResourceContext *resource_context, int resource_type, int frame_tree_node_id)
+ : m_resource_context(resource_context), m_resource_type(resource_type), m_frame_tree_node_id(frame_tree_node_id)
+{}
+
+PluginResponseInterceptorURLLoaderThrottle::PluginResponseInterceptorURLLoaderThrottle(
+ content::BrowserContext *browser_context, int resource_type, int frame_tree_node_id)
+ : m_browser_context(browser_context), m_resource_type(resource_type), m_frame_tree_node_id(frame_tree_node_id)
+{}
+
+void PluginResponseInterceptorURLLoaderThrottle::WillProcessResponse(const GURL &response_url,
+ network::ResourceResponseHead *response_head,
+ bool *defer)
{
- content::ResourceRequestInfo *info = content::ResourceRequestInfo::ForRequest(request);
- std::map<net::URLRequest *, StreamTargetInfo>::iterator ix = stream_target_info_.find(request);
- CHECK(ix != stream_target_info_.end());
- int render_frame_id = -1;
- int render_process_id = -1;
- if (!content::ResourceRequestInfo::GetRenderFrameForRequest(request, &render_process_id, &render_frame_id)) {
- stream_target_info_.erase(request);
- request->Cancel();
+ Q_UNUSED(defer);
+ if (content::download_utils::MustDownload(response_url, response_head->headers.get(), response_head->mime_type))
return;
+
+ if (m_resource_context) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+ } else {
+ DCHECK(m_browser_context);
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
}
+ std::string extension_id;
+ // FIXME: We should use extensions::InfoMap in the future:
+ if (response_head->mime_type == "application/pdf")
+ extension_id = extension_misc::kPdfExtensionId;
+ if (extension_id.empty())
+ return;
+
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
- base::BindOnce(&OnPdfStreamIntercepted,
- request->url(), ix->second.extension_id,
- info->GetFrameTreeNodeId(), info->GetWebContentsGetterForRequest()));
- stream_target_info_.erase(request);
+ base::BindOnce(&onPdfStreamIntercepted,
+ response_url,
+ extension_id,
+ m_frame_tree_node_id));
}
} // namespace QtWebEngineCore
diff --git a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.h b/src/core/net/plugin_response_interceptor_url_loader_throttle.h
index d9ee83581..82384e11e 100644
--- a/src/core/renderer_host/resource_dispatcher_host_delegate_qt.h
+++ b/src/core/net/plugin_response_interceptor_url_loader_throttle.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2018 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -37,43 +37,40 @@
**
****************************************************************************/
-#ifndef RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H
-#define RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H
+#ifndef PLUGIN_RESPONSE_INTERCEPTOR_URL_LOADER_THROTTLE_H_
+#define PLUGIN_RESPONSE_INTERCEPTOR_URL_LOADER_THROTTLE_H_
-#include "content/public/browser/resource_dispatcher_host_delegate.h"
-#include "extensions/buildflags/buildflags.h"
+#include "base/macros.h"
+#include "content/public/common/url_loader_throttle.h"
-#include "web_contents_adapter_client.h"
+namespace content {
+class BrowserContext;
+class ResourceContext;
+}
namespace QtWebEngineCore {
-class ResourceDispatcherHostDelegateQt : public content::ResourceDispatcherHostDelegate
+class PluginResponseInterceptorURLLoaderThrottle : public content::URLLoaderThrottle
{
public:
- // If the stream will be rendered in a BrowserPlugin, |payload| will contain
- // the data that should be given to the old ResourceHandler to forward to the
- // renderer process.
- bool ShouldInterceptResourceAsStream(net::URLRequest *request,
- const std::string &mime_type,
- GURL *origin,
- std::string *payload) override;
-
- // Informs the delegate that a Stream was created. The Stream can be read from
- // the blob URL of the Stream, but can only be read once.
- void OnStreamCreated(net::URLRequest *request,
- std::unique_ptr<content::StreamInfo> stream) override;
+ PluginResponseInterceptorURLLoaderThrottle(content::ResourceContext *resource_context,
+ int resource_type, int frame_tree_node_id);
+ PluginResponseInterceptorURLLoaderThrottle(content::BrowserContext *browser_context,
+ int resource_type, int frame_tree_node_id);
+ ~PluginResponseInterceptorURLLoaderThrottle() override = default;
private:
-#if BUILDFLAG(ENABLE_EXTENSIONS)
- struct StreamTargetInfo
- {
- std::string extension_id;
- std::string view_id;
- };
- std::map<net::URLRequest *, StreamTargetInfo> stream_target_info_;
-#endif
+ // content::URLLoaderThrottle overrides;
+ void WillProcessResponse(const GURL &response_url, network::ResourceResponseHead *response_head, bool *defer) override;
+
+ content::ResourceContext *m_resource_context = nullptr;
+ content::BrowserContext *m_browser_context = nullptr;
+ const int m_resource_type;
+ const int m_frame_tree_node_id;
+
+ DISALLOW_COPY_AND_ASSIGN(PluginResponseInterceptorURLLoaderThrottle);
};
} // namespace QtWebEngineCore
-#endif // RESOURCE_DISPATCHER_HOST_DELEGATE_QT_H
+#endif // PLUGIN_RESPONSE_INTERCEPTOR_URL_LOADER_THROTTLE_H_