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

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: rebase Created 4 years, 6 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/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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 }; 584 };
574 585
575 class LocalStorageInfoReadyCallback { 586 class LocalStorageInfoReadyCallback {
576 public: 587 public:
577 explicit LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback) 588 explicit LocalStorageInfoReadyCallback(const JavaRef<jobject>& java_callback)
578 : env_(base::android::AttachCurrentThread()), 589 : env_(base::android::AttachCurrentThread()),
579 java_callback_(java_callback) { 590 java_callback_(java_callback) {
580 } 591 }
581 592
582 void OnLocalStorageModelInfoLoaded( 593 void OnLocalStorageModelInfoLoaded(
594 Profile* profile,
583 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>& 595 const std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>&
584 local_storage_info) { 596 local_storage_info) {
585 ScopedJavaLocalRef<jobject> map = 597 ScopedJavaLocalRef<jobject> map =
586 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_); 598 Java_WebsitePreferenceBridge_createLocalStorageInfoMap(env_);
587 599
600 std::vector<std::string> important_domains =
601 ImportantSitesUtil::GetImportantRegisterableDomains(
602 profile, kMaxImportantSites, nullptr);
603
588 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator 604 std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>::const_iterator
589 i; 605 i;
590 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) { 606 for (i = local_storage_info.begin(); i != local_storage_info.end(); ++i) {
591 ScopedJavaLocalRef<jstring> full_origin = 607 ScopedJavaLocalRef<jstring> full_origin =
592 ConvertUTF8ToJavaString(env_, i->origin_url.spec()); 608 ConvertUTF8ToJavaString(env_, i->origin_url.spec());
609 std::string origin_str = i->origin_url.GetOrigin().spec();
610 bool important = false;
611 std::string registerable_domain;
612 if (i->origin_url.HostIsIPAddress()) {
613 registerable_domain = i->origin_url.host();
614 } else {
615 registerable_domain =
616 net::registry_controlled_domains::GetDomainAndRegistry(
617 i->origin_url,
618 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
619 }
620 if (std::find(important_domains.begin(), important_domains.end(),
621 registerable_domain) != important_domains.end()) {
622 important = true;
623 }
593 // Remove the trailing backslash so the origin is matched correctly in 624 // Remove the trailing backslash so the origin is matched correctly in
594 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin. 625 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin.
595 std::string origin_str = i->origin_url.GetOrigin().spec();
596 DCHECK(origin_str[origin_str.size() - 1] == '/'); 626 DCHECK(origin_str[origin_str.size() - 1] == '/');
597 origin_str = origin_str.substr(0, origin_str.size() - 1); 627 origin_str = origin_str.substr(0, origin_str.size() - 1);
598 ScopedJavaLocalRef<jstring> origin = 628 ScopedJavaLocalRef<jstring> origin =
599 ConvertUTF8ToJavaString(env_, origin_str); 629 ConvertUTF8ToJavaString(env_, origin_str);
600 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap( 630 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap(
601 env_, map.obj(), origin.obj(), full_origin.obj(), i->size); 631 env_, map.obj(), origin.obj(), full_origin.obj(), i->size, important);
602 } 632 }
603 633
604 base::android::RunCallbackAndroid(java_callback_, map); 634 base::android::RunCallbackAndroid(java_callback_, map);
605 delete this; 635 delete this;
606 } 636 }
607 637
608 private: 638 private:
609 JNIEnv* env_; 639 JNIEnv* env_;
610 ScopedJavaGlobalRef<jobject> java_callback_; 640 ScopedJavaGlobalRef<jobject> java_callback_;
611 }; 641 };
(...skipping 14 matching lines...) Expand all
626 const JavaParamRef<jclass>& clazz, 656 const JavaParamRef<jclass>& clazz,
627 const JavaParamRef<jobject>& java_callback) { 657 const JavaParamRef<jobject>& java_callback) {
628 Profile* profile = ProfileManager::GetActiveUserProfile(); 658 Profile* profile = ProfileManager::GetActiveUserProfile();
629 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( 659 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper(
630 new BrowsingDataLocalStorageHelper(profile)); 660 new BrowsingDataLocalStorageHelper(profile));
631 // local_storage_callback will delete itself when it is run. 661 // local_storage_callback will delete itself when it is run.
632 LocalStorageInfoReadyCallback* local_storage_callback = 662 LocalStorageInfoReadyCallback* local_storage_callback =
633 new LocalStorageInfoReadyCallback(java_callback); 663 new LocalStorageInfoReadyCallback(java_callback);
634 local_storage_helper->StartFetching( 664 local_storage_helper->StartFetching(
635 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded, 665 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded,
636 base::Unretained(local_storage_callback))); 666 base::Unretained(local_storage_callback), profile));
637 } 667 }
638 668
639 static void FetchStorageInfo(JNIEnv* env, 669 static void FetchStorageInfo(JNIEnv* env,
640 const JavaParamRef<jclass>& clazz, 670 const JavaParamRef<jclass>& clazz,
641 const JavaParamRef<jobject>& java_callback) { 671 const JavaParamRef<jobject>& java_callback) {
642 Profile* profile = ProfileManager::GetActiveUserProfile(); 672 Profile* profile = ProfileManager::GetActiveUserProfile();
643 673
644 // storage_info_ready_callback will delete itself when it is run. 674 // storage_info_ready_callback will delete itself when it is run.
645 StorageInfoReadyCallback* storage_info_ready_callback = 675 StorageInfoReadyCallback* storage_info_ready_callback =
646 new StorageInfoReadyCallback(java_callback); 676 new StorageInfoReadyCallback(java_callback);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 GURL url(ConvertJavaStringToUTF8(env, jorigin)); 718 GURL url(ConvertJavaStringToUTF8(env, jorigin));
689 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( 719 scoped_refptr<SiteDataDeleteHelper> site_data_deleter(
690 new SiteDataDeleteHelper(profile, url)); 720 new SiteDataDeleteHelper(profile, url));
691 site_data_deleter->Run(); 721 site_data_deleter->Run();
692 } 722 }
693 723
694 // Register native methods 724 // Register native methods
695 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { 725 bool RegisterWebsitePreferenceBridge(JNIEnv* env) {
696 return RegisterNativesImpl(env); 726 return RegisterNativesImpl(env);
697 } 727 }
OLDNEW
« no previous file with comments | « chrome/browser/android/preferences/pref_service_bridge.cc ('k') | chrome/test/data/android/storage_persistance.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698