Chromium Code Reviews| 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..b94a16ae157d646331586d459c71c0f358e5234c |
| --- /dev/null |
| +++ b/chrome/browser/resources/settings/site_settings/site_settings_behavior.js |
| @@ -0,0 +1,189 @@ |
| +// 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. |
| + * NOTE: This behavior depends on PrefsBehavior so classes that need this |
| + * behavior must first list the PrefsBehavior (ahead of this behavior). |
| + */ |
| + |
| +/** @polymerBehavior */ |
| +var SiteSettingsBehavior = { |
|
Dan Beam
2015/10/29 21:10:39
if this is going to call getPref_, it should have:
Finnur
2015/10/30 12:13:47
I experimented with making behaviors inherit from
Dan Beam
2015/10/30 20:23:53
cool with me
|
| + /** |
| + * 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 |
| + */ |
| + isCategoryAllowed_: function(category) { |
| + var pref = this.getPref_(this.computeCategoryPrefName_(this.category)); |
| + |
| + // FullScreen is Allow vs. Ask. |
| + if (category == settings.ContentSettingsTypes.FULLSCREEN) |
| + return pref.value != settings.DefaultValues.ASK; |
| + |
| + return pref.value != settings.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 |
| + */ |
| + computeIconForContentCategory_: function(category) { |
| + switch (category) { |
| + case settings.ContentSettingsTypes.COOKIES: |
| + return ''; // Haven't found a good cookies icon under iron-icons. |
| + case settings.ContentSettingsTypes.JAVASCRIPT: |
| + return 'icons:input'; |
| + case settings.ContentSettingsTypes.FULLSCREEN: |
| + return 'icons:fullscreen'; |
| + case settings.ContentSettingsTypes.POPUPS: |
| + return 'icons:open-in-new'; |
| + case settings.ContentSettingsTypes.GEOLOCATION: |
| + return 'communication:location-on'; |
| + case settings.ContentSettingsTypes.NOTIFICATION: |
| + return 'social:notifications'; |
| + case settings.ContentSettingsTypes.CAMERA: |
| + return 'av:videocam'; |
| + case settings.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 |
| + */ |
| + computeTitleForContentCategory_: function(category) { |
| + switch (category) { |
| + case settings.ContentSettingsTypes.COOKIES: |
| + return loadTimeData.getString('siteSettingsCookies'); |
| + case settings.ContentSettingsTypes.JAVASCRIPT: |
| + return loadTimeData.getString('siteSettingsJavascript'); |
| + case settings.ContentSettingsTypes.FULLSCREEN: |
| + return loadTimeData.getString('siteSettingsFullscreen'); |
| + case settings.ContentSettingsTypes.POPUPS: |
| + return loadTimeData.getString('siteSettingsPopups'); |
| + case settings.ContentSettingsTypes.GEOLOCATION: |
| + return loadTimeData.getString('siteSettingsLocation'); |
| + case settings.ContentSettingsTypes.NOTIFICATION: |
| + return loadTimeData.getString('siteSettingsNotifications'); |
| + case settings.ContentSettingsTypes.CAMERA: |
| + return loadTimeData.getString('siteSettingsCamera'); |
| + case settings.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 |
| + */ |
| + computeCategoryPrefName_: function(category) { |
| + return 'profile.default_content_setting_values.' + |
| + this.computeCategorySuffix_(category); |
| + }, |
| + |
| + /** |
| + * A utility function to compute the name of the pref for the exceptions |
| + * for a given category. |
| + * @param {number} category The category to find the pref name for. |
| + * @return {string} The pref name for the given category exceptions. |
| + * @private |
| + */ |
| + computeCategoryExceptionsPrefName_: function(category) { |
| + return 'profile.content_settings.exceptions.' + |
| + this.computeCategorySuffix_(category); |
| + }, |
| + |
| + /** |
| + * A utility function to convert the category enum into its text |
| + * representation, for use with prefs. |
| + * @param {number} category The category to find the pref name for. |
| + * @return {string} The pref name (suffix) for the given category. |
| + * @private |
| + */ |
| + computeCategorySuffix_: function(category) { |
| + switch (category) { |
| + case settings.ContentSettingsTypes.COOKIES: |
| + return 'cookies'; |
| + case settings.ContentSettingsTypes.JAVASCRIPT: |
| + return 'javascript'; |
| + case settings.ContentSettingsTypes.FULLSCREEN: |
| + return 'fullscreen'; |
| + case settings.ContentSettingsTypes.POPUPS: |
| + return 'popups'; |
| + case settings.ContentSettingsTypes.GEOLOCATION: |
| + return 'geolocation'; |
| + case settings.ContentSettingsTypes.NOTIFICATION: |
| + return 'notifications'; |
| + case settings.ContentSettingsTypes.CAMERA: |
| + return 'media_stream_camera'; |
| + case settings.ContentSettingsTypes.MIC: |
| + return '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 |
| + */ |
| + computeCategoryDesc_: function(category, categoryEnabled) { |
| + switch (category) { |
| + case settings.ContentSettingsTypes.JAVASCRIPT: |
| + // "Allowed (recommended)" vs "Blocked". |
| + return categoryEnabled ? |
| + loadTimeData.getString('siteSettingsAllowedRecommended') : |
| + loadTimeData.getString('siteSettingsBlocked'); |
| + case settings.ContentSettingsTypes.POPUPS: |
| + // "Allowed" vs "Blocked (recommended)". |
| + return categoryEnabled ? |
| + loadTimeData.getString('siteSettingsAllowed') : |
| + loadTimeData.getString('siteSettingsBlockedRecommended'); |
| + case settings.ContentSettingsTypes.NOTIFICATION: |
| + // "Ask before sending (recommended)" vs "Blocked". |
| + return categoryEnabled ? |
| + loadTimeData.getString('siteSettingsAskBeforeSending') : |
| + loadTimeData.getString('siteSettingsBlocked'); |
| + case settings.ContentSettingsTypes.GEOLOCATION: |
| + case settings.ContentSettingsTypes.CAMERA: |
| + case settings.ContentSettingsTypes.MIC: |
| + // "Ask before accessing (recommended)" vs "Blocked". |
| + return categoryEnabled ? |
| + loadTimeData.getString('siteSettingsAskBeforeAccessing') : |
| + loadTimeData.getString('siteSettingsBlocked'); |
| + case settings.ContentSettingsTypes.FULLSCREEN: |
| + // "Allowed" vs. "Ask first (recommended)". |
| + return categoryEnabled ? |
| + loadTimeData.getString('siteSettingsAllowed') : |
| + loadTimeData.getString('siteSettingsAskFirstRecommended'); |
| + case settings.ContentSettingsTypes.COOKIES: |
| + // "Allow sites to save and read cookie data" vs "Blocked". |
| + return categoryEnabled ? |
| + loadTimeData.getString('siteSettingsCookiesAllowed') : |
| + loadTimeData.getString('siteSettingsBlocked'); |
| + default: |
| + assertNotReached(); |
| + return ''; |
| + } |
| + }, |
| +}; |