Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/browser/android/preferences/website_preference_bridge.cc

Issue 1465363002: [Storage] Android - ManageSpace UI, Important Origins, and CBD Dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Favicon support, and scroll indicators Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 in
53 // ManageSpaceActivity.java.
54 const int kMaxImportantSites = 10;
44 55
45 Profile* GetActiveUserProfile(bool is_incognito) { 56 Profile* GetActiveUserProfile(bool is_incognito) {
46 Profile* profile = ProfileManager::GetActiveUserProfile(); 57 Profile* profile = ProfileManager::GetActiveUserProfile();
47 if (is_incognito) 58 if (is_incognito)
48 profile = profile->GetOffTheRecordProfile(); 59 profile = profile->GetOffTheRecordProfile();
49 return profile; 60 return profile;
50 } 61 }
51 62
52 HostContentSettingsMap* GetHostContentSettingsMap(bool is_incognito) { 63 HostContentSettingsMap* GetHostContentSettingsMap(bool is_incognito) {
53 return HostContentSettingsMapFactory::GetForProfile( 64 return HostContentSettingsMapFactory::GetForProfile(
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 }; 588 };
578 589
579 class LocalStorageInfoReadyCallback { 590 class LocalStorageInfoReadyCallback {
580 public: 591 public:
581 explicit LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback) 592 explicit LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback)
582 : env_(base::android::AttachCurrentThread()), 593 : env_(base::android::AttachCurrentThread()),
583 java_callback_(java_callback) { 594 java_callback_(java_callback) {
584 } 595 }
585 596
586 void OnLocalStorageModelInfoLoaded( 597 void OnLocalStorageModelInfoLoaded(
598 Profile* profile,
587 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>& 599 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>&
588 local_storage_info) { 600 local_storage_info) {
589 ScopedJavaLocalRef<jobject> map = 601 ScopedJavaLocalRef<jobject> map =
590 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_); 602 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_);
591 603
604 std::vector<std::string> important_domains =
605 ImportantSitesUtil::GetImportantRegisterableDomains(
606 profile, kMaxImportantSites, nullptr);
607
592 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator 608 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator
593 i; 609 i;
594 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) { 610 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) {
595 ScopedJavaLocalRef<jstring> full_origin = 611 ScopedJavaLocalRef<jstring> full_origin =
596 ConvertUTF8ToJavaString(env_, i->origin_url.spec()); 612 ConvertUTF8ToJavaString(env_, i->origin_url.spec());
613 std::string origin_str = i->origin_url.GetOrigin().spec();
614 bool important = false;
615 std::string registerable_domain;
616 if (i->origin_url.HostIsIPAddress()) {
617 registerable_domain = i->origin_url.host();
618 } else {
619 registerable_domain =
620 net::registry_controlled_domains::GetDomainAndRegistry(
621 i->origin_url,
622 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
623 }
624 if (std::find(important_domains.begin(), important_domains.end(),
625 registerable_domain) != important_domains.end()) {
626 important = true;
627 }
597 // Remove the trailing backslash so the origin is matched correctly in 628 // Remove the trailing backslash so the origin is matched correctly in
598 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin. 629 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin.
599 std::string origin_str = i->origin_url.GetOrigin().spec();
600 DCHECK(origin_str[origin_str.size() - 1] == '/'); 630 DCHECK(origin_str[origin_str.size() - 1] == '/');
601 origin_str = origin_str.substr(0, origin_str.size() - 1); 631 origin_str = origin_str.substr(0, origin_str.size() - 1);
602 ScopedJavaLocalRef<jstring> origin = 632 ScopedJavaLocalRef<jstring> origin =
603 ConvertUTF8ToJavaString(env_, origin_str); 633 ConvertUTF8ToJavaString(env_, origin_str);
604 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap( 634 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap(
605 env_, map.obj(), origin.obj(), full_origin.obj(), i->size); 635 env_, map.obj(), origin.obj(), full_origin.obj(), i->size, important);
606 } 636 }
607 637
608 Java_LocalStorageInfoReadyCallback_onLocalStorageInfoReady( 638 Java_LocalStorageInfoReadyCallback_onLocalStorageInfoReady(
609 env_, java_callback_.obj(), map.obj()); 639 env_, java_callback_.obj(), map.obj());
610 delete this; 640 delete this;
611 } 641 }
612 642
613 private: 643 private:
614 JNIEnv* env_; 644 JNIEnv* env_;
615 ScopedJavaGlobalRef<jobject> java_callback_; 645 ScopedJavaGlobalRef<jobject> java_callback_;
(...skipping 15 matching lines...) Expand all
631 const JavaParamRef<jclass>& clazz, 661 const JavaParamRef<jclass>& clazz,
632 const JavaParamRef<jobject>& java_callback) { 662 const JavaParamRef<jobject>& java_callback) {
633 Profile* profile = ProfileManager::GetActiveUserProfile(); 663 Profile* profile = ProfileManager::GetActiveUserProfile();
634 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( 664 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper(
635 new BrowsingDataLocalStorageHelper(profile)); 665 new BrowsingDataLocalStorageHelper(profile));
636 // local_storage_callback will delete itself when it is run. 666 // local_storage_callback will delete itself when it is run.
637 LocalStorageInfoReadyCallback* local_storage_callback = 667 LocalStorageInfoReadyCallback* local_storage_callback =
638 new LocalStorageInfoReadyCallback(java_callback); 668 new LocalStorageInfoReadyCallback(java_callback);
639 local_storage_helper->StartFetching( 669 local_storage_helper->StartFetching(
640 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded, 670 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded,
641 base::Unretained(local_storage_callback))); 671 base::Unretained(local_storage_callback), profile));
642 } 672 }
643 673
644 static void FetchStorageInfo(JNIEnv* env, 674 static void FetchStorageInfo(JNIEnv* env,
645 const JavaParamRef<jclass>& clazz, 675 const JavaParamRef<jclass>& clazz,
646 const JavaParamRef<jobject>& java_callback) { 676 const JavaParamRef<jobject>& java_callback) {
647 Profile* profile = ProfileManager::GetActiveUserProfile(); 677 Profile* profile = ProfileManager::GetActiveUserProfile();
648 678
649 // storage_info_ready_callback will delete itself when it is run. 679 // storage_info_ready_callback will delete itself when it is run.
650 StorageInfoReadyCallback* storage_info_ready_callback = 680 StorageInfoReadyCallback* storage_info_ready_callback =
651 new StorageInfoReadyCallback(java_callback); 681 new StorageInfoReadyCallback(java_callback);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 GURL url(ConvertJavaStringToUTF8(env, jorigin)); 723 GURL url(ConvertJavaStringToUTF8(env, jorigin));
694 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( 724 scoped_refptr<SiteDataDeleteHelper> site_data_deleter(
695 new SiteDataDeleteHelper(profile, url)); 725 new SiteDataDeleteHelper(profile, url));
696 site_data_deleter->Run(); 726 site_data_deleter->Run();
697 } 727 }
698 728
699 // Register native methods 729 // Register native methods
700 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { 730 bool RegisterWebsitePreferenceBridge(JNIEnv* env) {
701 return RegisterNativesImpl(env); 731 return RegisterNativesImpl(env);
702 } 732 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698