OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 /** @const */ var Page = cr.ui.pageManager.Page; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
9 | 9 |
10 ///////////////////////////////////////////////////////////////////////////// | 10 ///////////////////////////////////////////////////////////////////////////// |
11 // WebsiteSettingsManager class: | 11 // WebsiteSettingsManager class: |
12 | 12 |
13 /** | 13 /** |
14 * Encapsulated handling of the website settings page. | 14 * Encapsulated handling of the website settings page. |
15 * @constructor | 15 * @constructor |
16 */ | 16 */ |
17 function WebsiteSettingsManager() { | 17 function WebsiteSettingsManager() { |
18 Page.call(this, 'websiteSettings', | 18 Page.call(this, 'websiteSettings', |
19 loadTimeData.getString('websitesOptionsPageTabTitle'), | 19 loadTimeData.getString('websitesOptionsPageTabTitle'), |
20 'website-settings-page'); | 20 'website-settings-page'); |
21 | |
Bernhard Bauer
2014/09/09 08:56:21
Nit: remove one blank line.
Daniel Nishi
2014/09/09 16:11:56
Done.
| |
22 | |
23 // Lookup table to generate the i18n strings. | |
24 this.permissionsLookup = { | |
Bernhard Bauer
2014/09/09 08:56:21
This can probably be made a constant in a var scop
Daniel Nishi
2014/09/09 16:11:56
Done.
| |
25 'geolocation': 'location_', | |
26 'notifications': 'notifications_', | |
27 'media-stream': 'mediaStream', | |
28 'cookies': 'cookies_', | |
29 'multiple-automatic-downloads': 'multiple-automatic-downloads_', | |
30 'images': 'images_', | |
31 'plugins': 'plugins_', | |
32 'popups': 'popups_', | |
33 'javascript': 'javascript_' | |
34 }; | |
21 } | 35 } |
22 | 36 |
23 cr.addSingletonGetter(WebsiteSettingsManager); | 37 cr.addSingletonGetter(WebsiteSettingsManager); |
24 | 38 |
25 WebsiteSettingsManager.prototype = { | 39 WebsiteSettingsManager.prototype = { |
26 __proto__: Page.prototype, | 40 __proto__: Page.prototype, |
27 | 41 |
28 /** | 42 /** |
29 * The saved allowed origins list. | 43 * The saved allowed origins list. |
30 * @type {OriginList} | 44 * @type {OriginList} |
(...skipping 14 matching lines...) Expand all Loading... | |
45 | 59 |
46 $('website-settings-overlay-confirm').onclick = | 60 $('website-settings-overlay-confirm').onclick = |
47 PageManager.closeOverlay.bind(PageManager); | 61 PageManager.closeOverlay.bind(PageManager); |
48 | 62 |
49 $('resourceType').onchange = function(event) { | 63 $('resourceType').onchange = function(event) { |
50 var target = event.target; | 64 var target = event.target; |
51 assert(target.tagName == 'SELECT'); | 65 assert(target.tagName == 'SELECT'); |
52 WebsiteSettingsManager.getInstance().updatePage_(target.value); | 66 WebsiteSettingsManager.getInstance().updatePage_(target.value); |
53 }; | 67 }; |
54 | 68 |
69 $('global-setting').onchange = function(event) { | |
70 chrome.send('setDefaultContentSetting', [this.value]); | |
71 }; | |
72 | |
55 var searchBox = $('website-settings-search-box'); | 73 var searchBox = $('website-settings-search-box'); |
56 searchBox.addEventListener('search', | 74 searchBox.addEventListener('search', |
57 this.handleSearchQueryChange_.bind(this)); | 75 this.handleSearchQueryChange_.bind(this)); |
58 | 76 |
59 searchBox.onkeydown = function(e) { | 77 searchBox.onkeydown = function(e) { |
60 if (e.keyIdentifier == 'Enter') | 78 if (e.keyIdentifier == 'Enter') |
61 e.preventDefault(); | 79 e.preventDefault(); |
62 }; | 80 }; |
63 | 81 |
64 this.createOriginsList_(); | 82 this.createOriginsList_(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 */ | 185 */ |
168 handleSearchQueryChange_: function(e) { | 186 handleSearchQueryChange_: function(e) { |
169 if (this.queryDelayTimerId_) | 187 if (this.queryDelayTimerId_) |
170 window.clearTimeout(this.queryDelayTimerId_); | 188 window.clearTimeout(this.queryDelayTimerId_); |
171 | 189 |
172 this.queryDelayTimerId_ = window.setTimeout(this.searchOrigins.bind(this), | 190 this.queryDelayTimerId_ = window.setTimeout(this.searchOrigins.bind(this), |
173 160); | 191 160); |
174 }, | 192 }, |
175 | 193 |
176 /** | 194 /** |
195 * Sets the default content setting dropdown on the page to the current | |
196 * default. | |
197 * @param {!Object} dict A dictionary with the management and value of the | |
198 * default setting for the last selected content setting.. | |
199 */ | |
200 updateDefault: function(dict) { | |
201 // TODO(dhnishi): Remove duplicate default handling in the Content | |
202 // Settings page and here. | |
203 var managedBy = dict.managedBy; | |
204 var controlledBy = managedBy == 'policy' || managedBy == 'extension' ? | |
205 managedBy : null; | |
206 $('global-setting').disabled = (managedBy != 'default'); | |
207 | |
208 var options = $('global-setting').options; | |
209 for (var i = 0; i < options.length; i++) { | |
210 if (options[i].value == dict.value) { | |
211 options.selectedIndex = i; | |
212 } | |
213 } | |
214 }, | |
215 | |
216 /** | |
177 * Updates the page with the given content setting or resource name's | 217 * Updates the page with the given content setting or resource name's |
178 * information. | 218 * information. |
179 * @param {string} typeName The name of the content setting or resource. | 219 * @param {string} typeName The name of the content setting or resource. |
180 */ | 220 */ |
181 updatePage_: function(typeName) { | 221 updatePage_: function(typeName) { |
182 if (typeName == 'storage') | 222 if (typeName == 'storage') |
183 chrome.send('updateLocalStorage'); | 223 chrome.send('updateLocalStorage'); |
184 else if (typeName == 'battery') | 224 else if (typeName == 'battery') |
185 chrome.send('updateBatteryUsage'); | 225 chrome.send('updateBatteryUsage'); |
186 else | 226 else |
187 chrome.send('updateOrigins', [typeName]); | 227 chrome.send('updateOrigins', [typeName]); |
228 | |
229 var permissions = ['allow', 'ask', 'block']; | |
230 if (typeName == 'media-stream') { | |
231 permissions = ['Allow', 'Ask', 'Block']; | |
Bernhard Bauer
2014/09/09 08:56:21
I would rather fix this up in ContentSettingsHandl
Daniel Nishi
2014/09/09 16:11:56
I converted over the Content Setting permission st
| |
232 } | |
233 | |
234 var options = $('global-setting').options; | |
235 options.length = 0; | |
236 var permissionString = | |
237 this.permissionsLookup[typeName]; | |
238 for (var i = 0; i < permissions.length; i++) { | |
239 var valueId = permissionString + permissions[i]; | |
240 if (loadTimeData.valueExists(valueId)) { | |
241 var loadString = loadTimeData.getString(valueId); | |
242 if (loadString != '') | |
Bernhard Bauer
2014/09/09 08:56:21
Do you actually need this check?
Daniel Nishi
2014/09/09 16:11:56
Nope.
Removed.
| |
243 options.add(new Option(loadTimeData.getString(valueId), | |
Bernhard Bauer
2014/09/09 08:56:21
You can use loadString here.
Also, looking at thi
Daniel Nishi
2014/09/09 16:11:56
Eliminated the use of an intermediate variable all
| |
244 permissions[i].toLowerCase())); | |
245 } | |
246 } | |
247 if (options.length == 0) { | |
248 $('website-settings-global-controls').hidden = true; | |
249 } | |
250 else { | |
Bernhard Bauer
2014/09/09 08:56:21
Nit: Move this to the same line as the closing bra
Daniel Nishi
2014/09/09 16:11:56
Done.
| |
251 $('website-settings-global-controls').hidden = false; | |
252 chrome.send('updateDefaultSetting'); | |
253 } | |
188 } | 254 } |
189 }; | 255 }; |
190 | 256 |
191 WebsiteSettingsManager.populateOrigins = function(allowedDict, blockedDict) { | 257 WebsiteSettingsManager.populateOrigins = function(allowedDict, blockedDict) { |
Bernhard Bauer
2014/09/09 08:56:21
It might start making sense to create these forwar
Daniel Nishi
2014/09/09 16:11:56
Looking at that made me realize one of these funct
| |
192 WebsiteSettingsManager.getInstance().populateOrigins(allowedDict, | 258 WebsiteSettingsManager.getInstance().populateOrigins(allowedDict, |
193 blockedDict); | 259 blockedDict); |
194 }; | 260 }; |
195 | 261 |
196 WebsiteSettingsManager.showEditPage = function(url) { | 262 WebsiteSettingsManager.showEditPage = function(url) { |
197 WebsiteSettingsEditor.getInstance().populatePage(url); | 263 WebsiteSettingsEditor.getInstance().populatePage(url); |
198 }; | 264 }; |
199 | 265 |
266 WebsiteSettingsManager.updateDefault = function(dict) { | |
267 WebsiteSettingsManager.getInstance().updateDefault(dict); | |
268 }; | |
269 | |
200 // Export | 270 // Export |
201 return { | 271 return { |
202 WebsiteSettingsManager: WebsiteSettingsManager | 272 WebsiteSettingsManager: WebsiteSettingsManager |
203 }; | 273 }; |
204 }); | 274 }); |
OLD | NEW |