Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / android / intercept_download_resource_throttle.cc
blobcde363cb8ec4a2d8b1b2c726685b72ff4452fe24
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 "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
8 #include "content/public/browser/android/download_controller_android.h"
9 #include "content/public/browser/resource_controller.h"
10 #include "net/http/http_request_headers.h"
11 #include "net/http/http_response_headers.h"
12 #include "net/url_request/url_request.h"
14 namespace chrome {
16 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle(
17 net::URLRequest* request,
18 int render_process_id,
19 int render_view_id,
20 int request_id)
21 : request_(request),
22 render_process_id_(render_process_id),
23 render_view_id_(render_view_id),
24 request_id_(request_id) {
27 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() {
30 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) {
31 ProcessDownloadRequest();
34 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const {
35 return "InterceptDownloadResourceThrottle";
38 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() {
39 // TODO(qinmin): add UMA stats for all reasons that downloads are not
40 // intercepted by the Android Download Manager. http://crbug.com/385272.
41 if (request_->url_chain().empty())
42 return;
44 GURL url = request_->url_chain().back();
45 if (!url.SchemeIsHTTPOrHTTPS())
46 return;
48 if (request_->method() != net::HttpRequestHeaders::kGetMethod)
49 return;
51 net::HttpRequestHeaders headers;
52 if (!request_->GetFullRequestHeaders(&headers))
53 return;
55 // In general, if the request uses HTTP authorization, either with the origin
56 // or a proxy, then the network stack should handle the download. The one
57 // exception is a request that is fetched via the Chrome Proxy and does not
58 // authenticate with the origin.
59 if (request_->response_info().did_use_http_auth) {
60 if (headers.HasHeader(net::HttpRequestHeaders::kAuthorization) ||
61 !(request_->response_info().headers.get() &&
62 data_reduction_proxy::HasDataReductionProxyViaHeader(
63 request_->response_info().headers.get(), NULL))) {
64 return;
68 // If the cookie is possibly channel-bound, don't pass it to android download
69 // manager.
70 // TODO(qinmin): add a test for this. http://crbug.com/430541.
71 if (request_->ssl_info().channel_id_sent)
72 return;
74 content::DownloadControllerAndroid::Get()->CreateGETDownload(
75 render_process_id_, render_view_id_, request_id_);
76 controller()->Cancel();
79 } // namespace chrome