| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 The Chromium Authors. All rights reserved. | 2 * Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 /** |
| 7 * @implements {WebInspector.ListWidget.Delegate} |
| 8 * @unrestricted |
| 9 */ |
| 10 WebInspector.FrameworkBlackboxSettingsTab = class extends WebInspector.VBox { |
| 11 constructor() { |
| 12 super(true); |
| 13 this.registerRequiredCSS('settings/frameworkBlackboxSettingsTab.css'); |
| 6 | 14 |
| 7 /** | 15 this.contentElement.createChild('div', 'header').textContent = WebInspector.
UIString('Framework Blackbox Patterns'); |
| 8 * @constructor | 16 this.contentElement.createChild('div', 'blackbox-content-scripts') |
| 9 * @extends {WebInspector.VBox} | 17 .appendChild(WebInspector.SettingsUI.createSettingCheckbox( |
| 10 * @implements {WebInspector.ListWidget.Delegate} | 18 WebInspector.UIString('Blackbox content scripts'), WebInspector.modu
leSetting('skipContentScripts'), true)); |
| 11 */ | |
| 12 WebInspector.FrameworkBlackboxSettingsTab = function() | |
| 13 { | |
| 14 WebInspector.VBox.call(this, true); | |
| 15 this.registerRequiredCSS("settings/frameworkBlackboxSettingsTab.css"); | |
| 16 | 19 |
| 17 this.contentElement.createChild("div", "header").textContent = WebInspector.
UIString("Framework Blackbox Patterns"); | 20 this._blackboxLabel = WebInspector.UIString('Blackbox'); |
| 18 this.contentElement.createChild("div", "blackbox-content-scripts").appendChi
ld(WebInspector.SettingsUI.createSettingCheckbox(WebInspector.UIString("Blackbox
content scripts"), WebInspector.moduleSetting("skipContentScripts"), true)); | 21 this._disabledLabel = WebInspector.UIString('Disabled'); |
| 19 | |
| 20 this._blackboxLabel = WebInspector.UIString("Blackbox"); | |
| 21 this._disabledLabel = WebInspector.UIString("Disabled"); | |
| 22 | 22 |
| 23 this._list = new WebInspector.ListWidget(this); | 23 this._list = new WebInspector.ListWidget(this); |
| 24 this._list.element.classList.add("blackbox-list"); | 24 this._list.element.classList.add('blackbox-list'); |
| 25 this._list.registerRequiredCSS("settings/frameworkBlackboxSettingsTab.css"); | 25 this._list.registerRequiredCSS('settings/frameworkBlackboxSettingsTab.css'); |
| 26 | 26 |
| 27 var placeholder = createElementWithClass("div", "blackbox-list-empty"); | 27 var placeholder = createElementWithClass('div', 'blackbox-list-empty'); |
| 28 placeholder.textContent = WebInspector.UIString("No blackboxed patterns"); | 28 placeholder.textContent = WebInspector.UIString('No blackboxed patterns'); |
| 29 this._list.setEmptyPlaceholder(placeholder); | 29 this._list.setEmptyPlaceholder(placeholder); |
| 30 this._list.show(this.contentElement); | 30 this._list.show(this.contentElement); |
| 31 var addPatternButton = createTextButton(WebInspector.UIString("Add pattern..
."), this._addButtonClicked.bind(this), "add-button"); | 31 var addPatternButton = |
| 32 createTextButton(WebInspector.UIString('Add pattern...'), this._addButto
nClicked.bind(this), 'add-button'); |
| 32 this.contentElement.appendChild(addPatternButton); | 33 this.contentElement.appendChild(addPatternButton); |
| 33 | 34 |
| 34 this._setting = WebInspector.moduleSetting("skipStackFramesPattern"); | 35 this._setting = WebInspector.moduleSetting('skipStackFramesPattern'); |
| 35 this._setting.addChangeListener(this._settingUpdated, this); | 36 this._setting.addChangeListener(this._settingUpdated, this); |
| 36 | 37 |
| 37 this.setDefaultFocusedElement(addPatternButton); | 38 this.setDefaultFocusedElement(addPatternButton); |
| 38 this.contentElement.tabIndex = 0; | 39 this.contentElement.tabIndex = 0; |
| 39 }; | 40 } |
| 40 | 41 |
| 41 WebInspector.FrameworkBlackboxSettingsTab.prototype = { | 42 /** |
| 42 wasShown: function() | 43 * @override |
| 43 { | 44 */ |
| 44 WebInspector.SettingsTab.prototype.wasShown.call(this); | 45 wasShown() { |
| 45 this._settingUpdated(); | 46 super.wasShown(); |
| 46 }, | 47 this._settingUpdated(); |
| 48 } |
| 47 | 49 |
| 48 _settingUpdated: function() | 50 _settingUpdated() { |
| 49 { | 51 this._list.clear(); |
| 50 this._list.clear(); | 52 var patterns = this._setting.getAsArray(); |
| 51 var patterns = this._setting.getAsArray(); | 53 for (var i = 0; i < patterns.length; ++i) |
| 52 for (var i = 0; i < patterns.length; ++i) | 54 this._list.appendItem(patterns[i], true); |
| 53 this._list.appendItem(patterns[i], true); | 55 } |
| 54 }, | |
| 55 | 56 |
| 56 _addButtonClicked: function() | 57 _addButtonClicked() { |
| 57 { | 58 this._list.addNewItem(this._setting.getAsArray().length, {pattern: '', disab
led: false}); |
| 58 this._list.addNewItem(this._setting.getAsArray().length, {pattern: "", d
isabled: false}); | 59 } |
| 59 }, | 60 |
| 61 /** |
| 62 * @override |
| 63 * @param {*} item |
| 64 * @param {boolean} editable |
| 65 * @return {!Element} |
| 66 */ |
| 67 renderItem(item, editable) { |
| 68 var element = createElementWithClass('div', 'blackbox-list-item'); |
| 69 var pattern = element.createChild('div', 'blackbox-pattern'); |
| 70 pattern.textContent = item.pattern; |
| 71 pattern.title = item.pattern; |
| 72 element.createChild('div', 'blackbox-separator'); |
| 73 element.createChild('div', 'blackbox-behavior').textContent = |
| 74 item.disabled ? this._disabledLabel : this._blackboxLabel; |
| 75 if (item.disabled) |
| 76 element.classList.add('blackbox-disabled'); |
| 77 return element; |
| 78 } |
| 79 |
| 80 /** |
| 81 * @override |
| 82 * @param {*} item |
| 83 * @param {number} index |
| 84 */ |
| 85 removeItemRequested(item, index) { |
| 86 var patterns = this._setting.getAsArray(); |
| 87 patterns.splice(index, 1); |
| 88 this._setting.setAsArray(patterns); |
| 89 } |
| 90 |
| 91 /** |
| 92 * @override |
| 93 * @param {*} item |
| 94 * @param {!WebInspector.ListWidget.Editor} editor |
| 95 * @param {boolean} isNew |
| 96 */ |
| 97 commitEdit(item, editor, isNew) { |
| 98 item.pattern = editor.control('pattern').value.trim(); |
| 99 item.disabled = editor.control('behavior').value === this._disabledLabel; |
| 100 |
| 101 var list = this._setting.getAsArray(); |
| 102 if (isNew) |
| 103 list.push(item); |
| 104 this._setting.setAsArray(list); |
| 105 } |
| 106 |
| 107 /** |
| 108 * @override |
| 109 * @param {*} item |
| 110 * @return {!WebInspector.ListWidget.Editor} |
| 111 */ |
| 112 beginEdit(item) { |
| 113 var editor = this._createEditor(); |
| 114 editor.control('pattern').value = item.pattern; |
| 115 editor.control('behavior').value = item.disabled ? this._disabledLabel : thi
s._blackboxLabel; |
| 116 return editor; |
| 117 } |
| 118 |
| 119 /** |
| 120 * @return {!WebInspector.ListWidget.Editor} |
| 121 */ |
| 122 _createEditor() { |
| 123 if (this._editor) |
| 124 return this._editor; |
| 125 |
| 126 var editor = new WebInspector.ListWidget.Editor(); |
| 127 this._editor = editor; |
| 128 var content = editor.contentElement(); |
| 129 |
| 130 var titles = content.createChild('div', 'blackbox-edit-row'); |
| 131 titles.createChild('div', 'blackbox-pattern').textContent = WebInspector.UIS
tring('Pattern'); |
| 132 titles.createChild('div', 'blackbox-separator blackbox-separator-invisible')
; |
| 133 titles.createChild('div', 'blackbox-behavior').textContent = WebInspector.UI
String('Behavior'); |
| 134 |
| 135 var fields = content.createChild('div', 'blackbox-edit-row'); |
| 136 fields.createChild('div', 'blackbox-pattern') |
| 137 .appendChild(editor.createInput('pattern', 'text', '/framework\\.js$', p
atternValidator.bind(this))); |
| 138 fields.createChild('div', 'blackbox-separator blackbox-separator-invisible')
; |
| 139 fields.createChild('div', 'blackbox-behavior') |
| 140 .appendChild(editor.createSelect('behavior', [this._blackboxLabel, this.
_disabledLabel], behaviorValidator)); |
| 141 |
| 142 return editor; |
| 60 | 143 |
| 61 /** | 144 /** |
| 62 * @override | |
| 63 * @param {*} item | 145 * @param {*} item |
| 64 * @param {boolean} editable | 146 * @param {number} index |
| 65 * @return {!Element} | 147 * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 148 * @this {WebInspector.FrameworkBlackboxSettingsTab} |
| 149 * @return {boolean} |
| 66 */ | 150 */ |
| 67 renderItem: function(item, editable) | 151 function patternValidator(item, index, input) { |
| 68 { | 152 var pattern = input.value.trim(); |
| 69 var element = createElementWithClass("div", "blackbox-list-item"); | 153 var patterns = this._setting.getAsArray(); |
| 70 var pattern = element.createChild("div", "blackbox-pattern"); | 154 for (var i = 0; i < patterns.length; ++i) { |
| 71 pattern.textContent = item.pattern; | 155 if (i !== index && patterns[i].pattern === pattern) |
| 72 pattern.title = item.pattern; | 156 return false; |
| 73 element.createChild("div", "blackbox-separator"); | 157 } |
| 74 element.createChild("div", "blackbox-behavior").textContent = item.disab
led ? this._disabledLabel : this._blackboxLabel; | 158 |
| 75 if (item.disabled) | 159 var regex; |
| 76 element.classList.add("blackbox-disabled"); | 160 try { |
| 77 return element; | 161 regex = new RegExp(pattern); |
| 78 }, | 162 } catch (e) { |
| 163 } |
| 164 return !!(pattern && regex); |
| 165 } |
| 79 | 166 |
| 80 /** | 167 /** |
| 81 * @override | |
| 82 * @param {*} item | 168 * @param {*} item |
| 83 * @param {number} index | 169 * @param {number} index |
| 170 * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 171 * @return {boolean} |
| 84 */ | 172 */ |
| 85 removeItemRequested: function(item, index) | 173 function behaviorValidator(item, index, input) { |
| 86 { | 174 return true; |
| 87 var patterns = this._setting.getAsArray(); | 175 } |
| 88 patterns.splice(index, 1); | 176 } |
| 89 this._setting.setAsArray(patterns); | |
| 90 }, | |
| 91 | |
| 92 /** | |
| 93 * @override | |
| 94 * @param {*} item | |
| 95 * @param {!WebInspector.ListWidget.Editor} editor | |
| 96 * @param {boolean} isNew | |
| 97 */ | |
| 98 commitEdit: function(item, editor, isNew) | |
| 99 { | |
| 100 item.pattern = editor.control("pattern").value.trim(); | |
| 101 item.disabled = editor.control("behavior").value === this._disabledLabel
; | |
| 102 | |
| 103 var list = this._setting.getAsArray(); | |
| 104 if (isNew) | |
| 105 list.push(item); | |
| 106 this._setting.setAsArray(list); | |
| 107 }, | |
| 108 | |
| 109 /** | |
| 110 * @override | |
| 111 * @param {*} item | |
| 112 * @return {!WebInspector.ListWidget.Editor} | |
| 113 */ | |
| 114 beginEdit: function(item) | |
| 115 { | |
| 116 var editor = this._createEditor(); | |
| 117 editor.control("pattern").value = item.pattern; | |
| 118 editor.control("behavior").value = item.disabled ? this._disabledLabel :
this._blackboxLabel; | |
| 119 return editor; | |
| 120 }, | |
| 121 | |
| 122 /** | |
| 123 * @return {!WebInspector.ListWidget.Editor} | |
| 124 */ | |
| 125 _createEditor: function() | |
| 126 { | |
| 127 if (this._editor) | |
| 128 return this._editor; | |
| 129 | |
| 130 var editor = new WebInspector.ListWidget.Editor(); | |
| 131 this._editor = editor; | |
| 132 var content = editor.contentElement(); | |
| 133 | |
| 134 var titles = content.createChild("div", "blackbox-edit-row"); | |
| 135 titles.createChild("div", "blackbox-pattern").textContent = WebInspector
.UIString("Pattern"); | |
| 136 titles.createChild("div", "blackbox-separator blackbox-separator-invisib
le"); | |
| 137 titles.createChild("div", "blackbox-behavior").textContent = WebInspecto
r.UIString("Behavior"); | |
| 138 | |
| 139 var fields = content.createChild("div", "blackbox-edit-row"); | |
| 140 fields.createChild("div", "blackbox-pattern").appendChild(editor.createI
nput("pattern", "text", "/framework\\.js$", patternValidator.bind(this))); | |
| 141 fields.createChild("div", "blackbox-separator blackbox-separator-invisib
le"); | |
| 142 fields.createChild("div", "blackbox-behavior").appendChild(editor.create
Select("behavior", [this._blackboxLabel, this._disabledLabel], behaviorValidator
)); | |
| 143 | |
| 144 return editor; | |
| 145 | |
| 146 /** | |
| 147 * @param {*} item | |
| 148 * @param {number} index | |
| 149 * @param {!HTMLInputElement|!HTMLSelectElement} input | |
| 150 * @this {WebInspector.FrameworkBlackboxSettingsTab} | |
| 151 * @return {boolean} | |
| 152 */ | |
| 153 function patternValidator(item, index, input) | |
| 154 { | |
| 155 var pattern = input.value.trim(); | |
| 156 var patterns = this._setting.getAsArray(); | |
| 157 for (var i = 0; i < patterns.length; ++i) { | |
| 158 if (i !== index && patterns[i].pattern === pattern) | |
| 159 return false; | |
| 160 } | |
| 161 | |
| 162 var regex; | |
| 163 try { | |
| 164 regex = new RegExp(pattern); | |
| 165 } catch (e) { | |
| 166 } | |
| 167 return !!(pattern && regex); | |
| 168 } | |
| 169 | |
| 170 /** | |
| 171 * @param {*} item | |
| 172 * @param {number} index | |
| 173 * @param {!HTMLInputElement|!HTMLSelectElement} input | |
| 174 * @return {boolean} | |
| 175 */ | |
| 176 function behaviorValidator(item, index, input) | |
| 177 { | |
| 178 return true; | |
| 179 } | |
| 180 }, | |
| 181 | |
| 182 __proto__: WebInspector.VBox.prototype | |
| 183 }; | 177 }; |
| OLD | NEW |