| OLD | NEW |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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/download/intercept_download_resource_throttle.h
" | 5 #include "chrome/browser/android/download/intercept_download_resource_throttle.h
" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "net/http/http_request_headers.h" | 8 #include "net/http/http_request_headers.h" |
| 9 #include "net/http/http_response_headers.h" | 9 #include "net/http/http_response_headers.h" |
| 10 #include "net/url_request/url_request.h" | 10 #include "net/url_request/url_request.h" |
| 11 #include "net/url_request/url_request_context.h" | 11 #include "net/url_request/url_request_context.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 static const char kOMADrmMessageMimeType[] = "application/vnd.oma.drm.message"; | 14 static const char kOMADrmMessageMimeType[] = "application/vnd.oma.drm.message"; |
| 15 static const char kOMADrmContentMimeType[] = "application/vnd.oma.drm.content"; |
| 16 static const char kOMADrmRightsMimeType1[] = |
| 17 "application/vnd.oma.drm.rights+xml"; |
| 18 static const char kOMADrmRightsMimeType2[] = |
| 19 "application/vnd.oma.drm.rights+wbxml"; |
| 15 } | 20 } |
| 16 | 21 |
| 17 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle( | 22 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle( |
| 18 net::URLRequest* request, | 23 net::URLRequest* request, |
| 19 const content::ResourceRequestInfo::WebContentsGetter& wc_getter) | 24 const content::ResourceRequestInfo::WebContentsGetter& wc_getter) |
| 20 : request_(request), | 25 : request_(request), |
| 21 wc_getter_(wc_getter), | 26 wc_getter_(wc_getter), |
| 22 weak_factory_(this) { | 27 weak_factory_(this) { |
| 23 } | 28 } |
| 24 | 29 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 | 40 |
| 36 if (request_->method() != net::HttpRequestHeaders::kGetMethod) | 41 if (request_->method() != net::HttpRequestHeaders::kGetMethod) |
| 37 return; | 42 return; |
| 38 | 43 |
| 39 net::HttpRequestHeaders headers; | 44 net::HttpRequestHeaders headers; |
| 40 if (!request_->GetFullRequestHeaders(&headers)) | 45 if (!request_->GetFullRequestHeaders(&headers)) |
| 41 return; | 46 return; |
| 42 | 47 |
| 43 std::string mime_type; | 48 std::string mime_type; |
| 44 request_->response_headers()->GetMimeType(&mime_type); | 49 request_->response_headers()->GetMimeType(&mime_type); |
| 45 if (!base::EqualsCaseInsensitiveASCII(mime_type, kOMADrmMessageMimeType)) | 50 if (!base::EqualsCaseInsensitiveASCII(mime_type, kOMADrmMessageMimeType) && |
| 51 !base::EqualsCaseInsensitiveASCII(mime_type, kOMADrmContentMimeType) && |
| 52 !base::EqualsCaseInsensitiveASCII(mime_type, kOMADrmRightsMimeType1) && |
| 53 !base::EqualsCaseInsensitiveASCII(mime_type, kOMADrmRightsMimeType2)) { |
| 46 return; | 54 return; |
| 55 } |
| 47 | 56 |
| 48 net::CookieStore* cookie_store = request_->context()->cookie_store(); | 57 net::CookieStore* cookie_store = request_->context()->cookie_store(); |
| 49 if (cookie_store) { | 58 if (cookie_store) { |
| 50 // Cookie is obtained via asynchonous call. Setting |*defer| to true | 59 // Cookie is obtained via asynchonous call. Setting |*defer| to true |
| 51 // keeps the throttle alive in the meantime. | 60 // keeps the throttle alive in the meantime. |
| 52 *defer = true; | 61 *defer = true; |
| 53 net::CookieOptions options; | 62 net::CookieOptions options; |
| 54 options.set_include_httponly(); | 63 options.set_include_httponly(); |
| 55 cookie_store->GetCookieListWithOptionsAsync( | 64 cookie_store->GetCookieListWithOptionsAsync( |
| 56 request_->url(), | 65 request_->url(), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 77 info.cookie = cookie; | 86 info.cookie = cookie; |
| 78 } | 87 } |
| 79 StartDownload(info); | 88 StartDownload(info); |
| 80 } | 89 } |
| 81 | 90 |
| 82 void InterceptDownloadResourceThrottle::StartDownload( | 91 void InterceptDownloadResourceThrottle::StartDownload( |
| 83 const DownloadInfo& info) { | 92 const DownloadInfo& info) { |
| 84 DownloadControllerBase::Get()->CreateAndroidDownload(wc_getter_, info); | 93 DownloadControllerBase::Get()->CreateAndroidDownload(wc_getter_, info); |
| 85 Cancel(); | 94 Cancel(); |
| 86 } | 95 } |
| OLD | NEW |