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

Side by Side Diff: chrome/browser/resources/settings/site_settings/site_list.js

Issue 2769303004: [MD setting] tool tips on controlledBy site exceptions (Closed)
Patch Set: unit test and review changes Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * Enumeration mapping all possible controlled-by values for exceptions to
7 * icons.
8 * @enum {string}
9 */
10 var iconControlledBy = {
11 'extension': 'cr:extension',
12 'HostedApp': 'cr:extension',
13 'platform_app': 'cr:extension',
14 'policy' : 'cr20:domain',
15 };
16
17 /**
18 * @fileoverview 6 * @fileoverview
19 * 'site-list' shows a list of Allowed and Blocked sites for a given 7 * 'site-list' shows a list of Allowed and Blocked sites for a given
20 * category. 8 * category.
21 */ 9 */
22 Polymer({ 10 Polymer({
23 11
24 is: 'site-list', 12 is: 'site-list',
25 13
26 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], 14 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior],
27 15
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 this.populateList_(); 161 this.populateList_();
174 162
175 // The Session permissions are only for cookies. 163 // The Session permissions are only for cookies.
176 if (this.categorySubtype == settings.PermissionValues.SESSION_ONLY) { 164 if (this.categorySubtype == settings.PermissionValues.SESSION_ONLY) {
177 this.$.category.hidden = 165 this.$.category.hidden =
178 this.category != settings.ContentSettingsTypes.COOKIES; 166 this.category != settings.ContentSettingsTypes.COOKIES;
179 } 167 }
180 }, 168 },
181 169
182 /** 170 /**
183 * Returns which icon, if any, should represent the fact that this exception
184 * is controlled.
185 * @param {!SiteException} item The item from the list we're computing the
186 * icon for.
187 * @return {string} The icon to show (or blank, if none).
188 */
189 computeIconControlledBy_: function(item) {
190 if (this.allSites)
191 return '';
192 return iconControlledBy[item.source] || '';
193 },
194
195 /**
196 * Whether there are any site exceptions added for this content setting. 171 * Whether there are any site exceptions added for this content setting.
197 * @return {boolean} 172 * @return {boolean}
198 * @private 173 * @private
199 */ 174 */
200 hasSites_: function() { 175 hasSites_: function() {
201 return !!this.sites.length; 176 return !!this.sites.length;
202 }, 177 },
203 178
204 /** 179 /**
205 * @param {string} source Where the setting came from. 180 * @param {chrome.settingsPrivate.Enforcement} enforcement The level of
181 * enforcement.
206 * @param {boolean} readOnlyList Whether the site exception list is read-only. 182 * @param {boolean} readOnlyList Whether the site exception list is read-only.
207 * @return {boolean} 183 * @return {boolean}
208 * @private 184 * @private
209 */ 185 */
210 isResetButtonHidden_: function(source, readOnlyList) { 186 isResetButtonHidden_: function(enforcement, readOnlyList) {
211 return this.isExceptionControlled_(source) || this.allSites || 187 return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED ||
212 !readOnlyList; 188 this.allSites || !readOnlyList;
213 }, 189 },
214 190
215 /** 191 /**
216 * @param {string} source Where the setting came from. 192 * @param {string} enforcement Whether the exception is controlled.
217 * @param {boolean} readOnlyList Whether the site exception list is read-only. 193 * @param {boolean} readOnlyList Whether the site exception list is read-only.
218 * @return {boolean} 194 * @return {boolean}
219 * @private 195 * @private
220 */ 196 */
221 isActionMenuHidden_: function(source, readOnlyList) { 197 isActionMenuHidden_: function(enforcement, readOnlyList) {
222 return this.isExceptionControlled_(source) || this.allSites || readOnlyList; 198 return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED ||
199 this.allSites || readOnlyList;
223 }, 200 },
224 201
225 /** 202 /**
226 * A handler for the Add Site button. 203 * A handler for the Add Site button.
227 * @param {!Event} e 204 * @param {!Event} e
228 * @private 205 * @private
229 */ 206 */
230 onAddSiteTap_: function(e) { 207 onAddSiteTap_: function(e) {
231 assert(!this.readOnlyList); 208 assert(!this.readOnlyList);
232 e.preventDefault(); 209 e.preventDefault();
(...skipping 23 matching lines...) Expand all
256 this.browserProxy_.getExceptionList(this.category).then( 233 this.browserProxy_.getExceptionList(this.category).then(
257 function(exceptionList) { 234 function(exceptionList) {
258 this.processExceptions_([exceptionList]); 235 this.processExceptions_([exceptionList]);
259 this.closeActionMenu_(); 236 this.closeActionMenu_();
260 }.bind(this)); 237 }.bind(this));
261 } 238 }
262 }, 239 },
263 240
264 /** 241 /**
265 * Process the exception list returned from the native layer. 242 * Process the exception list returned from the native layer.
266 * @param {!Array<!Array<SiteException>>} data List of sites (exceptions) to 243 * @param {!Array<!Array<RawSiteException>>} data List of sites (exceptions)
267 * process. 244 * to process.
268 * @private 245 * @private
269 */ 246 */
270 processExceptions_: function(data) { 247 processExceptions_: function(data) {
271 var sites = []; 248 var sites = /** @type {!Array<RawSiteException>} */ ([]);
272 for (var i = 0; i < data.length; ++i) 249 for (var i = 0; i < data.length; ++i) {
273 sites = this.appendSiteList_(sites, data[i]); 250 var exceptionList = data[i];
251 for (var k = 0; k < exceptionList.length; ++k) {
252 if (!this.allSites &&
253 (exceptionList[k].setting == settings.PermissionValues.DEFAULT ||
254 exceptionList[k].setting != this.categorySubtype)) {
255 continue;
256 }
257
258 sites.push(exceptionList[k]);
259 }
260 }
274 this.sites = this.toSiteArray_(sites); 261 this.sites = this.toSiteArray_(sites);
275 }, 262 },
276 263
277 /** 264 /**
278 * Retrieves a list of all known sites (any category/setting). 265 * Retrieves a list of all known sites (any category/setting).
279 * @return {!Promise} 266 * @return {!Promise}
280 * @private 267 * @private
281 */ 268 */
282 getAllSitesList_: function() { 269 getAllSitesList_: function() {
283 var promiseList = []; 270 var promiseList = [];
(...skipping 10 matching lines...) Expand all
294 281
295 promiseList.push( 282 promiseList.push(
296 this.browserProxy_.getExceptionList( 283 this.browserProxy_.getExceptionList(
297 settings.ContentSettingsTypes[type])); 284 settings.ContentSettingsTypes[type]));
298 } 285 }
299 286
300 return Promise.all(promiseList); 287 return Promise.all(promiseList);
301 }, 288 },
302 289
303 /** 290 /**
304 * Appends to |list| the sites for a given category and subtype.
305 * @param {!Array<SiteException>} sites The site list to add to.
306 * @param {!Array<SiteException>} exceptionList List of sites (exceptions) to
307 * add.
308 * @return {!Array<SiteException>} The list of sites.
309 * @private
310 */
311 appendSiteList_: function(sites, exceptionList) {
312 for (var i = 0; i < exceptionList.length; ++i) {
313 if (!this.allSites) {
314 if (exceptionList[i].setting == settings.PermissionValues.DEFAULT)
315 continue;
316
317 if (exceptionList[i].setting != this.categorySubtype)
318 continue;
319 }
320
321 sites.push(exceptionList[i]);
322 }
323 return sites;
324 },
325
326 /**
327 * Converts a list of exceptions received from the C++ handler to 291 * Converts a list of exceptions received from the C++ handler to
328 * full SiteException objects. If this site-list is used as an all sites 292 * full SiteException objects. If this site-list is used as an all sites
329 * view, the list is sorted by site name, then protocol and port and de-duped 293 * view, the list is sorted by site name, then protocol and port and de-duped
330 * (by origin). 294 * (by origin).
331 * @param {!Array<SiteException>} sites A list of sites to convert. 295 * @param {!Array<RawSiteException>} sites A list of sites to convert.
332 * @return {!Array<SiteException>} A list of full SiteExceptions. Sorted and 296 * @return {!Array<SiteException>} A list of full SiteExceptions. Sorted and
333 * deduped if allSites is set. 297 * deduped if allSites is set.
334 * @private 298 * @private
335 */ 299 */
336 toSiteArray_: function(sites) { 300 toSiteArray_: function(sites) {
337 var self = this; 301 var self = this;
338 if (this.allSites) { 302 if (this.allSites) {
339 sites.sort(function(a, b) { 303 sites.sort(function(a, b) {
340 var url1 = self.toUrl(a.origin); 304 var url1 = self.toUrl(a.origin);
341 var url2 = self.toUrl(b.origin); 305 var url2 = self.toUrl(b.origin);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 483
520 /** @private */ 484 /** @private */
521 closeActionMenu_: function() { 485 closeActionMenu_: function() {
522 this.actionMenuSite_ = null; 486 this.actionMenuSite_ = null;
523 var actionMenu = /** @type {!CrActionMenuElement} */ ( 487 var actionMenu = /** @type {!CrActionMenuElement} */ (
524 this.$$('dialog[is=cr-action-menu]')); 488 this.$$('dialog[is=cr-action-menu]'));
525 if (actionMenu.open) 489 if (actionMenu.open)
526 actionMenu.close(); 490 actionMenu.close();
527 }, 491 },
528 }); 492 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698