blob: a47ea0f80225f5d586c03e40054ef834ddcda617 [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 */
10Settings.FrameworkBlackboxSettingsTab = class extends UI.VBox {
11 constructor() {
12 super(true);
13 this.registerRequiredCSS('settings/frameworkBlackboxSettingsTab.css');
14
Harley Li4ca27832019-05-23 23:14:5115 this.contentElement.createChild('div', 'header').textContent = Common.UIString('Framework Blackboxing');
16 this.contentElement.createChild('div', 'intro').textContent =
17 ls`Debugger will skip through the scripts and will not stop on exceptions thrown by them.`;
18
19 const blackboxContentScripts = this.contentElement.createChild('div', 'blackbox-content-scripts');
20 blackboxContentScripts.appendChild(UI.SettingsUI.createSettingCheckbox(
21 ls`Blackbox content scripts`, Common.moduleSetting('skipContentScripts'), true));
22 blackboxContentScripts.title = ls`Blackbox content scripts (extension scripts in the page)`;
Blink Reformat4c46d092018-04-07 15:32:3723
24 this._blackboxLabel = Common.UIString('Blackbox');
25 this._disabledLabel = Common.UIString('Disabled');
26
27 this._list = new UI.ListWidget(this);
28 this._list.element.classList.add('blackbox-list');
29 this._list.registerRequiredCSS('settings/frameworkBlackboxSettingsTab.css');
30
31 const placeholder = createElementWithClass('div', 'blackbox-list-empty');
32 placeholder.textContent = Common.UIString('No blackboxed patterns');
33 this._list.setEmptyPlaceholder(placeholder);
34 this._list.show(this.contentElement);
35 const addPatternButton =
36 UI.createTextButton(Common.UIString('Add pattern...'), this._addButtonClicked.bind(this), 'add-button');
37 this.contentElement.appendChild(addPatternButton);
38
39 this._setting = Common.moduleSetting('skipStackFramesPattern');
40 this._setting.addChangeListener(this._settingUpdated, this);
41
42 this.setDefaultFocusedElement(addPatternButton);
Collin Baker54daf082019-05-17 21:26:0743 this.contentElement.tabIndex = 0;
Blink Reformat4c46d092018-04-07 15:32:3744 }
45
46 /**
47 * @override
48 */
49 wasShown() {
50 super.wasShown();
51 this._settingUpdated();
52 }
53
54 _settingUpdated() {
55 this._list.clear();
56 const patterns = this._setting.getAsArray();
57 for (let i = 0; i < patterns.length; ++i)
58 this._list.appendItem(patterns[i], true);
59 }
60
61 _addButtonClicked() {
62 this._list.addNewItem(this._setting.getAsArray().length, {pattern: '', disabled: false});
63 }
64
65 /**
66 * @override
67 * @param {*} item
68 * @param {boolean} editable
69 * @return {!Element}
70 */
71 renderItem(item, editable) {
72 const element = createElementWithClass('div', 'blackbox-list-item');
73 const pattern = element.createChild('div', 'blackbox-pattern');
74 pattern.textContent = item.pattern;
Harley Li4ca27832019-05-23 23:14:5175 pattern.title = ls`Blackbox scripts whose names match` +
76 ' \'' + item.pattern + '\'';
Blink Reformat4c46d092018-04-07 15:32:3777 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');
Collin Baker54daf082019-05-17 21:26:07141 fields.createChild('div', 'blackbox-pattern')
142 .appendChild(editor.createInput('pattern', 'text', '/framework\\.js$', patternValidator.bind(this)));
Blink Reformat4c46d092018-04-07 15:32:37143 fields.createChild('div', 'blackbox-separator blackbox-separator-invisible');
Collin Baker54daf082019-05-17 21:26:07144 fields.createChild('div', 'blackbox-behavior')
145 .appendChild(editor.createSelect('behavior', [this._blackboxLabel, this._disabledLabel], behaviorValidator));
Blink Reformat4c46d092018-04-07 15:32:37146
147 return editor;
148
149 /**
150 * @param {*} item
151 * @param {number} index
152 * @param {!HTMLInputElement|!HTMLSelectElement} input
153 * @this {Settings.FrameworkBlackboxSettingsTab}
154 * @return {boolean}
155 */
156 function patternValidator(item, index, input) {
157 const pattern = input.value.trim();
158 const patterns = this._setting.getAsArray();
159 for (let i = 0; i < patterns.length; ++i) {
160 if (i !== index && patterns[i].pattern === pattern)
161 return false;
162 }
163
164 let regex;
165 try {
166 regex = new RegExp(pattern);
167 } catch (e) {
168 }
169 return !!(pattern && regex);
170 }
171
172 /**
173 * @param {*} item
174 * @param {number} index
175 * @param {!HTMLInputElement|!HTMLSelectElement} input
176 * @return {boolean}
177 */
178 function behaviorValidator(item, index, input) {
179 return true;
180 }
181 }
182};