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