OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.contentSettings', function() { | 5 cr.define('options.managedUserSettings', function() { |
6 /** @const */ var ControlledSettingIndicator = | 6 /** @const */ var ControlledSettingIndicator = |
7 options.ControlledSettingIndicator; | 7 options.ControlledSettingIndicator; |
8 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; | 8 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; |
9 /** @const */ var InlineEditableItem = options.InlineEditableItem; | 9 /** @const */ var InlineEditableItem = options.InlineEditableItem; |
10 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 10 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
11 | 11 |
12 /** | 12 /** |
13 * Creates a new exceptions list item. | 13 * Creates a new exceptions list item. |
14 * | 14 * |
15 * @param {string} contentType The type of the list. | |
James Hawkins
2013/04/02 15:57:33
What is up with all the code removal in this file?
Sergiu
2013/04/02 17:14:09
This is Rietveld being a bit confused, I picked up
Bernhard Bauer
2013/04/02 17:18:55
To be exact, this is due to the output of git diff
James Hawkins
2013/04/02 17:19:09
OK. I'm very concerned about how much code is now
| |
16 * @param {string} mode The browser mode, 'otr' or 'normal'. | |
17 * @param {boolean} enableAskOption Whether to show an 'ask every time' | |
18 * option in the select. | |
19 * @param {Object} exception A dictionary that contains the data of the | 15 * @param {Object} exception A dictionary that contains the data of the |
20 * exception. | 16 * exception. |
21 * @constructor | 17 * @constructor |
22 * @extends {options.InlineEditableItem} | 18 * @extends {options.InlineEditableItem} |
23 */ | 19 */ |
24 function ExceptionsListItem(contentType, mode, enableAskOption, exception) { | 20 function ExceptionsListItem(exception) { |
25 var el = cr.doc.createElement('div'); | 21 var el = cr.doc.createElement('div'); |
26 el.mode = mode; | 22 el.contentType = 'manual-exceptions'; |
27 el.contentType = contentType; | |
28 el.enableAskOption = enableAskOption; | |
29 el.dataItem = exception; | 23 el.dataItem = exception; |
30 el.__proto__ = ExceptionsListItem.prototype; | 24 el.__proto__ = ExceptionsListItem.prototype; |
31 el.decorate(); | 25 el.decorate(); |
32 | 26 |
33 return el; | 27 return el; |
34 } | 28 } |
35 | 29 |
36 ExceptionsListItem.prototype = { | 30 ExceptionsListItem.prototype = { |
37 __proto__: InlineEditableItem.prototype, | 31 __proto__: InlineEditableItem.prototype, |
38 | 32 |
(...skipping 24 matching lines...) Expand all Loading... | |
63 this.contentElement.appendChild(settingLabel); | 57 this.contentElement.appendChild(settingLabel); |
64 this.settingLabel = settingLabel; | 58 this.settingLabel = settingLabel; |
65 } | 59 } |
66 | 60 |
67 // Setting select element for edit mode. | 61 // Setting select element for edit mode. |
68 var select = cr.doc.createElement('select'); | 62 var select = cr.doc.createElement('select'); |
69 var optionAllow = cr.doc.createElement('option'); | 63 var optionAllow = cr.doc.createElement('option'); |
70 optionAllow.textContent = loadTimeData.getString('allowException'); | 64 optionAllow.textContent = loadTimeData.getString('allowException'); |
71 optionAllow.value = 'allow'; | 65 optionAllow.value = 'allow'; |
72 select.appendChild(optionAllow); | 66 select.appendChild(optionAllow); |
73 | 67 var optionBlock = cr.doc.createElement('option'); |
74 if (this.enableAskOption) { | 68 optionBlock.textContent = loadTimeData.getString('blockException'); |
75 var optionAsk = cr.doc.createElement('option'); | 69 optionBlock.value = 'block'; |
76 optionAsk.textContent = loadTimeData.getString('askException'); | 70 select.appendChild(optionBlock); |
77 optionAsk.value = 'ask'; | |
78 select.appendChild(optionAsk); | |
79 } | |
80 | |
81 if (this.contentType == 'cookies') { | |
82 var optionSession = cr.doc.createElement('option'); | |
83 optionSession.textContent = loadTimeData.getString('sessionException'); | |
84 optionSession.value = 'session'; | |
85 select.appendChild(optionSession); | |
86 } | |
87 | |
88 if (this.contentType != 'fullscreen') { | |
89 var optionBlock = cr.doc.createElement('option'); | |
90 optionBlock.textContent = loadTimeData.getString('blockException'); | |
91 optionBlock.value = 'block'; | |
92 select.appendChild(optionBlock); | |
93 } | |
94 | |
95 if (this.isEmbeddingRule()) { | |
96 this.patternLabel.classList.add('sublabel'); | |
97 this.editable = false; | |
98 } | |
99 | |
100 if (this.setting == 'default') { | |
101 // Items that don't have their own settings (parents of 'embedded on' | |
102 // items) aren't deletable. | |
103 this.deletable = false; | |
104 this.editable = false; | |
105 } | |
106 | 71 |
107 this.contentElement.appendChild(select); | 72 this.contentElement.appendChild(select); |
108 select.className = 'exception-setting'; | 73 select.className = 'exception-setting'; |
109 if (this.pattern) | 74 if (this.pattern) |
110 select.setAttribute('displaymode', 'edit'); | 75 select.setAttribute('displaymode', 'edit'); |
111 | 76 |
112 if (this.contentType == 'media-stream') { | |
113 this.settingLabel.classList.add('media-audio-setting'); | |
114 | |
115 var videoSettingLabel = cr.doc.createElement('span'); | |
116 videoSettingLabel.textContent = this.videoSettingForDisplay(); | |
117 videoSettingLabel.className = 'exception-setting'; | |
118 videoSettingLabel.classList.add('media-video-setting'); | |
119 videoSettingLabel.setAttribute('displaymode', 'static'); | |
120 this.contentElement.appendChild(videoSettingLabel); | |
121 } | |
122 | |
123 // Used to track whether the URL pattern in the input is valid. | 77 // Used to track whether the URL pattern in the input is valid. |
124 // This will be true if the browser process has informed us that the | 78 // This will be true if the browser process has informed us that the |
125 // current text in the input is valid. Changing the text resets this to | 79 // current text in the input is valid. Changing the text resets this to |
126 // false, and getting a response from the browser sets it back to true. | 80 // false, and getting a response from the browser sets it back to true. |
127 // It starts off as false for empty string (new exceptions) or true for | 81 // It starts off as false for empty string (new exceptions) or true for |
128 // already-existing exceptions (which we assume are valid). | 82 // already-existing exceptions (which we assume are valid). |
129 this.inputValidityKnown = this.pattern; | 83 this.inputValidityKnown = this.pattern; |
130 // This one tracks the actual validity of the pattern in the input. This | 84 // This one tracks the actual validity of the pattern in the input. This |
131 // starts off as true so as not to annoy the user when he adds a new and | 85 // starts off as true so as not to annoy the user when he adds a new and |
132 // empty input. | 86 // empty input. |
133 this.inputIsValid = true; | 87 this.inputIsValid = true; |
134 | 88 |
135 this.input = input; | 89 this.input = input; |
136 this.select = select; | 90 this.select = select; |
137 | 91 |
138 this.updateEditables(); | 92 this.updateEditables(); |
139 | 93 |
140 // Editing notifications, geolocation and media-stream is disabled for | |
141 // now. | |
142 if (this.contentType == 'notifications' || | |
143 this.contentType == 'location' || | |
144 this.contentType == 'media-stream') { | |
145 this.editable = false; | |
146 } | |
147 | |
148 // If the source of the content setting exception is not a user | |
149 // preference, that source controls the exception and the user cannot edit | |
150 // or delete it. | |
151 var controlledBy = | |
152 this.dataItem.source && this.dataItem.source != 'preference' ? | |
153 this.dataItem.source : null; | |
154 | |
155 if (controlledBy) { | |
156 this.setAttribute('controlled-by', controlledBy); | |
157 this.deletable = false; | |
158 this.editable = false; | |
159 } | |
160 | |
161 if (controlledBy == 'policy' || controlledBy == 'extension') { | |
162 this.querySelector('.row-delete-button').hidden = true; | |
163 var indicator = ControlledSettingIndicator(); | |
164 indicator.setAttribute('content-exception', this.contentType); | |
165 // Create a synthetic pref change event decorated as | |
166 // CoreOptionsHandler::CreateValueForPref() does. | |
167 var event = new cr.Event(this.contentType); | |
168 event.value = { controlledBy: controlledBy }; | |
169 indicator.handlePrefChange(event); | |
170 this.appendChild(indicator); | |
171 } | |
172 | |
173 // If the exception comes from a hosted app, display the name and the | |
174 // icon of the app. | |
175 if (controlledBy == 'HostedApp') { | |
176 this.title = | |
177 loadTimeData.getString('set_by') + ' ' + this.dataItem.appName; | |
178 var button = this.querySelector('.row-delete-button'); | |
179 // Use the host app's favicon (16px, match bigger size). | |
180 // See c/b/ui/webui/extensions/extension_icon_source.h | |
181 // for a description of the chrome://extension-icon URL. | |
182 button.style.backgroundImage = | |
183 'url(\'chrome://extension-icon/' + this.dataItem.appId + '/16/1\')'; | |
184 } | |
185 | |
186 var listItem = this; | 94 var listItem = this; |
187 // Handle events on the editable nodes. | 95 // Handle events on the editable nodes. |
188 input.oninput = function(event) { | 96 input.oninput = function(event) { |
189 listItem.inputValidityKnown = false; | 97 listItem.inputValidityKnown = false; |
190 chrome.send('checkExceptionPatternValidity', | 98 chrome.send('checkManualExceptionValidity', |
191 [listItem.contentType, listItem.mode, input.value]); | 99 [input.value]); |
192 }; | 100 }; |
193 | 101 |
194 // Listen for edit events. | 102 // Listen for edit events. |
195 this.addEventListener('canceledit', this.onEditCancelled_); | 103 this.addEventListener('canceledit', this.onEditCancelled_); |
196 this.addEventListener('commitedit', this.onEditCommitted_); | 104 this.addEventListener('commitedit', this.onEditCommitted_); |
197 }, | 105 }, |
198 | 106 |
199 isEmbeddingRule: function() { | |
200 return this.dataItem.embeddingOrigin && | |
201 this.dataItem.embeddingOrigin !== this.dataItem.origin; | |
202 }, | |
203 | |
204 /** | 107 /** |
205 * The pattern (e.g., a URL) for the exception. | 108 * The pattern (e.g., a URL) for the exception. |
206 * | 109 * |
207 * @type {string} | 110 * @type {string} |
208 */ | 111 */ |
209 get pattern() { | 112 get pattern() { |
210 if (!this.isEmbeddingRule()) { | 113 return this.dataItem.pattern; |
211 return this.dataItem.origin; | |
212 } else { | |
213 return loadTimeData.getStringF('embeddedOnHost', | |
214 this.dataItem.embeddingOrigin); | |
215 } | |
216 | |
217 return this.dataItem.displayPattern; | |
218 }, | 114 }, |
219 set pattern(pattern) { | 115 set pattern(pattern) { |
220 if (!this.editable) | 116 if (!this.editable) |
221 console.error('Tried to change uneditable pattern'); | 117 console.error('Tried to change uneditable pattern'); |
222 | 118 |
223 this.dataItem.displayPattern = pattern; | 119 this.dataItem.pattern = pattern; |
224 }, | 120 }, |
225 | 121 |
226 /** | 122 /** |
227 * The setting (allow/block) for the exception. | 123 * The setting (allow/block) for the exception. |
228 * | 124 * |
229 * @type {string} | 125 * @type {string} |
230 */ | 126 */ |
231 get setting() { | 127 get setting() { |
232 return this.dataItem.setting; | 128 return this.dataItem.setting; |
233 }, | 129 }, |
234 set setting(setting) { | 130 set setting(setting) { |
235 this.dataItem.setting = setting; | 131 this.dataItem.setting = setting; |
236 }, | 132 }, |
237 | 133 |
238 /** | 134 /** |
239 * Gets a human-readable setting string. | 135 * Gets a human-readable setting string. |
240 * | 136 * |
241 * @return {string} The display string. | 137 * @return {string} The display string. |
242 */ | 138 */ |
243 settingForDisplay: function() { | 139 settingForDisplay: function() { |
244 return this.getDisplayStringForSetting(this.setting); | 140 return this.getDisplayStringForSetting(this.setting); |
245 }, | 141 }, |
246 | 142 |
247 /** | 143 /** |
248 * media video specific function. | |
249 * Gets a human-readable video setting string. | |
250 * | |
251 * @return {string} The display string. | |
252 */ | |
253 videoSettingForDisplay: function() { | |
254 return this.getDisplayStringForSetting(this.dataItem.video); | |
255 }, | |
256 | |
257 /** | |
258 * Gets a human-readable display string for setting. | 144 * Gets a human-readable display string for setting. |
259 * | 145 * |
260 * @param {string} setting The setting to be displayed. | 146 * @param {string} setting The setting to be displayed. |
261 * @return {string} The display string. | 147 * @return {string} The display string. |
262 */ | 148 */ |
263 getDisplayStringForSetting: function(setting) { | 149 getDisplayStringForSetting: function(setting) { |
264 if (setting == 'allow') | 150 if (setting == 'allow') |
265 return loadTimeData.getString('allowException'); | 151 return loadTimeData.getString('allowException'); |
266 else if (setting == 'block') | 152 else if (setting == 'block') |
267 return loadTimeData.getString('blockException'); | 153 return loadTimeData.getString('blockException'); |
268 else if (setting == 'ask') | |
269 return loadTimeData.getString('askException'); | |
270 else if (setting == 'session') | |
271 return loadTimeData.getString('sessionException'); | |
272 else if (setting == 'default') | |
273 return ''; | |
274 | 154 |
275 console.error('Unknown setting: [' + setting + ']'); | 155 console.error('Unknown setting: [' + setting + ']'); |
276 return ''; | 156 return ''; |
277 }, | 157 }, |
278 | 158 |
279 /** | 159 /** |
280 * Update this list item to reflect whether the input is a valid pattern. | 160 * Update this list item to reflect whether the input is a valid pattern. |
281 * | 161 * |
282 * @param {boolean} valid Whether said pattern is valid in the context of a | 162 * @param {boolean} valid Whether said pattern is valid in the context of a |
283 * content exception setting. | 163 * content exception setting. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
347 this.setPatternValid(true); | 227 this.setPatternValid(true); |
348 }, | 228 }, |
349 | 229 |
350 /** | 230 /** |
351 * Editing is complete; update the model. | 231 * Editing is complete; update the model. |
352 * | 232 * |
353 * @param {string} newPattern The pattern that the user entered. | 233 * @param {string} newPattern The pattern that the user entered. |
354 * @param {string} newSetting The setting the user chose. | 234 * @param {string} newSetting The setting the user chose. |
355 */ | 235 */ |
356 finishEdit: function(newPattern, newSetting) { | 236 finishEdit: function(newPattern, newSetting) { |
237 this.setting = newSetting; | |
357 this.patternLabel.textContent = newPattern; | 238 this.patternLabel.textContent = newPattern; |
358 this.settingLabel.textContent = this.settingForDisplay(); | 239 this.settingLabel.textContent = this.settingForDisplay(); |
359 var oldPattern = this.pattern; | 240 var oldPattern = this.pattern; |
360 this.pattern = newPattern; | 241 this.pattern = newPattern; |
361 this.setting = newSetting; | 242 var needsUpdate = false; |
362 | 243 |
363 // TODO(estade): this will need to be updated if geolocation/notifications | |
364 // become editable. | |
365 if (oldPattern != newPattern) { | 244 if (oldPattern != newPattern) { |
366 chrome.send('removeException', | 245 needsUpdate = true; |
367 [this.contentType, this.mode, oldPattern]); | 246 chrome.send('removeManualException', [oldPattern]); |
368 } | 247 } |
369 | 248 |
370 chrome.send('setException', | 249 // If only the setting is changed for this pattern and not the pattern |
371 [this.contentType, this.mode, newPattern, newSetting]); | 250 // itself then the interface is already updated so we don't need to |
251 // trigger it then processing is completed. | |
252 chrome.send('setManualException', [newPattern, newSetting, needsUpdate]); | |
372 } | 253 } |
373 }; | 254 }; |
374 | 255 |
375 /** | 256 /** |
376 * Creates a new list item for the Add New Item row, which doesn't represent | 257 * Creates a new list item for the Add New Item row, which doesn't represent |
377 * an actual entry in the exceptions list but allows the user to add new | 258 * an actual entry in the exceptions list but allows the user to add new |
378 * exceptions. | 259 * exceptions. |
379 * | 260 * |
380 * @param {string} contentType The type of the list. | |
381 * @param {string} mode The browser mode, 'otr' or 'normal'. | |
382 * @param {boolean} enableAskOption Whether to show an 'ask every time' option | |
383 * in the select. | |
384 * @constructor | 261 * @constructor |
385 * @extends {cr.ui.ExceptionsListItem} | 262 * @extends {cr.ui.ExceptionsListItem} |
386 */ | 263 */ |
387 function ExceptionsAddRowListItem(contentType, mode, enableAskOption) { | 264 function ExceptionsAddRowListItem() { |
388 var el = cr.doc.createElement('div'); | 265 var el = cr.doc.createElement('div'); |
389 el.mode = mode; | |
390 el.contentType = contentType; | |
391 el.enableAskOption = enableAskOption; | |
392 el.dataItem = []; | 266 el.dataItem = []; |
393 el.__proto__ = ExceptionsAddRowListItem.prototype; | 267 el.__proto__ = ExceptionsAddRowListItem.prototype; |
394 el.decorate(); | 268 el.decorate(); |
395 | 269 |
396 return el; | 270 return el; |
397 } | 271 } |
398 | 272 |
399 ExceptionsAddRowListItem.prototype = { | 273 ExceptionsAddRowListItem.prototype = { |
400 __proto__: ExceptionsListItem.prototype, | 274 __proto__: ExceptionsListItem.prototype, |
401 | 275 |
402 decorate: function() { | 276 decorate: function() { |
403 ExceptionsListItem.prototype.decorate.call(this); | 277 ExceptionsListItem.prototype.decorate.call(this); |
404 | 278 |
405 this.input.placeholder = | 279 this.input.placeholder = |
406 loadTimeData.getString('addNewExceptionInstructions'); | 280 loadTimeData.getString('addNewExceptionInstructions'); |
407 | 281 |
408 // Do we always want a default of allow? | 282 // Set 'Allow' as default for new entries. |
409 this.setting = 'allow'; | 283 this.setting = 'allow'; |
410 }, | 284 }, |
411 | 285 |
412 /** | 286 /** |
413 * Clear the <input> and let the placeholder text show again. | 287 * Clear the <input> and let the placeholder text show again. |
414 */ | 288 */ |
415 resetInput: function() { | 289 resetInput: function() { |
416 this.input.value = ''; | 290 this.input.value = ''; |
417 }, | 291 }, |
418 | 292 |
419 /** @override */ | 293 /** @override */ |
420 get hasBeenEdited() { | 294 get hasBeenEdited() { |
421 return this.input.value != ''; | 295 return this.input.value != ''; |
422 }, | 296 }, |
423 | 297 |
424 /** | 298 /** |
425 * Editing is complete; update the model. As long as the pattern isn't | 299 * Editing is complete; update the model. As long as the pattern isn't |
426 * empty, we'll just add it. | 300 * empty, we'll just add it. |
427 * | 301 * |
428 * @param {string} newPattern The pattern that the user entered. | 302 * @param {string} newPattern The pattern that the user entered. |
429 * @param {string} newSetting The setting the user chose. | 303 * @param {string} newSetting The setting the user chose. |
430 */ | 304 */ |
431 finishEdit: function(newPattern, newSetting) { | 305 finishEdit: function(newPattern, newSetting) { |
432 this.resetInput(); | 306 this.resetInput(); |
433 chrome.send('setException', | 307 // We're adding a new entry, update the model once that is done. |
434 [this.contentType, this.mode, newPattern, newSetting]); | 308 chrome.send('setManualException', [newPattern, newSetting, true]); |
435 }, | 309 }, |
436 }; | 310 }; |
437 | 311 |
438 /** | 312 /** |
313 * Compares two elements in the list. Removes the schema if present and then | |
314 * compares the two strings. | |
315 * @param {string} a First element to compare. | |
316 * @param {string} b Second element to compare. | |
317 * @return {int} Result of comparison between a and b. | |
318 */ | |
319 function comparePatterns(a, b) { | |
320 // Remove the schema (part before ://) if any. | |
321 var stripString = function(str) { | |
322 var indexStr = str.indexOf('://'); | |
323 if (indexStr != -1) | |
324 return str.slice(indexStr + 3); | |
325 return str; | |
326 }; | |
327 if (a) | |
328 a = stripString(a['pattern']); | |
329 if (b) | |
330 b = stripString(b['pattern']); | |
331 return this.dataModel.defaultValuesCompareFunction(a, b); | |
332 } | |
333 | |
334 /** | |
439 * Creates a new exceptions list. | 335 * Creates a new exceptions list. |
440 * | 336 * |
441 * @constructor | 337 * @constructor |
442 * @extends {cr.ui.List} | 338 * @extends {cr.ui.List} |
443 */ | 339 */ |
444 var ExceptionsList = cr.ui.define('list'); | 340 var ExceptionsList = cr.ui.define('list'); |
445 | 341 |
446 ExceptionsList.prototype = { | 342 ExceptionsList.prototype = { |
447 __proto__: InlineEditableItemList.prototype, | 343 __proto__: InlineEditableItemList.prototype, |
448 | 344 |
449 /** | 345 /** |
450 * Called when an element is decorated as a list. | 346 * Called when an element is decorated as a list. |
451 */ | 347 */ |
452 decorate: function() { | 348 decorate: function() { |
453 InlineEditableItemList.prototype.decorate.call(this); | 349 InlineEditableItemList.prototype.decorate.call(this); |
454 | 350 |
455 this.classList.add('settings-list'); | 351 this.classList.add('settings-list'); |
456 | 352 |
457 for (var parentNode = this.parentNode; parentNode; | |
458 parentNode = parentNode.parentNode) { | |
459 if (parentNode.hasAttribute('contentType')) { | |
460 this.contentType = parentNode.getAttribute('contentType'); | |
461 break; | |
462 } | |
463 } | |
464 | |
465 this.mode = this.getAttribute('mode'); | |
466 | |
467 // Whether the exceptions in this list allow an 'Ask every time' option. | |
468 this.enableAskOption = this.contentType == 'plugins'; | |
469 | |
470 this.autoExpands = true; | 353 this.autoExpands = true; |
471 this.reset(); | 354 this.reset(); |
472 }, | 355 }, |
473 | 356 |
474 /** | 357 /** |
475 * Creates an item to go in the list. | 358 * Creates an item to go in the list. |
476 * | 359 * |
477 * @param {Object} entry The element from the data model for this row. | 360 * @param {Object} entry The element from the data model for this row. |
478 */ | 361 */ |
479 createItem: function(entry) { | 362 createItem: function(entry) { |
480 if (entry) { | 363 if (entry) { |
481 return new ExceptionsListItem(this.contentType, | 364 return new ExceptionsListItem(entry); |
482 this.mode, | |
483 this.enableAskOption, | |
484 entry); | |
485 } else { | 365 } else { |
486 var addRowItem = new ExceptionsAddRowListItem(this.contentType, | 366 var addRowItem = new ExceptionsAddRowListItem(); |
487 this.mode, | |
488 this.enableAskOption); | |
489 addRowItem.deletable = false; | 367 addRowItem.deletable = false; |
490 return addRowItem; | 368 return addRowItem; |
491 } | 369 } |
492 }, | 370 }, |
493 | 371 |
494 /** | 372 /** |
495 * Sets the exceptions in the js model. | 373 * Sets the exceptions in the js model. |
496 * | 374 * |
497 * @param {Object} entries A list of dictionaries of values, each dictionary | 375 * @param {Object} entries A list of dictionaries of values, each dictionary |
498 * represents an exception. | 376 * represents an exception. |
499 */ | 377 */ |
500 setExceptions: function(entries) { | 378 setManualExceptions: function(entries) { |
501 var deleteCount = this.dataModel.length; | 379 // We don't want to remove the Add New Exception row. |
502 | 380 var deleteCount = this.dataModel.length - 1; |
503 if (this.isEditable()) { | |
504 // We don't want to remove the Add New Exception row. | |
505 deleteCount = deleteCount - 1; | |
506 } | |
507 | 381 |
508 var args = [0, deleteCount]; | 382 var args = [0, deleteCount]; |
509 args.push.apply(args, entries); | 383 args.push.apply(args, entries); |
510 this.dataModel.splice.apply(this.dataModel, args); | 384 this.dataModel.splice.apply(this.dataModel, args); |
511 }, | 385 }, |
512 | 386 |
513 /** | 387 /** |
514 * The browser has finished checking a pattern for validity. Update the list | 388 * The browser has finished checking a pattern for validity. Update the list |
515 * item to reflect this. | 389 * item to reflect this. |
516 * | 390 * |
517 * @param {string} pattern The pattern. | 391 * @param {string} pattern The pattern. |
518 * @param {bool} valid Whether said pattern is valid in the context of a | 392 * @param {bool} valid Whether said pattern is valid in the context of a |
519 * content exception setting. | 393 * content exception setting. |
520 */ | 394 */ |
521 patternValidityCheckComplete: function(pattern, valid) { | 395 patternValidityCheckComplete: function(pattern, valid) { |
522 var listItems = this.items; | 396 var listItems = this.items; |
523 for (var i = 0; i < listItems.length; i++) { | 397 for (var i = 0; i < listItems.length; i++) { |
524 var listItem = listItems[i]; | 398 var listItem = listItems[i]; |
525 // Don't do anything for messages for the item if it is not the intended | 399 // Don't do anything for messages for the item if it is not the intended |
526 // recipient, or if the response is stale (i.e. the input value has | 400 // recipient, or if the response is stale (i.e. the input value has |
527 // changed since we sent the request to analyze it). | 401 // changed since we sent the request to analyze it). |
528 if (pattern == listItem.input.value) | 402 if (pattern == listItem.input.value) |
529 listItem.setPatternValid(valid); | 403 listItem.setPatternValid(valid); |
530 } | 404 } |
531 }, | 405 }, |
532 | 406 |
533 /** | 407 /** |
534 * Returns whether the rows are editable in this list. | |
535 */ | |
536 isEditable: function() { | |
537 // Exceptions of the following lists are not editable for now. | |
538 return !(this.contentType == 'notifications' || | |
539 this.contentType == 'location' || | |
540 this.contentType == 'fullscreen' || | |
541 this.contentType == 'media-stream'); | |
542 }, | |
543 | |
544 /** | |
545 * Removes all exceptions from the js model. | 408 * Removes all exceptions from the js model. |
546 */ | 409 */ |
547 reset: function() { | 410 reset: function() { |
548 if (this.isEditable()) { | 411 // The null creates the Add New Exception row. |
549 // The null creates the Add New Exception row. | 412 this.dataModel = new ArrayDataModel([null]); |
550 this.dataModel = new ArrayDataModel([null]); | 413 |
551 } else { | 414 // Set the initial sort order. |
552 this.dataModel = new ArrayDataModel([]); | 415 this.dataModel.setCompareFunction('pattern', comparePatterns.bind(this)); |
553 } | 416 this.dataModel.sort('pattern', 'asc'); |
554 }, | 417 }, |
555 | 418 |
556 /** @override */ | 419 /** @override */ |
557 deleteItemAtIndex: function(index) { | 420 deleteItemAtIndex: function(index) { |
558 var listItem = this.getListItemByIndex(index); | 421 var listItem = this.getListItemByIndex(index); |
559 if (!listItem.deletable) | 422 if (!listItem.deletable) |
560 return; | 423 return; |
561 | 424 |
562 var dataItem = listItem.dataItem; | 425 var dataItem = listItem.dataItem; |
563 var args = [listItem.contentType]; | 426 var args = []; |
564 if (listItem.contentType == 'notifications') | 427 args.push(dataItem.pattern); |
565 args.push(dataItem.origin, dataItem.setting); | |
566 else | |
567 args.push(listItem.mode, dataItem.origin, dataItem.embeddingOrigin); | |
568 | 428 |
569 chrome.send('removeException', args); | 429 chrome.send('removeManualException', args); |
570 }, | 430 }, |
571 }; | 431 }; |
572 | 432 |
573 var OptionsPage = options.OptionsPage; | 433 var OptionsPage = options.OptionsPage; |
574 | 434 |
575 /** | 435 /** |
576 * Encapsulated handling of content settings list subpage. | 436 * Encapsulated handling of content settings list subpage. |
577 * | 437 * |
578 * @constructor | 438 * @constructor |
579 */ | 439 */ |
580 function ContentSettingsExceptionsArea() { | 440 function ManagedUserSettingsExceptionsArea() { |
581 OptionsPage.call(this, 'contentExceptions', | 441 OptionsPage.call(this, 'manualExceptions', |
582 loadTimeData.getString('contentSettingsPageTabTitle'), | 442 loadTimeData.getString('managedUserSettingsPageTabTitle'), |
583 'content-settings-exceptions-area'); | 443 'managed-user-exceptions-area'); |
584 } | 444 } |
585 | 445 |
586 cr.addSingletonGetter(ContentSettingsExceptionsArea); | 446 cr.addSingletonGetter(ManagedUserSettingsExceptionsArea); |
587 | 447 |
588 ContentSettingsExceptionsArea.prototype = { | 448 ManagedUserSettingsExceptionsArea.prototype = { |
589 __proto__: OptionsPage.prototype, | 449 __proto__: OptionsPage.prototype, |
590 | 450 |
591 initializePage: function() { | 451 initializePage: function() { |
592 OptionsPage.prototype.initializePage.call(this); | 452 OptionsPage.prototype.initializePage.call(this); |
593 | 453 |
594 var exceptionsLists = this.pageDiv.querySelectorAll('list'); | 454 var exceptionsLists = this.pageDiv.querySelectorAll('list'); |
595 for (var i = 0; i < exceptionsLists.length; i++) { | 455 for (var i = 0; i < exceptionsLists.length; i++) { |
596 options.contentSettings.ExceptionsList.decorate(exceptionsLists[i]); | 456 options.managedUserSettings.ExceptionsList.decorate(exceptionsLists[i]); |
597 } | 457 } |
598 | 458 |
599 ContentSettingsExceptionsArea.hideOTRLists(false); | 459 $('managed-user-settings-exceptions-overlay-confirm').onclick = |
600 | |
601 // If the user types in the URL without a hash, show just cookies. | |
602 this.showList('cookies'); | |
603 | |
604 $('content-settings-exceptions-overlay-confirm').onclick = | |
605 OptionsPage.closeOverlay.bind(OptionsPage); | 460 OptionsPage.closeOverlay.bind(OptionsPage); |
606 }, | 461 }, |
607 | |
608 /** | |
609 * Shows one list and hides all others. | |
610 * | |
611 * @param {string} type The content type. | |
612 */ | |
613 showList: function(type) { | |
614 var header = this.pageDiv.querySelector('h1'); | |
615 header.textContent = loadTimeData.getString(type + '_header'); | |
616 | |
617 var divs = this.pageDiv.querySelectorAll('div[contentType]'); | |
618 for (var i = 0; i < divs.length; i++) { | |
619 if (divs[i].getAttribute('contentType') == type) | |
620 divs[i].hidden = false; | |
621 else | |
622 divs[i].hidden = true; | |
623 } | |
624 | |
625 var mediaHeader = this.pageDiv.querySelector('.media-header'); | |
626 mediaHeader.hidden = type != 'media-stream'; | |
627 }, | |
628 | |
629 /** | |
630 * Called after the page has been shown. Show the content type for the | |
631 * location's hash. | |
632 */ | |
633 didShowPage: function() { | |
634 var hash = location.hash; | |
635 if (hash) | |
636 this.showList(hash.slice(1)); | |
637 }, | |
638 }; | |
639 | |
640 /** | |
641 * Called when the last incognito window is closed. | |
642 */ | |
643 ContentSettingsExceptionsArea.OTRProfileDestroyed = function() { | |
644 this.hideOTRLists(true); | |
645 }; | |
646 | |
647 /** | |
648 * Hides the incognito exceptions lists and optionally clears them as well. | |
649 * @param {boolean} clear Whether to clear the lists. | |
650 */ | |
651 ContentSettingsExceptionsArea.hideOTRLists = function(clear) { | |
652 var otrLists = document.querySelectorAll('list[mode=otr]'); | |
653 | |
654 for (var i = 0; i < otrLists.length; i++) { | |
655 otrLists[i].parentNode.hidden = true; | |
656 if (clear) | |
657 otrLists[i].reset(); | |
658 } | |
659 }; | 462 }; |
660 | 463 |
661 return { | 464 return { |
662 ExceptionsListItem: ExceptionsListItem, | 465 ExceptionsListItem: ExceptionsListItem, |
663 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 466 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
664 ExceptionsList: ExceptionsList, | 467 ExceptionsList: ExceptionsList, |
665 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | 468 ManagedUserSettingsExceptionsArea: ManagedUserSettingsExceptionsArea, |
666 }; | 469 }; |
667 }); | 470 }); |
OLD | NEW |