OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @fileoverview |
| 7 * 'settings-site-list' shows a list of Allowed and Blocked sites for a given |
| 8 * category. |
| 9 * |
| 10 * Example: |
| 11 * <settings-site-list prefs="{{prefs}}" |
| 12 * category="[[category]]"> |
| 13 * </settings-site-list> |
| 14 * |
| 15 * @group Chrome Settings Elements |
| 16 * @element settings-site-list |
| 17 */ |
| 18 Polymer({ |
| 19 is: 'settings-site-list', |
| 20 |
| 21 behaviors: [PrefsBehavior, SiteSettingsBehavior], |
| 22 |
| 23 properties: { |
| 24 /** |
| 25 * Preferences state. |
| 26 */ |
| 27 prefs: { |
| 28 type: Object, |
| 29 notify: true, |
| 30 }, |
| 31 |
| 32 /** |
| 33 * The origin that was selected by the user in the dropdown list. |
| 34 */ |
| 35 selectedOrigin: { |
| 36 type: String, |
| 37 notify: true, |
| 38 }, |
| 39 |
| 40 /** |
| 41 * Array of sites to display in the widget. |
| 42 */ |
| 43 sites_: { |
| 44 type: Array, |
| 45 value: function() { return []; }, |
| 46 observer: 'onDataChanged_', |
| 47 }, |
| 48 |
| 49 /** |
| 50 * The ID of the category this widget is displaying data for. |
| 51 * See site_settings/constants.js for possible values. |
| 52 */ |
| 53 category: Number, |
| 54 |
| 55 /** |
| 56 * The type of category this widget is displaying data for. Normally |
| 57 * either ALLOW or BLOCK, representing which sites are allowed or blocked |
| 58 * respectively. |
| 59 */ |
| 60 categorySubtype: Number, |
| 61 |
| 62 /** |
| 63 * Represents the state of the main toggle shown for the category. For |
| 64 * example, the Location category can be set to Block/Ask so false, in that |
| 65 * case, represents Block and true represents Ask. |
| 66 */ |
| 67 categoryEnabled: { |
| 68 type: Boolean, |
| 69 observer: 'onDataChanged_', |
| 70 }, |
| 71 |
| 72 /** |
| 73 * Whether to show the Allow action in the action menu. |
| 74 */ |
| 75 showAllowAction_: Boolean, |
| 76 |
| 77 /** |
| 78 * Whether to show the Block action in the action menu. |
| 79 */ |
| 80 showBlockAction_: Boolean, |
| 81 |
| 82 /** |
| 83 * All possible actions in the action menu. |
| 84 */ |
| 85 actions_: { |
| 86 readOnly: true, |
| 87 type: Object, |
| 88 values: { |
| 89 ALLOW: 'Allow', |
| 90 BLOCK: 'Block', |
| 91 RESET: 'Reset', |
| 92 } |
| 93 }, |
| 94 |
| 95 i18n_: { |
| 96 readOnly: true, |
| 97 type: Object, |
| 98 value: function() { |
| 99 return { |
| 100 allowAction: loadTimeData.getString('siteSettingsActionAllow'), |
| 101 blockAction: loadTimeData.getString('siteSettingsActionBlock'), |
| 102 resetAction: loadTimeData.getString('siteSettingsActionReset'), |
| 103 }; |
| 104 }, |
| 105 }, |
| 106 }, |
| 107 |
| 108 ready: function() { |
| 109 CrSettingsPrefs.initialized.then(function() { |
| 110 this.setUpActionMenu_(); |
| 111 this.populateList_(); |
| 112 }.bind(this)); |
| 113 }, |
| 114 |
| 115 /** |
| 116 * Handles the data changing, for example when the category is flipped from |
| 117 * ALLOW to BLOCK or sites are added to the list. |
| 118 * @private |
| 119 */ |
| 120 onDataChanged_: function(newValue, oldValue) { |
| 121 this.$.category.hidden = |
| 122 !this.showSiteList_(this.sites_, this.categoryEnabled); |
| 123 }, |
| 124 |
| 125 /** |
| 126 * Handles the expanding and collapsing of the sites list. |
| 127 * @private |
| 128 */ |
| 129 onToggle_: function(e) { |
| 130 if (this.$.category.opened) |
| 131 this.$.icon.icon = 'icons:expand-less'; |
| 132 else |
| 133 this.$.icon.icon = 'icons:expand-more'; |
| 134 }, |
| 135 |
| 136 /** |
| 137 * Populate the sites list for display. |
| 138 * @private |
| 139 */ |
| 140 populateList_: function() { |
| 141 var newList = []; |
| 142 var pref = this.getPref( |
| 143 this.computeCategoryExceptionsPrefName(this.category)); |
| 144 var sites = pref.value; |
| 145 for (var origin in sites) { |
| 146 if (sites[origin].setting == this.categorySubtype) { |
| 147 var tokens = origin.split(','); |
| 148 newList.push({url: tokens[0]}); |
| 149 } |
| 150 } |
| 151 |
| 152 this.sites_ = newList; |
| 153 }, |
| 154 |
| 155 /** |
| 156 * Setup the values to use for the action menu. |
| 157 * @private |
| 158 */ |
| 159 setUpActionMenu_: function() { |
| 160 this.showAllowAction_ = |
| 161 this.categorySubtype == settings.DefaultValues.BLOCK; |
| 162 this.showBlockAction_ = |
| 163 this.categorySubtype == settings.DefaultValues.ALLOW && |
| 164 this.category != settings.ContentSettingsTypes.FULLSCREEN; |
| 165 }, |
| 166 |
| 167 /** |
| 168 * A handler for selecting a site (by clicking on the origin). |
| 169 * @private |
| 170 */ |
| 171 onOriginTap_: function(event) { |
| 172 this.selectedOrigin = event.model.item.url; |
| 173 }, |
| 174 |
| 175 /** |
| 176 * A handler for activating one of the menu action items. |
| 177 * @private |
| 178 */ |
| 179 onActionMenuIronSelect_: function(event) { |
| 180 // TODO(finnur): Implement. |
| 181 }, |
| 182 |
| 183 /** |
| 184 * Returns the appropriate header value for display. |
| 185 * @param {array<string>} siteList The list of all sites to display for this |
| 186 * category subtype. |
| 187 * @param {boolean} toggleState The state of the global toggle for this |
| 188 * category. |
| 189 * @private |
| 190 */ |
| 191 computeSiteListHeader_: function(siteList, toggleState) { |
| 192 if (this.categorySubtype == settings.DefaultValues.ALLOW) { |
| 193 return loadTimeData.getStringF( |
| 194 'titleAndCount', |
| 195 loadTimeData.getString( |
| 196 toggleState ? 'siteSettingsAllow' : 'siteSettingsExceptions'), |
| 197 siteList.length); |
| 198 } else { |
| 199 return loadTimeData.getStringF( |
| 200 'titleAndCount', |
| 201 loadTimeData.getString('siteSettingsBlock'), |
| 202 siteList.length); |
| 203 } |
| 204 }, |
| 205 |
| 206 /** |
| 207 * Returns true if this widget is showing the allow list. |
| 208 * @private |
| 209 */ |
| 210 isAllowList_: function() { |
| 211 return this.categorySubtype == settings.DefaultValues.ALLOW; |
| 212 }, |
| 213 |
| 214 /** |
| 215 * Returns whether to show the site list. |
| 216 * @param {array} siteList The list of all sites to display for this category |
| 217 * subtype. |
| 218 * @param {boolean} toggleState The state of the global toggle for this |
| 219 * category. |
| 220 * @private |
| 221 */ |
| 222 showSiteList_: function(siteList, toggleState) { |
| 223 if (siteList.length == 0) |
| 224 return false; |
| 225 // The Block list is only shown when the category is set to Allow since it |
| 226 // is redundant to also list all the sites that are blocked. |
| 227 if (this.isAllowList_()) |
| 228 return true; |
| 229 |
| 230 return toggleState; |
| 231 }, |
| 232 |
| 233 /** |
| 234 * Returns the icon to use for a given site. |
| 235 * @param {string} url The url of the site to fetch the icon for. |
| 236 * @private |
| 237 */ |
| 238 computeSiteIcon_: function(url) { |
| 239 // TODO(finnur): For now, we're returning a placeholder image for each site |
| 240 // but the actual favicon for each site will need to be returned. |
| 241 return 'communication:message'; |
| 242 }, |
| 243 }); |
OLD | NEW |