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"
15 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle(
16 net::URLRequest
* request
,
17 int render_process_id
,
21 render_process_id_(render_process_id
),
22 render_view_id_(render_view_id
),
23 request_id_(request_id
) {
26 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() {
29 void InterceptDownloadResourceThrottle::WillStartRequest(bool* defer
) {
30 ProcessDownloadRequest();
33 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer
) {
34 ProcessDownloadRequest();
37 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const {
38 return "InterceptDownloadResourceThrottle";
41 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() {
42 if (request_
->method() != net::HttpRequestHeaders::kGetMethod
)
45 // In general, if the request uses HTTP authorization, either with the origin
46 // or a proxy, then the network stack should handle the download. The one
47 // exception is a request that is fetched via the Chrome Proxy and does not
48 // authenticate with the origin.
49 if (request_
->response_info().did_use_http_auth
) {
50 #if defined(SPDY_PROXY_AUTH_ORIGIN)
51 net::HttpRequestHeaders headers
;
52 request_
->GetFullRequestHeaders(&headers
);
53 if (headers
.HasHeader(net::HttpRequestHeaders::kAuthorization
) ||
54 !(request_
->response_info().headers
&&
55 request_
->response_info().headers
->
56 IsDataReductionProxyResponse())) {
64 if (request_
->url_chain().empty())
67 GURL url
= request_
->url_chain().back();
68 if (!url
.SchemeIsHTTPOrHTTPS())
71 content::DownloadControllerAndroid::Get()->CreateGETDownload(
72 render_process_id_
, render_view_id_
, request_id_
);
73 controller()->Cancel();