Chromium Code Reviews| 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..2c7b730135b76744e7399cb7cf7f08e3de05cc44 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,35 @@ 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( |
| + 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(); |
| + DCHECK(entry); |
|
Dmitry Titov
2017/04/27 23:02:45
I'd just do if(!entry) return here...
Otherwise it
jianli
2017/04/28 00:21:59
GetLastCommittedURL should return an empty URL if
|
| + 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( |