| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/offline_page_bridge.h" | 5 #include "chrome/browser/android/offline_pages/offline_page_bridge.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 const JavaParamRef<jstring>& j_url, | 624 const JavaParamRef<jstring>& j_url, |
| 625 int ui_action) { | 625 int ui_action) { |
| 626 content::WebContents* web_contents = | 626 content::WebContents* web_contents = |
| 627 content::WebContents::FromJavaWebContents(j_web_contents); | 627 content::WebContents::FromJavaWebContents(j_web_contents); |
| 628 OfflinePageUtils::ScheduleDownload( | 628 OfflinePageUtils::ScheduleDownload( |
| 629 web_contents, ConvertJavaStringToUTF8(env, j_namespace), | 629 web_contents, ConvertJavaStringToUTF8(env, j_namespace), |
| 630 GURL(ConvertJavaStringToUTF8(env, j_url)), | 630 GURL(ConvertJavaStringToUTF8(env, j_url)), |
| 631 static_cast<OfflinePageUtils::DownloadUIActionFlags>(ui_action)); | 631 static_cast<OfflinePageUtils::DownloadUIActionFlags>(ui_action)); |
| 632 } | 632 } |
| 633 | 633 |
| 634 jboolean OfflinePageBridge::IsOfflinePage( |
| 635 JNIEnv* env, |
| 636 const JavaParamRef<jobject>& obj, |
| 637 const base::android::JavaParamRef<jobject>& j_web_contents) { |
| 638 content::WebContents* web_contents = |
| 639 content::WebContents::FromJavaWebContents(j_web_contents); |
| 640 return offline_pages::OfflinePageUtils::GetOfflinePageFromWebContents( |
| 641 web_contents) != nullptr; |
| 642 } |
| 643 |
| 644 ScopedJavaLocalRef<jobject> OfflinePageBridge::GetOfflinePage( |
| 645 JNIEnv* env, |
| 646 const JavaParamRef<jobject>& obj, |
| 647 const base::android::JavaParamRef<jobject>& j_web_contents) { |
| 648 const offline_pages::OfflinePageItem* offline_page = |
| 649 offline_pages::OfflinePageUtils::GetOfflinePageFromWebContents( |
| 650 content::WebContents::FromJavaWebContents(j_web_contents)); |
| 651 if (!offline_page) |
| 652 return ScopedJavaLocalRef<jobject>(); |
| 653 |
| 654 return offline_pages::android::OfflinePageBridge::ConvertToJavaOfflinePage( |
| 655 env, *offline_page); |
| 656 } |
| 657 |
| 634 void OfflinePageBridge::NotifyIfDoneLoading() const { | 658 void OfflinePageBridge::NotifyIfDoneLoading() const { |
| 635 if (!offline_page_model_->is_loaded()) | 659 if (!offline_page_model_->is_loaded()) |
| 636 return; | 660 return; |
| 637 JNIEnv* env = base::android::AttachCurrentThread(); | 661 JNIEnv* env = base::android::AttachCurrentThread(); |
| 638 Java_OfflinePageBridge_offlinePageModelLoaded(env, java_ref_); | 662 Java_OfflinePageBridge_offlinePageModelLoaded(env, java_ref_); |
| 639 } | 663 } |
| 640 | 664 |
| 641 | 665 |
| 642 ScopedJavaLocalRef<jobject> OfflinePageBridge::CreateClientId( | 666 ScopedJavaLocalRef<jobject> OfflinePageBridge::CreateClientId( |
| 643 JNIEnv* env, | 667 JNIEnv* env, |
| 644 const ClientId& client_id) const { | 668 const ClientId& client_id) const { |
| 645 return Java_OfflinePageBridge_createClientId( | 669 return Java_OfflinePageBridge_createClientId( |
| 646 env, ConvertUTF8ToJavaString(env, client_id.name_space), | 670 env, ConvertUTF8ToJavaString(env, client_id.name_space), |
| 647 ConvertUTF8ToJavaString(env, client_id.id)); | 671 ConvertUTF8ToJavaString(env, client_id.id)); |
| 648 } | 672 } |
| 649 | 673 |
| 650 bool RegisterOfflinePageBridge(JNIEnv* env) { | 674 bool RegisterOfflinePageBridge(JNIEnv* env) { |
| 651 return RegisterNativesImpl(env); | 675 return RegisterNativesImpl(env); |
| 652 } | 676 } |
| 653 | 677 |
| 654 } // namespace android | 678 } // namespace android |
| 655 } // namespace offline_pages | 679 } // namespace offline_pages |
| OLD | NEW |