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

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: Address feedback Created 5 years, 2 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..85ff565e135ea5928b9d8b9252e1dec8d99b2b8a 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,285 @@ 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,
+ categoryEnabled: {
+ type: Boolean,
},
/**
- * Array of objects with url members.
+ * The ID of the category this widget is displaying data for.
+ * See |categories| for possible values.
*/
- block: {
- type: Array,
+ 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.
Dan Beam 2015/10/10 01:27:40 we shouldn't have to copy this or make new referen
Finnur 2015/10/15 15:46:32 Moved to constants.js.
*/
- allow: {
- type: Array,
+ categories: {
+ type: Object,
+ },
+
+ /**
+ * An enum containing the two possible values for the site list (allowed
+ * list and blocked list).
+ */
+ defaultValues: {
+ readOnly: true,
+ type: Object,
+ value: {
+ ALLOW: 1,
+ BLOCK: 2,
+ ASK: 3,
Dan Beam 2015/10/10 01:27:40 this should probably be in the same constants file
Finnur 2015/10/15 15:46:32 Ditto.
+ },
},
},
+ observers: [
+ 'categoryPrefChanged_(prefs.profile.' +
+ 'default_content_setting_values.cookies.value)',
+ 'categoryPrefChanged_(prefs.profile.' +
+ 'default_content_setting_values.javascript.value)',
+ 'categoryPrefChanged_(prefs.profile.' +
+ 'default_content_setting_values.fullscreen.value)',
+ 'categoryPrefChanged_(prefs.profile.' +
+ 'default_content_setting_values.popups.value)',
+ 'categoryPrefChanged_(prefs.profile.' +
+ 'default_content_setting_values.geolocation.value)',
+ 'categoryPrefChanged_(prefs.profile.' +
+ 'default_content_setting_values.notifications.value)',
+ 'categoryPrefChanged_(prefs.profile.' +
+ 'default_content_setting_values.media_stream_camera.value)',
+ 'categoryPrefChanged_(prefs.profile.' +
+ 'default_content_setting_values.media_stream_mic.value)',
Dan Beam 2015/10/10 01:27:40 'categoryPrefChanged_(prefs.profile.default_conten
Finnur 2015/10/15 15:46:32 Done.
+ ],
+
ready: function() {
- this.block = [];
- this.allow = [];
+ CrSettingsPrefs.initialized.then(function() {
+ this.categoryEnabled = this.isPrefEnabled_(this.category);
+ }.bind(this));
+ },
+
+ /**
+ * Gets the pref at the given key. Asserts if the pref is not found.
Dan Beam 2015/10/10 01:27:40 nit: Asserts -> Throws
Finnur 2015/10/15 15:46:32 Done.
+ * @param {string} key
Dan Beam 2015/10/10 01:27:40 key -> prefPath
Finnur 2015/10/15 15:46:32 Done.
+ * @return {!chrome.settingsPrivate.PrefObject}
+ */
+ getPref_: function(key) {
+ var pref = /** @type {!chrome.settingsPrivate.PrefObject} */(
+ this.get(key, this.prefs));
+ assert(typeof pref != 'undefined', 'Pref is missing: ' + key);
+ return pref;
+ },
+
+ /**
+ * Sets the value of the pref at the given key. Asserts if the pref is not
+ * found.
+ * @param {string} key
+ * @param {*} value
+ */
+ setPrefValue_: function(key, value) {
+ this.getPref_(key);
Dan Beam 2015/10/10 01:27:40 why are you calling getPref_ here? just for the a
Finnur 2015/10/15 15:46:32 Hmm... redundant. Removed.
+ this.set('prefs.' + key + '.value', value);
+ },
+
+ /**
+ * Handles when the global toggle changes.
+ * @private
+ */
+ categoryPrefChanged_: function() {
+ this.categoryEnabled = this.isPrefEnabled_(this.category);
+ },
+
+ /**
+ * A handler for flipping the toggle value.
+ * @private
+ */
+ handleToggleChange_: function(event) {
+ assert(CrSettingsPrefs.isInitialized);
+
+ switch (this.category) {
+ case this.categories.COOKIES:
+ case this.categories.JAVASCRIPT:
+ case this.categories.POPUPS:
+ // "Allowed" vs "Blocked".
+ this.setPrefValue_(this.computePrefName_(this.category),
+ this.categoryEnabled ?
+ this.defaultValues.ALLOW :
+ this.defaultValues.BLOCK);
+ break;
+ case this.categories.NOTIFICATION:
+ case this.categories.GEOLOCATION:
+ case this.categories.CAMERA:
+ case this.categories.MIC:
+ // "Ask" vs "Blocked".
+ this.setPrefValue_(this.computePrefName_(this.category),
+ this.categoryEnabled ?
+ this.defaultValues.ASK :
+ this.defaultValues.BLOCK);
+ break;
+ case this.categories.FULLSCREEN:
+ // "Allowed" vs. "Ask first".
+ this.setPrefValue_(this.computePrefName_(this.category),
+ this.categoryEnabled ?
+ this.defaultValues.ALLOW :
+ this.defaultValues.ASK);
+ break;
+ default:
+ assertNotReached();
+ }
+ },
+
+ /**
+ * Returns whether the category default is set to enabled or not.
+ * @param {number} category The category to show the icon for.
+ * @private
+ */
+ isPrefEnabled_: function(category) {
+ var pref = this.getPref_(this.computePrefName_(this.category));
+
+ // FullScreen is Allow vs. Ask.
+ if (category == this.categories.FULLSCREEN)
+ return pref.value != this.defaultValues.ALLOW;
+
+ return pref.value != this.defaultValues.BLOCK;
+ },
+
+ /**
+ * 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 '';
+ }
+ },
+
+ /**
+ * A utility function to compute the name of the pref for the category.
+ * @param {number} category The category to find the pref name for.
+ * @private
+ */
+ computePrefName_: function(category) {
+ switch (category) {
+ case this.categories.COOKIES:
+ return 'profile.default_content_setting_values.cookies';
+ case this.categories.JAVASCRIPT:
+ return 'profile.default_content_setting_values.javascript';
+ case this.categories.FULLSCREEN:
+ return 'profile.default_content_setting_values.fullscreen';
+ case this.categories.POPUPS:
+ return 'profile.default_content_setting_values.popups';
+ case this.categories.GEOLOCATION:
+ return 'profile.default_content_setting_values.geolocation';
+ case this.categories.NOTIFICATION:
+ return 'profile.default_content_setting_values.notifications';
+ case this.categories.CAMERA:
+ return 'profile.default_content_setting_values.media_stream_camera';
+ case this.categories.MIC:
+ return 'profile.default_content_setting_values.media_stream_mic';
+ 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} categoryEnabled The state of the global toggle.
+ * @private
+ */
+ computeDesc_: function(category, categoryEnabled) {
+ switch (category) {
+ case this.categories.JAVASCRIPT:
+ // "Allowed (recommended)" vs "Blocked".
+ return categoryEnabled ?
+ loadTimeData.getString('siteSettingsAllowedRecommended') :
+ loadTimeData.getString('siteSettingsBlocked');
+ case this.categories.POPUPS:
+ // "Allowed" vs "Blocked (recommended)".
+ return categoryEnabled ?
+ loadTimeData.getString('siteSettingsAllowed') :
+ loadTimeData.getString('siteSettingsBlockedRecommended');
+ case this.categories.NOTIFICATION:
+ // "Ask before sending (recommended)" vs "Blocked".
+ return categoryEnabled ?
+ 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 categoryEnabled ?
+ loadTimeData.getString('siteSettingsAskBeforeAccessing') :
+ loadTimeData.getString('siteSettingsBlocked');
+ case this.categories.FULLSCREEN:
+ // "Allowed" vs. "Ask first (recommended)".
+ return categoryEnabled ?
+ loadTimeData.getString('siteSettingsAllowed') :
+ loadTimeData.getString('siteSettingsAskFirstRecommended');
+ case this.categories.COOKIES:
+ // "Allow sites to save and read cookie data" vs "Blocked".
+ return categoryEnabled ?
+ loadTimeData.getString('siteSettingsCookiesAllowed') :
+ loadTimeData.getString('siteSettingsBlocked');
+ default:
+ assertNotReached();
+ return '';
+ }
},
});

Powered by Google App Engine
This is Rietveld 408576698