Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: chrome/browser/android/download/intercept_download_resource_throttle.cc

Issue 2642683005: reintroduce InterceptDownloadResourceThrottle for some OMA DRM downloads (Closed)
Patch Set: rename CreateGetDownload to CreateAndroidDownload Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/download/intercept_download_resource_throttle.h "
6
7 #include "base/strings/string_util.h"
8 #include "net/http/http_request_headers.h"
9 #include "net/http/http_response_headers.h"
10 #include "net/url_request/url_request.h"
11 #include "net/url_request/url_request_context.h"
12
13 namespace {
14 static const char kOMADrmMessageMimeType[] = "application/vnd.oma.drm.message";
15 }
16
17 InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle(
18 net::URLRequest* request,
19 const content::ResourceRequestInfo::WebContentsGetter& wc_getter)
20 : request_(request),
21 wc_getter_(wc_getter),
22 weak_factory_(this) {
23 }
24
25 InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() {
David Trainor- moved to gerrit 2017/01/27 17:16:46 does = default fail here because complex destructo
qinmin 2017/01/27 21:29:54 Done.
26 }
27
28 void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) {
29 if (request_->url_chain().empty())
30 return;
31
32 GURL url = request_->url_chain().back();
33 if (!url.SchemeIsHTTPOrHTTPS())
34 return;
35
36 if (request_->method() != net::HttpRequestHeaders::kGetMethod)
37 return;
38
39 net::HttpRequestHeaders headers;
40 if (!request_->GetFullRequestHeaders(&headers))
41 return;
42
43 std::string mime_type;
44 request_->response_headers()->GetMimeType(&mime_type);
45 if (!base::EqualsCaseInsensitiveASCII(mime_type, kOMADrmMessageMimeType))
46 return;
47
48 net::CookieStore* cookie_store = request_->context()->cookie_store();
49 if (cookie_store) {
50 // Cookie is obtained via asynchonous call. Setting |*defer| to true
51 // keeps the throttle alive in the meantime.
52 *defer = true;
53 net::CookieOptions options;
54 options.set_include_httponly();
55 cookie_store->GetCookieListWithOptionsAsync(
56 request_->url(),
57 options,
58 base::Bind(&InterceptDownloadResourceThrottle::CheckCookiePolicy,
59 weak_factory_.GetWeakPtr()));
60 } else {
61 // Can't get any cookies, start android download.
62 StartDownload(DownloadInfo(request_));
63 }
64 }
65
66 const char* InterceptDownloadResourceThrottle::GetNameForLogging() const {
67 return "InterceptDownloadResourceThrottle";
68 }
69
70 void InterceptDownloadResourceThrottle::CheckCookiePolicy(
71 const net::CookieList& cookie_list) {
72 DownloadInfo info(request_);
73 if (request_->context()->network_delegate()->CanGetCookies(*request_,
74 cookie_list)) {
75 std::string cookie = net::CookieStore::BuildCookieLine(cookie_list);
76 if (!cookie.empty())
77 info.cookie = cookie;
78 }
79 StartDownload(info);
80 }
81
82 void InterceptDownloadResourceThrottle::StartDownload(
83 const DownloadInfo& info) {
84 DownloadControllerBase::Get()->CreateAndroidDownload(wc_getter_, info);
85 Cancel();
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698