Chromium Code Reviews| 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 * 'cr-settings-site-list' is the widget that shows Allowed and Blocked sites. | |
| 8 * | |
| 9 * Example: | |
| 10 * | |
| 11 * <cr-settings-site-list | |
| 12 * category="[[category]]" | |
| 13 * categories="[[categories]]" | |
| 14 * category-subtype="[[allowOrBlock.BLOCK]]" | |
| 15 * category-subtypes="[[allowOrBlock]]> | |
| 16 * </cr-settings-site-list> | |
| 17 * ... other pages ... | |
|
Dan Beam
2015/10/10 01:27:40
indent weird
Finnur
2015/10/15 15:46:33
Done.
| |
| 18 * | |
| 19 * @group Chrome Settings Elements | |
| 20 * @element cr-settings-site-list | |
| 21 */ | |
| 22 Polymer({ | |
| 23 is: 'cr-settings-site-list', | |
| 24 | |
| 25 properties: { | |
| 26 /** | |
| 27 * Array of sites to display in the widget. | |
| 28 */ | |
| 29 siteList_: { | |
| 30 type: Array, | |
| 31 }, | |
| 32 | |
| 33 /** | |
| 34 * The ID of the category this widget is displaying data for. | |
| 35 * See |categories| for possible values. | |
| 36 */ | |
| 37 category: { | |
| 38 type: Number, | |
| 39 }, | |
| 40 | |
| 41 /** | |
| 42 * An enum containing all the possible category numbers. Corresponds to | |
| 43 * the values found in the ContentSettingsType. | |
| 44 */ | |
| 45 categories: { | |
| 46 type: Object, | |
| 47 }, | |
|
Dan Beam
2015/10/10 01:27:40
can this be removed?
Finnur
2015/10/15 15:46:33
Done.
| |
| 48 | |
| 49 /** | |
| 50 * The type of category this widget is displaying data for. Normally | |
| 51 * either ALLOW or BLOCK, representing which sites are allowed or blocked | |
| 52 * respectively. | |
| 53 */ | |
| 54 categorySubtype: { | |
| 55 type: Number, | |
| 56 }, | |
| 57 | |
| 58 /** | |
| 59 * An enum containing the list of all possible category subtypes. | |
| 60 */ | |
| 61 categorySubtypes: { | |
| 62 type: Object, | |
| 63 }, | |
|
Dan Beam
2015/10/10 01:27:40
do we need this?
Finnur
2015/10/15 15:46:33
Done.
| |
| 64 | |
| 65 /** | |
| 66 * What the main toggle for the category is set to (the global default if | |
|
Dan Beam
2015/10/10 01:27:40
i still have no idea what this means
Finnur
2015/10/15 15:46:33
Sorry, forgot to update this comment, only did so
| |
| 67 * no other policy is in effect). | |
| 68 */ | |
| 69 toggleState_: { | |
| 70 type: Boolean, | |
| 71 value: false, | |
| 72 }, | |
| 73 | |
| 74 /** | |
| 75 * The site that was selected by the user in the dropdown list. | |
| 76 */ | |
| 77 selectedOrigin: { | |
|
Dan Beam
2015/10/10 01:27:40
siteOrigin?
Finnur
2015/10/15 15:46:33
I kind of like your previous suggestion better (se
| |
| 78 type: String, | |
| 79 notify: true, | |
| 80 }, | |
| 81 | |
| 82 /** | |
| 83 * Whether to show the Allow action in the action menu. | |
| 84 */ | |
| 85 showAllowAction_: { | |
| 86 type: Boolean, | |
| 87 }, | |
| 88 | |
| 89 /** | |
| 90 * Whether to show the Block action in the action menu. | |
| 91 */ | |
| 92 showBlockAction_: { | |
| 93 type: Boolean, | |
| 94 }, | |
| 95 | |
| 96 /** | |
| 97 * The label to show for the Allow action menu item. | |
| 98 */ | |
| 99 allowActionLabel_: { | |
| 100 type: String, | |
| 101 }, | |
| 102 | |
| 103 /** | |
| 104 * The label to show for the Block action menu item. | |
| 105 */ | |
| 106 blockActionLabel_: { | |
| 107 type: String, | |
| 108 }, | |
| 109 | |
| 110 /** | |
| 111 * The label to show for the Reset action menu item. | |
| 112 */ | |
| 113 resetActionLabel_: { | |
| 114 type: String, | |
| 115 }, | |
|
Dan Beam
2015/10/10 01:27:40
for all these Label_*, can we do 1 of 2 things:
a
Finnur
2015/10/15 15:46:33
Oooh, I like that idea. Converted to b).
| |
| 116 }, | |
| 117 | |
| 118 ready: function() { | |
| 119 // By default we hide and only appear if there's something to show. | |
| 120 this.hidden = true; | |
|
Dan Beam
2015/10/10 01:27:40
move this to the template's HTML
Finnur
2015/10/15 15:46:33
Done.
| |
| 121 | |
| 122 this.setupActionMenu_(); | |
| 123 chrome.send('fetchContentSettingsData', | |
| 124 [this.category, this.categorySubtype == this.categorySubtypes.ALLOW]); | |
| 125 }, | |
| 126 | |
| 127 attached: function() { | |
| 128 var self = this; | |
| 129 if (this.categorySubtype == this.categorySubtypes.ALLOW) { | |
| 130 cr.define('Settings', function() { | |
| 131 return { | |
| 132 receiveAllowedData: function() { | |
| 133 return self.receiveSiteList_.apply(self, arguments); | |
| 134 }, | |
| 135 }; | |
| 136 }); | |
| 137 } else { | |
| 138 cr.define('Settings', function() { | |
| 139 return { | |
| 140 receiveBlockedData: function() { | |
| 141 return self.receiveSiteList_.apply(self, arguments); | |
| 142 }, | |
| 143 }; | |
| 144 }); | |
| 145 } | |
| 146 }, | |
| 147 | |
| 148 /** | |
| 149 * Setup the values to use for the action menu. | |
| 150 * @private | |
| 151 */ | |
| 152 setupActionMenu_: function() { | |
| 153 this.showAllowAction_ = this.categorySubtype == this.categorySubtypes.BLOCK; | |
| 154 this.showBlockAction_ = | |
| 155 this.categorySubtype == this.categorySubtypes.ALLOW && | |
| 156 this.category != this.categories.FULLSCREEN; | |
| 157 | |
| 158 this.allowActionLabel_ = loadTimeData.getString('siteSettingsActionAllow'); | |
| 159 this.blockActionLabel_ = loadTimeData.getString('siteSettingsActionBlock'); | |
| 160 this.resetActionLabel_ = loadTimeData.getString('siteSettingsActionReset'); | |
| 161 }, | |
| 162 | |
| 163 /** | |
| 164 * Receive the site list and the toggle state (from the native level). | |
| 165 * @param {array} siteList The list of all sites to display for this category | |
|
Dan Beam
2015/10/10 01:27:40
Array preferably with types, i.e. Array<string>
a
Finnur
2015/10/15 15:46:33
Done.
Need to figure out the closure compiling th
| |
| 166 * subtype. | |
| 167 * @param {boolean} toggleState The state of the global toggle for this | |
| 168 * category. | |
| 169 * @private | |
| 170 */ | |
| 171 receiveSiteList_: function(siteList, toggleState) { | |
| 172 this.siteList_ = siteList; | |
| 173 this.toggleState_ = toggleState; | |
| 174 this.hidden = !this.showSiteList_(siteList, toggleState); | |
| 175 }, | |
| 176 | |
| 177 /** | |
| 178 * A handler for selecting a site (by clicking on the name). | |
| 179 * @private | |
| 180 */ | |
| 181 handleClick_: function(event) { | |
| 182 this.selectedOrigin = event.model.item.url; | |
| 183 }, | |
| 184 | |
| 185 /** | |
| 186 * A handler for activating one of the menu action items. | |
| 187 * @private | |
| 188 */ | |
| 189 selectAction_: function(event) { | |
| 190 // TODO(finnur): Implement. | |
| 191 }, | |
| 192 | |
| 193 /** | |
| 194 * Returns the appropriate header value for display. | |
| 195 * @param {array} siteList The list of all sites to display for this category | |
| 196 * subtype. | |
| 197 * @param {boolean} toggleState The state of the global toggle for this | |
| 198 * category. | |
| 199 * @private | |
| 200 */ | |
| 201 computeSiteListHeader_: function(siteList, toggleState) { | |
| 202 if (this.categorySubtype == this.categorySubtypes.ALLOW) { | |
| 203 return loadTimeData.getStringF( | |
| 204 'titleAndCount', | |
| 205 loadTimeData.getString( | |
| 206 toggleState ? 'siteSettingsAllow' : 'siteSettingsExceptions'), | |
| 207 siteList.length); | |
| 208 } else { | |
| 209 return loadTimeData.getStringF( | |
| 210 'titleAndCount', | |
| 211 loadTimeData.getString('siteSettingsBlock'), | |
| 212 siteList.length); | |
| 213 } | |
| 214 }, | |
| 215 | |
| 216 /** | |
| 217 * Returns true if this widget is showing the allow list. | |
| 218 * @private | |
| 219 */ | |
| 220 isAllowList_: function() { | |
| 221 return this.categorySubtype == this.categorySubtypes.ALLOW; | |
| 222 }, | |
| 223 | |
| 224 /** | |
| 225 * Returns whether to show the site list. | |
| 226 * @param {array} siteList The list of all sites to display for this category | |
| 227 * subtype. | |
| 228 * @param {boolean} toggleState The state of the global toggle for this | |
| 229 * category. | |
| 230 * @private | |
| 231 */ | |
| 232 showSiteList_: function(siteList, toggleState) { | |
| 233 if (this.isAllowList_()) | |
| 234 return siteList.length > 0; | |
| 235 else | |
| 236 return siteList.length > 0 && toggleState; | |
| 237 }, | |
| 238 | |
| 239 /** | |
| 240 * Returns the icon to use for a given site. | |
| 241 * @param {string} url The url of the site to fetch the icon for. | |
| 242 * @private | |
| 243 */ | |
| 244 computeSiteIcon_: function(url) { | |
| 245 return 'communication:message'; // TODO(finnur): Implement actual favicons. | |
|
Dan Beam
2015/10/10 01:27:40
favicons are the icons you see next to the title o
Finnur
2015/10/15 15:46:33
I am aware of that, as evident by the fact that I
Dan Beam
2015/10/19 07:24:27
what I'm saying is that this comment seems as if t
Finnur
2015/10/19 13:53:58
Oh, I see. Good point. Changed.
| |
| 246 }, | |
| 247 | |
| 248 }); | |
| OLD | NEW |