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/preferences/website_preference_bridge.h" | 5 #include "chrome/browser/android/preferences/website_preference_bridge.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 delete this; | 638 delete this; |
639 } | 639 } |
640 | 640 |
641 private: | 641 private: |
642 JNIEnv* env_; | 642 JNIEnv* env_; |
643 ScopedJavaGlobalRef<jobject> java_callback_; | 643 ScopedJavaGlobalRef<jobject> java_callback_; |
644 }; | 644 }; |
645 | 645 |
646 class LocalStorageInfoReadyCallback { | 646 class LocalStorageInfoReadyCallback { |
647 public: | 647 public: |
648 explicit LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback) | 648 LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback, |
649 bool fetch_important) | |
649 : env_(base::android::AttachCurrentThread()), | 650 : env_(base::android::AttachCurrentThread()), |
650 java_callback_(java_callback) { | 651 java_callback_(java_callback), |
651 } | 652 fetch_important_(fetch_important) {} |
652 | 653 |
653 void OnLocalStorageModelInfoLoaded( | 654 void OnLocalStorageModelInfoLoaded( |
654 Profile* profile, | 655 Profile* profile, |
655 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>& | 656 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>& |
656 local_storage_info) { | 657 local_storage_info) { |
657 ScopedJavaLocalRef<jobject> map = | 658 ScopedJavaLocalRef<jobject> map = |
658 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_); | 659 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_); |
659 | 660 |
660 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_domains = | 661 std::vector<ImportantSitesUtil::ImportantDomainInfo> important_domains; |
661 ImportantSitesUtil::GetImportantRegisterableDomains(profile, | 662 if (fetch_important_) { |
662 kMaxImportantSites); | 663 important_domains = ImportantSitesUtil::GetImportantRegisterableDomains( |
664 profile, kMaxImportantSites); | |
665 } | |
663 | 666 |
664 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator | 667 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator |
665 i; | 668 i; |
666 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) { | 669 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) { |
667 ScopedJavaLocalRef<jstring> full_origin = | 670 ScopedJavaLocalRef<jstring> full_origin = |
668 ConvertUTF8ToJavaString(env_, i->origin_url.spec()); | 671 ConvertUTF8ToJavaString(env_, i->origin_url.spec()); |
669 std::string origin_str = i->origin_url.GetOrigin().spec(); | 672 std::string origin_str = i->origin_url.GetOrigin().spec(); |
673 | |
670 bool important = false; | 674 bool important = false; |
671 std::string registerable_domain; | 675 if (fetch_important_) { |
672 if (i->origin_url.HostIsIPAddress()) { | 676 std::string registerable_domain; |
673 registerable_domain = i->origin_url.host(); | 677 if (i->origin_url.HostIsIPAddress()) { |
674 } else { | 678 registerable_domain = i->origin_url.host(); |
675 registerable_domain = | 679 } else { |
676 net::registry_controlled_domains::GetDomainAndRegistry( | 680 registerable_domain = |
677 i->origin_url, | 681 net::registry_controlled_domains::GetDomainAndRegistry( |
678 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); | 682 i->origin_url, |
679 } | 683 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
680 auto important_domain_search = [®isterable_domain]( | 684 } |
681 const ImportantSitesUtil::ImportantDomainInfo& item) { | 685 auto important_domain_search = |
682 return item.registerable_domain == registerable_domain; | 686 [®isterable_domain]( |
683 }; | 687 const ImportantSitesUtil::ImportantDomainInfo& item) { |
684 if (std::find_if(important_domains.begin(), important_domains.end(), | 688 return item.registerable_domain == registerable_domain; |
685 important_domain_search) != important_domains.end()) { | 689 }; |
686 important = true; | 690 if (std::find_if(important_domains.begin(), important_domains.end(), |
691 important_domain_search) != important_domains.end()) { | |
692 important = true; | |
693 } | |
687 } | 694 } |
688 // Remove the trailing slash so the origin is matched correctly in | 695 // Remove the trailing slash so the origin is matched correctly in |
689 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin. | 696 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin. |
690 DCHECK_EQ('/', origin_str.back()); | 697 DCHECK_EQ('/', origin_str.back()); |
691 origin_str.pop_back(); | 698 origin_str.pop_back(); |
692 ScopedJavaLocalRef<jstring> origin = | 699 ScopedJavaLocalRef<jstring> origin = |
693 ConvertUTF8ToJavaString(env_, origin_str); | 700 ConvertUTF8ToJavaString(env_, origin_str); |
694 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap( | 701 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap( |
695 env_, map, origin, full_origin, i->size, important); | 702 env_, map, origin, full_origin, i->size, important); |
696 } | 703 } |
697 | 704 |
698 base::android::RunCallbackAndroid(java_callback_, map); | 705 base::android::RunCallbackAndroid(java_callback_, map); |
699 delete this; | 706 delete this; |
700 } | 707 } |
701 | 708 |
702 private: | 709 private: |
703 JNIEnv* env_; | 710 JNIEnv* env_; |
704 ScopedJavaGlobalRef<jobject> java_callback_; | 711 ScopedJavaGlobalRef<jobject> java_callback_; |
712 bool fetch_important_; | |
705 }; | 713 }; |
706 | 714 |
707 } // anonymous namespace | 715 } // anonymous namespace |
708 | 716 |
709 // TODO(jknotten): These methods should not be static. Instead we should | 717 // TODO(jknotten): These methods should not be static. Instead we should |
710 // expose a class to Java so that the fetch requests can be cancelled, | 718 // expose a class to Java so that the fetch requests can be cancelled, |
711 // and manage the lifetimes of the callback (and indirectly the helper | 719 // and manage the lifetimes of the callback (and indirectly the helper |
712 // by having a reference to it). | 720 // by having a reference to it). |
713 | 721 |
714 // The helper methods (StartFetching, DeleteLocalStorageFile, DeleteDatabase) | 722 // The helper methods (StartFetching, DeleteLocalStorageFile, DeleteDatabase) |
715 // are asynchronous. A "use after free" error is not possible because the | 723 // are asynchronous. A "use after free" error is not possible because the |
716 // helpers keep a reference to themselves for the duration of their tasks, | 724 // helpers keep a reference to themselves for the duration of their tasks, |
717 // which includes callback invocation. | 725 // which includes callback invocation. |
718 | 726 |
719 static void FetchLocalStorageInfo(JNIEnv* env, | 727 static void FetchLocalStorageInfo(JNIEnv* env, |
720 const JavaParamRef<jclass>& clazz, | 728 const JavaParamRef<jclass>& clazz, |
721 const JavaParamRef<jobject>& java_callback) { | 729 const JavaParamRef<jobject>& java_callback, |
730 jboolean fetch_important) { | |
722 Profile* profile = ProfileManager::GetActiveUserProfile(); | 731 Profile* profile = ProfileManager::GetActiveUserProfile(); |
723 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( | 732 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( |
724 new BrowsingDataLocalStorageHelper(profile)); | 733 new BrowsingDataLocalStorageHelper(profile)); |
725 // local_storage_callback will delete itself when it is run. | 734 // local_storage_callback will delete itself when it is run. |
726 LocalStorageInfoReadyCallback* local_storage_callback = | 735 LocalStorageInfoReadyCallback* local_storage_callback = |
727 new LocalStorageInfoReadyCallback(java_callback); | 736 new LocalStorageInfoReadyCallback(java_callback, |
737 fetch_important == JNI_TRUE); | |
Ted C
2017/06/22 20:06:49
do you need the == JNI_TRUE here? In general, I'v
dmurph
2017/06/23 00:22:48
No - I can remove it.
| |
728 local_storage_helper->StartFetching( | 738 local_storage_helper->StartFetching( |
729 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded, | 739 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded, |
730 base::Unretained(local_storage_callback), profile)); | 740 base::Unretained(local_storage_callback), profile)); |
731 } | 741 } |
732 | 742 |
733 static void FetchStorageInfo(JNIEnv* env, | 743 static void FetchStorageInfo(JNIEnv* env, |
734 const JavaParamRef<jclass>& clazz, | 744 const JavaParamRef<jclass>& clazz, |
735 const JavaParamRef<jobject>& java_callback) { | 745 const JavaParamRef<jobject>& java_callback) { |
736 Profile* profile = ProfileManager::GetActiveUserProfile(); | 746 Profile* profile = ProfileManager::GetActiveUserProfile(); |
737 | 747 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
828 const JavaParamRef<jstring>& jorigin) { | 838 const JavaParamRef<jstring>& jorigin) { |
829 GURL url(ConvertJavaStringToUTF8(env, jorigin)); | 839 GURL url(ConvertJavaStringToUTF8(env, jorigin)); |
830 return !!GetHostContentSettingsMap(false)->GetWebsiteSetting( | 840 return !!GetHostContentSettingsMap(false)->GetWebsiteSetting( |
831 url, GURL(), CONTENT_SETTINGS_TYPE_ADS_DATA, std::string(), nullptr); | 841 url, GURL(), CONTENT_SETTINGS_TYPE_ADS_DATA, std::string(), nullptr); |
832 } | 842 } |
833 | 843 |
834 // Register native methods | 844 // Register native methods |
835 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { | 845 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { |
836 return RegisterNativesImpl(env); | 846 return RegisterNativesImpl(env); |
837 } | 847 } |
OLD | NEW |