Commit eda5899e authored by dhnishi's avatar dhnishi Committed by Commit bot

Surface battery auditing information on the website settings option page.

BUG=372607

Review URL: https://codereview.chromium.org/501063002

Cr-Commit-Position: refs/heads/master@{#292190}
parent a1a039ae
...@@ -344,6 +344,9 @@ are declared in build/common.gypi. ...@@ -344,6 +344,9 @@ are declared in build/common.gypi.
<message name="IDS_WEBSITE_SETTINGS_PERMISSION_ASK" desc="The label used in the permissions dropdowns for the option that makes the browser asks for permission. "> <message name="IDS_WEBSITE_SETTINGS_PERMISSION_ASK" desc="The label used in the permissions dropdowns for the option that makes the browser asks for permission. ">
ask ask
</message> </message>
<message name="IDS_WEBSITE_SETTINGS_TYPE_BATTERY" desc="The label used for the battery consumption type in the Manage Sites settings.">
Battery
</message>
<message name="IDS_WEBSITE_SETTINGS_TYPE_IMAGES" desc="The label used for images permission controls in the Website Settings popup."> <message name="IDS_WEBSITE_SETTINGS_TYPE_IMAGES" desc="The label used for images permission controls in the Website Settings popup.">
Images Images
</message> </message>
...@@ -7980,10 +7983,18 @@ Keep your key file in a safe place. You will need it to create new versions of y ...@@ -7980,10 +7983,18 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_WEBSITE_SETTINGS_STORAGE_USED" desc="The status text for how much local storage a website origin is using."> <message name="IDS_WEBSITE_SETTINGS_STORAGE_USED" desc="The status text for how much local storage a website origin is using.">
<ph name="USAGE">$1<ex>2.0 KB</ex></ph> stored data <ph name="USAGE">$1<ex>2.0 KB</ex></ph> stored data
</message> </message>
<message name="IDS_WEBSITE_SETTINGS_BATTERY_USED" desc="The status text for how much power a website origin is using.">
<ph name="USAGE">$1<ex>16</ex></ph>% of battery
</message>
<message name="IDS_WEBSITE_SETTINGS_STORAGE_CLEAR_BUTTON" desc="The 'Clear' button in the Website Settings single site view dialog."> <message name="IDS_WEBSITE_SETTINGS_STORAGE_CLEAR_BUTTON" desc="The 'Clear' button in the Website Settings single site view dialog.">
Clear Clear
</message> </message>
<message name="IDS_WEBSITE_SETTINGS_BATTERY_STOP_BUTTON" desc="The 'Stop' button in the Website Settings single site view dialog.">
Stop
</message>
<message name="IDS_WEBSITE_SETTINGS_BATTERY_PERCENT" desc="The percent from 0 to 100 of battery consumption from a given origin or app on the Website Settings dialog.">
<ph name="VALUE">$1<ex>100</ex></ph>%
</message>
<!-- Automatic updates --> <!-- Automatic updates -->
<if expr="is_macosx"> <if expr="is_macosx">
......
...@@ -62,10 +62,11 @@ ...@@ -62,10 +62,11 @@
.website-properties { .website-properties {
-webkit-margin-after: 8px; -webkit-margin-after: 8px;
-webkit-margin-start: 8px; -webkit-margin-start: 8px;
-webkit-padding-after: 4px;
} }
.website-property-area { .website-property-area {
-webkit-margin-after: 22px; -webkit-margin-after: 8px;
align-items: center; align-items: center;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
...@@ -102,6 +103,14 @@ ...@@ -102,6 +103,14 @@
border: 1px solid #d9d9d9; border: 1px solid #d9d9d9;
} }
#website-settings-edit-page .website-property-button {
min-width: 70px;
}
#website-settings-edit-page .website-property-controls {
min-width: 165px;
}
/* Styles for the origin list elements in the website settings page. */ /* Styles for the origin list elements in the website settings page. */
#origin-list { #origin-list {
border: 1px solid #d9d9d9; border: 1px solid #d9d9d9;
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
i18n-content="websitesLabelNotifications"></option> i18n-content="websitesLabelNotifications"></option>
<option value="storage" <option value="storage"
i18n-content="websitesLabelStorage"></option> i18n-content="websitesLabelStorage"></option>
<option value="battery"
i18n-content="websitesLabelBattery"></option>
</select> </select>
<input type="search" id="website-settings-search-box" <input type="search" id="website-settings-search-box"
i18n-values="placeholder:websitesSearch" incremental> i18n-values="placeholder:websitesSearch" incremental>
......
...@@ -44,6 +44,8 @@ cr.define('options', function() { ...@@ -44,6 +44,8 @@ cr.define('options', function() {
assert(target.tagName == 'SELECT'); assert(target.tagName == 'SELECT');
if (target.value == 'storage') if (target.value == 'storage')
chrome.send('updateLocalStorage'); chrome.send('updateLocalStorage');
else if (target.value == 'battery')
chrome.send('updateBatteryUsage');
else else
chrome.send('updateOrigins', [target.value]); chrome.send('updateOrigins', [target.value]);
}; };
......
...@@ -34,6 +34,10 @@ cr.define('options.WebsiteSettings', function() { ...@@ -34,6 +34,10 @@ cr.define('options.WebsiteSettings', function() {
chrome.send('deleteLocalStorage'); chrome.send('deleteLocalStorage');
}; };
$('website-settings-battery-stop-button').onclick = function(event) {
chrome.send('stopOrigin');
};
$('websiteSettingsEditorCancelButton').onclick = $('websiteSettingsEditorCancelButton').onclick =
PageManager.closeOverlay.bind(PageManager); PageManager.closeOverlay.bind(PageManager);
...@@ -61,13 +65,16 @@ cr.define('options.WebsiteSettings', function() { ...@@ -61,13 +65,16 @@ cr.define('options.WebsiteSettings', function() {
/** /**
* Populates and displays the page with given origin information. * Populates and displays the page with given origin information.
* @param {string} localStorage A string describing the local storage use. * @param {string} localStorage A string describing the local storage use.
* @param {string} batteryUsage A string describing the battery use.
* @param {Object} permissions A dictionary of permissions to their * @param {Object} permissions A dictionary of permissions to their
* available and current settings, and if it is editable. * available and current settings, and if it is editable.
* @param {boolean} showPage If the page should raised. * @param {boolean} showPage If the page should raised.
* @private * @private
*/ */
populateOrigin_: function(localStorage, permissions, showPage) { populateOrigin_: function(localStorage, batteryUsage, permissions,
showPage) {
$('local-storage-title').textContent = localStorage; $('local-storage-title').textContent = localStorage;
$('battery-title').textContent = batteryUsage;
for (var key in permissions) { for (var key in permissions) {
var selector = $(key + '-select-option'); var selector = $(key + '-select-option');
...@@ -98,9 +105,10 @@ cr.define('options.WebsiteSettings', function() { ...@@ -98,9 +105,10 @@ cr.define('options.WebsiteSettings', function() {
}, },
}; };
WebsiteSettingsEditor.populateOrigin = function(localStorage, permissions, WebsiteSettingsEditor.populateOrigin = function(localStorage, batteryUsage,
showPage) { permissions, showPage) {
WebsiteSettingsEditor.getInstance().populateOrigin_(localStorage, WebsiteSettingsEditor.getInstance().populateOrigin_(localStorage,
batteryUsage,
permissions, permissions,
showPage); showPage);
}; };
......
...@@ -6,8 +6,19 @@ ...@@ -6,8 +6,19 @@
<h3 id="website-title" class="title favicon-cell weaktrl"></h3> <h3 id="website-title" class="title favicon-cell weaktrl"></h3>
<div class="website-property-area"> <div class="website-property-area">
<div id="local-storage-title" class="website-property"></div> <div id="local-storage-title" class="website-property"></div>
<button id="website-settings-storage-delete-button" <div class="website-property-controls">
class="website-permission-button" i18n-content="websitesButtonClear"> <button id="website-settings-storage-delete-button"
class="website-property-button"
i18n-content="websitesButtonClear">
</div>
</div>
<div class="website-property-area">
<div id="battery-title" class="website-property"></div>
<div class="website-property-controls">
<button id="website-settings-battery-stop-button"
class="website-property-button"
i18n-content="websitesButtonStop">
</div>
</div> </div>
</div> </div>
<div class="website-column-headers"> <div class="website-column-headers">
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "chrome/browser/ui/browser_iterator.h" #include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.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/dom_storage_context.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -25,6 +27,9 @@ ...@@ -25,6 +27,9 @@
#include "ui/base/l10n/time_format.h" #include "ui/base/l10n/time_format.h"
#include "ui/base/text/bytes_formatting.h" #include "ui/base/text/bytes_formatting.h"
using power::OriginPowerMap;
using power::OriginPowerMapFactory;
namespace { namespace {
const int kHttpPort = 80; const int kHttpPort = 80;
...@@ -61,6 +66,7 @@ void WebsiteSettingsHandler::GetLocalizedValues( ...@@ -61,6 +66,7 @@ void WebsiteSettingsHandler::GetLocalizedValues(
{"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM}, {"websitesLabelMediaStream", IDS_WEBSITE_SETTINGS_TYPE_MEDIASTREAM},
{"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS}, {"websitesLabelNotifications", IDS_WEBSITE_SETTINGS_TYPE_NOTIFICATIONS},
{"websitesLabelStorage", IDS_WEBSITE_SETTINGS_TYPE_STORAGE}, {"websitesLabelStorage", IDS_WEBSITE_SETTINGS_TYPE_STORAGE},
{"websitesLabelBattery", IDS_WEBSITE_SETTINGS_TYPE_BATTERY},
{"websitesCookiesDescription", IDS_WEBSITE_SETTINGS_COOKIES_DESCRIPTION}, {"websitesCookiesDescription", IDS_WEBSITE_SETTINGS_COOKIES_DESCRIPTION},
{"websitesLocationDescription", {"websitesLocationDescription",
IDS_WEBSITE_SETTINGS_LOCATION_DESCRIPTION}, IDS_WEBSITE_SETTINGS_LOCATION_DESCRIPTION},
...@@ -69,6 +75,7 @@ void WebsiteSettingsHandler::GetLocalizedValues( ...@@ -69,6 +75,7 @@ void WebsiteSettingsHandler::GetLocalizedValues(
{"websitesNotificationsDescription", {"websitesNotificationsDescription",
IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION}, IDS_WEBSITE_SETTINGS_NOTIFICATIONS_DESCRIPTION},
{"websitesButtonClear", IDS_WEBSITE_SETTINGS_STORAGE_CLEAR_BUTTON}, {"websitesButtonClear", IDS_WEBSITE_SETTINGS_STORAGE_CLEAR_BUTTON},
{"websitesButtonStop", IDS_WEBSITE_SETTINGS_BATTERY_STOP_BUTTON},
}; };
RegisterStrings(localized_strings, resources, arraysize(resources)); RegisterStrings(localized_strings, resources, arraysize(resources));
...@@ -98,6 +105,11 @@ void WebsiteSettingsHandler::RegisterMessages() { ...@@ -98,6 +105,11 @@ void WebsiteSettingsHandler::RegisterMessages() {
base::Bind(&WebsiteSettingsHandler::HandleUpdateLocalStorage, base::Bind(&WebsiteSettingsHandler::HandleUpdateLocalStorage,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"updateBatteryUsage",
base::Bind(&WebsiteSettingsHandler::HandleUpdateBatteryUsage,
base::Unretained(this)));
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"getOriginInfo", "getOriginInfo",
base::Bind(&WebsiteSettingsHandler::HandleGetOriginInfo, base::Bind(&WebsiteSettingsHandler::HandleGetOriginInfo,
...@@ -364,6 +376,34 @@ void WebsiteSettingsHandler::HandleSetOriginPermission( ...@@ -364,6 +376,34 @@ void WebsiteSettingsHandler::HandleSetOriginPermission(
info); 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->SetInteger("usage", it->second);
origin_entry->SetString(
"usageString",
l10n_util::GetStringFUTF16Int(IDS_WEBSITE_SETTINGS_BATTERY_PERCENT,
it->second));
origin_entry->SetStringWithoutPathExpansion(
"readableName", GetReadableName(it->first));
power_map.SetWithoutPathExpansion(origin, origin_entry);
}
web_ui()->CallJavascriptFunction("WebsiteSettingsManager.populateOrigins",
power_map);
}
void WebsiteSettingsHandler::HandleDeleteLocalStorage( void WebsiteSettingsHandler::HandleDeleteLocalStorage(
const base::ListValue* args) { const base::ListValue* args) {
DCHECK(!last_site_.is_empty()); DCHECK(!last_site_.is_empty());
...@@ -390,6 +430,10 @@ void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url, ...@@ -390,6 +430,10 @@ void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url,
} }
} }
int battery = 0;
battery = OriginPowerMapFactory::GetForBrowserContext(
Profile::FromWebUI(web_ui()))->GetPowerForOrigin(site_url);
base::DictionaryValue* permissions = new base::DictionaryValue; base::DictionaryValue* permissions = new base::DictionaryValue;
for (size_t i = 0; i < arraysize(kValidTypes); ++i) { for (size_t i = 0; i < arraysize(kValidTypes); ++i) {
ContentSettingsType permission_type = kValidTypes[i]; ContentSettingsType permission_type = kValidTypes[i];
...@@ -451,9 +495,13 @@ void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url, ...@@ -451,9 +495,13 @@ void WebsiteSettingsHandler::GetInfoForOrigin(const GURL& site_url,
base::Value* storage_used = new base::StringValue(l10n_util::GetStringFUTF16( base::Value* storage_used = new base::StringValue(l10n_util::GetStringFUTF16(
IDS_WEBSITE_SETTINGS_STORAGE_USED, ui::FormatBytes(storage))); 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", web_ui()->CallJavascriptFunction("WebsiteSettingsEditor.populateOrigin",
*storage_used, *storage_used,
*battery_used,
*permissions, *permissions,
base::FundamentalValue(show_page)); base::FundamentalValue(show_page));
} }
......
...@@ -70,6 +70,10 @@ class WebsiteSettingsHandler : public content_settings::Observer, ...@@ -70,6 +70,10 @@ class WebsiteSettingsHandler : public content_settings::Observer,
// |args| is the URL. // |args| is the URL.
void HandleMaybeShowEditPage(const base::ListValue* args); void HandleMaybeShowEditPage(const base::ListValue* args);
// Get all origins that have used power, filter them by |last_filter_|, and
// update the page.
void HandleUpdateBatteryUsage(const base::ListValue* args);
// Deletes the local storage and repopulates the page. // Deletes the local storage and repopulates the page.
void HandleDeleteLocalStorage(const base::ListValue* args); void HandleDeleteLocalStorage(const base::ListValue* args);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment