Tim van der Lippe | 83f02be | 2020-01-23 11:11:40 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Tim van der Lippe | 1ebfc50 | 2020-01-15 13:45:09 | [diff] [blame] | 4 | |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 5 | import * as Common from '../common/common.js'; |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 6 | import * as i18n from '../i18n/i18n.js'; |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 7 | import * as UI from '../ui/ui.js'; |
| 8 | |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 9 | export const UIStrings = { |
| 10 | /** |
| 11 | *@description Header text content in Framework Blackbox Settings Tab of the Settings |
| 12 | */ |
| 13 | frameworkBlackboxing: 'Framework Blackboxing', |
| 14 | /** |
| 15 | *@description Text in Framework Blackbox Settings Tab of the Settings |
| 16 | */ |
| 17 | debuggerWillSkipThroughThe: 'Debugger will skip through the scripts and will not stop on exceptions thrown by them.', |
| 18 | /** |
| 19 | *@description Text in Framework Blackbox Settings Tab of the Settings |
| 20 | */ |
| 21 | blackboxContentScripts: 'Blackbox content scripts', |
| 22 | /** |
| 23 | *@description Blackbox content scripts title in Framework Blackbox Settings Tab of the Settings |
| 24 | */ |
| 25 | blackboxContentScriptsExtension: 'Blackbox content scripts (extension scripts in the page)', |
| 26 | /** |
| 27 | *@description Blackbox label in Framework Blackbox Settings Tab of the Settings |
| 28 | */ |
| 29 | blackbox: 'Blackbox', |
| 30 | /** |
| 31 | *@description Text to indicate something is not enabled |
| 32 | */ |
| 33 | disabled: 'Disabled', |
| 34 | /** |
| 35 | *@description Placeholder text content in Framework Blackbox Settings Tab of the Settings |
| 36 | */ |
| 37 | noBlackboxedPatterns: 'No blackboxed patterns', |
| 38 | /** |
| 39 | *@description Text of the add pattern button in Framework Blackbox Settings Tab of the Settings |
| 40 | */ |
| 41 | addPattern: 'Add pattern...', |
| 42 | /** |
| 43 | *@description Aria accessible name in Framework Blackbox Settings Tab of the Settings |
| 44 | */ |
| 45 | addFilenamePattern: 'Add filename pattern', |
| 46 | /** |
| 47 | *@description Pattern title in Framework Blackbox Settings Tab of the Settings |
| 48 | *@example {ad.*?} PH1 |
| 49 | */ |
| 50 | blackboxScriptsWhoseNamesMatchS: 'Blackbox scripts whose names match \'{PH1}\'', |
| 51 | /** |
| 52 | *@description Aria accessible name in Framework Blackbox Settings Tab of the Settings |
| 53 | */ |
| 54 | pattern: 'Pattern', |
| 55 | /** |
| 56 | *@description Aria accessible name in Framework Blackbox Settings Tab of the Settings |
| 57 | */ |
| 58 | behavior: 'Behavior', |
| 59 | /** |
| 60 | *@description Error message in Framework Blackbox settings pane that declares pattern must not be empty |
| 61 | */ |
| 62 | patternCannotBeEmpty: 'Pattern cannot be empty', |
| 63 | /** |
| 64 | *@description Error message in Framework Blackbox settings pane that declares pattern already exits |
| 65 | */ |
| 66 | patternAlreadyExists: 'Pattern already exists', |
| 67 | /** |
| 68 | *@description Error message in Framework Blackbox settings pane that declares pattern must be a valid regular expression |
| 69 | */ |
| 70 | patternMustBeAValidRegular: 'Pattern must be a valid regular expression', |
| 71 | }; |
| 72 | const str_ = i18n.i18n.registerUIStrings('settings/FrameworkBlackboxSettingsTab.js', UIStrings); |
| 73 | const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); |
| 74 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 75 | /** |
Andres Olivares | 52c4816 | 2020-10-23 02:50:49 | [diff] [blame] | 76 | * @implements {UI.ListWidget.Delegate<Common.Settings.RegExpSettingItem>} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 77 | * @unrestricted |
| 78 | */ |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 79 | export class FrameworkBlackboxSettingsTab extends UI.Widget.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 80 | constructor() { |
| 81 | super(true); |
Jack Franklin | 71519f8 | 2020-11-03 12:08:59 | [diff] [blame^] | 82 | this.registerRequiredCSS('settings/frameworkBlackboxSettingsTab.css', {enableLegacyPatching: true}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 83 | |
Chandani Shrestha | 97a703ee | 2019-06-03 22:45:11 | [diff] [blame] | 84 | const header = this.contentElement.createChild('div', 'header'); |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 85 | header.textContent = i18nString(UIStrings.frameworkBlackboxing); |
Chandani Shrestha | 97a703ee | 2019-06-03 22:45:11 | [diff] [blame] | 86 | UI.ARIAUtils.markAsHeading(header, 1); |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 87 | this.contentElement.createChild('div', 'intro').textContent = i18nString(UIStrings.debuggerWillSkipThroughThe); |
Harley Li | 4ca2783 | 2019-05-23 23:14:51 | [diff] [blame] | 88 | |
| 89 | const blackboxContentScripts = this.contentElement.createChild('div', 'blackbox-content-scripts'); |
| 90 | blackboxContentScripts.appendChild(UI.SettingsUI.createSettingCheckbox( |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 91 | i18nString(UIStrings.blackboxContentScripts), |
| 92 | Common.Settings.Settings.instance().moduleSetting('skipContentScripts'), true)); |
| 93 | blackboxContentScripts.title = i18nString(UIStrings.blackboxContentScriptsExtension); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 94 | |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 95 | this._blackboxLabel = i18nString(UIStrings.blackbox); |
| 96 | this._disabledLabel = i18nString(UIStrings.disabled); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 97 | |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 98 | this._list = new UI.ListWidget.ListWidget(this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 99 | this._list.element.classList.add('blackbox-list'); |
Jack Franklin | 71519f8 | 2020-11-03 12:08:59 | [diff] [blame^] | 100 | this._list.registerRequiredCSS('settings/frameworkBlackboxSettingsTab.css', {enableLegacyPatching: true}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 101 | |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 102 | const placeholder = document.createElement('div'); |
| 103 | placeholder.classList.add('blackbox-list-empty'); |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 104 | placeholder.textContent = i18nString(UIStrings.noBlackboxedPatterns); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 105 | this._list.setEmptyPlaceholder(placeholder); |
| 106 | this._list.show(this.contentElement); |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 107 | const addPatternButton = |
| 108 | UI.UIUtils.createTextButton(i18nString(UIStrings.addPattern), this._addButtonClicked.bind(this), 'add-button'); |
| 109 | UI.ARIAUtils.setAccessibleName(addPatternButton, i18nString(UIStrings.addFilenamePattern)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 110 | this.contentElement.appendChild(addPatternButton); |
| 111 | |
Andres Olivares | 52c4816 | 2020-10-23 02:50:49 | [diff] [blame] | 112 | /** @type {!Common.Settings.RegExpSetting} */ |
| 113 | this._setting = /** @type {!Common.Settings.RegExpSetting} */ ( |
| 114 | Common.Settings.Settings.instance().moduleSetting('skipStackFramesPattern')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 115 | this._setting.addChangeListener(this._settingUpdated, this); |
| 116 | |
| 117 | this.setDefaultFocusedElement(addPatternButton); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @override |
| 122 | */ |
| 123 | wasShown() { |
| 124 | super.wasShown(); |
| 125 | this._settingUpdated(); |
| 126 | } |
| 127 | |
| 128 | _settingUpdated() { |
| 129 | this._list.clear(); |
| 130 | const patterns = this._setting.getAsArray(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 131 | for (let i = 0; i < patterns.length; ++i) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 132 | this._list.appendItem(patterns[i], true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 133 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | _addButtonClicked() { |
| 137 | this._list.addNewItem(this._setting.getAsArray().length, {pattern: '', disabled: false}); |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * @override |
Andres Olivares | 52c4816 | 2020-10-23 02:50:49 | [diff] [blame] | 142 | * @param {!Common.Settings.RegExpSettingItem} item |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 143 | * @param {boolean} editable |
| 144 | * @return {!Element} |
| 145 | */ |
| 146 | renderItem(item, editable) { |
Tim van der Lippe | f49e232 | 2020-05-01 15:03:09 | [diff] [blame] | 147 | const element = document.createElement('div'); |
| 148 | element.classList.add('blackbox-list-item'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 149 | const pattern = element.createChild('div', 'blackbox-pattern'); |
| 150 | pattern.textContent = item.pattern; |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 151 | pattern.title = i18nString(UIStrings.blackboxScriptsWhoseNamesMatchS, {PH1: item.pattern}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 152 | element.createChild('div', 'blackbox-separator'); |
| 153 | element.createChild('div', 'blackbox-behavior').textContent = |
| 154 | item.disabled ? this._disabledLabel : this._blackboxLabel; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 155 | if (item.disabled) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 156 | element.classList.add('blackbox-disabled'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 157 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 158 | return element; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * @override |
Andres Olivares | 52c4816 | 2020-10-23 02:50:49 | [diff] [blame] | 163 | * @param {!Common.Settings.RegExpSettingItem} item |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 164 | * @param {number} index |
| 165 | */ |
| 166 | removeItemRequested(item, index) { |
| 167 | const patterns = this._setting.getAsArray(); |
| 168 | patterns.splice(index, 1); |
| 169 | this._setting.setAsArray(patterns); |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * @override |
Andres Olivares | 52c4816 | 2020-10-23 02:50:49 | [diff] [blame] | 174 | * @param {!Common.Settings.RegExpSettingItem} item |
| 175 | * @param {!UI.ListWidget.Editor<!Common.Settings.RegExpSettingItem>} editor |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 176 | * @param {boolean} isNew |
| 177 | */ |
| 178 | commitEdit(item, editor, isNew) { |
| 179 | item.pattern = editor.control('pattern').value.trim(); |
| 180 | item.disabled = editor.control('behavior').value === this._disabledLabel; |
| 181 | |
| 182 | const list = this._setting.getAsArray(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 183 | if (isNew) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 184 | list.push(item); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 185 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 186 | this._setting.setAsArray(list); |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * @override |
Andres Olivares | 52c4816 | 2020-10-23 02:50:49 | [diff] [blame] | 191 | * @param {!Common.Settings.RegExpSettingItem} item |
| 192 | * @return {!UI.ListWidget.Editor<!Common.Settings.RegExpSettingItem>} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 193 | */ |
| 194 | beginEdit(item) { |
| 195 | const editor = this._createEditor(); |
| 196 | editor.control('pattern').value = item.pattern; |
| 197 | editor.control('behavior').value = item.disabled ? this._disabledLabel : this._blackboxLabel; |
| 198 | return editor; |
| 199 | } |
| 200 | |
| 201 | /** |
Andres Olivares | 52c4816 | 2020-10-23 02:50:49 | [diff] [blame] | 202 | * @return {!UI.ListWidget.Editor<!Common.Settings.RegExpSettingItem>} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 203 | */ |
| 204 | _createEditor() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 205 | if (this._editor) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 206 | return this._editor; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 207 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 208 | |
| 209 | const editor = new UI.ListWidget.Editor(); |
| 210 | this._editor = editor; |
| 211 | const content = editor.contentElement(); |
| 212 | |
| 213 | const titles = content.createChild('div', 'blackbox-edit-row'); |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 214 | titles.createChild('div', 'blackbox-pattern').textContent = i18nString(UIStrings.pattern); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 215 | titles.createChild('div', 'blackbox-separator blackbox-separator-invisible'); |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 216 | titles.createChild('div', 'blackbox-behavior').textContent = i18nString(UIStrings.behavior); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 217 | |
| 218 | const fields = content.createChild('div', 'blackbox-edit-row'); |
Chandani Shrestha | 97a703ee | 2019-06-03 22:45:11 | [diff] [blame] | 219 | const pattern = editor.createInput('pattern', 'text', '/framework\\.js$', patternValidator.bind(this)); |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 220 | UI.ARIAUtils.setAccessibleName(pattern, i18nString(UIStrings.pattern)); |
Chandani Shrestha | 97a703ee | 2019-06-03 22:45:11 | [diff] [blame] | 221 | fields.createChild('div', 'blackbox-pattern').appendChild(pattern); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 222 | fields.createChild('div', 'blackbox-separator blackbox-separator-invisible'); |
Chandani Shrestha | 97a703ee | 2019-06-03 22:45:11 | [diff] [blame] | 223 | const behavior = editor.createSelect('behavior', [this._blackboxLabel, this._disabledLabel], behaviorValidator); |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 224 | UI.ARIAUtils.setAccessibleName(behavior, i18nString(UIStrings.behavior)); |
Chandani Shrestha | 97a703ee | 2019-06-03 22:45:11 | [diff] [blame] | 225 | fields.createChild('div', 'blackbox-behavior').appendChild(behavior); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 226 | |
| 227 | return editor; |
| 228 | |
| 229 | /** |
Andres Olivares | 52c4816 | 2020-10-23 02:50:49 | [diff] [blame] | 230 | * @param {!Common.Settings.RegExpSettingItem} item |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 231 | * @param {number} index |
| 232 | * @param {!HTMLInputElement|!HTMLSelectElement} input |
Tim van der Lippe | 1ebfc50 | 2020-01-15 13:45:09 | [diff] [blame] | 233 | * @this {FrameworkBlackboxSettingsTab} |
Amanda Baker | ca50282 | 2019-07-02 00:01:28 | [diff] [blame] | 234 | * @return {!UI.ListWidget.ValidatorResult} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 235 | */ |
| 236 | function patternValidator(item, index, input) { |
| 237 | const pattern = input.value.trim(); |
| 238 | const patterns = this._setting.getAsArray(); |
Chandani Shrestha | 810233b | 2019-07-29 20:04:16 | [diff] [blame] | 239 | |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 240 | if (!pattern.length) { |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 241 | return {valid: false, errorMessage: i18nString(UIStrings.patternCannotBeEmpty)}; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 242 | } |
Chandani Shrestha | 810233b | 2019-07-29 20:04:16 | [diff] [blame] | 243 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 244 | for (let i = 0; i < patterns.length; ++i) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 245 | if (i !== index && patterns[i].pattern === pattern) { |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 246 | return {valid: false, errorMessage: i18nString(UIStrings.patternAlreadyExists)}; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 247 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | let regex; |
| 251 | try { |
| 252 | regex = new RegExp(pattern); |
| 253 | } catch (e) { |
| 254 | } |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 255 | if (!regex) { |
vidorteg | c1aeb63 | 2020-10-22 02:59:33 | [diff] [blame] | 256 | return {valid: false, errorMessage: i18nString(UIStrings.patternMustBeAValidRegular)}; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 257 | } |
Andres Olivares | 52c4816 | 2020-10-23 02:50:49 | [diff] [blame] | 258 | return {valid: true, errorMessage: undefined}; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** |
Andres Olivares | 52c4816 | 2020-10-23 02:50:49 | [diff] [blame] | 262 | * @param {!Common.Settings.RegExpSettingItem} item |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 263 | * @param {number} index |
| 264 | * @param {!HTMLInputElement|!HTMLSelectElement} input |
Amanda Baker | ca50282 | 2019-07-02 00:01:28 | [diff] [blame] | 265 | * @return {!UI.ListWidget.ValidatorResult} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 266 | */ |
| 267 | function behaviorValidator(item, index, input) { |
Andres Olivares | 52c4816 | 2020-10-23 02:50:49 | [diff] [blame] | 268 | return {valid: true, errorMessage: undefined}; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 269 | } |
| 270 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 271 | } |