| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/android/intercept_download_resource_throttle.h" | 5 #include "chrome/browser/android/intercept_download_resource_throttle.h" |
| 6 | 6 |
| 7 #include "content/public/browser/android/download_controller_android.h" | 7 #include "content/public/browser/android/download_controller_android.h" |
| 8 #include "content/public/browser/resource_controller.h" | 8 #include "content/public/browser/resource_controller.h" |
| 9 #include "net/http/http_request_headers.h" | 9 #include "net/http/http_request_headers.h" |
| 10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
| 11 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
| 12 | 12 |
| 13 namespace chrome { | 13 namespace chrome { |
| 14 | 14 |
| 15 static const char kOmaDrmContentMime[] = "application/vnd.oma.drm.content"; |
| 16 static const char kOmaDrmMessageMime[] = "application/vnd.oma.drm.message"; |
| 17 |
| 15 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle( | 18 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle( |
| 16 net::URLRequest* request, | 19 net::URLRequest* request, |
| 17 int render_process_id, | 20 int render_process_id, |
| 18 int render_view_id, | 21 int render_view_id, |
| 19 int request_id) | 22 int request_id) |
| 20 : request_(request), | 23 : request_(request), |
| 21 render_process_id_(render_process_id), | 24 render_process_id_(render_process_id), |
| 22 render_view_id_(render_view_id), | 25 render_view_id_(render_view_id), |
| 23 request_id_(request_id) { | 26 request_id_(request_id) { |
| 24 } | 27 } |
| 25 | 28 |
| 26 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() { | 29 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() { |
| 27 } | 30 } |
| 28 | 31 |
| 29 void InterceptDownloadResourceThrottle::WillStartRequest(bool* defer) { | 32 void InterceptDownloadResourceThrottle::WillStartRequest(bool* defer) { |
| 30 ProcessDownloadRequest(); | 33 ProcessDownloadRequest(); |
| 31 } | 34 } |
| 32 | 35 |
| 33 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) { | 36 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) { |
| 34 ProcessDownloadRequest(); | 37 ProcessDownloadRequest(); |
| 35 } | 38 } |
| 36 | 39 |
| 37 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const { | 40 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const { |
| 38 return "InterceptDownloadResourceThrottle"; | 41 return "InterceptDownloadResourceThrottle"; |
| 39 } | 42 } |
| 40 | 43 |
| 41 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() { | 44 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() { |
| 45 if (request_->url_chain().empty()) |
| 46 return; |
| 47 |
| 48 GURL url = request_->url_chain().back(); |
| 49 if (!url.SchemeIsHTTPOrHTTPS()) |
| 50 return; |
| 51 |
| 42 if (request_->method() != net::HttpRequestHeaders::kGetMethod) | 52 if (request_->method() != net::HttpRequestHeaders::kGetMethod) |
| 43 return; | 53 return; |
| 44 | 54 |
| 45 // In general, if the request uses HTTP authorization, either with the origin | 55 // 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 | 56 // 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 | 57 // exception is a request that is fetched via the Chrome Proxy and does not |
| 48 // authenticate with the origin. | 58 // authenticate with the origin. |
| 49 if (request_->response_info().did_use_http_auth) { | 59 if (request_->response_info().did_use_http_auth) { |
| 50 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 60 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 51 net::HttpRequestHeaders headers; | 61 net::HttpRequestHeaders headers; |
| 52 request_->GetFullRequestHeaders(&headers); | 62 request_->GetFullRequestHeaders(&headers); |
| 53 if (headers.HasHeader(net::HttpRequestHeaders::kAuthorization) || | 63 if (headers.HasHeader(net::HttpRequestHeaders::kAuthorization) || |
| 54 !(request_->response_info().headers && | 64 !(request_->response_info().headers && |
| 55 request_->response_info().headers-> | 65 request_->response_info().headers-> |
| 56 IsDataReductionProxyResponse())) { | 66 IsDataReductionProxyResponse())) { |
| 57 return; | 67 return; |
| 58 } | 68 } |
| 59 #else | 69 #else |
| 60 return; | 70 return; |
| 61 #endif | 71 #endif |
| 62 } | 72 } |
| 63 | 73 |
| 64 if (request_->url_chain().empty()) | 74 // For OMA DRM downloads, Android Download Manager doesn't handle them |
| 65 return; | 75 // correctly. Use chromium network stack instead. http://crbug.com/382698. |
| 66 | 76 std::string mime; |
| 67 GURL url = request_->url_chain().back(); | 77 const_cast<net::URLRequest*>(request_)->GetMimeType(&mime); |
| 68 if (!url.SchemeIsHTTPOrHTTPS()) | 78 if (!mime.compare(kOmaDrmContentMime) || !mime.compare(kOmaDrmMessageMime)) |
| 69 return; | 79 return; |
| 70 | 80 |
| 71 content::DownloadControllerAndroid::Get()->CreateGETDownload( | 81 content::DownloadControllerAndroid::Get()->CreateGETDownload( |
| 72 render_process_id_, render_view_id_, request_id_); | 82 render_process_id_, render_view_id_, request_id_); |
| 73 controller()->Cancel(); | 83 controller()->Cancel(); |
| 74 } | 84 } |
| 75 | 85 |
| 76 } // namespace chrome | 86 } // namespace chrome |
| OLD | NEW |