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> |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
7 #include "base/android/callback_android.h" | 11 #include "base/android/callback_android.h" |
8 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
9 #include "base/android/jni_string.h" | 13 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
11 #include "base/bind.h" | 15 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 16 #include "base/bind_helpers.h" |
13 #include "base/logging.h" | 17 #include "base/logging.h" |
14 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "chrome/browser/android/preferences/important_sites_util.h" |
15 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" | 20 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
16 #include "chrome/browser/browsing_data/browsing_data_quota_helper.h" | 21 #include "chrome/browser/browsing_data/browsing_data_quota_helper.h" |
17 #include "chrome/browser/browsing_data/cookies_tree_model.h" | 22 #include "chrome/browser/browsing_data/cookies_tree_model.h" |
18 #include "chrome/browser/browsing_data/local_data_container.h" | 23 #include "chrome/browser/browsing_data/local_data_container.h" |
19 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 24 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
20 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 25 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
21 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 26 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
22 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" | 27 #include "chrome/browser/content_settings/web_site_settings_uma_util.h" |
23 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 28 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
24 #include "chrome/browser/permissions/permission_util.h" | 29 #include "chrome/browser/permissions/permission_util.h" |
25 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/profiles/profile_manager.h" | 31 #include "chrome/browser/profiles/profile_manager.h" |
27 #include "chrome/browser/storage/storage_info_fetcher.h" | 32 #include "chrome/browser/storage/storage_info_fetcher.h" |
28 #include "components/content_settings/core/browser/cookie_settings.h" | 33 #include "components/content_settings/core/browser/cookie_settings.h" |
29 #include "components/content_settings/core/browser/host_content_settings_map.h" | 34 #include "components/content_settings/core/browser/host_content_settings_map.h" |
30 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/storage_partition.h" | 36 #include "content/public/browser/storage_partition.h" |
32 #include "jni/WebsitePreferenceBridge_jni.h" | 37 #include "jni/WebsitePreferenceBridge_jni.h" |
| 38 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
33 #include "storage/browser/quota/quota_manager.h" | 39 #include "storage/browser/quota/quota_manager.h" |
34 #include "storage/common/quota/quota_status_code.h" | 40 #include "storage/common/quota/quota_status_code.h" |
35 #include "url/url_constants.h" | 41 #include "url/url_constants.h" |
36 | 42 |
37 using base::android::ConvertJavaStringToUTF8; | 43 using base::android::ConvertJavaStringToUTF8; |
38 using base::android::ConvertUTF8ToJavaString; | 44 using base::android::ConvertUTF8ToJavaString; |
39 using base::android::JavaRef; | 45 using base::android::JavaRef; |
40 using base::android::ScopedJavaGlobalRef; | 46 using base::android::ScopedJavaGlobalRef; |
41 using base::android::ScopedJavaLocalRef; | 47 using base::android::ScopedJavaLocalRef; |
42 using content::BrowserThread; | 48 using content::BrowserThread; |
43 | 49 |
44 namespace { | 50 namespace { |
| 51 // We need to limit our size due to the algorithm in ImportantSiteUtil, but we |
| 52 // want to be more on the liberal side here as we're not exposing these sites |
| 53 // to the user, we're just using them for our 'clear unimportant' feature in |
| 54 // ManageSpaceActivity.java. |
| 55 const int kMaxImportantSites = 10; |
45 | 56 |
46 Profile* GetActiveUserProfile(bool is_incognito) { | 57 Profile* GetActiveUserProfile(bool is_incognito) { |
47 Profile* profile = ProfileManager::GetActiveUserProfile(); | 58 Profile* profile = ProfileManager::GetActiveUserProfile(); |
48 if (is_incognito) | 59 if (is_incognito) |
49 profile = profile->GetOffTheRecordProfile(); | 60 profile = profile->GetOffTheRecordProfile(); |
50 return profile; | 61 return profile; |
51 } | 62 } |
52 | 63 |
53 HostContentSettingsMap* GetHostContentSettingsMap(bool is_incognito) { | 64 HostContentSettingsMap* GetHostContentSettingsMap(bool is_incognito) { |
54 return HostContentSettingsMapFactory::GetForProfile( | 65 return HostContentSettingsMapFactory::GetForProfile( |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 }; | 587 }; |
577 | 588 |
578 class LocalStorageInfoReadyCallback { | 589 class LocalStorageInfoReadyCallback { |
579 public: | 590 public: |
580 explicit LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback) | 591 explicit LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback) |
581 : env_(base::android::AttachCurrentThread()), | 592 : env_(base::android::AttachCurrentThread()), |
582 java_callback_(java_callback) { | 593 java_callback_(java_callback) { |
583 } | 594 } |
584 | 595 |
585 void OnLocalStorageModelInfoLoaded( | 596 void OnLocalStorageModelInfoLoaded( |
| 597 Profile* profile, |
586 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>& | 598 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>& |
587 local_storage_info) { | 599 local_storage_info) { |
588 ScopedJavaLocalRef<jobject> map = | 600 ScopedJavaLocalRef<jobject> map = |
589 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_); | 601 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_); |
590 | 602 |
| 603 std::vector<std::string> important_domains = |
| 604 ImportantSitesUtil::GetImportantRegisterableDomains( |
| 605 profile, kMaxImportantSites, nullptr); |
| 606 |
591 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator | 607 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator |
592 i; | 608 i; |
593 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) { | 609 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) { |
594 ScopedJavaLocalRef<jstring> full_origin = | 610 ScopedJavaLocalRef<jstring> full_origin = |
595 ConvertUTF8ToJavaString(env_, i->origin_url.spec()); | 611 ConvertUTF8ToJavaString(env_, i->origin_url.spec()); |
| 612 std::string origin_str = i->origin_url.GetOrigin().spec(); |
| 613 bool important = false; |
| 614 std::string registerable_domain; |
| 615 if (i->origin_url.HostIsIPAddress()) { |
| 616 registerable_domain = i->origin_url.host(); |
| 617 } else { |
| 618 registerable_domain = |
| 619 net::registry_controlled_domains::GetDomainAndRegistry( |
| 620 i->origin_url, |
| 621 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 622 } |
| 623 if (std::find(important_domains.begin(), important_domains.end(), |
| 624 registerable_domain) != important_domains.end()) { |
| 625 important = true; |
| 626 } |
596 // Remove the trailing backslash so the origin is matched correctly in | 627 // Remove the trailing backslash so the origin is matched correctly in |
597 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin. | 628 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin. |
598 std::string origin_str = i->origin_url.GetOrigin().spec(); | |
599 DCHECK(origin_str[origin_str.size() - 1] == '/'); | 629 DCHECK(origin_str[origin_str.size() - 1] == '/'); |
600 origin_str = origin_str.substr(0, origin_str.size() - 1); | 630 origin_str = origin_str.substr(0, origin_str.size() - 1); |
601 ScopedJavaLocalRef<jstring> origin = | 631 ScopedJavaLocalRef<jstring> origin = |
602 ConvertUTF8ToJavaString(env_, origin_str); | 632 ConvertUTF8ToJavaString(env_, origin_str); |
603 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap( | 633 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap( |
604 env_, map.obj(), origin.obj(), full_origin.obj(), i->size); | 634 env_, map.obj(), origin.obj(), full_origin.obj(), i->size, important); |
605 } | 635 } |
606 | 636 |
607 base::android::RunCallbackAndroid(java_callback_, map); | 637 base::android::RunCallbackAndroid(java_callback_, map); |
608 delete this; | 638 delete this; |
609 } | 639 } |
610 | 640 |
611 private: | 641 private: |
612 JNIEnv* env_; | 642 JNIEnv* env_; |
613 ScopedJavaGlobalRef<jobject> java_callback_; | 643 ScopedJavaGlobalRef<jobject> java_callback_; |
614 }; | 644 }; |
(...skipping 14 matching lines...) Expand all Loading... |
629 const JavaParamRef<jclass>& clazz, | 659 const JavaParamRef<jclass>& clazz, |
630 const JavaParamRef<jobject>& java_callback) { | 660 const JavaParamRef<jobject>& java_callback) { |
631 Profile* profile = ProfileManager::GetActiveUserProfile(); | 661 Profile* profile = ProfileManager::GetActiveUserProfile(); |
632 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( | 662 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( |
633 new BrowsingDataLocalStorageHelper(profile)); | 663 new BrowsingDataLocalStorageHelper(profile)); |
634 // local_storage_callback will delete itself when it is run. | 664 // local_storage_callback will delete itself when it is run. |
635 LocalStorageInfoReadyCallback* local_storage_callback = | 665 LocalStorageInfoReadyCallback* local_storage_callback = |
636 new LocalStorageInfoReadyCallback(java_callback); | 666 new LocalStorageInfoReadyCallback(java_callback); |
637 local_storage_helper->StartFetching( | 667 local_storage_helper->StartFetching( |
638 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded, | 668 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded, |
639 base::Unretained(local_storage_callback))); | 669 base::Unretained(local_storage_callback), profile)); |
640 } | 670 } |
641 | 671 |
642 static void FetchStorageInfo(JNIEnv* env, | 672 static void FetchStorageInfo(JNIEnv* env, |
643 const JavaParamRef<jclass>& clazz, | 673 const JavaParamRef<jclass>& clazz, |
644 const JavaParamRef<jobject>& java_callback) { | 674 const JavaParamRef<jobject>& java_callback) { |
645 Profile* profile = ProfileManager::GetActiveUserProfile(); | 675 Profile* profile = ProfileManager::GetActiveUserProfile(); |
646 | 676 |
647 // storage_info_ready_callback will delete itself when it is run. | 677 // storage_info_ready_callback will delete itself when it is run. |
648 StorageInfoReadyCallback* storage_info_ready_callback = | 678 StorageInfoReadyCallback* storage_info_ready_callback = |
649 new StorageInfoReadyCallback(java_callback); | 679 new StorageInfoReadyCallback(java_callback); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 GURL url(ConvertJavaStringToUTF8(env, jorigin)); | 721 GURL url(ConvertJavaStringToUTF8(env, jorigin)); |
692 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( | 722 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( |
693 new SiteDataDeleteHelper(profile, url)); | 723 new SiteDataDeleteHelper(profile, url)); |
694 site_data_deleter->Run(); | 724 site_data_deleter->Run(); |
695 } | 725 } |
696 | 726 |
697 // Register native methods | 727 // Register native methods |
698 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { | 728 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { |
699 return RegisterNativesImpl(env); | 729 return RegisterNativesImpl(env); |
700 } | 730 } |
OLD | NEW |