Commit 031b31c4 authored by Andrey Kosyakov's avatar Andrey Kosyakov Committed by Commit Bot

DevTools: fix interception for <a download='...'> downloads with network service

Bug: 721408

Change-Id: I60f0cf81a69d7826d2043aa8222d2e69ff9e406a
Reviewed-on: https://chromium-review.googlesource.com/1006231
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550690}
parent f3b75573
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "components/download/public/common/url_download_handler_factory.h" #include "components/download/public/common/url_download_handler_factory.h"
#include "content/browser/byte_stream.h" #include "content/browser/byte_stream.h"
#include "content/browser/child_process_security_policy_impl.h" #include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h"
#include "content/browser/download/blob_download_url_loader_factory_getter.h" #include "content/browser/download/blob_download_url_loader_factory_getter.h"
#include "content/browser/download/byte_stream_input_stream.h" #include "content/browser/download/byte_stream_input_stream.h"
#include "content/browser/download/download_resource_handler.h" #include "content/browser/download/download_resource_handler.h"
...@@ -1304,6 +1305,8 @@ void DownloadManagerImpl::BeginDownloadInternal( ...@@ -1304,6 +1305,8 @@ void DownloadManagerImpl::BeginDownloadInternal(
std::unique_ptr<network::ResourceRequest> request = std::unique_ptr<network::ResourceRequest> request =
download::CreateResourceRequest(params.get()); download::CreateResourceRequest(params.get());
GURL site_url, tab_url, tab_referrer_url; GURL site_url, tab_url, tab_referrer_url;
network::mojom::URLLoaderFactoryPtrInfo proxy_factory_ptr_info;
network::mojom::URLLoaderFactoryRequest proxy_factory_request;
auto* rfh = RenderFrameHost::FromID(params->render_process_host_id(), auto* rfh = RenderFrameHost::FromID(params->render_process_host_id(),
params->render_frame_host_routing_id()); params->render_frame_host_routing_id());
if (rfh) { if (rfh) {
...@@ -1314,6 +1317,15 @@ void DownloadManagerImpl::BeginDownloadInternal( ...@@ -1314,6 +1317,15 @@ void DownloadManagerImpl::BeginDownloadInternal(
tab_url = entry->GetURL(); tab_url = entry->GetURL();
tab_referrer_url = entry->GetReferrer().url; tab_referrer_url = entry->GetReferrer().url;
} }
network::mojom::URLLoaderFactoryPtrInfo devtools_factory_ptr_info;
network::mojom::URLLoaderFactoryRequest devtools_factory_request =
MakeRequest(&devtools_factory_ptr_info);
if (RenderFrameDevToolsAgentHost::WillCreateURLLoaderFactory(
static_cast<RenderFrameHostImpl*>(rfh), true,
&devtools_factory_request)) {
proxy_factory_ptr_info = std::move(devtools_factory_ptr_info);
proxy_factory_request = std::move(devtools_factory_request);
}
} }
scoped_refptr<download::DownloadURLLoaderFactoryGetter> scoped_refptr<download::DownloadURLLoaderFactoryGetter>
...@@ -1325,7 +1337,9 @@ void DownloadManagerImpl::BeginDownloadInternal( ...@@ -1325,7 +1337,9 @@ void DownloadManagerImpl::BeginDownloadInternal(
} else { } else {
url_loader_factory_getter = url_loader_factory_getter =
base::MakeRefCounted<NetworkDownloadURLLoaderFactoryGetter>( base::MakeRefCounted<NetworkDownloadURLLoaderFactoryGetter>(
storage_partition->url_loader_factory_getter()); storage_partition->url_loader_factory_getter(),
std::move(proxy_factory_ptr_info),
std::move(proxy_factory_request));
} }
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
......
...@@ -6,13 +6,18 @@ ...@@ -6,13 +6,18 @@
#include "components/download/public/common/download_task_runner.h" #include "components/download/public/common/download_task_runner.h"
#include "content/browser/url_loader_factory_getter.h" #include "content/browser/url_loader_factory_getter.h"
#include "content/common/wrapper_shared_url_loader_factory.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
namespace content { namespace content {
NetworkDownloadURLLoaderFactoryGetter::NetworkDownloadURLLoaderFactoryGetter( NetworkDownloadURLLoaderFactoryGetter::NetworkDownloadURLLoaderFactoryGetter(
scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter) scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter,
: url_loader_factory_getter_(url_loader_factory_getter) {} network::mojom::URLLoaderFactoryPtrInfo proxy_factory_ptr_info,
network::mojom::URLLoaderFactoryRequest proxy_factory_request)
: url_loader_factory_getter_(url_loader_factory_getter),
proxy_factory_ptr_info_(std::move(proxy_factory_ptr_info)),
proxy_factory_request_(std::move(proxy_factory_request)) {}
NetworkDownloadURLLoaderFactoryGetter:: NetworkDownloadURLLoaderFactoryGetter::
~NetworkDownloadURLLoaderFactoryGetter() = default; ~NetworkDownloadURLLoaderFactoryGetter() = default;
...@@ -21,7 +26,17 @@ scoped_refptr<network::SharedURLLoaderFactory> ...@@ -21,7 +26,17 @@ scoped_refptr<network::SharedURLLoaderFactory>
NetworkDownloadURLLoaderFactoryGetter::GetURLLoaderFactory() { NetworkDownloadURLLoaderFactoryGetter::GetURLLoaderFactory() {
DCHECK(download::GetIOTaskRunner()); DCHECK(download::GetIOTaskRunner());
DCHECK(download::GetIOTaskRunner()->BelongsToCurrentThread()); DCHECK(download::GetIOTaskRunner()->BelongsToCurrentThread());
return url_loader_factory_getter_->GetNetworkFactory(); if (lazy_factory_)
return lazy_factory_;
if (proxy_factory_request_.is_pending()) {
url_loader_factory_getter_->CloneNetworkFactory(
std::move(proxy_factory_request_));
lazy_factory_ = base::MakeRefCounted<WrapperSharedURLLoaderFactory>(
std::move(proxy_factory_ptr_info_));
} else {
lazy_factory_ = url_loader_factory_getter_->GetNetworkFactory();
}
return lazy_factory_;
} }
} // namespace content } // namespace content
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CONTENT_BROWSER_DOWNLOAD_NETWORK_DOWNLOAD_URL_LOADER_FACTORY_GETTER_H_ #define CONTENT_BROWSER_DOWNLOAD_NETWORK_DOWNLOAD_URL_LOADER_FACTORY_GETTER_H_
#include "components/download/public/common/download_url_loader_factory_getter.h" #include "components/download/public/common/download_url_loader_factory_getter.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
namespace content { namespace content {
...@@ -15,8 +16,10 @@ class URLLoaderFactoryGetter; ...@@ -15,8 +16,10 @@ class URLLoaderFactoryGetter;
class NetworkDownloadURLLoaderFactoryGetter class NetworkDownloadURLLoaderFactoryGetter
: public download::DownloadURLLoaderFactoryGetter { : public download::DownloadURLLoaderFactoryGetter {
public: public:
explicit NetworkDownloadURLLoaderFactoryGetter( NetworkDownloadURLLoaderFactoryGetter(
scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter); scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter,
network::mojom::URLLoaderFactoryPtrInfo proxy_factory_ptr_info,
network::mojom::URLLoaderFactoryRequest proxy_factory_request);
// download::DownloadURLLoaderFactoryGetter implementation. // download::DownloadURLLoaderFactoryGetter implementation.
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override; scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
...@@ -26,6 +29,9 @@ class NetworkDownloadURLLoaderFactoryGetter ...@@ -26,6 +29,9 @@ class NetworkDownloadURLLoaderFactoryGetter
private: private:
scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter_; scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter_;
scoped_refptr<network::SharedURLLoaderFactory> lazy_factory_;
network::mojom::URLLoaderFactoryPtrInfo proxy_factory_ptr_info_;
network::mojom::URLLoaderFactoryRequest proxy_factory_request_;
DISALLOW_COPY_AND_ASSIGN(NetworkDownloadURLLoaderFactoryGetter); DISALLOW_COPY_AND_ASSIGN(NetworkDownloadURLLoaderFactoryGetter);
}; };
......
Tests that downloads are intercepted when interception is enabled for page.
Intercepted: http://127.0.0.1:8000/devtools/network/resources/resource.php
(async function(testRunner) {
var {page, session, dp} = await testRunner.startBlank(
`Tests that downloads are intercepted when interception is enabled for page.`);
await session.protocol.Network.clearBrowserCache();
await session.protocol.Network.setCacheDisabled({cacheDisabled: true});
await session.protocol.Network.enable();
await session.protocol.Runtime.enable();
await dp.Network.setRequestInterception({patterns: [{}]});
session.evaluate(`
const a = document.createElement('a');
a.href = '/devtools/network/resources/resource.php';
a.download = 'hello.text';
document.body.appendChild(a);
a.click();
`);
const event = await dp.Network.onceRequestIntercepted();
testRunner.log(`Intercepted: ${event.params.request.url}`);
testRunner.completeTest();
})
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment