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

Unified Diff: chrome/browser/android/download/intercept_download_resource_throttle.cc

Issue 2642683005: reintroduce InterceptDownloadResourceThrottle for some OMA DRM downloads (Closed)
Patch Set: function name change to avoid findbugs confusion Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/download/intercept_download_resource_throttle.cc
diff --git a/chrome/browser/android/download/intercept_download_resource_throttle.cc b/chrome/browser/android/download/intercept_download_resource_throttle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1321f2e877b80d8034d91ef2b3d28ddeebb0eba4
--- /dev/null
+++ b/chrome/browser/android/download/intercept_download_resource_throttle.cc
@@ -0,0 +1,86 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/download/intercept_download_resource_throttle.h"
+
+#include "base/strings/string_util.h"
+#include "net/http/http_request_headers.h"
+#include "net/http/http_response_headers.h"
+#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_context.h"
+
+namespace {
+static const char kOMADrmMessageMimeType[] = "application/vnd.oma.drm.message";
+}
+
+InterceptDownloadResourceThrottle::InterceptDownloadResourceThrottle(
+ net::URLRequest* request,
+ const content::ResourceRequestInfo::WebContentsGetter& wc_getter)
+ : request_(request),
+ wc_getter_(wc_getter),
+ weak_factory_(this) {
+}
+
+InterceptDownloadResourceThrottle::~InterceptDownloadResourceThrottle() =
+ default;
+
+void InterceptDownloadResourceThrottle::WillProcessResponse(bool* defer) {
+ if (request_->url_chain().empty())
+ return;
+
+ GURL url = request_->url_chain().back();
+ if (!url.SchemeIsHTTPOrHTTPS())
+ return;
+
+ if (request_->method() != net::HttpRequestHeaders::kGetMethod)
+ return;
+
+ net::HttpRequestHeaders headers;
+ if (!request_->GetFullRequestHeaders(&headers))
+ return;
+
+ std::string mime_type;
+ request_->response_headers()->GetMimeType(&mime_type);
+ if (!base::EqualsCaseInsensitiveASCII(mime_type, kOMADrmMessageMimeType))
+ return;
+
+ net::CookieStore* cookie_store = request_->context()->cookie_store();
+ if (cookie_store) {
+ // Cookie is obtained via asynchonous call. Setting |*defer| to true
+ // keeps the throttle alive in the meantime.
+ *defer = true;
+ net::CookieOptions options;
+ options.set_include_httponly();
+ cookie_store->GetCookieListWithOptionsAsync(
+ request_->url(),
+ options,
+ base::Bind(&InterceptDownloadResourceThrottle::CheckCookiePolicy,
+ weak_factory_.GetWeakPtr()));
+ } else {
+ // Can't get any cookies, start android download.
+ StartDownload(DownloadInfo(request_));
+ }
+}
+
+const char* InterceptDownloadResourceThrottle::GetNameForLogging() const {
+ return "InterceptDownloadResourceThrottle";
+}
+
+void InterceptDownloadResourceThrottle::CheckCookiePolicy(
+ const net::CookieList& cookie_list) {
+ DownloadInfo info(request_);
+ if (request_->context()->network_delegate()->CanGetCookies(*request_,
+ cookie_list)) {
+ std::string cookie = net::CookieStore::BuildCookieLine(cookie_list);
+ if (!cookie.empty())
+ info.cookie = cookie;
+ }
+ StartDownload(info);
+}
+
+void InterceptDownloadResourceThrottle::StartDownload(
+ const DownloadInfo& info) {
+ DownloadControllerBase::Get()->CreateAndroidDownload(wc_getter_, info);
+ Cancel();
+}

Powered by Google App Engine
This is Rietveld 408576698