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

Unified Diff: chrome/browser/resources/settings/location_page/location_page.js

Issue 1372053002: Flesh out the location-page class to make it more general. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split list into two Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/settings/location_page/location_page.js
diff --git a/chrome/browser/resources/settings/location_page/location_page.js b/chrome/browser/resources/settings/location_page/location_page.js
index 1d8201bb641ed66a583086969914c07b7f65bd5d..27facc42cf725cb83c0148a2e6b5e6ac651e65c6 100644
--- a/chrome/browser/resources/settings/location_page/location_page.js
+++ b/chrome/browser/resources/settings/location_page/location_page.js
@@ -16,6 +16,7 @@
* @element cr-settings-location-page
*/
Polymer({
+ /* TODO(finnur): Rename this to cr-settings-site-category. */
is: 'cr-settings-location-page',
properties: {
@@ -59,36 +60,178 @@ Polymer({
},
/**
- * Name of the 'iron-icon' to show.
+ * What the main toggle for the category is set to (the global default when
+ * no other policy is in effect).
*/
- icon: {
- type: String,
- value: 'communication:location-on',
- readOnly: true,
+ toggleState: {
+ type: Boolean,
+ },
+
+ /**
+ * The ID of the category this widget is displaying data for.
+ * See |categories| for possible values.
+ */
+ category: {
+ type: Number,
},
/**
- * Array of objects with url members.
+ * An enum containing all the possible category numbers. Corresponds to
+ * the values found in the ContentSettingsType.
*/
- block: {
- type: Array,
+ categories: {
+ type: Object,
},
/**
- * Array of objects with url members.
+ * An enum containing the two possible values for the site list (allowed
+ * list and blocked list).
*/
- allow: {
- type: Array,
+ allowOrBlock: {
+ readOnly: true,
+ type: Object,
+ value: {
+ BLOCK: 0,
+ ALLOW: 1,
+ },
},
},
ready: function() {
- this.block = [];
- this.allow = [];
+ chrome.send('fetchToggleState', [this.category]);
+ },
+
+ attached: function() {
+ var self = this;
+ cr.define('Settings', function() {
+ return {
+ receiveToggleState: function() {
+ return self.receiveToggleState_.apply(self, arguments);
+ },
+ };
+ });
+ },
+
+ /**
+ * Receive the state of the toggle (from the native level).
+ * @param {boolean} toggleState The initial value of the toggle.
+ * @private
+ */
+ receiveToggleState_: function(toggleState) {
+ this.toggleState = toggleState;
+ },
+
+ /**
+ * A handler for flipping the toggle value.
+ * @private
+ */
+ handleToggleChange_: function(event) {
+ chrome.send(
+ 'toggleChanged', [this.category, this.toggleState]);
+ },
+
+ /**
+ * A utility function to compute the icon to use for the category.
+ * @param {number} category The category to show the icon for.
+ * @private
+ */
+ computeIcon_: function(category) {
+ // Wonder if any of these enum values are directly accessible from .js?
+ switch (category) {
+ case this.categories.COOKIES:
+ return ''; // Haven't found a good cookies icon under iron-icons.
+ case this.categories.JAVASCRIPT:
+ return 'icons:input';
+ case this.categories.FULLSCREEN:
+ return 'icons:fullscreen';
+ case this.categories.POPUPS:
+ return 'icons:open-in-new';
+ case this.categories.GEOLOCATION:
+ return 'communication:location-on';
+ case this.categories.NOTIFICATION:
+ return 'social:notifications';
+ case this.categories.CAMERA:
+ return 'av:videocam';
+ case this.categories.MIC:
+ return 'av:mic';
+ default:
+ assertNotReached();
+ return '';
+ }
+ },
+
+ /**
+ * A utility function to compute the title of the category.
+ * @param {number} category The category to show the title for.
+ * @private
+ */
+ computeTitle_: function(category) {
+ switch (category) {
+ case this.categories.COOKIES:
+ return loadTimeData.getString('siteSettingsCookies');
+ case this.categories.JAVASCRIPT:
+ return loadTimeData.getString('siteSettingsJavascript');
+ case this.categories.FULLSCREEN:
+ return loadTimeData.getString('siteSettingsFullscreen');
+ case this.categories.POPUPS:
+ return loadTimeData.getString('siteSettingsPopups');
+ case this.categories.GEOLOCATION:
+ return loadTimeData.getString('siteSettingsLocation');
+ case this.categories.NOTIFICATION:
+ return loadTimeData.getString('siteSettingsNotifications');
+ case this.categories.CAMERA:
+ return loadTimeData.getString('siteSettingsCamera');
+ case this.categories.MIC:
+ return loadTimeData.getString('siteSettingsMic');
+ default:
+ assertNotReached();
+ return '';
+ }
},
- getTitleAndCount_: function(title, count) {
- return loadTimeData.getStringF(
- 'titleAndCount', loadTimeData.getString(title), count);
+ /**
+ * A utility function to compute the description for the category.
+ * @param {number} category The category to show the description for.
+ * @param {boolean} toggleState The state of the global toggle.
+ * @private
+ */
+ computeDesc_: function(category, toggleState) {
+ switch (category) {
+ case this.categories.JAVASCRIPT:
+ // "Allowed (recommended)" vs "Blocked".
+ return toggleState ?
+ loadTimeData.getString('siteSettingsAllowedRecommended') :
+ loadTimeData.getString('siteSettingsBlocked');
+ case this.categories.POPUPS:
+ // "Allowed" vs "Blocked (recommended)".
+ return toggleState ?
+ loadTimeData.getString('siteSettingsAllowed') :
+ loadTimeData.getString('siteSettingsBlockedRecommended');
+ case this.categories.NOTIFICATION:
+ // "Ask before sending (recommended)" vs "Blocked".
+ return toggleState ?
+ loadTimeData.getString('siteSettingsAskBeforeSending') :
+ loadTimeData.getString('siteSettingsBlocked');
+ case this.categories.GEOLOCATION:
+ case this.categories.CAMERA:
+ case this.categories.MIC:
+ // "Ask before accessing (recommended)" vs "Blocked".
+ return toggleState ?
+ loadTimeData.getString('siteSettingsAskBeforeAccessing') :
+ loadTimeData.getString('siteSettingsBlocked');
+ case this.categories.FULLSCREEN:
+ // "Allowed" vs. "Ask first (recommended)".
+ return toggleState ?
+ loadTimeData.getString('siteSettingsAllowed') :
+ loadTimeData.getString('siteSettingsAskFirstRecommended');
+ case this.categories.COOKIES:
+ // "Allow sites to save and read cookie data" vs "Blocked".
+ return toggleState ?
+ loadTimeData.getString('siteSettingsCookiesAllowed') :
+ loadTimeData.getString('siteSettingsBlocked');
+ default:
+ assertNotReached();
+ return '';
+ }
},
});

Powered by Google App Engine
This is Rietveld 408576698