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

Side by Side Diff: chrome/browser/resources/settings/site_settings/site_settings_behavior.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 from Michael Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview Behavior common to Site Settings classes.
7 * NOTE: This behavior depends on PrefsBehavior so classes that need this
8 * behavior must first list the PrefsBehavior (ahead of this behavior).
9 */
10
11 /** @polymerBehavior */
12 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
13 /**
14 * Returns whether the category default is set to enabled or not.
15 * @param {number} category The category to check.
16 * @return {boolean} True if the category default is set to enabled.
17 * @private
18 */
19 isCategoryAllowed_: function(category) {
20 var pref = this.getPref_(this.computeCategoryPrefName_(this.category));
21
22 // FullScreen is Allow vs. Ask.
23 if (category == settings.ContentSettingsTypes.FULLSCREEN)
24 return pref.value != settings.DefaultValues.ASK;
25
26 return pref.value != settings.DefaultValues.BLOCK;
27 },
28
29 /**
30 * A utility function to compute the icon to use for the category.
31 * @param {number} category The category to show the icon for.
32 * @return {string} The id of the icon for the given category.
33 * @private
34 */
35 computeIconForContentCategory_: function(category) {
36 switch (category) {
37 case settings.ContentSettingsTypes.COOKIES:
38 return ''; // Haven't found a good cookies icon under iron-icons.
39 case settings.ContentSettingsTypes.JAVASCRIPT:
40 return 'icons:input';
41 case settings.ContentSettingsTypes.FULLSCREEN:
42 return 'icons:fullscreen';
43 case settings.ContentSettingsTypes.POPUPS:
44 return 'icons:open-in-new';
45 case settings.ContentSettingsTypes.GEOLOCATION:
46 return 'communication:location-on';
47 case settings.ContentSettingsTypes.NOTIFICATION:
48 return 'social:notifications';
49 case settings.ContentSettingsTypes.CAMERA:
50 return 'av:videocam';
51 case settings.ContentSettingsTypes.MIC:
52 return 'av:mic';
53 default:
54 assertNotReached();
55 return '';
56 }
57 },
58
59 /**
60 * A utility function to compute the title of the category.
61 * @param {number} category The category to show the title for.
62 * @return {string} The title for the given category.
63 * @private
64 */
65 computeTitleForContentCategory_: function(category) {
66 switch (category) {
67 case settings.ContentSettingsTypes.COOKIES:
68 return loadTimeData.getString('siteSettingsCookies');
69 case settings.ContentSettingsTypes.JAVASCRIPT:
70 return loadTimeData.getString('siteSettingsJavascript');
71 case settings.ContentSettingsTypes.FULLSCREEN:
72 return loadTimeData.getString('siteSettingsFullscreen');
73 case settings.ContentSettingsTypes.POPUPS:
74 return loadTimeData.getString('siteSettingsPopups');
75 case settings.ContentSettingsTypes.GEOLOCATION:
76 return loadTimeData.getString('siteSettingsLocation');
77 case settings.ContentSettingsTypes.NOTIFICATION:
78 return loadTimeData.getString('siteSettingsNotifications');
79 case settings.ContentSettingsTypes.CAMERA:
80 return loadTimeData.getString('siteSettingsCamera');
81 case settings.ContentSettingsTypes.MIC:
82 return loadTimeData.getString('siteSettingsMic');
83 default:
84 assertNotReached();
85 return '';
86 }
87 },
88
89 /**
90 * A utility function to compute the name of the pref for the category.
91 * @param {number} category The category to find the pref name for.
92 * @return {string} The pref name for the given category.
93 * @private
94 */
95 computeCategoryPrefName_: function(category) {
96 return 'profile.default_content_setting_values.' +
97 this.computeCategorySuffix_(category);
98 },
99
100 /**
101 * A utility function to compute the name of the pref for the exceptions
102 * for a given category.
103 * @param {number} category The category to find the pref name for.
104 * @return {string} The pref name for the given category exceptions.
105 * @private
106 */
107 computeCategoryExceptionsPrefName_: function(category) {
108 return 'profile.content_settings.exceptions.' +
109 this.computeCategorySuffix_(category);
110 },
111
112 /**
113 * A utility function to convert the category enum into its text
114 * representation, for use with prefs.
115 * @param {number} category The category to find the pref name for.
116 * @return {string} The pref name (suffix) for the given category.
117 * @private
118 */
119 computeCategorySuffix_: function(category) {
120 switch (category) {
121 case settings.ContentSettingsTypes.COOKIES:
122 return 'cookies';
123 case settings.ContentSettingsTypes.JAVASCRIPT:
124 return 'javascript';
125 case settings.ContentSettingsTypes.FULLSCREEN:
126 return 'fullscreen';
127 case settings.ContentSettingsTypes.POPUPS:
128 return 'popups';
129 case settings.ContentSettingsTypes.GEOLOCATION:
130 return 'geolocation';
131 case settings.ContentSettingsTypes.NOTIFICATION:
132 return 'notifications';
133 case settings.ContentSettingsTypes.CAMERA:
134 return 'media_stream_camera';
135 case settings.ContentSettingsTypes.MIC:
136 return 'media_stream_mic';
137 default:
138 assertNotReached();
139 return '';
140 }
141 },
142
143 /**
144 * A utility function to compute the description for the category.
145 * @param {number} category The category to show the description for.
146 * @param {boolean} categoryEnabled The state of the global toggle.
147 * @return {string} The category description.
148 * @private
149 */
150 computeCategoryDesc_: function(category, categoryEnabled) {
151 switch (category) {
152 case settings.ContentSettingsTypes.JAVASCRIPT:
153 // "Allowed (recommended)" vs "Blocked".
154 return categoryEnabled ?
155 loadTimeData.getString('siteSettingsAllowedRecommended') :
156 loadTimeData.getString('siteSettingsBlocked');
157 case settings.ContentSettingsTypes.POPUPS:
158 // "Allowed" vs "Blocked (recommended)".
159 return categoryEnabled ?
160 loadTimeData.getString('siteSettingsAllowed') :
161 loadTimeData.getString('siteSettingsBlockedRecommended');
162 case settings.ContentSettingsTypes.NOTIFICATION:
163 // "Ask before sending (recommended)" vs "Blocked".
164 return categoryEnabled ?
165 loadTimeData.getString('siteSettingsAskBeforeSending') :
166 loadTimeData.getString('siteSettingsBlocked');
167 case settings.ContentSettingsTypes.GEOLOCATION:
168 case settings.ContentSettingsTypes.CAMERA:
169 case settings.ContentSettingsTypes.MIC:
170 // "Ask before accessing (recommended)" vs "Blocked".
171 return categoryEnabled ?
172 loadTimeData.getString('siteSettingsAskBeforeAccessing') :
173 loadTimeData.getString('siteSettingsBlocked');
174 case settings.ContentSettingsTypes.FULLSCREEN:
175 // "Allowed" vs. "Ask first (recommended)".
176 return categoryEnabled ?
177 loadTimeData.getString('siteSettingsAllowed') :
178 loadTimeData.getString('siteSettingsAskFirstRecommended');
179 case settings.ContentSettingsTypes.COOKIES:
180 // "Allow sites to save and read cookie data" vs "Blocked".
181 return categoryEnabled ?
182 loadTimeData.getString('siteSettingsCookiesAllowed') :
183 loadTimeData.getString('siteSettingsBlocked');
184 default:
185 assertNotReached();
186 return '';
187 }
188 },
189 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698