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

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: 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 {string} enforcement Whether the exception is controlled.
tommycli 2017/03/27 16:02:07 nit: you may be able to use the actual chrome.sett
dschuyler 2017/03/28 01:05:53 Done.
206 * @param {boolean} readOnlyList Whether the site exception list is read-only. 181 * @param {boolean} readOnlyList Whether the site exception list is read-only.
207 * @return {boolean} 182 * @return {boolean}
208 * @private 183 * @private
209 */ 184 */
210 isResetButtonHidden_: function(source, readOnlyList) { 185 isResetButtonHidden_: function(enforcement, readOnlyList) {
211 return this.isExceptionControlled_(source) || this.allSites || 186 return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED ||
212 !readOnlyList; 187 this.allSites || !readOnlyList;
213 }, 188 },
214 189
215 /** 190 /**
216 * @param {string} source Where the setting came from. 191 * @param {string} enforcement Whether the exception is controlled.
217 * @param {boolean} readOnlyList Whether the site exception list is read-only. 192 * @param {boolean} readOnlyList Whether the site exception list is read-only.
218 * @return {boolean} 193 * @return {boolean}
219 * @private 194 * @private
220 */ 195 */
221 isActionMenuHidden_: function(source, readOnlyList) { 196 isActionMenuHidden_: function(enforcement, readOnlyList) {
222 return this.isExceptionControlled_(source) || this.allSites || readOnlyList; 197 return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED ||
198 this.allSites || readOnlyList;
223 }, 199 },
224 200
225 /** 201 /**
226 * A handler for the Add Site button. 202 * A handler for the Add Site button.
227 * @param {!Event} e 203 * @param {!Event} e
228 * @private 204 * @private
229 */ 205 */
230 onAddSiteTap_: function(e) { 206 onAddSiteTap_: function(e) {
231 assert(!this.readOnlyList); 207 assert(!this.readOnlyList);
232 e.preventDefault(); 208 e.preventDefault();
(...skipping 23 matching lines...) Expand all
256 this.browserProxy_.getExceptionList(this.category).then( 232 this.browserProxy_.getExceptionList(this.category).then(
257 function(exceptionList) { 233 function(exceptionList) {
258 this.processExceptions_([exceptionList]); 234 this.processExceptions_([exceptionList]);
259 this.closeActionMenu_(); 235 this.closeActionMenu_();
260 }.bind(this)); 236 }.bind(this));
261 } 237 }
262 }, 238 },
263 239
264 /** 240 /**
265 * Process the exception list returned from the native layer. 241 * Process the exception list returned from the native layer.
266 * @param {!Array<!Array<SiteException>>} data List of sites (exceptions) to 242 * @param {!Array<!Array<RawSiteException>>} data List of sites (exceptions)
267 * process. 243 * to process.
268 * @private 244 * @private
269 */ 245 */
270 processExceptions_: function(data) { 246 processExceptions_: function(data) {
271 var sites = []; 247 var sites = /** @type {!Array<RawSiteException>} */ ([]);
272 for (var i = 0; i < data.length; ++i) 248 for (var i = 0; i < data.length; ++i) {
273 sites = this.appendSiteList_(sites, data[i]); 249 var exceptionList = data[i];
250 for (var k = 0; k < exceptionList.length; ++k) {
251 if (!this.allSites &&
252 (exceptionList[k].setting == settings.PermissionValues.DEFAULT ||
253 exceptionList[k].setting != this.categorySubtype)) {
254 continue;
255 }
256
257 sites.push(exceptionList[k]);
258 }
259 }
274 this.sites = this.toSiteArray_(sites); 260 this.sites = this.toSiteArray_(sites);
275 }, 261 },
276 262
277 /** 263 /**
278 * Retrieves a list of all known sites (any category/setting). 264 * Retrieves a list of all known sites (any category/setting).
279 * @return {!Promise} 265 * @return {!Promise}
280 * @private 266 * @private
281 */ 267 */
282 getAllSitesList_: function() { 268 getAllSitesList_: function() {
283 var promiseList = []; 269 var promiseList = [];
(...skipping 10 matching lines...) Expand all
294 280
295 promiseList.push( 281 promiseList.push(
296 this.browserProxy_.getExceptionList( 282 this.browserProxy_.getExceptionList(
297 settings.ContentSettingsTypes[type])); 283 settings.ContentSettingsTypes[type]));
298 } 284 }
299 285
300 return Promise.all(promiseList); 286 return Promise.all(promiseList);
301 }, 287 },
302 288
303 /** 289 /**
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 290 * 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 291 * 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 292 * view, the list is sorted by site name, then protocol and port and de-duped
330 * (by origin). 293 * (by origin).
331 * @param {!Array<SiteException>} sites A list of sites to convert. 294 * @param {!Array<RawSiteException>} sites A list of sites to convert.
332 * @return {!Array<SiteException>} A list of full SiteExceptions. Sorted and 295 * @return {!Array<SiteException>} A list of full SiteExceptions. Sorted and
333 * deduped if allSites is set. 296 * deduped if allSites is set.
334 * @private 297 * @private
335 */ 298 */
336 toSiteArray_: function(sites) { 299 toSiteArray_: function(sites) {
337 var self = this; 300 var self = this;
338 if (this.allSites) { 301 if (this.allSites) {
339 sites.sort(function(a, b) { 302 sites.sort(function(a, b) {
340 var url1 = self.toUrl(a.origin); 303 var url1 = self.toUrl(a.origin);
341 var url2 = self.toUrl(b.origin); 304 var url2 = self.toUrl(b.origin);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 482
520 /** @private */ 483 /** @private */
521 closeActionMenu_: function() { 484 closeActionMenu_: function() {
522 this.actionMenuSite_ = null; 485 this.actionMenuSite_ = null;
523 var actionMenu = /** @type {!CrActionMenuElement} */ ( 486 var actionMenu = /** @type {!CrActionMenuElement} */ (
524 this.$$('dialog[is=cr-action-menu]')); 487 this.$$('dialog[is=cr-action-menu]'));
525 if (actionMenu.open) 488 if (actionMenu.open)
526 actionMenu.close(); 489 actionMenu.close();
527 }, 490 },
528 }); 491 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698