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 "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 7 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
8 #include "content/public/browser/android/download_controller_android.h" | 8 #include "content/public/browser/android/download_controller_android.h" |
9 #include "content/public/browser/resource_controller.h" | 9 #include "content/public/browser/resource_controller.h" |
10 #include "net/http/http_request_headers.h" | 10 #include "net/http/http_request_headers.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 : request_(request), | 24 : request_(request), |
25 render_process_id_(render_process_id), | 25 render_process_id_(render_process_id), |
26 render_view_id_(render_view_id), | 26 render_view_id_(render_view_id), |
27 request_id_(request_id) { | 27 request_id_(request_id) { |
28 } | 28 } |
29 | 29 |
30 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() { | 30 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() { |
31 } | 31 } |
32 | 32 |
33 void InterceptDownloadResourceThrottle::WillStartRequest(bool* defer) { | 33 void InterceptDownloadResourceThrottle::WillStartRequest(bool* defer) { |
34 ProcessDownloadRequest(); | 34 ProcessDownloadRequest(); |
asanka
2014/07/16 16:53:08
This won't do anything now. WillStartRequest is ca
qinmin
2014/07/16 17:13:39
Remove the call to ProcessDownloadRequest here.
O
| |
35 } | 35 } |
36 | 36 |
37 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) { | 37 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) { |
38 ProcessDownloadRequest(); | 38 ProcessDownloadRequest(); |
39 } | 39 } |
40 | 40 |
41 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const { | 41 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const { |
42 return "InterceptDownloadResourceThrottle"; | 42 return "InterceptDownloadResourceThrottle"; |
43 } | 43 } |
44 | 44 |
45 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() { | 45 void InterceptDownloadResourceThrottle::ProcessDownloadRequest() { |
46 if (request_->url_chain().empty()) | 46 if (request_->url_chain().empty()) |
47 return; | 47 return; |
48 | 48 |
49 GURL url = request_->url_chain().back(); | 49 GURL url = request_->url_chain().back(); |
50 if (!url.SchemeIsHTTPOrHTTPS()) | 50 if (!url.SchemeIsHTTPOrHTTPS()) |
51 return; | 51 return; |
52 | 52 |
53 if (request_->method() != net::HttpRequestHeaders::kGetMethod) | 53 if (request_->method() != net::HttpRequestHeaders::kGetMethod) |
54 return; | 54 return; |
55 | 55 |
56 net::HttpRequestHeaders headers; | |
57 if (!request_->GetFullRequestHeaders(&headers)) | |
58 return; | |
59 | |
56 // In general, if the request uses HTTP authorization, either with the origin | 60 // 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 | 61 // 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 | 62 // exception is a request that is fetched via the Chrome Proxy and does not |
59 // authenticate with the origin. | 63 // authenticate with the origin. |
60 if (request_->response_info().did_use_http_auth) { | 64 if (request_->response_info().did_use_http_auth) { |
61 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 65 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
62 net::HttpRequestHeaders headers; | |
63 request_->GetFullRequestHeaders(&headers); | |
64 if (headers.HasHeader(net::HttpRequestHeaders::kAuthorization) || | 66 if (headers.HasHeader(net::HttpRequestHeaders::kAuthorization) || |
65 !(request_->response_info().headers && | 67 !(request_->response_info().headers && |
66 data_reduction_proxy::HasDataReductionProxyViaHeader( | 68 data_reduction_proxy::HasDataReductionProxyViaHeader( |
67 request_->response_info().headers))) { | 69 request_->response_info().headers))) { |
68 return; | 70 return; |
69 } | 71 } |
70 #else | 72 #else |
71 return; | 73 return; |
72 #endif | 74 #endif |
73 } | 75 } |
74 | 76 |
75 // For OMA DRM downloads, Android Download Manager doesn't handle them | 77 // For OMA DRM downloads, Android Download Manager doesn't handle them |
76 // correctly. Use chromium network stack instead. http://crbug.com/382698. | 78 // correctly. Use chromium network stack instead. http://crbug.com/382698. |
77 std::string mime; | 79 std::string mime; |
78 const_cast<net::URLRequest*>(request_)->GetMimeType(&mime); | 80 const_cast<net::URLRequest*>(request_)->GetMimeType(&mime); |
asanka
2014/07/16 16:53:08
Why the const_cast here?
qinmin
2014/07/16 17:13:39
GetMimeType() was recently changed to a const call
| |
79 if (!mime.compare(kOmaDrmContentMime) || !mime.compare(kOmaDrmMessageMime)) | 81 if (!mime.compare(kOmaDrmContentMime) || !mime.compare(kOmaDrmMessageMime)) |
80 return; | 82 return; |
81 | 83 |
82 content::DownloadControllerAndroid::Get()->CreateGETDownload( | 84 content::DownloadControllerAndroid::Get()->CreateGETDownload( |
83 render_process_id_, render_view_id_, request_id_); | 85 render_process_id_, render_view_id_, request_id_); |
84 controller()->Cancel(); | 86 controller()->Cancel(); |
85 } | 87 } |
86 | 88 |
87 } // namespace chrome | 89 } // namespace chrome |
OLD | NEW |