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/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"
16 static const char kOmaDrmContentMime
[] = "application/vnd.oma.drm.content";
17 static const char kOmaDrmMessageMime
[] = "application/vnd.oma.drm.message";
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::WillProcessResponse(bool* defer
) {
34 ProcessDownloadRequest();
37 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const {
38 return "InterceptDownloadResourceThrottle";
41 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() {
42 if (request_
->url_chain().empty())
45 GURL url
= request_
->url_chain().back();
46 if (!url
.SchemeIsHTTPOrHTTPS())
49 if (request_
->method() != net::HttpRequestHeaders::kGetMethod
)
52 net::HttpRequestHeaders headers
;
53 if (!request_
->GetFullRequestHeaders(&headers
))
56 // In general, if the request uses HTTP authorization, either with the origin
57 // or a proxy, then the network stack should handle the download. The one
58 // exception is a request that is fetched via the Chrome Proxy and does not
59 // authenticate with the origin.
60 if (request_
->response_info().did_use_http_auth
) {
61 #if defined(SPDY_PROXY_AUTH_ORIGIN)
62 if (headers
.HasHeader(net::HttpRequestHeaders::kAuthorization
) ||
63 !(request_
->response_info().headers
&&
64 data_reduction_proxy::HasDataReductionProxyViaHeader(
65 request_
->response_info().headers
))) {
73 // For OMA DRM downloads, Android Download Manager doesn't handle them
74 // correctly. Use chromium network stack instead. http://crbug.com/382698.
76 request_
->GetMimeType(&mime
);
77 if (!mime
.compare(kOmaDrmContentMime
) || !mime
.compare(kOmaDrmMessageMime
))
80 content::DownloadControllerAndroid::Get()->CreateGETDownload(
81 render_process_id_
, render_view_id_
, request_id_
);
82 controller()->Cancel();