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