Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 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 |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | /** |
| 7 | * @implements {UI.ListWidget.Delegate} |
| 8 | * @unrestricted |
| 9 | */ |
| 10 | Settings.FrameworkBlackboxSettingsTab = class extends UI.VBox { |
| 11 | constructor() { |
| 12 | super(true); |
| 13 | this.registerRequiredCSS('settings/frameworkBlackboxSettingsTab.css'); |
| 14 | |
Chandani Shrestha | 97a703ee | 2019-06-03 22:45:11 | [diff] [blame] | 15 | const header = this.contentElement.createChild('div', 'header'); |
| 16 | header.textContent = ls`Framework Blackboxing`; |
| 17 | UI.ARIAUtils.markAsHeading(header, 1); |
Harley Li | 4ca2783 | 2019-05-23 23:14:51 | [diff] [blame] | 18 | this.contentElement.createChild('div', 'intro').textContent = |
| 19 | ls`Debugger will skip through the scripts and will not stop on exceptions thrown by them.`; |
| 20 | |
| 21 | const blackboxContentScripts = this.contentElement.createChild('div', 'blackbox-content-scripts'); |
| 22 | blackboxContentScripts.appendChild(UI.SettingsUI.createSettingCheckbox( |
| 23 | ls`Blackbox content scripts`, Common.moduleSetting('skipContentScripts'), true)); |
| 24 | blackboxContentScripts.title = ls`Blackbox content scripts (extension scripts in the page)`; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 25 | |
| 26 | this._blackboxLabel = Common.UIString('Blackbox'); |
| 27 | this._disabledLabel = Common.UIString('Disabled'); |
| 28 | |
| 29 | this._list = new UI.ListWidget(this); |
| 30 | this._list.element.classList.add('blackbox-list'); |
| 31 | this._list.registerRequiredCSS('settings/frameworkBlackboxSettingsTab.css'); |
| 32 | |
| 33 | const placeholder = createElementWithClass('div', 'blackbox-list-empty'); |
| 34 | placeholder.textContent = Common.UIString('No blackboxed patterns'); |
| 35 | this._list.setEmptyPlaceholder(placeholder); |
| 36 | this._list.show(this.contentElement); |
| 37 | const addPatternButton = |
| 38 | UI.createTextButton(Common.UIString('Add pattern...'), this._addButtonClicked.bind(this), 'add-button'); |
| 39 | this.contentElement.appendChild(addPatternButton); |
| 40 | |
| 41 | this._setting = Common.moduleSetting('skipStackFramesPattern'); |
| 42 | this._setting.addChangeListener(this._settingUpdated, this); |
| 43 | |
| 44 | this.setDefaultFocusedElement(addPatternButton); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @override |
| 49 | */ |
| 50 | wasShown() { |
| 51 | super.wasShown(); |
| 52 | this._settingUpdated(); |
| 53 | } |
| 54 | |
| 55 | _settingUpdated() { |
| 56 | this._list.clear(); |
| 57 | const patterns = this._setting.getAsArray(); |
| 58 | for (let i = 0; i < patterns.length; ++i) |
| 59 | this._list.appendItem(patterns[i], true); |
| 60 | } |
| 61 | |
| 62 | _addButtonClicked() { |
| 63 | this._list.addNewItem(this._setting.getAsArray().length, {pattern: '', disabled: false}); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @override |
| 68 | * @param {*} item |
| 69 | * @param {boolean} editable |
| 70 | * @return {!Element} |
| 71 | */ |
| 72 | renderItem(item, editable) { |
| 73 | const element = createElementWithClass('div', 'blackbox-list-item'); |
| 74 | const pattern = element.createChild('div', 'blackbox-pattern'); |
| 75 | pattern.textContent = item.pattern; |
Mandy Chen | 31930c4 | 2019-06-05 00:47:08 | [diff] [blame^] | 76 | pattern.title = ls`Blackbox scripts whose names match '${item.pattern}'`; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 77 | element.createChild('div', 'blackbox-separator'); |
| 78 | element.createChild('div', 'blackbox-behavior').textContent = |
| 79 | item.disabled ? this._disabledLabel : this._blackboxLabel; |
| 80 | if (item.disabled) |
| 81 | element.classList.add('blackbox-disabled'); |
| 82 | return element; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @override |
| 87 | * @param {*} item |
| 88 | * @param {number} index |
| 89 | */ |
| 90 | removeItemRequested(item, index) { |
| 91 | const patterns = this._setting.getAsArray(); |
| 92 | patterns.splice(index, 1); |
| 93 | this._setting.setAsArray(patterns); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @override |
| 98 | * @param {*} item |
| 99 | * @param {!UI.ListWidget.Editor} editor |
| 100 | * @param {boolean} isNew |
| 101 | */ |
| 102 | commitEdit(item, editor, isNew) { |
| 103 | item.pattern = editor.control('pattern').value.trim(); |
| 104 | item.disabled = editor.control('behavior').value === this._disabledLabel; |
| 105 | |
| 106 | const list = this._setting.getAsArray(); |
| 107 | if (isNew) |
| 108 | list.push(item); |
| 109 | this._setting.setAsArray(list); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @override |
| 114 | * @param {*} item |
| 115 | * @return {!UI.ListWidget.Editor} |
| 116 | */ |
| 117 | beginEdit(item) { |
| 118 | const editor = this._createEditor(); |
| 119 | editor.control('pattern').value = item.pattern; |
| 120 | editor.control('behavior').value = item.disabled ? this._disabledLabel : this._blackboxLabel; |
| 121 | return editor; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * @return {!UI.ListWidget.Editor} |
| 126 | */ |
| 127 | _createEditor() { |
| 128 | if (this._editor) |
| 129 | return this._editor; |
| 130 | |
| 131 | const editor = new UI.ListWidget.Editor(); |
| 132 | this._editor = editor; |
| 133 | const content = editor.contentElement(); |
| 134 | |
| 135 | const titles = content.createChild('div', 'blackbox-edit-row'); |
| 136 | titles.createChild('div', 'blackbox-pattern').textContent = Common.UIString('Pattern'); |
| 137 | titles.createChild('div', 'blackbox-separator blackbox-separator-invisible'); |
| 138 | titles.createChild('div', 'blackbox-behavior').textContent = Common.UIString('Behavior'); |
| 139 | |
| 140 | const fields = content.createChild('div', 'blackbox-edit-row'); |
Chandani Shrestha | 97a703ee | 2019-06-03 22:45:11 | [diff] [blame] | 141 | const pattern = editor.createInput('pattern', 'text', '/framework\\.js$', patternValidator.bind(this)); |
| 142 | UI.ARIAUtils.setAccessibleName(pattern, ls`Pattern`); |
| 143 | fields.createChild('div', 'blackbox-pattern').appendChild(pattern); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 144 | fields.createChild('div', 'blackbox-separator blackbox-separator-invisible'); |
Chandani Shrestha | 97a703ee | 2019-06-03 22:45:11 | [diff] [blame] | 145 | const behavior = editor.createSelect('behavior', [this._blackboxLabel, this._disabledLabel], behaviorValidator); |
| 146 | UI.ARIAUtils.setAccessibleName(behavior, ls`Behavior`); |
| 147 | fields.createChild('div', 'blackbox-behavior').appendChild(behavior); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 148 | |
| 149 | return editor; |
| 150 | |
| 151 | /** |
| 152 | * @param {*} item |
| 153 | * @param {number} index |
| 154 | * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 155 | * @this {Settings.FrameworkBlackboxSettingsTab} |
| 156 | * @return {boolean} |
| 157 | */ |
| 158 | function patternValidator(item, index, input) { |
| 159 | const pattern = input.value.trim(); |
| 160 | const patterns = this._setting.getAsArray(); |
| 161 | for (let i = 0; i < patterns.length; ++i) { |
| 162 | if (i !== index && patterns[i].pattern === pattern) |
| 163 | return false; |
| 164 | } |
| 165 | |
| 166 | let regex; |
| 167 | try { |
| 168 | regex = new RegExp(pattern); |
| 169 | } catch (e) { |
| 170 | } |
| 171 | return !!(pattern && regex); |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * @param {*} item |
| 176 | * @param {number} index |
| 177 | * @param {!HTMLInputElement|!HTMLSelectElement} input |
| 178 | * @return {boolean} |
| 179 | */ |
| 180 | function behaviorValidator(item, index, input) { |
| 181 | return true; |
| 182 | } |
| 183 | } |
| 184 | }; |