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

Unified Diff: chrome/browser/android/offline_pages/downloads/resource_throttle.cc

Issue 2528483003: [Android Downloads] Long-press menu item "Download Link" should delegate job to OfflinePages backen… (Closed)
Patch Set: check for buildflag Created 4 years 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/offline_pages/downloads/resource_throttle.cc
diff --git a/chrome/browser/android/offline_pages/downloads/resource_throttle.cc b/chrome/browser/android/offline_pages/downloads/resource_throttle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7341b45dda298a11ff03dd169b8772f2c49f736e
--- /dev/null
+++ b/chrome/browser/android/offline_pages/downloads/resource_throttle.cc
@@ -0,0 +1,69 @@
+// Copyright 2015 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/offline_pages/downloads/resource_throttle.h"
asanka 2016/12/07 16:37:40 You could use the SaveLinkAsReferrerPolicyOrigin t
+
+#include "base/logging.h"
+#include "chrome/browser/android/offline_pages/offline_page_utils.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/resource_controller.h"
+#include "content/public/browser/resource_request_info.h"
+#include "content/public/browser/web_contents.h"
+#include "net/base/mime_util.h"
+
+ namespace {
asanka 2016/12/07 16:37:40 Nit: whitespace. Perhaps run this through 'git cl
+ // Mime type of download resource that should trigger handoff to OfflinePages
+ // backend for full page load and snapshot.
+const char kHTMLMimeType[] = "text/html";
asanka 2016/12/07 16:37:40 SavePackage considers both text/html and applicati
+
+void WillStartOfflineRequestOnUIThread(
+ const GURL& url,
+ const content::ResourceRequestInfo::WebContentsGetter& contents_getter) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ content::WebContents* web_contents = contents_getter.Run();
+ if (!web_contents)
+ return;
+ offline_pages::OfflinePageUtils::StartOfflinePageDownload(
+ web_contents->GetBrowserContext(), url);
+}
+} // namespace
+
+namespace offline_pages {
+namespace downloads {
+
+ResourceThrottle::ResourceThrottle(const net::URLRequest* request)
+ : request_(request) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+}
+
+ResourceThrottle::~ResourceThrottle() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+}
+
+void ResourceThrottle::WillProcessResponse(bool* defer) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+ std::string mime_type;
+ request_->GetMimeType(&mime_type);
+ if (net::MatchesMimeType(kHTMLMimeType, mime_type)) {
+ controller()->Cancel();
asanka 2016/12/07 16:37:40 Let's defer the Cancel() call until after you're d
+
+ const content::ResourceRequestInfo* info =
+ content::ResourceRequestInfo::ForRequest(request_);
+ if (!info)
+ return;
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE,
+ base::Bind(&WillStartOfflineRequestOnUIThread,
+ request_->url(),
+ info->GetWebContentsGetterForRequest()));
+ }
+}
+
+const char* ResourceThrottle::GetNameForLogging() const {
+ return "offline_pages::downloads::ResourceThrottle";
+}
+
+} // namespace downloads
+} // namespace offline_pages
+

Powered by Google App Engine
This is Rietveld 408576698