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 /** | 5 /** |
6 * Enumeration mapping all possible controlled-by values for exceptions to | 6 * Enumeration mapping all possible controlled-by values for exceptions to |
7 * icons. | 7 * icons. |
8 * @enum {string} | 8 * @enum {string} |
9 */ | 9 */ |
10 var iconControlledBy = { | 10 var iconControlledBy = { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 */ | 162 */ |
163 configureWidget_: function() { | 163 configureWidget_: function() { |
164 // The observer for All Sites fires before the attached/ready event, so | 164 // The observer for All Sites fires before the attached/ready event, so |
165 // initialize this here. | 165 // initialize this here. |
166 if (this.browserProxy_ === undefined) { | 166 if (this.browserProxy_ === undefined) { |
167 this.browserProxy_ = | 167 this.browserProxy_ = |
168 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | 168 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); |
169 } | 169 } |
170 | 170 |
171 this.setUpActionMenu_(); | 171 this.setUpActionMenu_(); |
172 this.ensureOpened_(); | |
173 this.populateList_(); | 172 this.populateList_(); |
174 }, | 173 }, |
175 | 174 |
176 /** | 175 /** |
177 * Ensures the widget is |opened| when needed when displayed initially. | |
178 * @private | |
179 */ | |
180 ensureOpened_: function() { | |
181 // Allowed list and Clear on Exit lists are always shown opened by default | |
182 // and All Sites is presented all in one list (nothing closed by default). | |
183 if (this.allSites || | |
184 this.categorySubtype == settings.PermissionValues.ALLOW || | |
185 this.categorySubtype == settings.PermissionValues.SESSION_ONLY) { | |
186 this.$.category.opened = true; | |
187 return; | |
188 } | |
189 | |
190 // Block list should only be shown opened if there is nothing to show in | |
191 // the other lists. | |
192 if (this.category != settings.INVALID_CATEGORY_SUBTYPE) { | |
193 this.browserProxy_.getExceptionList(this.category).then( | |
194 function(exceptionList) { | |
195 var othersExists = exceptionList.some(function(exception) { | |
196 return exception.setting == settings.PermissionValues.ALLOW || | |
197 exception.setting == settings.PermissionValues.SESSION_ONLY; | |
198 }); | |
199 if (othersExists) | |
200 return; | |
201 this.$.category.opened = true; | |
202 }.bind(this)); | |
203 } else { | |
204 this.$.category.opened = true; | |
205 } | |
206 }, | |
207 | |
208 /** | |
209 * Returns which icon, if any, should represent the fact that this exception | 176 * Returns which icon, if any, should represent the fact that this exception |
210 * is controlled. | 177 * is controlled. |
211 * @param {!SiteException} item The item from the list we're computing the | 178 * @param {!SiteException} item The item from the list we're computing the |
212 * icon for. | 179 * icon for. |
213 * @return {string} The icon to show (or blank, if none). | 180 * @return {string} The icon to show (or blank, if none). |
214 */ | 181 */ |
215 computeIconControlledBy_: function(item) { | 182 computeIconControlledBy_: function(item) { |
216 if (this.allSites) | 183 if (this.allSites) |
217 return ''; | 184 return ''; |
218 return iconControlledBy[item.source] || ''; | 185 return iconControlledBy[item.source] || ''; |
(...skipping 27 matching lines...) Expand all Loading... |
246 this.shadowRoot.appendChild(dialog); | 213 this.shadowRoot.appendChild(dialog); |
247 | 214 |
248 dialog.open(this.categorySubtype); | 215 dialog.open(this.categorySubtype); |
249 | 216 |
250 dialog.addEventListener('close', function() { | 217 dialog.addEventListener('close', function() { |
251 dialog.remove(); | 218 dialog.remove(); |
252 }); | 219 }); |
253 }, | 220 }, |
254 | 221 |
255 /** | 222 /** |
256 * Handles the expanding and collapsing of the sites list. | |
257 * @private | |
258 */ | |
259 onToggle_: function(e) { | |
260 if (this.$.category.opened) | |
261 this.$.icon.icon = 'cr:expand-less'; | |
262 else | |
263 this.$.icon.icon = 'cr:expand-more'; | |
264 }, | |
265 | |
266 /** | |
267 * Populate the sites list for display. | 223 * Populate the sites list for display. |
268 * @private | 224 * @private |
269 */ | 225 */ |
270 populateList_: function() { | 226 populateList_: function() { |
271 if (this.allSites) { | 227 if (this.allSites) { |
272 this.getAllSitesList_().then(function(lists) { | 228 this.getAllSitesList_().then(function(lists) { |
273 this.processExceptions_(lists); | 229 this.processExceptions_(lists); |
274 }.bind(this)); | 230 }.bind(this)); |
275 } else { | 231 } else { |
276 this.browserProxy_.getExceptionList(this.category).then( | 232 this.browserProxy_.getExceptionList(this.category).then( |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 // is redundant to also list all the sites that are blocked. | 476 // is redundant to also list all the sites that are blocked. |
521 if (this.isAllowList_()) | 477 if (this.isAllowList_()) |
522 return true; | 478 return true; |
523 | 479 |
524 if (this.isSessionOnlyList_()) | 480 if (this.isSessionOnlyList_()) |
525 return siteList.length > 0; | 481 return siteList.length > 0; |
526 | 482 |
527 return toggleState; | 483 return toggleState; |
528 }, | 484 }, |
529 }); | 485 }); |
OLD | NEW |