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

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

Issue 2841823004: Use DownloadManager to download non-html res when download icon pressed (Closed)
Patch Set: Add comment Created 3 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/downloads/resource_throttle.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/offline_pages/downloads/offline_page_download_bridge.cc
diff --git a/chrome/browser/android/offline_pages/downloads/offline_page_download_bridge.cc b/chrome/browser/android/offline_pages/downloads/offline_page_download_bridge.cc
index 928418495a72cce89553fd27e0f3a02693f18b20..4758d2f9a29e93122f5b673af60d845bb5e0a0e8 100644
--- a/chrome/browser/android/offline_pages/downloads/offline_page_download_bridge.cc
+++ b/chrome/browser/android/offline_pages/downloads/offline_page_download_bridge.cc
@@ -28,6 +28,9 @@
#include "components/offline_pages/core/offline_page_feature.h"
#include "components/offline_pages/core/offline_page_model.h"
#include "content/public/browser/browser_context.h"
+#include "content/public/browser/download_manager.h"
+#include "content/public/browser/download_url_parameters.h"
+#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
#include "jni/OfflinePageDownloadBridge_jni.h"
#include "net/base/filename_util.h"
@@ -337,10 +340,37 @@ void OfflinePageDownloadBridge::StartDownload(
return;
GURL url = web_contents->GetLastCommittedURL();
+ if (url.is_empty())
+ return;
+
GURL original_url =
offline_pages::OfflinePageUtils::GetOriginalURLFromWebContents(
web_contents);
+ // If the page is not a HTML page, route to DownloadManager.
+ if (!offline_pages::OfflinePageUtils::CanDownloadAsOfflinePage(
+ url, web_contents->GetContentsMimeType())) {
+ content::DownloadManager* dlm = content::BrowserContext::GetDownloadManager(
+ web_contents->GetBrowserContext());
+ std::unique_ptr<content::DownloadUrlParameters> dl_params(
+ content::DownloadUrlParameters::CreateForWebContentsMainFrame(
+ web_contents, url));
+
+ content::NavigationEntry* entry =
+ web_contents->GetController().GetLastCommittedEntry();
+ // |entry| should not be null since otherwise an empty URL is returned from
+ // calling GetLastCommittedURL and we should bail out earlier.
+ DCHECK(entry);
+ content::Referrer referrer =
+ content::Referrer::SanitizeForRequest(url, entry->GetReferrer());
+ dl_params->set_referrer(referrer);
+
+ dl_params->set_prefer_cache(true);
+ dl_params->set_prompt(false);
+ dlm->DownloadUrl(std::move(dl_params));
+ return;
+ }
+
ScopedJavaGlobalRef<jobject> j_tab_ref(env, j_tab);
OfflinePageUtils::CheckDuplicateDownloads(
« no previous file with comments | « no previous file | chrome/browser/android/offline_pages/downloads/resource_throttle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698