| Index: chrome/browser/resources/settings/site_settings/site_settings_behavior.js
|
| diff --git a/chrome/browser/resources/settings/site_settings/site_settings_behavior.js b/chrome/browser/resources/settings/site_settings/site_settings_behavior.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c91b10a00350b174bf4df1abcda520758709edc1
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/settings/site_settings/site_settings_behavior.js
|
| @@ -0,0 +1,188 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +/**
|
| + * @fileoverview Behavior common to Site Settings classes.
|
| + */
|
| +
|
| +/** @polymerBehavior */
|
| +var SiteSettingsBehavior = {
|
| + /**
|
| + * Gets the pref at the given prefPath. Throws if the pref is not found.
|
| + * @param {string} prefPath
|
| + * @return {!chrome.settingsPrivate.PrefObject}
|
| + * @private
|
| + */
|
| + getPref_: function(prefPath) {
|
| + var pref = /** @type {!chrome.settingsPrivate.PrefObject} */(
|
| + this.get(prefPath, this.prefs));
|
| + assert(typeof pref != 'undefined', 'Pref is missing: ' + prefPath);
|
| + return pref;
|
| + },
|
| +
|
| + /**
|
| + * Sets the value of the pref at the given prefPath. Throws if the pref is not
|
| + * found.
|
| + * @param {string} prefPath
|
| + * @param {*} value
|
| + * @private
|
| + */
|
| + setPrefValue_: function(prefPath, value) {
|
| + this.set('prefs.' + prefPath + '.value', value);
|
| + },
|
| +
|
| + /**
|
| + * Returns whether the category default is set to enabled or not.
|
| + * @param {number} category The category to check.
|
| + * @return {boolean} True if the category default is set to enabled.
|
| + * @private
|
| + */
|
| + isPrefEnabled_: function(category) {
|
| + var pref = this.getPref_(this.computePrefName_(this.category));
|
| +
|
| + // FullScreen is Allow vs. Ask.
|
| + if (category == siteSettings.ContentSettingsTypes.FULLSCREEN)
|
| + return pref.value != siteSettings.DefaultValues.ALLOW;
|
| +
|
| + return pref.value != siteSettings.DefaultValues.BLOCK;
|
| + },
|
| +
|
| + /**
|
| + * A utility function to compute the icon to use for the category.
|
| + * @param {number} category The category to show the icon for.
|
| + * @return {string} The id of the icon for the given category.
|
| + * @private
|
| + */
|
| + computeIcon_: function(category) {
|
| + // Wonder if any of these enum values are directly accessible from .js?
|
| + switch (category) {
|
| + case siteSettings.ContentSettingsTypes.COOKIES:
|
| + return ''; // Haven't found a good cookies icon under iron-icons.
|
| + case siteSettings.ContentSettingsTypes.JAVASCRIPT:
|
| + return 'icons:input';
|
| + case siteSettings.ContentSettingsTypes.FULLSCREEN:
|
| + return 'icons:fullscreen';
|
| + case siteSettings.ContentSettingsTypes.POPUPS:
|
| + return 'icons:open-in-new';
|
| + case siteSettings.ContentSettingsTypes.GEOLOCATION:
|
| + return 'communication:location-on';
|
| + case siteSettings.ContentSettingsTypes.NOTIFICATION:
|
| + return 'social:notifications';
|
| + case siteSettings.ContentSettingsTypes.CAMERA:
|
| + return 'av:videocam';
|
| + case siteSettings.ContentSettingsTypes.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.
|
| + * @return {string} The title for the given category.
|
| + * @private
|
| + */
|
| + computeTitle_: function(category) {
|
| + switch (category) {
|
| + case siteSettings.ContentSettingsTypes.COOKIES:
|
| + return loadTimeData.getString('siteSettingsCookies');
|
| + case siteSettings.ContentSettingsTypes.JAVASCRIPT:
|
| + return loadTimeData.getString('siteSettingsJavascript');
|
| + case siteSettings.ContentSettingsTypes.FULLSCREEN:
|
| + return loadTimeData.getString('siteSettingsFullscreen');
|
| + case siteSettings.ContentSettingsTypes.POPUPS:
|
| + return loadTimeData.getString('siteSettingsPopups');
|
| + case siteSettings.ContentSettingsTypes.GEOLOCATION:
|
| + return loadTimeData.getString('siteSettingsLocation');
|
| + case siteSettings.ContentSettingsTypes.NOTIFICATION:
|
| + return loadTimeData.getString('siteSettingsNotifications');
|
| + case siteSettings.ContentSettingsTypes.CAMERA:
|
| + return loadTimeData.getString('siteSettingsCamera');
|
| + case siteSettings.ContentSettingsTypes.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.
|
| + * @return {string} The pref name for the given category.
|
| + * @private
|
| + */
|
| + computePrefName_: function(category) {
|
| + switch (category) {
|
| + case siteSettings.ContentSettingsTypes.COOKIES:
|
| + return 'profile.default_content_setting_values.cookies';
|
| + case siteSettings.ContentSettingsTypes.JAVASCRIPT:
|
| + return 'profile.default_content_setting_values.javascript';
|
| + case siteSettings.ContentSettingsTypes.FULLSCREEN:
|
| + return 'profile.default_content_setting_values.fullscreen';
|
| + case siteSettings.ContentSettingsTypes.POPUPS:
|
| + return 'profile.default_content_setting_values.popups';
|
| + case siteSettings.ContentSettingsTypes.GEOLOCATION:
|
| + return 'profile.default_content_setting_values.geolocation';
|
| + case siteSettings.ContentSettingsTypes.NOTIFICATION:
|
| + return 'profile.default_content_setting_values.notifications';
|
| + case siteSettings.ContentSettingsTypes.CAMERA:
|
| + return 'profile.default_content_setting_values.media_stream_camera';
|
| + case siteSettings.ContentSettingsTypes.MIC:
|
| + return 'profile.default_content_setting_values.media_stream_mic';
|
| + default:
|
| + assertNotReached();
|
| + return '';
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * 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.
|
| + * @return {string} The category description.
|
| + * @private
|
| + */
|
| + computeDesc_: function(category, categoryEnabled) {
|
| + switch (category) {
|
| + case siteSettings.ContentSettingsTypes.JAVASCRIPT:
|
| + // "Allowed (recommended)" vs "Blocked".
|
| + return categoryEnabled ?
|
| + loadTimeData.getString('siteSettingsAllowedRecommended') :
|
| + loadTimeData.getString('siteSettingsBlocked');
|
| + case siteSettings.ContentSettingsTypes.POPUPS:
|
| + // "Allowed" vs "Blocked (recommended)".
|
| + return categoryEnabled ?
|
| + loadTimeData.getString('siteSettingsAllowed') :
|
| + loadTimeData.getString('siteSettingsBlockedRecommended');
|
| + case siteSettings.ContentSettingsTypes.NOTIFICATION:
|
| + // "Ask before sending (recommended)" vs "Blocked".
|
| + return categoryEnabled ?
|
| + loadTimeData.getString('siteSettingsAskBeforeSending') :
|
| + loadTimeData.getString('siteSettingsBlocked');
|
| + case siteSettings.ContentSettingsTypes.GEOLOCATION:
|
| + case siteSettings.ContentSettingsTypes.CAMERA:
|
| + case siteSettings.ContentSettingsTypes.MIC:
|
| + // "Ask before accessing (recommended)" vs "Blocked".
|
| + return categoryEnabled ?
|
| + loadTimeData.getString('siteSettingsAskBeforeAccessing') :
|
| + loadTimeData.getString('siteSettingsBlocked');
|
| + case siteSettings.ContentSettingsTypes.FULLSCREEN:
|
| + // "Allowed" vs. "Ask first (recommended)".
|
| + return categoryEnabled ?
|
| + loadTimeData.getString('siteSettingsAllowed') :
|
| + loadTimeData.getString('siteSettingsAskFirstRecommended');
|
| + case siteSettings.ContentSettingsTypes.COOKIES:
|
| + // "Allow sites to save and read cookie data" vs "Blocked".
|
| + return categoryEnabled ?
|
| + loadTimeData.getString('siteSettingsCookiesAllowed') :
|
| + loadTimeData.getString('siteSettingsBlocked');
|
| + default:
|
| + assertNotReached();
|
| + return '';
|
| + }
|
| + },
|
| +};
|
|
|