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 8999398729c5b6544fce9b9304da7b763dc23797..5fe1f952c2e9ccc3c7a199f4abadd812a5dc15e1 100644 |
| --- a/chrome/browser/ui/webui/options/website_settings_handler.cc |
| +++ b/chrome/browser/ui/webui/options/website_settings_handler.cc |
| @@ -11,6 +11,8 @@ |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_iterator.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "components/power/origin_power_map.h" |
| +#include "components/power/origin_power_map_factory.h" |
| #include "content/public/browser/dom_storage_context.h" |
| #include "content/public/browser/storage_partition.h" |
| #include "content/public/browser/web_contents.h" |
| @@ -23,6 +25,9 @@ |
| #include "ui/base/l10n/time_format.h" |
| #include "ui/base/text/bytes_formatting.h" |
| +using power::OriginPowerMap; |
| +using power::OriginPowerMapFactory; |
| + |
| namespace { |
| const int kHttpPort = 80; |
| @@ -57,6 +62,7 @@ void WebsiteSettingsHandler::GetLocalizedValues( |
| {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, |
| {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, |
| {"websitesLabelStorage", IDS_WEBSITE_SETTINGS_TYPE_STORAGE}, |
| + {"websitesLabelBattery", IDS_WEBSITE_SETTINGS_TYPE_BATTERY}, |
| {"websitesLocationDescription", |
| IDS_WEBSITE_SETTINGS_LOCATION_DESCRIPTION}, |
| {"websitesMediastreamDescription", |
| @@ -64,6 +70,7 @@ void WebsiteSettingsHandler::GetLocalizedValues( |
| {"websitesNotificationsDescription", |
| IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION}, |
| {"websitesButtonClear", IDS_WEBSITE_SETTINGS_STORAGE_CLEAR_BUTTON}, |
| + {"websitesButtonStop", IDS_WEBSITE_SETTINGS_BATTERY_STOP_BUTTON}, |
| }; |
| RegisterStrings(localized_strings, resources, arraysize(resources)); |
| @@ -94,6 +101,11 @@ void WebsiteSettingsHandler::RegisterMessages() { |
| base::Unretained(this))); |
| web_ui()->RegisterMessageCallback( |
| + "updateBatteryUsage", |
| + base::Bind(&WebsiteSettingsHandler::HandleUpdateBatteryUsage, |
| + base::Unretained(this))); |
| + |
| + web_ui()->RegisterMessageCallback( |
| "getOriginInfo", |
| base::Bind(&WebsiteSettingsHandler::HandleGetOriginInfo, |
| base::Unretained(this))); |
| @@ -346,6 +358,33 @@ void WebsiteSettingsHandler::HandleSetOriginPermission( |
| info); |
| } |
| +void WebsiteSettingsHandler::HandleUpdateBatteryUsage( |
| + const base::ListValue* args) { |
| + base::DictionaryValue power_map; |
| + OriginPowerMap* origins = |
| + OriginPowerMapFactory::GetForBrowserContext(Profile::FromWebUI(web_ui())); |
| + OriginPowerMap::PercentOriginMap percent_map = origins->GetPercentOriginMap(); |
| + for (std::map<GURL, int>::iterator it = percent_map.begin(); |
| + it != percent_map.end(); |
| + ++it) { |
| + std::string origin = it->first.spec(); |
| + |
| + if (origin.find(last_filter_) == base::string16::npos) |
| + continue; |
| + |
| + base::DictionaryValue* origin_entry = new base::DictionaryValue(); |
| + origin_entry->SetWithoutPathExpansion( |
|
Bernhard Bauer
2014/08/26 08:16:07
The ...WithoutPathExpansion variant isn't necessar
Daniel Nishi
2014/08/26 17:45:39
Done.
|
| + "usage", new base::FundamentalValue(it->second)); |
| + origin_entry->SetWithoutPathExpansion( |
|
Bernhard Bauer
2014/08/26 08:16:07
SetString() here.
Daniel Nishi
2014/08/26 17:45:39
Done.
|
| + "usageString", |
| + new base::StringValue(l10n_util::GetStringFUTF16Int( |
| + IDS_WEBSITE_SETTINGS_BATTERY_PERCENT, it->second))); |
| + power_map.SetWithoutPathExpansion(origin, origin_entry); |
| + } |
| + web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins", |
| + power_map); |
| +} |
| + |
| void WebsiteSettingsHandler::HandleDeleteLocalStorage( |
| const base::ListValue* args) { |
| DCHECK(!last_site_.is_empty()); |
| @@ -372,6 +411,10 @@ void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url, |
| } |
| } |
| + int battery = 0; |
| + battery = OriginPowerMapFactory::GetForBrowserContext( |
| + Profile::FromWebUI(web_ui()))->GetPowerForOrigin(site_url); |
|
Bernhard Bauer
2014/08/26 08:16:08
Indent just four spaces w/r/t the preceding line.
Daniel Nishi
2014/08/26 17:45:39
Done.
|
| + |
| base::DictionaryValue* permissions = new base::DictionaryValue; |
| for (size_t i = 0; i < arraysize(kValidTypes); ++i) { |
| ContentSettingsType permission_type = kValidTypes[i]; |
| @@ -429,9 +472,13 @@ void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url, |
| base::Value* storage_used = new base::StringValue(l10n_util::GetStringFUTF16( |
| IDS_WEBSITE_SETTINGS_STORAGE_USED, ui::FormatBytes(storage))); |
| + base::Value* battery_used = |
| + new base::StringValue(l10n_util::GetStringFUTF16Int( |
| + IDS_WEBSITE_SETTINGS_BATTERY_USED, battery)); |
| web_ui()->CallJavascriptFunction("WebsiteSettingsEditor.populateOrigin", |
| *storage_used, |
| + *battery_used, |
| *permissions, |
| base::FundamentalValue(show_page)); |
| } |