blob: 910d63e2f57288357d4da65bb9f4e166fcf99e95 [file] [log] [blame]
Tim van der Lippe83f02be2020-01-23 11:11:401// 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 Lippe1ebfc502020-01-15 13:45:094
Tim van der Lippe66684e92020-01-24 14:01:185import * as Common from '../common/common.js';
vidortegc1aeb632020-10-22 02:59:336import * as i18n from '../i18n/i18n.js';
Tim van der Lippe66684e92020-01-24 14:01:187import * as UI from '../ui/ui.js';
8
vidortegc1aeb632020-10-22 02:59:339export 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};
72const str_ = i18n.i18n.registerUIStrings('settings/FrameworkBlackboxSettingsTab.js', UIStrings);
73const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
74
Blink Reformat4c46d092018-04-07 15:32:3775/**
Andres Olivares52c48162020-10-23 02:50:4976 * @implements {UI.ListWidget.Delegate<Common.Settings.RegExpSettingItem>}
Blink Reformat4c46d092018-04-07 15:32:3777 * @unrestricted
78 */
Tim van der Lippe66684e92020-01-24 14:01:1879export class FrameworkBlackboxSettingsTab extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3780 constructor() {
81 super(true);
Jack Franklin71519f82020-11-03 12:08:5982 this.registerRequiredCSS('settings/frameworkBlackboxSettingsTab.css', {enableLegacyPatching: true});
Blink Reformat4c46d092018-04-07 15:32:3783
Chandani Shrestha97a703ee2019-06-03 22:45:1184 const header = this.contentElement.createChild('div', 'header');
vidortegc1aeb632020-10-22 02:59:3385 header.textContent = i18nString(UIStrings.frameworkBlackboxing);
Chandani Shrestha97a703ee2019-06-03 22:45:1186 UI.ARIAUtils.markAsHeading(header, 1);
vidortegc1aeb632020-10-22 02:59:3387 this.contentElement.createChild('div', 'intro').textContent = i18nString(UIStrings.debuggerWillSkipThroughThe);
Harley Li4ca27832019-05-23 23:14:5188
89 const blackboxContentScripts = this.contentElement.createChild('div', 'blackbox-content-scripts');
90 blackboxContentScripts.appendChild(UI.SettingsUI.createSettingCheckbox(
vidortegc1aeb632020-10-22 02:59:3391 i18nString(UIStrings.blackboxContentScripts),
92 Common.Settings.Settings.instance().moduleSetting('skipContentScripts'), true));
93 blackboxContentScripts.title = i18nString(UIStrings.blackboxContentScriptsExtension);
Blink Reformat4c46d092018-04-07 15:32:3794
vidortegc1aeb632020-10-22 02:59:3395 this._blackboxLabel = i18nString(UIStrings.blackbox);
96 this._disabledLabel = i18nString(UIStrings.disabled);
Blink Reformat4c46d092018-04-07 15:32:3797
Tim van der Lippe66684e92020-01-24 14:01:1898 this._list = new UI.ListWidget.ListWidget(this);
Blink Reformat4c46d092018-04-07 15:32:3799 this._list.element.classList.add('blackbox-list');
Jack Franklin71519f82020-11-03 12:08:59100 this._list.registerRequiredCSS('settings/frameworkBlackboxSettingsTab.css', {enableLegacyPatching: true});
Blink Reformat4c46d092018-04-07 15:32:37101
Tim van der Lippef49e2322020-05-01 15:03:09102 const placeholder = document.createElement('div');
103 placeholder.classList.add('blackbox-list-empty');
vidortegc1aeb632020-10-22 02:59:33104 placeholder.textContent = i18nString(UIStrings.noBlackboxedPatterns);
Blink Reformat4c46d092018-04-07 15:32:37105 this._list.setEmptyPlaceholder(placeholder);
106 this._list.show(this.contentElement);
vidortegc1aeb632020-10-22 02:59:33107 const addPatternButton =
108 UI.UIUtils.createTextButton(i18nString(UIStrings.addPattern), this._addButtonClicked.bind(this), 'add-button');
109 UI.ARIAUtils.setAccessibleName(addPatternButton, i18nString(UIStrings.addFilenamePattern));
Blink Reformat4c46d092018-04-07 15:32:37110 this.contentElement.appendChild(addPatternButton);
111
Andres Olivares52c48162020-10-23 02:50:49112 /** @type {!Common.Settings.RegExpSetting} */
113 this._setting = /** @type {!Common.Settings.RegExpSetting} */ (
114 Common.Settings.Settings.instance().moduleSetting('skipStackFramesPattern'));
Blink Reformat4c46d092018-04-07 15:32:37115 this._setting.addChangeListener(this._settingUpdated, this);
116
117 this.setDefaultFocusedElement(addPatternButton);
Blink Reformat4c46d092018-04-07 15:32:37118 }
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 Lippe1d6e57a2019-09-30 11:55:34131 for (let i = 0; i < patterns.length; ++i) {
Blink Reformat4c46d092018-04-07 15:32:37132 this._list.appendItem(patterns[i], true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34133 }
Blink Reformat4c46d092018-04-07 15:32:37134 }
135
136 _addButtonClicked() {
137 this._list.addNewItem(this._setting.getAsArray().length, {pattern: '', disabled: false});
138 }
139
140 /**
141 * @override
Andres Olivares52c48162020-10-23 02:50:49142 * @param {!Common.Settings.RegExpSettingItem} item
Blink Reformat4c46d092018-04-07 15:32:37143 * @param {boolean} editable
144 * @return {!Element}
145 */
146 renderItem(item, editable) {
Tim van der Lippef49e2322020-05-01 15:03:09147 const element = document.createElement('div');
148 element.classList.add('blackbox-list-item');
Blink Reformat4c46d092018-04-07 15:32:37149 const pattern = element.createChild('div', 'blackbox-pattern');
150 pattern.textContent = item.pattern;
vidortegc1aeb632020-10-22 02:59:33151 pattern.title = i18nString(UIStrings.blackboxScriptsWhoseNamesMatchS, {PH1: item.pattern});
Blink Reformat4c46d092018-04-07 15:32:37152 element.createChild('div', 'blackbox-separator');
153 element.createChild('div', 'blackbox-behavior').textContent =
154 item.disabled ? this._disabledLabel : this._blackboxLabel;
Tim van der Lippe1d6e57a2019-09-30 11:55:34155 if (item.disabled) {
Blink Reformat4c46d092018-04-07 15:32:37156 element.classList.add('blackbox-disabled');
Tim van der Lippe1d6e57a2019-09-30 11:55:34157 }
Blink Reformat4c46d092018-04-07 15:32:37158 return element;
159 }
160
161 /**
162 * @override
Andres Olivares52c48162020-10-23 02:50:49163 * @param {!Common.Settings.RegExpSettingItem} item
Blink Reformat4c46d092018-04-07 15:32:37164 * @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 Olivares52c48162020-10-23 02:50:49174 * @param {!Common.Settings.RegExpSettingItem} item
175 * @param {!UI.ListWidget.Editor<!Common.Settings.RegExpSettingItem>} editor
Blink Reformat4c46d092018-04-07 15:32:37176 * @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 Lippe1d6e57a2019-09-30 11:55:34183 if (isNew) {
Blink Reformat4c46d092018-04-07 15:32:37184 list.push(item);
Tim van der Lippe1d6e57a2019-09-30 11:55:34185 }
Blink Reformat4c46d092018-04-07 15:32:37186 this._setting.setAsArray(list);
187 }
188
189 /**
190 * @override
Andres Olivares52c48162020-10-23 02:50:49191 * @param {!Common.Settings.RegExpSettingItem} item
192 * @return {!UI.ListWidget.Editor<!Common.Settings.RegExpSettingItem>}
Blink Reformat4c46d092018-04-07 15:32:37193 */
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 Olivares52c48162020-10-23 02:50:49202 * @return {!UI.ListWidget.Editor<!Common.Settings.RegExpSettingItem>}
Blink Reformat4c46d092018-04-07 15:32:37203 */
204 _createEditor() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34205 if (this._editor) {
Blink Reformat4c46d092018-04-07 15:32:37206 return this._editor;
Tim van der Lippe1d6e57a2019-09-30 11:55:34207 }
Blink Reformat4c46d092018-04-07 15:32:37208
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');
vidortegc1aeb632020-10-22 02:59:33214 titles.createChild('div', 'blackbox-pattern').textContent = i18nString(UIStrings.pattern);
Blink Reformat4c46d092018-04-07 15:32:37215 titles.createChild('div', 'blackbox-separator blackbox-separator-invisible');
vidortegc1aeb632020-10-22 02:59:33216 titles.createChild('div', 'blackbox-behavior').textContent = i18nString(UIStrings.behavior);
Blink Reformat4c46d092018-04-07 15:32:37217
218 const fields = content.createChild('div', 'blackbox-edit-row');
Chandani Shrestha97a703ee2019-06-03 22:45:11219 const pattern = editor.createInput('pattern', 'text', '/framework\\.js$', patternValidator.bind(this));
vidortegc1aeb632020-10-22 02:59:33220 UI.ARIAUtils.setAccessibleName(pattern, i18nString(UIStrings.pattern));
Chandani Shrestha97a703ee2019-06-03 22:45:11221 fields.createChild('div', 'blackbox-pattern').appendChild(pattern);
Blink Reformat4c46d092018-04-07 15:32:37222 fields.createChild('div', 'blackbox-separator blackbox-separator-invisible');
Chandani Shrestha97a703ee2019-06-03 22:45:11223 const behavior = editor.createSelect('behavior', [this._blackboxLabel, this._disabledLabel], behaviorValidator);
vidortegc1aeb632020-10-22 02:59:33224 UI.ARIAUtils.setAccessibleName(behavior, i18nString(UIStrings.behavior));
Chandani Shrestha97a703ee2019-06-03 22:45:11225 fields.createChild('div', 'blackbox-behavior').appendChild(behavior);
Blink Reformat4c46d092018-04-07 15:32:37226
227 return editor;
228
229 /**
Andres Olivares52c48162020-10-23 02:50:49230 * @param {!Common.Settings.RegExpSettingItem} item
Blink Reformat4c46d092018-04-07 15:32:37231 * @param {number} index
232 * @param {!HTMLInputElement|!HTMLSelectElement} input
Tim van der Lippe1ebfc502020-01-15 13:45:09233 * @this {FrameworkBlackboxSettingsTab}
Amanda Bakerca502822019-07-02 00:01:28234 * @return {!UI.ListWidget.ValidatorResult}
Blink Reformat4c46d092018-04-07 15:32:37235 */
236 function patternValidator(item, index, input) {
237 const pattern = input.value.trim();
238 const patterns = this._setting.getAsArray();
Chandani Shrestha810233b2019-07-29 20:04:16239
Tim van der Lippe1d6e57a2019-09-30 11:55:34240 if (!pattern.length) {
vidortegc1aeb632020-10-22 02:59:33241 return {valid: false, errorMessage: i18nString(UIStrings.patternCannotBeEmpty)};
Tim van der Lippe1d6e57a2019-09-30 11:55:34242 }
Chandani Shrestha810233b2019-07-29 20:04:16243
Blink Reformat4c46d092018-04-07 15:32:37244 for (let i = 0; i < patterns.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34245 if (i !== index && patterns[i].pattern === pattern) {
vidortegc1aeb632020-10-22 02:59:33246 return {valid: false, errorMessage: i18nString(UIStrings.patternAlreadyExists)};
Tim van der Lippe1d6e57a2019-09-30 11:55:34247 }
Blink Reformat4c46d092018-04-07 15:32:37248 }
249
250 let regex;
251 try {
252 regex = new RegExp(pattern);
253 } catch (e) {
254 }
Tim van der Lippe1d6e57a2019-09-30 11:55:34255 if (!regex) {
vidortegc1aeb632020-10-22 02:59:33256 return {valid: false, errorMessage: i18nString(UIStrings.patternMustBeAValidRegular)};
Tim van der Lippe1d6e57a2019-09-30 11:55:34257 }
Andres Olivares52c48162020-10-23 02:50:49258 return {valid: true, errorMessage: undefined};
Blink Reformat4c46d092018-04-07 15:32:37259 }
260
261 /**
Andres Olivares52c48162020-10-23 02:50:49262 * @param {!Common.Settings.RegExpSettingItem} item
Blink Reformat4c46d092018-04-07 15:32:37263 * @param {number} index
264 * @param {!HTMLInputElement|!HTMLSelectElement} input
Amanda Bakerca502822019-07-02 00:01:28265 * @return {!UI.ListWidget.ValidatorResult}
Blink Reformat4c46d092018-04-07 15:32:37266 */
267 function behaviorValidator(item, index, input) {
Andres Olivares52c48162020-10-23 02:50:49268 return {valid: true, errorMessage: undefined};
Blink Reformat4c46d092018-04-07 15:32:37269 }
270 }
Paul Lewis5d4133e2019-11-27 13:06:01271}