OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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.contentSettings', function() { |
6 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; | 6 /** @const */ var InlineEditableItemList = options.InlineEditableItemList; |
7 /** @const */ var InlineEditableItem = options.InlineEditableItem; | 7 /** @const */ var InlineEditableItem = options.InlineEditableItem; |
8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
9 | 9 |
10 /** | 10 /** |
11 * Creates a new exceptions list item. | 11 * Creates a new exceptions list item. |
| 12 * |
12 * @param {string} contentType The type of the list. | 13 * @param {string} contentType The type of the list. |
13 * @param {string} mode The browser mode, 'otr' or 'normal'. | 14 * @param {string} mode The browser mode, 'otr' or 'normal'. |
14 * @param {boolean} enableAskOption Whether to show an 'ask every time' | 15 * @param {boolean} enableAskOption Whether to show an 'ask every time' |
15 * option in the select. | 16 * option in the select. |
16 * @param {Object} exception A dictionary that contains the data of the | 17 * @param {Object} exception A dictionary that contains the data of the |
17 * exception. | 18 * exception. |
18 * @constructor | 19 * @constructor |
19 * @extends {options.InlineEditableItem} | 20 * @extends {options.InlineEditableItem} |
20 */ | 21 */ |
21 function ExceptionsListItem(contentType, mode, enableAskOption, exception) { | 22 function ExceptionsListItem(contentType, mode, enableAskOption, exception) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // This one tracks the actual validity of the pattern in the input. This | 105 // This one tracks the actual validity of the pattern in the input. This |
105 // starts off as true so as not to annoy the user when he adds a new and | 106 // starts off as true so as not to annoy the user when he adds a new and |
106 // empty input. | 107 // empty input. |
107 this.inputIsValid = true; | 108 this.inputIsValid = true; |
108 | 109 |
109 this.input = input; | 110 this.input = input; |
110 this.select = select; | 111 this.select = select; |
111 | 112 |
112 this.updateEditables(); | 113 this.updateEditables(); |
113 | 114 |
114 // Editing notifications and geolocation is disabled for now. | 115 // Editing notifications, geolocation and media-stream is disabled for |
| 116 // now. |
115 if (this.contentType == 'notifications' || | 117 if (this.contentType == 'notifications' || |
116 this.contentType == 'location') { | 118 this.contentType == 'location' || |
| 119 this.contentType == 'media-stream') { |
117 this.editable = false; | 120 this.editable = false; |
118 } | 121 } |
119 | 122 |
120 // If the source of the content setting exception is not the user | 123 // If the source of the content setting exception is not the user |
121 // preference, then the content settings exception is managed and the user | 124 // preference, then the content settings exception is managed and the user |
122 // can't edit it. | 125 // can't edit it. |
123 if (this.dataItem.source && | 126 if (this.dataItem.source && |
124 this.dataItem.source != 'preference') { | 127 this.dataItem.source != 'preference') { |
125 this.setAttribute('managedby', this.dataItem.source); | 128 this.setAttribute('managedby', this.dataItem.source); |
126 this.deletable = false; | 129 this.deletable = false; |
(...skipping 21 matching lines...) Expand all Loading... |
148 [listItem.contentType, listItem.mode, input.value]); | 151 [listItem.contentType, listItem.mode, input.value]); |
149 }; | 152 }; |
150 | 153 |
151 // Listen for edit events. | 154 // Listen for edit events. |
152 this.addEventListener('canceledit', this.onEditCancelled_); | 155 this.addEventListener('canceledit', this.onEditCancelled_); |
153 this.addEventListener('commitedit', this.onEditCommitted_); | 156 this.addEventListener('commitedit', this.onEditCommitted_); |
154 }, | 157 }, |
155 | 158 |
156 /** | 159 /** |
157 * The pattern (e.g., a URL) for the exception. | 160 * The pattern (e.g., a URL) for the exception. |
| 161 * |
158 * @type {string} | 162 * @type {string} |
159 */ | 163 */ |
160 get pattern() { | 164 get pattern() { |
161 return this.dataItem['displayPattern']; | 165 return this.dataItem['displayPattern']; |
162 }, | 166 }, |
163 set pattern(pattern) { | 167 set pattern(pattern) { |
164 this.dataItem['displayPattern'] = pattern; | 168 this.dataItem['displayPattern'] = pattern; |
165 }, | 169 }, |
166 | 170 |
167 /** | 171 /** |
168 * The setting (allow/block) for the exception. | 172 * The setting (allow/block) for the exception. |
| 173 * |
169 * @type {string} | 174 * @type {string} |
170 */ | 175 */ |
171 get setting() { | 176 get setting() { |
172 return this.dataItem['setting']; | 177 return this.dataItem['setting']; |
173 }, | 178 }, |
174 set setting(setting) { | 179 set setting(setting) { |
175 this.dataItem['setting'] = setting; | 180 this.dataItem['setting'] = setting; |
176 }, | 181 }, |
177 | 182 |
178 /** | 183 /** |
179 * Gets a human-readable setting string. | 184 * Gets a human-readable setting string. |
| 185 * |
180 * @type {string} | 186 * @type {string} |
181 */ | 187 */ |
182 settingForDisplay: function() { | 188 settingForDisplay: function() { |
183 var setting = this.setting; | 189 var setting = this.setting; |
184 if (setting == 'allow') | 190 if (setting == 'allow') |
185 return loadTimeData.getString('allowException'); | 191 return loadTimeData.getString('allowException'); |
186 else if (setting == 'block') | 192 else if (setting == 'block') |
187 return loadTimeData.getString('blockException'); | 193 return loadTimeData.getString('blockException'); |
188 else if (setting == 'ask') | 194 else if (setting == 'ask') |
189 return loadTimeData.getString('askException'); | 195 return loadTimeData.getString('askException'); |
190 else if (setting == 'session') | 196 else if (setting == 'session') |
191 return loadTimeData.getString('sessionException'); | 197 return loadTimeData.getString('sessionException'); |
192 }, | 198 }, |
193 | 199 |
194 /** | 200 /** |
195 * Update this list item to reflect whether the input is a valid pattern. | 201 * Update this list item to reflect whether the input is a valid pattern. |
196 * @param {boolean} valid Whether said pattern is valid in the context of | 202 * |
197 * a content exception setting. | 203 * @param {boolean} valid Whether said pattern is valid in the context of a |
| 204 * content exception setting. |
198 */ | 205 */ |
199 setPatternValid: function(valid) { | 206 setPatternValid: function(valid) { |
200 if (valid || !this.input.value) | 207 if (valid || !this.input.value) |
201 this.input.setCustomValidity(''); | 208 this.input.setCustomValidity(''); |
202 else | 209 else |
203 this.input.setCustomValidity(' '); | 210 this.input.setCustomValidity(' '); |
204 this.inputIsValid = valid; | 211 this.inputIsValid = valid; |
205 this.inputValidityKnown = true; | 212 this.inputValidityKnown = true; |
206 }, | 213 }, |
207 | 214 |
(...skipping 24 matching lines...) Expand all Loading... |
232 | 239 |
233 /** @inheritDoc */ | 240 /** @inheritDoc */ |
234 get hasBeenEdited() { | 241 get hasBeenEdited() { |
235 var livePattern = this.input.value; | 242 var livePattern = this.input.value; |
236 var liveSetting = this.select.value; | 243 var liveSetting = this.select.value; |
237 return livePattern != this.pattern || liveSetting != this.setting; | 244 return livePattern != this.pattern || liveSetting != this.setting; |
238 }, | 245 }, |
239 | 246 |
240 /** | 247 /** |
241 * Called when committing an edit. | 248 * Called when committing an edit. |
| 249 * |
242 * @param {Event} e The end event. | 250 * @param {Event} e The end event. |
243 * @private | 251 * @private |
244 */ | 252 */ |
245 onEditCommitted_: function(e) { | 253 onEditCommitted_: function(e) { |
246 var newPattern = this.input.value; | 254 var newPattern = this.input.value; |
247 var newSetting = this.select.value; | 255 var newSetting = this.select.value; |
248 | 256 |
249 this.finishEdit(newPattern, newSetting); | 257 this.finishEdit(newPattern, newSetting); |
250 }, | 258 }, |
251 | 259 |
252 /** | 260 /** |
253 * Called when cancelling an edit; resets the control states. | 261 * Called when cancelling an edit; resets the control states. |
| 262 * |
254 * @param {Event} e The cancel event. | 263 * @param {Event} e The cancel event. |
255 * @private | 264 * @private |
256 */ | 265 */ |
257 onEditCancelled_: function() { | 266 onEditCancelled_: function() { |
258 this.updateEditables(); | 267 this.updateEditables(); |
259 this.setPatternValid(true); | 268 this.setPatternValid(true); |
260 }, | 269 }, |
261 | 270 |
262 /** | 271 /** |
263 * Editing is complete; update the model. | 272 * Editing is complete; update the model. |
| 273 * |
264 * @param {string} newPattern The pattern that the user entered. | 274 * @param {string} newPattern The pattern that the user entered. |
265 * @param {string} newSetting The setting the user chose. | 275 * @param {string} newSetting The setting the user chose. |
266 */ | 276 */ |
267 finishEdit: function(newPattern, newSetting) { | 277 finishEdit: function(newPattern, newSetting) { |
268 this.patternLabel.textContent = newPattern; | 278 this.patternLabel.textContent = newPattern; |
269 this.settingLabel.textContent = this.settingForDisplay(); | 279 this.settingLabel.textContent = this.settingForDisplay(); |
270 var oldPattern = this.pattern; | 280 var oldPattern = this.pattern; |
271 this.pattern = newPattern; | 281 this.pattern = newPattern; |
272 this.setting = newSetting; | 282 this.setting = newSetting; |
273 | 283 |
274 // TODO(estade): this will need to be updated if geolocation/notifications | 284 // TODO(estade): this will need to be updated if geolocation/notifications |
275 // become editable. | 285 // become editable. |
276 if (oldPattern != newPattern) { | 286 if (oldPattern != newPattern) { |
277 chrome.send('removeException', | 287 chrome.send('removeException', |
278 [this.contentType, this.mode, oldPattern]); | 288 [this.contentType, this.mode, oldPattern]); |
279 } | 289 } |
280 | 290 |
281 chrome.send('setException', | 291 chrome.send('setException', |
282 [this.contentType, this.mode, newPattern, newSetting]); | 292 [this.contentType, this.mode, newPattern, newSetting]); |
283 } | 293 } |
284 }; | 294 }; |
285 | 295 |
286 /** | 296 /** |
287 * Creates a new list item for the Add New Item row, which doesn't represent | 297 * Creates a new list item for the Add New Item row, which doesn't represent |
288 * an actual entry in the exceptions list but allows the user to add new | 298 * an actual entry in the exceptions list but allows the user to add new |
289 * exceptions. | 299 * exceptions. |
| 300 * |
290 * @param {string} contentType The type of the list. | 301 * @param {string} contentType The type of the list. |
291 * @param {string} mode The browser mode, 'otr' or 'normal'. | 302 * @param {string} mode The browser mode, 'otr' or 'normal'. |
292 * @param {boolean} enableAskOption Whether to show an 'ask every time' | 303 * @param {boolean} enableAskOption Whether to show an 'ask every time' option |
293 * option in the select. | 304 * in the select. |
294 * @constructor | 305 * @constructor |
295 * @extends {cr.ui.ExceptionsListItem} | 306 * @extends {cr.ui.ExceptionsListItem} |
296 */ | 307 */ |
297 function ExceptionsAddRowListItem(contentType, mode, enableAskOption) { | 308 function ExceptionsAddRowListItem(contentType, mode, enableAskOption) { |
298 var el = cr.doc.createElement('div'); | 309 var el = cr.doc.createElement('div'); |
299 el.mode = mode; | 310 el.mode = mode; |
300 el.contentType = contentType; | 311 el.contentType = contentType; |
301 el.enableAskOption = enableAskOption; | 312 el.enableAskOption = enableAskOption; |
302 el.dataItem = []; | 313 el.dataItem = []; |
303 el.__proto__ = ExceptionsAddRowListItem.prototype; | 314 el.__proto__ = ExceptionsAddRowListItem.prototype; |
(...skipping 23 matching lines...) Expand all Loading... |
327 }, | 338 }, |
328 | 339 |
329 /** @inheritDoc */ | 340 /** @inheritDoc */ |
330 get hasBeenEdited() { | 341 get hasBeenEdited() { |
331 return this.input.value != ''; | 342 return this.input.value != ''; |
332 }, | 343 }, |
333 | 344 |
334 /** | 345 /** |
335 * Editing is complete; update the model. As long as the pattern isn't | 346 * Editing is complete; update the model. As long as the pattern isn't |
336 * empty, we'll just add it. | 347 * empty, we'll just add it. |
| 348 * |
337 * @param {string} newPattern The pattern that the user entered. | 349 * @param {string} newPattern The pattern that the user entered. |
338 * @param {string} newSetting The setting the user chose. | 350 * @param {string} newSetting The setting the user chose. |
339 */ | 351 */ |
340 finishEdit: function(newPattern, newSetting) { | 352 finishEdit: function(newPattern, newSetting) { |
341 this.resetInput(); | 353 this.resetInput(); |
342 chrome.send('setException', | 354 chrome.send('setException', |
343 [this.contentType, this.mode, newPattern, newSetting]); | 355 [this.contentType, this.mode, newPattern, newSetting]); |
344 }, | 356 }, |
345 }; | 357 }; |
346 | 358 |
347 /** | 359 /** |
348 * Creates a new exceptions list. | 360 * Creates a new exceptions list. |
| 361 * |
349 * @constructor | 362 * @constructor |
350 * @extends {cr.ui.List} | 363 * @extends {cr.ui.List} |
351 */ | 364 */ |
352 var ExceptionsList = cr.ui.define('list'); | 365 var ExceptionsList = cr.ui.define('list'); |
353 | 366 |
354 ExceptionsList.prototype = { | 367 ExceptionsList.prototype = { |
355 __proto__: InlineEditableItemList.prototype, | 368 __proto__: InlineEditableItemList.prototype, |
356 | 369 |
357 /** | 370 /** |
358 * Called when an element is decorated as a list. | 371 * Called when an element is decorated as a list. |
(...skipping 18 matching lines...) Expand all Loading... |
377 // Whether the exceptions in this list allow an 'Ask every time' option. | 390 // Whether the exceptions in this list allow an 'Ask every time' option. |
378 this.enableAskOption = this.contentType == 'plugins' || | 391 this.enableAskOption = this.contentType == 'plugins' || |
379 this.contentType == 'pepper-flash-cameramic'; | 392 this.contentType == 'pepper-flash-cameramic'; |
380 | 393 |
381 this.autoExpands = true; | 394 this.autoExpands = true; |
382 this.reset(); | 395 this.reset(); |
383 }, | 396 }, |
384 | 397 |
385 /** | 398 /** |
386 * Creates an item to go in the list. | 399 * Creates an item to go in the list. |
| 400 * |
387 * @param {Object} entry The element from the data model for this row. | 401 * @param {Object} entry The element from the data model for this row. |
388 */ | 402 */ |
389 createItem: function(entry) { | 403 createItem: function(entry) { |
390 if (entry) { | 404 if (entry) { |
391 return new ExceptionsListItem(this.contentType, | 405 return new ExceptionsListItem(this.contentType, |
392 this.mode, | 406 this.mode, |
393 this.enableAskOption, | 407 this.enableAskOption, |
394 entry); | 408 entry); |
395 } else { | 409 } else { |
396 var addRowItem = new ExceptionsAddRowListItem(this.contentType, | 410 var addRowItem = new ExceptionsAddRowListItem(this.contentType, |
397 this.mode, | 411 this.mode, |
398 this.enableAskOption); | 412 this.enableAskOption); |
399 addRowItem.deletable = false; | 413 addRowItem.deletable = false; |
400 return addRowItem; | 414 return addRowItem; |
401 } | 415 } |
402 }, | 416 }, |
403 | 417 |
404 /** | 418 /** |
405 * Sets the exceptions in the js model. | 419 * Sets the exceptions in the js model. |
| 420 * |
406 * @param {Object} entries A list of dictionaries of values, each dictionary | 421 * @param {Object} entries A list of dictionaries of values, each dictionary |
407 * represents an exception. | 422 * represents an exception. |
408 */ | 423 */ |
409 setExceptions: function(entries) { | 424 setExceptions: function(entries) { |
410 var deleteCount = this.dataModel.length; | 425 var deleteCount = this.dataModel.length; |
411 | 426 |
412 if (this.isEditable()) { | 427 if (this.isEditable()) { |
413 // We don't want to remove the Add New Exception row. | 428 // We don't want to remove the Add New Exception row. |
414 deleteCount = deleteCount - 1; | 429 deleteCount = deleteCount - 1; |
415 } | 430 } |
416 | 431 |
417 var args = [0, deleteCount]; | 432 var args = [0, deleteCount]; |
418 args.push.apply(args, entries); | 433 args.push.apply(args, entries); |
419 this.dataModel.splice.apply(this.dataModel, args); | 434 this.dataModel.splice.apply(this.dataModel, args); |
420 }, | 435 }, |
421 | 436 |
422 /** | 437 /** |
423 * The browser has finished checking a pattern for validity. Update the | 438 * The browser has finished checking a pattern for validity. Update the list |
424 * list item to reflect this. | 439 * item to reflect this. |
| 440 * |
425 * @param {string} pattern The pattern. | 441 * @param {string} pattern The pattern. |
426 * @param {bool} valid Whether said pattern is valid in the context of | 442 * @param {bool} valid Whether said pattern is valid in the context of a |
427 * a content exception setting. | 443 * content exception setting. |
428 */ | 444 */ |
429 patternValidityCheckComplete: function(pattern, valid) { | 445 patternValidityCheckComplete: function(pattern, valid) { |
430 var listItems = this.items; | 446 var listItems = this.items; |
431 for (var i = 0; i < listItems.length; i++) { | 447 for (var i = 0; i < listItems.length; i++) { |
432 var listItem = listItems[i]; | 448 var listItem = listItems[i]; |
433 // Don't do anything for messages for the item if it is not the intended | 449 // Don't do anything for messages for the item if it is not the intended |
434 // recipient, or if the response is stale (i.e. the input value has | 450 // recipient, or if the response is stale (i.e. the input value has |
435 // changed since we sent the request to analyze it). | 451 // changed since we sent the request to analyze it). |
436 if (pattern == listItem.input.value) | 452 if (pattern == listItem.input.value) |
437 listItem.setPatternValid(valid); | 453 listItem.setPatternValid(valid); |
438 } | 454 } |
439 }, | 455 }, |
440 | 456 |
441 /** | 457 /** |
442 * Returns whether the rows are editable in this list. | 458 * Returns whether the rows are editable in this list. |
443 */ | 459 */ |
444 isEditable: function() { | 460 isEditable: function() { |
445 // Editing notifications and geolocation is disabled for now. | 461 // Exceptions of the following lists are not editable for now. |
446 return !(this.contentType == 'notifications' || | 462 return !(this.contentType == 'notifications' || |
447 this.contentType == 'location' || | 463 this.contentType == 'location' || |
448 this.contentType == 'fullscreen'); | 464 this.contentType == 'fullscreen' || |
| 465 this.contentType == 'media-stream'); |
449 }, | 466 }, |
450 | 467 |
451 /** | 468 /** |
452 * Removes all exceptions from the js model. | 469 * Removes all exceptions from the js model. |
453 */ | 470 */ |
454 reset: function() { | 471 reset: function() { |
455 if (this.isEditable()) { | 472 if (this.isEditable()) { |
456 // The null creates the Add New Exception row. | 473 // The null creates the Add New Exception row. |
457 this.dataModel = new ArrayDataModel([null]); | 474 this.dataModel = new ArrayDataModel([null]); |
458 } else { | 475 } else { |
(...skipping 17 matching lines...) Expand all Loading... |
476 args.push(listItem.mode, listItem.pattern); | 493 args.push(listItem.mode, listItem.pattern); |
477 | 494 |
478 chrome.send('removeException', args); | 495 chrome.send('removeException', args); |
479 }, | 496 }, |
480 }; | 497 }; |
481 | 498 |
482 var OptionsPage = options.OptionsPage; | 499 var OptionsPage = options.OptionsPage; |
483 | 500 |
484 /** | 501 /** |
485 * Encapsulated handling of content settings list subpage. | 502 * Encapsulated handling of content settings list subpage. |
| 503 * |
486 * @constructor | 504 * @constructor |
487 */ | 505 */ |
488 function ContentSettingsExceptionsArea() { | 506 function ContentSettingsExceptionsArea() { |
489 OptionsPage.call(this, 'contentExceptions', | 507 OptionsPage.call(this, 'contentExceptions', |
490 loadTimeData.getString('contentSettingsPageTabTitle'), | 508 loadTimeData.getString('contentSettingsPageTabTitle'), |
491 'content-settings-exceptions-area'); | 509 'content-settings-exceptions-area'); |
492 } | 510 } |
493 | 511 |
494 cr.addSingletonGetter(ContentSettingsExceptionsArea); | 512 cr.addSingletonGetter(ContentSettingsExceptionsArea); |
495 | 513 |
(...skipping 12 matching lines...) Expand all Loading... |
508 | 526 |
509 // If the user types in the URL without a hash, show just cookies. | 527 // If the user types in the URL without a hash, show just cookies. |
510 this.showList('cookies'); | 528 this.showList('cookies'); |
511 | 529 |
512 $('content-settings-exceptions-overlay-confirm').onclick = | 530 $('content-settings-exceptions-overlay-confirm').onclick = |
513 OptionsPage.closeOverlay.bind(OptionsPage); | 531 OptionsPage.closeOverlay.bind(OptionsPage); |
514 }, | 532 }, |
515 | 533 |
516 /** | 534 /** |
517 * Shows one list and hides all others. | 535 * Shows one list and hides all others. |
| 536 * |
518 * @param {string} type The content type. | 537 * @param {string} type The content type. |
519 */ | 538 */ |
520 showList: function(type) { | 539 showList: function(type) { |
521 var header = this.pageDiv.querySelector('h1'); | 540 var header = this.pageDiv.querySelector('h1'); |
522 header.textContent = loadTimeData.getString(type + '_header'); | 541 header.textContent = loadTimeData.getString(type + '_header'); |
523 | 542 |
524 var divs = this.pageDiv.querySelectorAll('div[contentType]'); | 543 var divs = this.pageDiv.querySelectorAll('div[contentType]'); |
525 for (var i = 0; i < divs.length; i++) { | 544 for (var i = 0; i < divs.length; i++) { |
526 if (divs[i].getAttribute('contentType') == type) | 545 if (divs[i].getAttribute('contentType') == type) |
527 divs[i].hidden = false; | 546 divs[i].hidden = false; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 } | 579 } |
561 }; | 580 }; |
562 | 581 |
563 return { | 582 return { |
564 ExceptionsListItem: ExceptionsListItem, | 583 ExceptionsListItem: ExceptionsListItem, |
565 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 584 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
566 ExceptionsList: ExceptionsList, | 585 ExceptionsList: ExceptionsList, |
567 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | 586 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, |
568 }; | 587 }; |
569 }); | 588 }); |
OLD | NEW |