Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // Define a global boolean for notifications (only enabled in the test class). | |
| 6 cr.exportPath('settings_test'); | |
| 7 | |
| 8 /** @type {boolean} */ | |
| 9 settings_test.siteListNotifyForTest; | |
| 10 | |
| 11 /** | 5 /** |
| 12 * @fileoverview | 6 * @fileoverview |
| 13 * 'settings-site-list' shows a list of Allowed and Blocked sites for a given | 7 * 'settings-site-list' shows a list of Allowed and Blocked sites for a given |
| 14 * category. | 8 * category. |
| 15 */ | 9 */ |
| 16 Polymer({ | 10 Polymer({ |
| 17 | 11 |
| 18 is: 'settings-site-list', | 12 is: 'settings-site-list', |
| 19 | 13 |
| 20 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], | 14 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 32 * The site that was selected by the user in the dropdown list. | 26 * The site that was selected by the user in the dropdown list. |
| 33 * @type {SiteException} | 27 * @type {SiteException} |
| 34 */ | 28 */ |
| 35 selectedSite: { | 29 selectedSite: { |
| 36 type: Object, | 30 type: Object, |
| 37 notify: true, | 31 notify: true, |
| 38 }, | 32 }, |
| 39 | 33 |
| 40 /** | 34 /** |
| 41 * Array of sites to display in the widget. | 35 * Array of sites to display in the widget. |
| 36 * @type {!Array<SiteException>} | |
| 42 */ | 37 */ |
| 43 sites: { | 38 sites: { |
| 44 type: Array, | 39 type: Array, |
| 45 value: function() { return []; }, | 40 value: function() { return []; }, |
| 46 notify: true, // !!settings_test.siteListNotifyForTest, | |
| 47 }, | 41 }, |
| 48 | 42 |
| 49 /** | 43 /** |
| 50 * Whether this list is for the All Sites category. | 44 * Whether this list is for the All Sites category. |
| 51 */ | 45 */ |
| 52 allSites: { | 46 allSites: { |
| 53 type: Boolean, | 47 type: Boolean, |
| 54 value: false, | 48 value: false, |
| 55 }, | 49 }, |
| 56 | 50 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 // Allowed list is always shown opened by default and All Sites is presented | 142 // Allowed list is always shown opened by default and All Sites is presented |
| 149 // all in one list (nothing closed by default). | 143 // all in one list (nothing closed by default). |
| 150 if (this.allSites || | 144 if (this.allSites || |
| 151 this.categorySubtype == settings.PermissionValues.ALLOW) { | 145 this.categorySubtype == settings.PermissionValues.ALLOW) { |
| 152 this.$.category.opened = true; | 146 this.$.category.opened = true; |
| 153 return; | 147 return; |
| 154 } | 148 } |
| 155 | 149 |
| 156 // Block list should only be shown opened if there is nothing to show in | 150 // Block list should only be shown opened if there is nothing to show in |
| 157 // the allowed list. | 151 // the allowed list. |
| 158 var prefsProxy = settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | 152 if (this.category != settings.INVALID_CATEGORY_SUBTYPE) { |
| 159 prefsProxy.getExceptionList(this.category).then(function(exceptionList) { | 153 var browserProxy = |
|
dpapad
2016/03/31 17:37:07
Nit: Instead of calling getInstance() three times
Finnur
2016/04/04 13:59:24
Converted to this.browserProxy_.
| |
| 160 for (var i = 0; i < exceptionList.length; ++i) { | 154 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); |
| 161 if (exceptionList[i].setting == 'allow') | 155 browserProxy.getExceptionList(this.category).then( |
| 162 return; | 156 function(exceptionList) { |
| 163 } | 157 var allowExists = exceptionList.some(function(exception) { |
| 158 return exception.setting == settings.PermissionStringValues.ALLOW; | |
| 159 }); | |
| 160 if (allowExists) | |
| 161 return; | |
| 162 this.$.category.opened = true; | |
| 163 }.bind(this)); | |
| 164 } else { | |
| 164 this.$.category.opened = true; | 165 this.$.category.opened = true; |
| 165 }.bind(this)); | 166 } |
| 166 }, | 167 }, |
| 167 | 168 |
| 168 /** | 169 /** |
| 169 * Makes sure the visibility is correct for this widget (e.g. hidden if the | 170 * Makes sure the visibility is correct for this widget (e.g. hidden if the |
| 170 * block list is empty). | 171 * block list is empty). |
| 171 * @private | 172 * @private |
| 172 */ | 173 */ |
| 173 updateCategoryVisibility_: function() { | 174 updateCategoryVisibility_: function() { |
| 174 this.$.category.hidden = | 175 this.$.category.hidden = |
| 175 !this.showSiteList_(this.sites, this.categoryEnabled); | 176 !this.showSiteList_(this.sites, this.categoryEnabled); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 189 /** | 190 /** |
| 190 * Populate the sites list for display. | 191 * Populate the sites list for display. |
| 191 * @private | 192 * @private |
| 192 */ | 193 */ |
| 193 populateList_: function() { | 194 populateList_: function() { |
| 194 if (this.allSites) { | 195 if (this.allSites) { |
| 195 this.getAllSitesList_().then(function(lists) { | 196 this.getAllSitesList_().then(function(lists) { |
| 196 this.processExceptions_(lists); | 197 this.processExceptions_(lists); |
| 197 }.bind(this)); | 198 }.bind(this)); |
| 198 } else { | 199 } else { |
| 199 var prefsProxy = settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | 200 var browserProxy = |
| 200 prefsProxy.getExceptionList(this.category).then(function(exceptionList) { | 201 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); |
| 201 this.processExceptions_([exceptionList]); | 202 browserProxy.getExceptionList(this.category).then( |
| 203 function(exceptionList) { | |
| 204 this.processExceptions_([exceptionList]); | |
| 202 }.bind(this)); | 205 }.bind(this)); |
| 203 } | 206 } |
| 204 }, | 207 }, |
| 205 | 208 |
| 206 /** | 209 /** |
| 207 * Process the exception list returned from the native layer. | 210 * Process the exception list returned from the native layer. |
| 208 * @param {!Array<!Array<SiteException>>} data List of sites (exceptions) to | 211 * @param {!Array<!Array<SiteException>>} data List of sites (exceptions) to |
| 209 * process. | 212 * process. |
| 210 * @private | 213 * @private |
| 211 */ | 214 */ |
| 212 processExceptions_: function(data) { | 215 processExceptions_: function(data) { |
| 213 var sites = []; | 216 var sites = []; |
| 214 for (var i = 0; i < data.length; ++i) | 217 for (var i = 0; i < data.length; ++i) |
| 215 sites = this.appendSiteList_(sites, data[i]); | 218 sites = this.appendSiteList_(sites, data[i]); |
| 216 this.sites = this.toSiteArray_(sites); | 219 this.sites = this.toSiteArray_(sites); |
| 217 this.updateCategoryVisibility_(); | 220 this.updateCategoryVisibility_(); |
| 218 }, | 221 }, |
| 219 | 222 |
| 220 /** | 223 /** |
| 221 * Retrieves a list of all known sites (any category/setting). | 224 * Retrieves a list of all known sites (any category/setting). |
| 222 * @return {!Promise} | 225 * @return {!Promise} |
| 223 * @private | 226 * @private |
| 224 */ | 227 */ |
| 225 getAllSitesList_: function() { | 228 getAllSitesList_: function() { |
| 226 var prefsProxy = settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | 229 var browserProxy = settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); |
| 227 var promiseList = []; | 230 var promiseList = []; |
| 228 for (var type in settings.ContentSettingsTypes) { | 231 for (var type in settings.ContentSettingsTypes) { |
| 229 promiseList.push( | 232 promiseList.push( |
| 230 prefsProxy.getExceptionList(settings.ContentSettingsTypes[type])); | 233 browserProxy.getExceptionList(settings.ContentSettingsTypes[type])); |
| 231 } | 234 } |
| 232 | 235 |
| 233 return Promise.all(promiseList); | 236 return Promise.all(promiseList); |
| 234 }, | 237 }, |
| 235 | 238 |
| 236 /** | 239 /** |
| 237 * Appends to |list| the sites for a given category and subtype. | 240 * Appends to |list| the sites for a given category and subtype. |
| 238 * @param {!Array<SiteException>} sites The site list to add to. | 241 * @param {!Array<SiteException>} sites The site list to add to. |
| 239 * @param {!Array<SiteException>} exceptionList List of sites (exceptions) to | 242 * @param {!Array<SiteException>} exceptionList List of sites (exceptions) to |
| 240 * add. | 243 * add. |
| 241 * @return {!Array<SiteException>} The list of sites. | 244 * @return {!Array<SiteException>} The list of sites. |
| 242 * @private | 245 * @private |
| 243 */ | 246 */ |
| 244 appendSiteList_: function(sites, exceptionList) { | 247 appendSiteList_: function(sites, exceptionList) { |
| 245 for (var i = 0; i < exceptionList.length; ++i) { | 248 for (var i = 0; i < exceptionList.length; ++i) { |
| 246 if (this.category != settings.ALL_SITES) { | 249 if (this.category != settings.ALL_SITES) { |
| 247 // Filter out 'Block' values if this list is handling 'Allow' items. | 250 // Filter out 'Block' values if this list is handling 'Allow' items. |
| 248 if (exceptionList[i].setting == 'block' && | 251 if (exceptionList[i].setting == settings.PermissionStringValues.BLOCK && |
| 249 this.categorySubtype != settings.PermissionValues.BLOCK) { | 252 this.categorySubtype != settings.PermissionValues.BLOCK) { |
| 250 continue; | 253 continue; |
| 251 } | 254 } |
| 252 // Filter out 'Allow' values if this list is handling 'Block' items. | 255 // Filter out 'Allow' values if this list is handling 'Block' items. |
| 253 if (exceptionList[i].setting == 'allow' && | 256 if (exceptionList[i].setting == settings.PermissionStringValues.ALLOW && |
| 254 this.categorySubtype != settings.PermissionValues.ALLOW) { | 257 this.categorySubtype != settings.PermissionValues.ALLOW) { |
| 255 continue; | 258 continue; |
| 256 } | 259 } |
| 257 } | 260 } |
| 258 | 261 |
| 259 sites.push(exceptionList[i]); | 262 sites.push(exceptionList[i]); |
| 260 } | 263 } |
| 261 return sites; | 264 return sites; |
| 262 }, | 265 }, |
| 263 | 266 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 * Returns the icon to use for a given site. | 437 * Returns the icon to use for a given site. |
| 435 * @param {string} url The url of the site to fetch the icon for. | 438 * @param {string} url The url of the site to fetch the icon for. |
| 436 * @private | 439 * @private |
| 437 */ | 440 */ |
| 438 computeSiteIcon_: function(url) { | 441 computeSiteIcon_: function(url) { |
| 439 // TODO(finnur): For now, we're returning a placeholder image for each site | 442 // TODO(finnur): For now, we're returning a placeholder image for each site |
| 440 // but the actual favicon for each site will need to be returned. | 443 // but the actual favicon for each site will need to be returned. |
| 441 return 'communication:message'; | 444 return 'communication:message'; |
| 442 }, | 445 }, |
| 443 }); | 446 }); |
| OLD | NEW |