| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 siteWithinCategoryChanged_: function(category, site) { | 122 siteWithinCategoryChanged_: function(category, site) { |
| 129 if (category == this.category) | 123 if (category == this.category) |
| 130 this.configureWidget_(); | 124 this.configureWidget_(); |
| 131 }, | 125 }, |
| 132 | 126 |
| 133 /** | 127 /** |
| 134 * Configures the action menu, visibility of the widget and shows the list. | 128 * Configures the action menu, visibility of the widget and shows the list. |
| 135 * @private | 129 * @private |
| 136 */ | 130 */ |
| 137 configureWidget_: function() { | 131 configureWidget_: function() { |
| 132 // The observer for All Sites fires before the attached/ready event, so |
| 133 // initialize this here. |
| 134 if (this.browserProxy_ === undefined) { |
| 135 this.browserProxy_ = |
| 136 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); |
| 137 } |
| 138 |
| 138 this.setUpActionMenu_(); | 139 this.setUpActionMenu_(); |
| 139 this.ensureOpened_(); | 140 this.ensureOpened_(); |
| 140 this.populateList_(); | 141 this.populateList_(); |
| 141 }, | 142 }, |
| 142 | 143 |
| 143 /** | 144 /** |
| 144 * Ensures the widget is |opened| when needed when displayed initially. | 145 * Ensures the widget is |opened| when needed when displayed initially. |
| 145 * @private | 146 * @private |
| 146 */ | 147 */ |
| 147 ensureOpened_: function() { | 148 ensureOpened_: function() { |
| 148 // Allowed list is always shown opened by default and All Sites is presented | 149 // Allowed list is always shown opened by default and All Sites is presented |
| 149 // all in one list (nothing closed by default). | 150 // all in one list (nothing closed by default). |
| 150 if (this.allSites || | 151 if (this.allSites || |
| 151 this.categorySubtype == settings.PermissionValues.ALLOW) { | 152 this.categorySubtype == settings.PermissionValues.ALLOW) { |
| 152 this.$.category.opened = true; | 153 this.$.category.opened = true; |
| 153 return; | 154 return; |
| 154 } | 155 } |
| 155 | 156 |
| 156 // Block list should only be shown opened if there is nothing to show in | 157 // Block list should only be shown opened if there is nothing to show in |
| 157 // the allowed list. | 158 // the allowed list. |
| 158 var prefsProxy = settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | 159 if (this.category != settings.INVALID_CATEGORY_SUBTYPE) { |
| 159 prefsProxy.getExceptionList(this.category).then(function(exceptionList) { | 160 this.browserProxy_.getExceptionList(this.category).then( |
| 160 for (var i = 0; i < exceptionList.length; ++i) { | 161 function(exceptionList) { |
| 161 if (exceptionList[i].setting == 'allow') | 162 var allowExists = exceptionList.some(function(exception) { |
| 162 return; | 163 return exception.setting == settings.PermissionStringValues.ALLOW; |
| 163 } | 164 }); |
| 165 if (allowExists) |
| 166 return; |
| 167 this.$.category.opened = true; |
| 168 }.bind(this)); |
| 169 } else { |
| 164 this.$.category.opened = true; | 170 this.$.category.opened = true; |
| 165 }.bind(this)); | 171 } |
| 166 }, | 172 }, |
| 167 | 173 |
| 168 /** | 174 /** |
| 169 * Makes sure the visibility is correct for this widget (e.g. hidden if the | 175 * Makes sure the visibility is correct for this widget (e.g. hidden if the |
| 170 * block list is empty). | 176 * block list is empty). |
| 171 * @private | 177 * @private |
| 172 */ | 178 */ |
| 173 updateCategoryVisibility_: function() { | 179 updateCategoryVisibility_: function() { |
| 174 this.$.category.hidden = | 180 this.$.category.hidden = |
| 175 !this.showSiteList_(this.sites, this.categoryEnabled); | 181 !this.showSiteList_(this.sites, this.categoryEnabled); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 189 /** | 195 /** |
| 190 * Populate the sites list for display. | 196 * Populate the sites list for display. |
| 191 * @private | 197 * @private |
| 192 */ | 198 */ |
| 193 populateList_: function() { | 199 populateList_: function() { |
| 194 if (this.allSites) { | 200 if (this.allSites) { |
| 195 this.getAllSitesList_().then(function(lists) { | 201 this.getAllSitesList_().then(function(lists) { |
| 196 this.processExceptions_(lists); | 202 this.processExceptions_(lists); |
| 197 }.bind(this)); | 203 }.bind(this)); |
| 198 } else { | 204 } else { |
| 199 var prefsProxy = settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | 205 this.browserProxy_.getExceptionList(this.category).then( |
| 200 prefsProxy.getExceptionList(this.category).then(function(exceptionList) { | 206 function(exceptionList) { |
| 201 this.processExceptions_([exceptionList]); | 207 this.processExceptions_([exceptionList]); |
| 202 }.bind(this)); | 208 }.bind(this)); |
| 203 } | 209 } |
| 204 }, | 210 }, |
| 205 | 211 |
| 206 /** | 212 /** |
| 207 * Process the exception list returned from the native layer. | 213 * Process the exception list returned from the native layer. |
| 208 * @param {!Array<!Array<SiteException>>} data List of sites (exceptions) to | 214 * @param {!Array<!Array<SiteException>>} data List of sites (exceptions) to |
| 209 * process. | 215 * process. |
| 210 * @private | 216 * @private |
| 211 */ | 217 */ |
| 212 processExceptions_: function(data) { | 218 processExceptions_: function(data) { |
| 213 var sites = []; | 219 var sites = []; |
| 214 for (var i = 0; i < data.length; ++i) | 220 for (var i = 0; i < data.length; ++i) |
| 215 sites = this.appendSiteList_(sites, data[i]); | 221 sites = this.appendSiteList_(sites, data[i]); |
| 216 this.sites = this.toSiteArray_(sites); | 222 this.sites = this.toSiteArray_(sites); |
| 217 this.updateCategoryVisibility_(); | 223 this.updateCategoryVisibility_(); |
| 218 }, | 224 }, |
| 219 | 225 |
| 220 /** | 226 /** |
| 221 * Retrieves a list of all known sites (any category/setting). | 227 * Retrieves a list of all known sites (any category/setting). |
| 222 * @return {!Promise} | 228 * @return {!Promise} |
| 223 * @private | 229 * @private |
| 224 */ | 230 */ |
| 225 getAllSitesList_: function() { | 231 getAllSitesList_: function() { |
| 226 var prefsProxy = settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | |
| 227 var promiseList = []; | 232 var promiseList = []; |
| 228 for (var type in settings.ContentSettingsTypes) { | 233 for (var type in settings.ContentSettingsTypes) { |
| 229 promiseList.push( | 234 promiseList.push( |
| 230 prefsProxy.getExceptionList(settings.ContentSettingsTypes[type])); | 235 this.browserProxy_.getExceptionList( |
| 236 settings.ContentSettingsTypes[type])); |
| 231 } | 237 } |
| 232 | 238 |
| 233 return Promise.all(promiseList); | 239 return Promise.all(promiseList); |
| 234 }, | 240 }, |
| 235 | 241 |
| 236 /** | 242 /** |
| 237 * Appends to |list| the sites for a given category and subtype. | 243 * Appends to |list| the sites for a given category and subtype. |
| 238 * @param {!Array<SiteException>} sites The site list to add to. | 244 * @param {!Array<SiteException>} sites The site list to add to. |
| 239 * @param {!Array<SiteException>} exceptionList List of sites (exceptions) to | 245 * @param {!Array<SiteException>} exceptionList List of sites (exceptions) to |
| 240 * add. | 246 * add. |
| 241 * @return {!Array<SiteException>} The list of sites. | 247 * @return {!Array<SiteException>} The list of sites. |
| 242 * @private | 248 * @private |
| 243 */ | 249 */ |
| 244 appendSiteList_: function(sites, exceptionList) { | 250 appendSiteList_: function(sites, exceptionList) { |
| 245 for (var i = 0; i < exceptionList.length; ++i) { | 251 for (var i = 0; i < exceptionList.length; ++i) { |
| 246 if (this.category != settings.ALL_SITES) { | 252 if (this.category != settings.ALL_SITES) { |
| 247 // Filter out 'Block' values if this list is handling 'Allow' items. | 253 // Filter out 'Block' values if this list is handling 'Allow' items. |
| 248 if (exceptionList[i].setting == 'block' && | 254 if (exceptionList[i].setting == settings.PermissionStringValues.BLOCK && |
| 249 this.categorySubtype != settings.PermissionValues.BLOCK) { | 255 this.categorySubtype != settings.PermissionValues.BLOCK) { |
| 250 continue; | 256 continue; |
| 251 } | 257 } |
| 252 // Filter out 'Allow' values if this list is handling 'Block' items. | 258 // Filter out 'Allow' values if this list is handling 'Block' items. |
| 253 if (exceptionList[i].setting == 'allow' && | 259 if (exceptionList[i].setting == settings.PermissionStringValues.ALLOW && |
| 254 this.categorySubtype != settings.PermissionValues.ALLOW) { | 260 this.categorySubtype != settings.PermissionValues.ALLOW) { |
| 255 continue; | 261 continue; |
| 256 } | 262 } |
| 257 } | 263 } |
| 258 | 264 |
| 259 sites.push(exceptionList[i]); | 265 sites.push(exceptionList[i]); |
| 260 } | 266 } |
| 261 return sites; | 267 return sites; |
| 262 }, | 268 }, |
| 263 | 269 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 * Returns the icon to use for a given site. | 440 * Returns the icon to use for a given site. |
| 435 * @param {string} url The url of the site to fetch the icon for. | 441 * @param {string} url The url of the site to fetch the icon for. |
| 436 * @private | 442 * @private |
| 437 */ | 443 */ |
| 438 computeSiteIcon_: function(url) { | 444 computeSiteIcon_: function(url) { |
| 439 // TODO(finnur): For now, we're returning a placeholder image for each site | 445 // 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. | 446 // but the actual favicon for each site will need to be returned. |
| 441 return 'communication:message'; | 447 return 'communication:message'; |
| 442 }, | 448 }, |
| 443 }); | 449 }); |
| OLD | NEW |