blob: 490aedb85477090b6ce16c54f14290d0944eb88e [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
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 */
Paul Lewis5d4133e2019-11-27 13:06:0110export default class FrameworkBlackboxSettingsTab extends UI.VBox {
Blink Reformat4c46d092018-04-07 15:32:3711 constructor() {
12 super(true);
13 this.registerRequiredCSS('settings/frameworkBlackboxSettingsTab.css');
14
Chandani Shrestha97a703ee2019-06-03 22:45:1115 const header = this.contentElement.createChild('div', 'header');
16 header.textContent = ls`Framework Blackboxing`;
17 UI.ARIAUtils.markAsHeading(header, 1);
Harley Li4ca27832019-05-23 23:14:5118 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 Reformat4c46d092018-04-07 15:32:3725
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 Reformat4c46d092018-04-07 15:32:3745 }
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();
Tim van der Lippe1d6e57a2019-09-30 11:55:3458 for (let i = 0; i < patterns.length; ++i) {
Blink Reformat4c46d092018-04-07 15:32:3759 this._list.appendItem(patterns[i], true);
Tim van der Lippe1d6e57a2019-09-30 11:55:3460 }
Blink Reformat4c46d092018-04-07 15:32:3761 }
62
63 _addButtonClicked() {
64 this._list.addNewItem(this._setting.getAsArray().length, {pattern: '', disabled: false});
65 }
66
67 /**
68 * @override
69 * @param {*} item
70 * @param {boolean} editable
71 * @return {!Element}
72 */
73 renderItem(item, editable) {
74 const element = createElementWithClass('div', 'blackbox-list-item');
75 const pattern = element.createChild('div', 'blackbox-pattern');
76 pattern.textContent = item.pattern;
Mandy Chen31930c42019-06-05 00:47:0877 pattern.title = ls`Blackbox scripts whose names match '${item.pattern}'`;
Blink Reformat4c46d092018-04-07 15:32:3778 element.createChild('div', 'blackbox-separator');
79 element.createChild('div', 'blackbox-behavior').textContent =
80 item.disabled ? this._disabledLabel : this._blackboxLabel;
Tim van der Lippe1d6e57a2019-09-30 11:55:3481 if (item.disabled) {
Blink Reformat4c46d092018-04-07 15:32:3782 element.classList.add('blackbox-disabled');
Tim van der Lippe1d6e57a2019-09-30 11:55:3483 }
Blink Reformat4c46d092018-04-07 15:32:3784 return element;
85 }
86
87 /**
88 * @override
89 * @param {*} item
90 * @param {number} index
91 */
92 removeItemRequested(item, index) {
93 const patterns = this._setting.getAsArray();
94 patterns.splice(index, 1);
95 this._setting.setAsArray(patterns);
96 }
97
98 /**
99 * @override
100 * @param {*} item
101 * @param {!UI.ListWidget.Editor} editor
102 * @param {boolean} isNew
103 */
104 commitEdit(item, editor, isNew) {
105 item.pattern = editor.control('pattern').value.trim();
106 item.disabled = editor.control('behavior').value === this._disabledLabel;
107
108 const list = this._setting.getAsArray();
Tim van der Lippe1d6e57a2019-09-30 11:55:34109 if (isNew) {
Blink Reformat4c46d092018-04-07 15:32:37110 list.push(item);
Tim van der Lippe1d6e57a2019-09-30 11:55:34111 }
Blink Reformat4c46d092018-04-07 15:32:37112 this._setting.setAsArray(list);
113 }
114
115 /**
116 * @override
117 * @param {*} item
118 * @return {!UI.ListWidget.Editor}
119 */
120 beginEdit(item) {
121 const editor = this._createEditor();
122 editor.control('pattern').value = item.pattern;
123 editor.control('behavior').value = item.disabled ? this._disabledLabel : this._blackboxLabel;
124 return editor;
125 }
126
127 /**
128 * @return {!UI.ListWidget.Editor}
129 */
130 _createEditor() {
Tim van der Lippe1d6e57a2019-09-30 11:55:34131 if (this._editor) {
Blink Reformat4c46d092018-04-07 15:32:37132 return this._editor;
Tim van der Lippe1d6e57a2019-09-30 11:55:34133 }
Blink Reformat4c46d092018-04-07 15:32:37134
135 const editor = new UI.ListWidget.Editor();
136 this._editor = editor;
137 const content = editor.contentElement();
138
139 const titles = content.createChild('div', 'blackbox-edit-row');
140 titles.createChild('div', 'blackbox-pattern').textContent = Common.UIString('Pattern');
141 titles.createChild('div', 'blackbox-separator blackbox-separator-invisible');
142 titles.createChild('div', 'blackbox-behavior').textContent = Common.UIString('Behavior');
143
144 const fields = content.createChild('div', 'blackbox-edit-row');
Chandani Shrestha97a703ee2019-06-03 22:45:11145 const pattern = editor.createInput('pattern', 'text', '/framework\\.js$', patternValidator.bind(this));
146 UI.ARIAUtils.setAccessibleName(pattern, ls`Pattern`);
147 fields.createChild('div', 'blackbox-pattern').appendChild(pattern);
Blink Reformat4c46d092018-04-07 15:32:37148 fields.createChild('div', 'blackbox-separator blackbox-separator-invisible');
Chandani Shrestha97a703ee2019-06-03 22:45:11149 const behavior = editor.createSelect('behavior', [this._blackboxLabel, this._disabledLabel], behaviorValidator);
150 UI.ARIAUtils.setAccessibleName(behavior, ls`Behavior`);
151 fields.createChild('div', 'blackbox-behavior').appendChild(behavior);
Blink Reformat4c46d092018-04-07 15:32:37152
153 return editor;
154
155 /**
156 * @param {*} item
157 * @param {number} index
158 * @param {!HTMLInputElement|!HTMLSelectElement} input
159 * @this {Settings.FrameworkBlackboxSettingsTab}
Amanda Bakerca502822019-07-02 00:01:28160 * @return {!UI.ListWidget.ValidatorResult}
Blink Reformat4c46d092018-04-07 15:32:37161 */
162 function patternValidator(item, index, input) {
163 const pattern = input.value.trim();
164 const patterns = this._setting.getAsArray();
Chandani Shrestha810233b2019-07-29 20:04:16165
Tim van der Lippe1d6e57a2019-09-30 11:55:34166 if (!pattern.length) {
Chandani Shrestha810233b2019-07-29 20:04:16167 return {valid: false, errorMessage: ls`Pattern cannot be empty`};
Tim van der Lippe1d6e57a2019-09-30 11:55:34168 }
Chandani Shrestha810233b2019-07-29 20:04:16169
Blink Reformat4c46d092018-04-07 15:32:37170 for (let i = 0; i < patterns.length; ++i) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34171 if (i !== index && patterns[i].pattern === pattern) {
Chandani Shrestha810233b2019-07-29 20:04:16172 return {valid: false, errorMessage: ls`Pattern already exists`};
Tim van der Lippe1d6e57a2019-09-30 11:55:34173 }
Blink Reformat4c46d092018-04-07 15:32:37174 }
175
176 let regex;
177 try {
178 regex = new RegExp(pattern);
179 } catch (e) {
180 }
Tim van der Lippe1d6e57a2019-09-30 11:55:34181 if (!regex) {
Chandani Shrestha810233b2019-07-29 20:04:16182 return {valid: false, errorMessage: ls`Pattern must be a valid regular expression`};
Tim van der Lippe1d6e57a2019-09-30 11:55:34183 } else {
Chandani Shrestha810233b2019-07-29 20:04:16184 return {valid: true};
Tim van der Lippe1d6e57a2019-09-30 11:55:34185 }
Blink Reformat4c46d092018-04-07 15:32:37186 }
187
188 /**
189 * @param {*} item
190 * @param {number} index
191 * @param {!HTMLInputElement|!HTMLSelectElement} input
Amanda Bakerca502822019-07-02 00:01:28192 * @return {!UI.ListWidget.ValidatorResult}
Blink Reformat4c46d092018-04-07 15:32:37193 */
194 function behaviorValidator(item, index, input) {
Amanda Bakerca502822019-07-02 00:01:28195 return {valid: true};
Blink Reformat4c46d092018-04-07 15:32:37196 }
197 }
Paul Lewis5d4133e2019-11-27 13:06:01198}
199
200/* Legacy exported object */
201self.Settings = self.Settings || {};
202
203/* Legacy exported object */
204Settings = Settings || {};
205
206/**
207 * @constructor
208 */
209Settings.FrameworkBlackboxSettingsTab = FrameworkBlackboxSettingsTab;