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 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 * Returns whether exceptions list for the type is editable. | 13 * Returns whether exceptions list for the type is editable. |
14 * | 14 * |
15 * @param {string} contentType The type of the list. | 15 * @param {string} contentType The type of the list. |
16 */ | 16 */ |
17 function isEditableType(contentType) { | 17 function isEditableType(contentType) { |
18 // Exceptions of the following lists are not editable for now. | 18 // Exceptions of the following lists are not editable for now. |
19 return !(contentType == 'location' || | 19 return !( |
20 contentType == 'media-stream-mic' || | 20 contentType == 'location' || contentType == 'media-stream-mic' || |
21 contentType == 'media-stream-camera' || | 21 contentType == 'media-stream-camera' || contentType == 'midi-sysex' || |
22 contentType == 'midi-sysex' || | 22 contentType == 'zoomlevels' || isChosenObjectType(contentType)); |
23 contentType == 'zoomlevels' || | |
24 isChosenObjectType(contentType)); | |
25 } | 23 } |
26 | 24 |
27 /** | 25 /** |
28 * Returns whether exceptions of this type represent chosen objects. | 26 * Returns whether exceptions of this type represent chosen objects. |
29 * | 27 * |
30 * @param {string} contentType The type of the list. | 28 * @param {string} contentType The type of the list. |
31 */ | 29 */ |
32 function isChosenObjectType(contentType) { | 30 function isChosenObjectType(contentType) { |
33 return contentType == 'usb-devices'; | 31 return contentType == 'usb-devices'; |
34 } | 32 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 this.deletable = false; | 131 this.deletable = false; |
134 this.editable = false; | 132 this.editable = false; |
135 } | 133 } |
136 | 134 |
137 if (this.contentType != 'zoomlevels' && | 135 if (this.contentType != 'zoomlevels' && |
138 !isChosenObjectType(this.contentType)) { | 136 !isChosenObjectType(this.contentType)) { |
139 this.addEditField(select, this.settingLabel); | 137 this.addEditField(select, this.settingLabel); |
140 this.contentElement.appendChild(select); | 138 this.contentElement.appendChild(select); |
141 } | 139 } |
142 select.className = 'exception-setting'; | 140 select.className = 'exception-setting'; |
143 select.setAttribute('aria-labelledby', | 141 select.setAttribute( |
144 valueColumnForContentType(this.contentType)); | 142 'aria-labelledby', valueColumnForContentType(this.contentType)); |
145 | 143 |
146 if (this.pattern) | 144 if (this.pattern) |
147 select.setAttribute('displaymode', 'edit'); | 145 select.setAttribute('displaymode', 'edit'); |
148 | 146 |
149 if (this.contentType == 'zoomlevels') { | 147 if (this.contentType == 'zoomlevels') { |
150 this.deletable = true; | 148 this.deletable = true; |
151 | 149 |
152 var zoomLabel = cr.doc.createElement('span'); | 150 var zoomLabel = cr.doc.createElement('span'); |
153 zoomLabel.textContent = this.dataItem.zoom; | 151 zoomLabel.textContent = this.dataItem.zoom; |
154 zoomLabel.className = 'exception-setting'; | 152 zoomLabel.className = 'exception-setting'; |
(...skipping 30 matching lines...) Expand all Loading... |
185 this.select = select; | 183 this.select = select; |
186 | 184 |
187 this.updateEditables(); | 185 this.updateEditables(); |
188 this.editable = this.editable && isEditableType(this.contentType); | 186 this.editable = this.editable && isEditableType(this.contentType); |
189 | 187 |
190 // If the source of the content setting exception is not a user | 188 // If the source of the content setting exception is not a user |
191 // preference, that source controls the exception and the user cannot edit | 189 // preference, that source controls the exception and the user cannot edit |
192 // or delete it. | 190 // or delete it. |
193 var controlledBy = | 191 var controlledBy = |
194 this.dataItem.source && this.dataItem.source != 'preference' ? | 192 this.dataItem.source && this.dataItem.source != 'preference' ? |
195 this.dataItem.source : null; | 193 this.dataItem.source : |
| 194 null; |
196 | 195 |
197 if (controlledBy) { | 196 if (controlledBy) { |
198 this.setAttribute('controlled-by', controlledBy); | 197 this.setAttribute('controlled-by', controlledBy); |
199 this.deletable = false; | 198 this.deletable = false; |
200 this.editable = false; | 199 this.editable = false; |
201 } | 200 } |
202 | 201 |
203 if (controlledBy == 'policy' || controlledBy == 'extension') { | 202 if (controlledBy == 'policy' || controlledBy == 'extension') { |
204 this.querySelector('.row-delete-button').hidden = true; | 203 this.querySelector('.row-delete-button').hidden = true; |
205 this.appendIndicatorElement(controlledBy); | 204 this.appendIndicatorElement(controlledBy); |
206 } | 205 } |
207 | 206 |
208 // If the exception comes from a hosted app, display the name and the | 207 // If the exception comes from a hosted app, display the name and the |
209 // icon of the app. | 208 // icon of the app. |
210 if (controlledBy == 'HostedApp') { | 209 if (controlledBy == 'HostedApp') { |
211 this.title = | 210 this.title = |
212 loadTimeData.getString('setBy') + ' ' + this.dataItem.appName; | 211 loadTimeData.getString('setBy') + ' ' + this.dataItem.appName; |
213 var button = this.querySelector('.row-delete-button'); | 212 var button = this.querySelector('.row-delete-button'); |
214 // Use the host app's favicon (16px, match bigger size). | 213 // Use the host app's favicon (16px, match bigger size). |
215 // See c/b/ui/webui/extensions/extension_icon_source.h | 214 // See c/b/ui/webui/extensions/extension_icon_source.h |
216 // for a description of the chrome://extension-icon URL. | 215 // for a description of the chrome://extension-icon URL. |
217 button.style.backgroundImage = | 216 button.style.backgroundImage = |
218 'url(\'chrome://extension-icon/' + this.dataItem.appId + '/16/1\')'; | 217 'url(\'chrome://extension-icon/' + this.dataItem.appId + '/16/1\')'; |
219 } | 218 } |
220 | 219 |
221 var listItem = this; | 220 var listItem = this; |
222 // Handle events on the editable nodes. | 221 // Handle events on the editable nodes. |
223 input.oninput = function(event) { | 222 input.oninput = function(event) { |
224 listItem.inputValidityKnown = false; | 223 listItem.inputValidityKnown = false; |
225 chrome.send('checkExceptionPatternValidity', | 224 chrome.send( |
226 [listItem.contentType, listItem.mode, input.value]); | 225 'checkExceptionPatternValidity', |
| 226 [listItem.contentType, listItem.mode, input.value]); |
227 }; | 227 }; |
228 | 228 |
229 // Listen for edit events. | 229 // Listen for edit events. |
230 this.addEventListener('canceledit', this.onEditCancelled_); | 230 this.addEventListener('canceledit', this.onEditCancelled_); |
231 this.addEventListener('commitedit', this.onEditCommitted_); | 231 this.addEventListener('commitedit', this.onEditCommitted_); |
232 }, | 232 }, |
233 | 233 |
234 /** | 234 /** |
235 * Appends an indicator element to the item. Should be called at most once. | 235 * Appends an indicator element to the item. Should be called at most once. |
236 * | 236 * |
(...skipping 17 matching lines...) Expand all Loading... |
254 | 254 |
255 /** | 255 /** |
256 * The pattern (e.g., a URL) for the exception. | 256 * The pattern (e.g., a URL) for the exception. |
257 * | 257 * |
258 * @type {string} | 258 * @type {string} |
259 */ | 259 */ |
260 get pattern() { | 260 get pattern() { |
261 if (!this.isEmbeddingRule()) | 261 if (!this.isEmbeddingRule()) |
262 return this.dataItem.origin; | 262 return this.dataItem.origin; |
263 | 263 |
264 return loadTimeData.getStringF('embeddedOnHost', | 264 return loadTimeData.getStringF( |
265 this.dataItem.embeddingOrigin); | 265 'embeddedOnHost', this.dataItem.embeddingOrigin); |
266 }, | 266 }, |
267 set pattern(pattern) { | 267 set pattern(pattern) { |
268 if (!this.editable) | 268 if (!this.editable) |
269 console.error('Tried to change uneditable pattern'); | 269 console.error('Tried to change uneditable pattern'); |
270 | 270 |
271 this.dataItem.displayPattern = pattern; | 271 this.dataItem.displayPattern = pattern; |
272 }, | 272 }, |
273 | 273 |
274 /** | 274 /** |
275 * The setting (allow/block) for the exception. | 275 * The setting (allow/block) for the exception. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 finishEdit: function(newPattern, newSetting) { | 406 finishEdit: function(newPattern, newSetting) { |
407 this.patternLabel.textContent = newPattern; | 407 this.patternLabel.textContent = newPattern; |
408 this.settingLabel.textContent = this.settingForDisplay(); | 408 this.settingLabel.textContent = this.settingForDisplay(); |
409 var oldPattern = this.pattern; | 409 var oldPattern = this.pattern; |
410 this.pattern = newPattern; | 410 this.pattern = newPattern; |
411 this.setting = newSetting; | 411 this.setting = newSetting; |
412 | 412 |
413 // TODO(estade): this will need to be updated if geolocation/notifications | 413 // TODO(estade): this will need to be updated if geolocation/notifications |
414 // become editable. | 414 // become editable. |
415 if (oldPattern != newPattern) { | 415 if (oldPattern != newPattern) { |
416 chrome.send('removeException', | 416 chrome.send( |
417 [this.contentType, this.mode, oldPattern]); | 417 'removeException', [this.contentType, this.mode, oldPattern]); |
418 } | 418 } |
419 | 419 |
420 chrome.send('setException', | 420 chrome.send( |
421 [this.contentType, this.mode, newPattern, newSetting]); | 421 'setException', |
| 422 [this.contentType, this.mode, newPattern, newSetting]); |
422 }, | 423 }, |
423 }; | 424 }; |
424 | 425 |
425 /** | 426 /** |
426 * Creates a new list item for the Add New Item row, which doesn't represent | 427 * Creates a new list item for the Add New Item row, which doesn't represent |
427 * an actual entry in the exceptions list but allows the user to add new | 428 * an actual entry in the exceptions list but allows the user to add new |
428 * exceptions. | 429 * exceptions. |
429 * | 430 * |
430 * @param {string} contentType The type of the list. | 431 * @param {string} contentType The type of the list. |
431 * @param {string} mode The browser mode, 'otr' or 'normal'. | 432 * @param {string} mode The browser mode, 'otr' or 'normal'. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 471 |
471 /** | 472 /** |
472 * Editing is complete; update the model. As long as the pattern isn't | 473 * Editing is complete; update the model. As long as the pattern isn't |
473 * empty, we'll just add it. | 474 * empty, we'll just add it. |
474 * | 475 * |
475 * @param {string} newPattern The pattern that the user entered. | 476 * @param {string} newPattern The pattern that the user entered. |
476 * @param {string} newSetting The setting the user chose. | 477 * @param {string} newSetting The setting the user chose. |
477 */ | 478 */ |
478 finishEdit: function(newPattern, newSetting) { | 479 finishEdit: function(newPattern, newSetting) { |
479 this.resetInput(); | 480 this.resetInput(); |
480 chrome.send('setException', | 481 chrome.send( |
481 [this.contentType, this.mode, newPattern, newSetting]); | 482 'setException', |
| 483 [this.contentType, this.mode, newPattern, newSetting]); |
482 }, | 484 }, |
483 }; | 485 }; |
484 | 486 |
485 /** | 487 /** |
486 * Creates a new exceptions list. | 488 * Creates a new exceptions list. |
487 * | 489 * |
488 * @constructor | 490 * @constructor |
489 * @extends {options.InlineEditableItemList} | 491 * @extends {options.InlineEditableItemList} |
490 */ | 492 */ |
491 var ExceptionsList = cr.ui.define('list'); | 493 var ExceptionsList = cr.ui.define('list'); |
(...skipping 25 matching lines...) Expand all Loading... |
517 this.reset(); | 519 this.reset(); |
518 }, | 520 }, |
519 | 521 |
520 /** | 522 /** |
521 * Creates an item to go in the list. | 523 * Creates an item to go in the list. |
522 * | 524 * |
523 * @param {Object} entry The element from the data model for this row. | 525 * @param {Object} entry The element from the data model for this row. |
524 */ | 526 */ |
525 createItem: function(entry) { | 527 createItem: function(entry) { |
526 if (entry) { | 528 if (entry) { |
527 return new ExceptionsListItem(this.contentType, | 529 return new ExceptionsListItem(this.contentType, this.mode, entry); |
528 this.mode, | |
529 entry); | |
530 } else { | 530 } else { |
531 var addRowItem = new ExceptionsAddRowListItem(this.contentType, | 531 var addRowItem = |
532 this.mode); | 532 new ExceptionsAddRowListItem(this.contentType, this.mode); |
533 addRowItem.deletable = false; | 533 addRowItem.deletable = false; |
534 return addRowItem; | 534 return addRowItem; |
535 } | 535 } |
536 }, | 536 }, |
537 | 537 |
538 /** | 538 /** |
539 * Updates UI to indicate that user exceptions were overruled by a source. | 539 * Updates UI to indicate that user exceptions were overruled by a source. |
540 * | 540 * |
541 * @param {string} overruledBy The source that overrules user exceptions. | 541 * @param {string} overruledBy The source that overrules user exceptions. |
542 */ | 542 */ |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 } | 607 } |
608 }, | 608 }, |
609 | 609 |
610 /** @override */ | 610 /** @override */ |
611 deleteItemAtIndex: function(index) { | 611 deleteItemAtIndex: function(index) { |
612 var listItem = this.getListItemByIndex(index); | 612 var listItem = this.getListItemByIndex(index); |
613 if (!listItem.deletable) | 613 if (!listItem.deletable) |
614 return; | 614 return; |
615 | 615 |
616 var dataItem = listItem.dataItem; | 616 var dataItem = listItem.dataItem; |
617 var params = [listItem.contentType, | 617 var params = [ |
618 listItem.mode, | 618 listItem.contentType, listItem.mode, dataItem.origin, |
619 dataItem.origin, | 619 dataItem.embeddingOrigin |
620 dataItem.embeddingOrigin]; | 620 ]; |
621 | 621 |
622 if (isChosenObjectType(this.contentType)) | 622 if (isChosenObjectType(this.contentType)) |
623 params.push(dataItem.object); | 623 params.push(dataItem.object); |
624 | 624 |
625 chrome.send('removeException', params); | 625 chrome.send('removeException', params); |
626 }, | 626 }, |
627 }; | 627 }; |
628 | 628 |
629 var Page = cr.ui.pageManager.Page; | 629 var Page = cr.ui.pageManager.Page; |
630 var PageManager = cr.ui.pageManager.PageManager; | 630 var PageManager = cr.ui.pageManager.PageManager; |
631 | 631 |
632 /** | 632 /** |
633 * Encapsulated handling of content settings list subpage. | 633 * Encapsulated handling of content settings list subpage. |
634 * | 634 * |
635 * @constructor | 635 * @constructor |
636 * @extends {cr.ui.pageManager.Page} | 636 * @extends {cr.ui.pageManager.Page} |
637 */ | 637 */ |
638 function ContentSettingsExceptionsArea() { | 638 function ContentSettingsExceptionsArea() { |
639 Page.call(this, 'contentExceptions', | 639 Page.call( |
640 loadTimeData.getString('contentSettingsPageTabTitle'), | 640 this, 'contentExceptions', |
641 'content-settings-exceptions-area'); | 641 loadTimeData.getString('contentSettingsPageTabTitle'), |
| 642 'content-settings-exceptions-area'); |
642 } | 643 } |
643 | 644 |
644 cr.addSingletonGetter(ContentSettingsExceptionsArea); | 645 cr.addSingletonGetter(ContentSettingsExceptionsArea); |
645 | 646 |
646 ContentSettingsExceptionsArea.prototype = { | 647 ContentSettingsExceptionsArea.prototype = { |
647 __proto__: Page.prototype, | 648 __proto__: Page.prototype, |
648 | 649 |
649 /** @override */ | 650 /** @override */ |
650 initializePage: function() { | 651 initializePage: function() { |
651 Page.prototype.initializePage.call(this); | 652 Page.prototype.initializePage.call(this); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 } | 726 } |
726 }; | 727 }; |
727 | 728 |
728 return { | 729 return { |
729 ExceptionsListItem: ExceptionsListItem, | 730 ExceptionsListItem: ExceptionsListItem, |
730 ExceptionsAddRowListItem: ExceptionsAddRowListItem, | 731 ExceptionsAddRowListItem: ExceptionsAddRowListItem, |
731 ExceptionsList: ExceptionsList, | 732 ExceptionsList: ExceptionsList, |
732 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, | 733 ContentSettingsExceptionsArea: ContentSettingsExceptionsArea, |
733 }; | 734 }; |
734 }); | 735 }); |
OLD | NEW |