OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/android/offline_pages/downloads/offline_page_download_b ridge.h" | 5 #include "chrome/browser/android/offline_pages/downloads/offline_page_download_b ridge.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "chrome/browser/android/tab_android.h" | 21 #include "chrome/browser/android/tab_android.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/profiles/profile_android.h" | 23 #include "chrome/browser/profiles/profile_android.h" |
24 #include "components/offline_pages/core/background/request_coordinator.h" | 24 #include "components/offline_pages/core/background/request_coordinator.h" |
25 #include "components/offline_pages/core/client_namespace_constants.h" | 25 #include "components/offline_pages/core/client_namespace_constants.h" |
26 #include "components/offline_pages/core/client_policy_controller.h" | 26 #include "components/offline_pages/core/client_policy_controller.h" |
27 #include "components/offline_pages/core/downloads/download_ui_item.h" | 27 #include "components/offline_pages/core/downloads/download_ui_item.h" |
28 #include "components/offline_pages/core/offline_page_feature.h" | 28 #include "components/offline_pages/core/offline_page_feature.h" |
29 #include "components/offline_pages/core/offline_page_model.h" | 29 #include "components/offline_pages/core/offline_page_model.h" |
30 #include "content/public/browser/browser_context.h" | 30 #include "content/public/browser/browser_context.h" |
31 #include "content/public/browser/download_manager.h" | |
32 #include "content/public/browser/download_url_parameters.h" | |
33 #include "content/public/browser/navigation_entry.h" | |
31 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
32 #include "jni/OfflinePageDownloadBridge_jni.h" | 35 #include "jni/OfflinePageDownloadBridge_jni.h" |
33 #include "net/base/filename_util.h" | 36 #include "net/base/filename_util.h" |
34 #include "url/gurl.h" | 37 #include "url/gurl.h" |
35 | 38 |
36 using base::android::AttachCurrentThread; | 39 using base::android::AttachCurrentThread; |
37 using base::android::ConvertJavaStringToUTF8; | 40 using base::android::ConvertJavaStringToUTF8; |
38 using base::android::ConvertUTF8ToJavaString; | 41 using base::android::ConvertUTF8ToJavaString; |
39 using base::android::ConvertUTF16ToJavaString; | 42 using base::android::ConvertUTF16ToJavaString; |
40 using base::android::JavaParamRef; | 43 using base::android::JavaParamRef; |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 const JavaParamRef<jobject>& j_tab) { | 333 const JavaParamRef<jobject>& j_tab) { |
331 TabAndroid* tab = TabAndroid::GetNativeTab(env, j_tab); | 334 TabAndroid* tab = TabAndroid::GetNativeTab(env, j_tab); |
332 if (!tab) | 335 if (!tab) |
333 return; | 336 return; |
334 | 337 |
335 content::WebContents* web_contents = tab->web_contents(); | 338 content::WebContents* web_contents = tab->web_contents(); |
336 if (!web_contents) | 339 if (!web_contents) |
337 return; | 340 return; |
338 | 341 |
339 GURL url = web_contents->GetLastCommittedURL(); | 342 GURL url = web_contents->GetLastCommittedURL(); |
343 if (url.is_empty()) | |
344 return; | |
345 | |
340 GURL original_url = | 346 GURL original_url = |
341 offline_pages::OfflinePageUtils::GetOriginalURLFromWebContents( | 347 offline_pages::OfflinePageUtils::GetOriginalURLFromWebContents( |
342 web_contents); | 348 web_contents); |
343 | 349 |
350 // If the page is not a HTML page, route to DownloadManager. | |
351 if (!offline_pages::OfflinePageUtils::CanDownloadAsOfflinePage( | |
352 web_contents->GetContentsMimeType())) { | |
353 content::DownloadManager* dlm = content::BrowserContext::GetDownloadManager( | |
354 web_contents->GetBrowserContext()); | |
355 std::unique_ptr<content::DownloadUrlParameters> dl_params( | |
356 content::DownloadUrlParameters::CreateForWebContentsMainFrame( | |
357 web_contents, url)); | |
358 | |
359 content::NavigationEntry* entry = | |
360 web_contents->GetController().GetLastCommittedEntry(); | |
361 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
| |
362 content::Referrer referrer = | |
363 content::Referrer::SanitizeForRequest(url, entry->GetReferrer()); | |
364 dl_params->set_referrer(referrer); | |
365 | |
366 dl_params->set_prefer_cache(true); | |
367 dl_params->set_prompt(false); | |
368 dlm->DownloadUrl(std::move(dl_params)); | |
369 return; | |
370 } | |
371 | |
344 ScopedJavaGlobalRef<jobject> j_tab_ref(env, j_tab); | 372 ScopedJavaGlobalRef<jobject> j_tab_ref(env, j_tab); |
345 | 373 |
346 OfflinePageUtils::CheckDuplicateDownloads( | 374 OfflinePageUtils::CheckDuplicateDownloads( |
347 tab->GetProfile()->GetOriginalProfile(), url, | 375 tab->GetProfile()->GetOriginalProfile(), url, |
348 base::Bind(&DuplicateCheckDone, url, original_url, j_tab_ref)); | 376 base::Bind(&DuplicateCheckDone, url, original_url, j_tab_ref)); |
349 } | 377 } |
350 | 378 |
351 void OfflinePageDownloadBridge::CancelDownload( | 379 void OfflinePageDownloadBridge::CancelDownload( |
352 JNIEnv* env, | 380 JNIEnv* env, |
353 const JavaParamRef<jobject>& obj, | 381 const JavaParamRef<jobject>& obj, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
464 base::MakeUnique<DownloadUIAdapterDelegate>(offline_page_model)); | 492 base::MakeUnique<DownloadUIAdapterDelegate>(offline_page_model)); |
465 DownloadUIAdapter::AttachToOfflinePageModel(adapter, offline_page_model); | 493 DownloadUIAdapter::AttachToOfflinePageModel(adapter, offline_page_model); |
466 } | 494 } |
467 | 495 |
468 return reinterpret_cast<jlong>( | 496 return reinterpret_cast<jlong>( |
469 new OfflinePageDownloadBridge(env, obj, adapter, browser_context)); | 497 new OfflinePageDownloadBridge(env, obj, adapter, browser_context)); |
470 } | 498 } |
471 | 499 |
472 } // namespace android | 500 } // namespace android |
473 } // namespace offline_pages | 501 } // namespace offline_pages |
OLD | NEW |