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

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: whoops, forgot files 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.
Theresa 2016/05/13 06:02:31 s/feature/ feature in ManageSpaceActivity.java.
dmurph 2016/05/13 23:46:24 Done.
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
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 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 }
597 // Remove the trailing backslash so the origin is matched correctly in 627 // Remove the trailing backslash so the origin is matched correctly in
598 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin. 628 // SingleWebsitePreferences.mergePermissionInfoForTopLevelOrigin.
599 std::string origin_str = i->origin_url.GetOrigin().spec();
600 DCHECK(origin_str[origin_str.size() - 1] == '/'); 629 DCHECK(origin_str[origin_str.size() - 1] == '/');
601 origin_str = origin_str.substr(0, origin_str.size() - 1); 630 origin_str = origin_str.substr(0, origin_str.size() - 1);
602 ScopedJavaLocalRef<jstring> origin = 631 ScopedJavaLocalRef<jstring> origin =
603 ConvertUTF8ToJavaString(env_, origin_str); 632 ConvertUTF8ToJavaString(env_, origin_str);
604 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap( 633 Java_WebsitePreferenceBridge_insertLocalStorageInfoIntoMap(
605 env_, map.obj(), origin.obj(), full_origin.obj(), i->size); 634 env_, map.obj(), origin.obj(), full_origin.obj(), i->size, important);
606 } 635 }
607 636
608 Java_LocalStorageInfoReadyCallback_onLocalStorageInfoReady( 637 Java_LocalStorageInfoReadyCallback_onLocalStorageInfoReady(
609 env_, java_callback_.obj(), map.obj()); 638 env_, java_callback_.obj(), map.obj());
610 delete this; 639 delete this;
611 } 640 }
612 641
613 private: 642 private:
614 JNIEnv* env_; 643 JNIEnv* env_;
615 ScopedJavaGlobalRef<jobject> java_callback_; 644 ScopedJavaGlobalRef<jobject> java_callback_;
(...skipping 15 matching lines...) Expand all
631 const JavaParamRef<jclass>& clazz, 660 const JavaParamRef<jclass>& clazz,
632 const JavaParamRef<jobject>& java_callback) { 661 const JavaParamRef<jobject>& java_callback) {
633 Profile* profile = ProfileManager::GetActiveUserProfile(); 662 Profile* profile = ProfileManager::GetActiveUserProfile();
634 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper( 663 scoped_refptr<BrowsingDataLocalStorageHelper> local_storage_helper(
635 new BrowsingDataLocalStorageHelper(profile)); 664 new BrowsingDataLocalStorageHelper(profile));
636 // local_storage_callback will delete itself when it is run. 665 // local_storage_callback will delete itself when it is run.
637 LocalStorageInfoReadyCallback* local_storage_callback = 666 LocalStorageInfoReadyCallback* local_storage_callback =
638 new LocalStorageInfoReadyCallback(java_callback); 667 new LocalStorageInfoReadyCallback(java_callback);
639 local_storage_helper->StartFetching( 668 local_storage_helper->StartFetching(
640 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded, 669 base::Bind(&LocalStorageInfoReadyCallback::OnLocalStorageModelInfoLoaded,
641 base::Unretained(local_storage_callback))); 670 base::Unretained(local_storage_callback), profile));
642 } 671 }
643 672
644 static void FetchStorageInfo(JNIEnv* env, 673 static void FetchStorageInfo(JNIEnv* env,
645 const JavaParamRef<jclass>& clazz, 674 const JavaParamRef<jclass>& clazz,
646 const JavaParamRef<jobject>& java_callback) { 675 const JavaParamRef<jobject>& java_callback) {
647 Profile* profile = ProfileManager::GetActiveUserProfile(); 676 Profile* profile = ProfileManager::GetActiveUserProfile();
648 677
649 // storage_info_ready_callback will delete itself when it is run. 678 // storage_info_ready_callback will delete itself when it is run.
650 StorageInfoReadyCallback* storage_info_ready_callback = 679 StorageInfoReadyCallback* storage_info_ready_callback =
651 new StorageInfoReadyCallback(java_callback); 680 new StorageInfoReadyCallback(java_callback);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 GURL url(ConvertJavaStringToUTF8(env, jorigin)); 722 GURL url(ConvertJavaStringToUTF8(env, jorigin));
694 scoped_refptr<SiteDataDeleteHelper> site_data_deleter( 723 scoped_refptr<SiteDataDeleteHelper> site_data_deleter(
695 new SiteDataDeleteHelper(profile, url)); 724 new SiteDataDeleteHelper(profile, url));
696 site_data_deleter->Run(); 725 site_data_deleter->Run();
697 } 726 }
698 727
699 // Register native methods 728 // Register native methods
700 bool RegisterWebsitePreferenceBridge(JNIEnv* env) { 729 bool RegisterWebsitePreferenceBridge(JNIEnv* env) {
701 return RegisterNativesImpl(env); 730 return RegisterNativesImpl(env);
702 } 731 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698