Chromium Code Reviews| Index: chrome/browser/ui/webui/options/website_settings_handler.cc |
| diff --git a/chrome/browser/ui/webui/options/website_settings_handler.cc b/chrome/browser/ui/webui/options/website_settings_handler.cc |
| index a1b267de2230679d0f74ec09428c0d7b6aec063a..1351323626d0495aa2003c3a1c83ebd812a857be 100644 |
| --- a/chrome/browser/ui/webui/options/website_settings_handler.cc |
| +++ b/chrome/browser/ui/webui/options/website_settings_handler.cc |
| @@ -9,16 +9,20 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "content/public/browser/web_ui.h" |
| #include "grit/generated_resources.h" |
| +#include "ui/base/text/bytes_formatting.h" |
| namespace { |
| const char kPreferencesSource[] = "preference"; |
| - |
| +const char kStorage[] = "storage"; |
| +const ContentSettingsType kValidTypes[] = {CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + CONTENT_SETTINGS_TYPE_MEDIASTREAM}; |
| } // namespace |
| namespace options { |
| -WebsiteSettingsHandler::WebsiteSettingsHandler() { |
| +WebsiteSettingsHandler::WebsiteSettingsHandler() : weak_ptr_factory_(this) { |
| } |
| WebsiteSettingsHandler::~WebsiteSettingsHandler() { |
| @@ -35,6 +39,7 @@ void WebsiteSettingsHandler::GetLocalizedValues( |
| {"websitesLabelGeolocation", IDS_WEBSITE_SETTINGS_TYPE_LOCATION}, |
| {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, |
| {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, |
| + {"websitesLabelStorage", IDS_WEBSITE_SETTINGS_TYPE_STORAGE}, |
| }; |
| RegisterStrings(localized_strings, resources, arraysize(resources)); |
| @@ -52,27 +57,58 @@ void WebsiteSettingsHandler::RegisterMessages() { |
| "updateOriginsSearchResults", |
| base::Bind(&WebsiteSettingsHandler::HandleUpdateSearchResults, |
| base::Unretained(this))); |
| + |
| + web_ui()->RegisterMessageCallback( |
| + "updateLocalStorage", |
| + base::Bind(&WebsiteSettingsHandler::HandleUpdateLocalStorage, |
| + base::Unretained(this))); |
| } |
| void WebsiteSettingsHandler::HandleUpdateOrigins(const base::ListValue* args) { |
| std::string content_setting_name; |
| bool rv = args->GetString(0, &content_setting_name); |
| DCHECK(rv); |
| - ContentSettingsType content_type; |
| - content_settings::GetTypeFromName(content_setting_name, &content_type); |
| - last_setting_ = content_type; |
| + ContentSettingsType content_type; |
| + rv = content_settings::GetTypeFromName(content_setting_name, &content_type); |
| + DCHECK(rv); |
| + DCHECK_NE( |
| + std::end(kValidTypes), |
|
Bernhard Bauer
2014/07/22 08:51:48
Can you run some tryjobs for this, in particular o
|
| + std::find(std::begin(kValidTypes), std::end(kValidTypes), content_type)); |
|
Daniel Nishi
2014/07/22 22:30:56
I've removed the end iterator after running the tr
|
| - UpdateOrigins(std::string()); |
| + last_setting_ = content_setting_name; |
| + UpdateOrigins(last_filter_); |
| } |
| void WebsiteSettingsHandler::HandleUpdateSearchResults( |
| const base::ListValue* args) { |
| - std::string filter; |
| - bool rv = args->GetString(0, &filter); |
| + bool rv = args->GetString(0, &last_filter_); |
| DCHECK(rv); |
| - UpdateOrigins(filter); |
| + if (last_setting_ == kStorage) |
| + UpdateLocalStorage(last_filter_); |
| + else |
| + UpdateOrigins(last_filter_); |
| +} |
| + |
| +void WebsiteSettingsHandler::HandleUpdateLocalStorage( |
| + const base::ListValue* args) { |
| + if (!local_storage_) { |
| + Profile* profile = Profile::FromWebUI(web_ui()); |
| + local_storage_ = new BrowsingDataLocalStorageHelper(profile); |
| + } |
| + |
| + last_setting_ = kStorage; |
| + |
| + local_storage_->StartFetching( |
| + base::Bind(&WebsiteSettingsHandler::OnLocalStorageFetched, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void WebsiteSettingsHandler::OnLocalStorageFetched(const std::list< |
| + BrowsingDataLocalStorageHelper::LocalStorageInfo>& storage) { |
| + local_storage_list_ = storage; |
| + UpdateLocalStorage(last_filter_); |
| } |
| void WebsiteSettingsHandler::UpdateOrigins(const std::string& filter) { |
| @@ -80,7 +116,9 @@ void WebsiteSettingsHandler::UpdateOrigins(const std::string& filter) { |
| HostContentSettingsMap* settings = profile->GetHostContentSettingsMap(); |
| ContentSettingsForOneType all_settings; |
| - settings->GetSettingsForOneType(last_setting_, std::string(), &all_settings); |
| + ContentSettingsType last_setting; |
| + content_settings::GetTypeFromName(last_setting_, &last_setting); |
| + settings->GetSettingsForOneType(last_setting, std::string(), &all_settings); |
| base::DictionaryValue origins; |
| for (ContentSettingsForOneType::const_iterator it = all_settings.begin(); |
| @@ -106,4 +144,25 @@ void WebsiteSettingsHandler::UpdateOrigins(const std::string& filter) { |
| origins); |
| } |
| +void WebsiteSettingsHandler::UpdateLocalStorage(const std::string& filter) { |
|
Bernhard Bauer
2014/07/22 08:51:48
You don't need to pass the filter as an argument n
Daniel Nishi
2014/07/22 22:30:56
Done.
|
| + base::DictionaryValue local_storage_map; |
| + for (LocalStorageList::const_iterator it = local_storage_list_.begin(); |
| + it != local_storage_list_.end(); |
| + it++) { |
| + std::string origin = it->origin_url.spec(); |
| + |
| + if (origin.find(filter) == base::string16::npos) |
| + continue; |
| + |
| + base::DictionaryValue* origin_entry = new base::DictionaryValue(); |
| + origin_entry->SetWithoutPathExpansion( |
| + "usage", new base::FundamentalValue(static_cast<double>(it->size))); |
| + origin_entry->SetWithoutPathExpansion( |
| + "usageString", new base::StringValue(ui::FormatBytes(it->size))); |
| + local_storage_map.SetWithoutPathExpansion(origin, origin_entry); |
| + } |
| + web_ui()->CallJavascriptFunction( |
| + "WebsiteSettingsManager.populateLocalStorage", local_storage_map); |
| +} |
| + |
| } // namespace options |