1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/android/intercept_download_resource_throttle.h"
7 #include "content/public/browser/android/download_controller_android.h"
8 #include "content/public/browser/resource_controller.h"
9 #include "net/http/http_request_headers.h"
10 #include "net/http/http_response_headers.h"
11 #include "net/url_request/url_request.h"
13 #if defined(SPDY_PROXY_AUTH_ORIGIN)
14 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings.h"
15 #endif // defined(SPDY_PROXY_AUTH_ORIGIN)
19 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle(
20 net::URLRequest
* request
,
21 int render_process_id
,
25 render_process_id_(render_process_id
),
26 render_view_id_(render_view_id
),
27 request_id_(request_id
) {
30 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() {
33 void InterceptDownloadResourceThrottle::WillStartRequest(bool* defer
) {
34 ProcessDownloadRequest();
37 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer
) {
38 ProcessDownloadRequest();
41 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const {
42 return "InterceptDownloadResourceThrottle";
45 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() {
46 if (request_
->method() != net::HttpRequestHeaders::kGetMethod
)
49 // In general, if the request uses HTTP authorization, either with the origin
50 // or a proxy, then the network stack should handle the download. The one
51 // exception is a request that is fetched via the Chrome Proxy and does not
52 // authenticate with the origin.
53 if (request_
->response_info().did_use_http_auth
) {
54 #if defined(SPDY_PROXY_AUTH_ORIGIN)
55 net::HttpRequestHeaders headers
;
56 request_
->GetFullRequestHeaders(&headers
);
57 if (headers
.HasHeader(net::HttpRequestHeaders::kAuthorization
) ||
58 !DataReductionProxySettings::WasFetchedViaProxy(
59 request_
->response_info().headers
)) {
67 if (request_
->url_chain().empty())
70 GURL url
= request_
->url_chain().back();
71 if (!url
.SchemeIsHTTPOrHTTPS())
74 content::DownloadControllerAndroid::Get()->CreateGETDownload(
75 render_process_id_
, render_view_id_
, request_id_
);
76 controller()->Cancel();