blob: cdac67a4a0d1743f646c5d32b457f2c5755d117e [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
Tim van der Lippe66684e92020-01-24 14:01:1830
Jan Schefflerd8380b62020-07-28 16:14:1531
Tim van der Lippe66684e92020-01-24 14:01:1832import * as Common from '../common/common.js';
33import * as Components from '../components/components.js';
34import * as Host from '../host/host.js';
vidortegc1aeb632020-10-22 02:59:3335import * as i18n from '../i18n/i18n.js';
Tim van der Lippe7f2002c2020-09-28 14:54:0136import * as Root from '../root/root.js';
Tim van der Lippe66684e92020-01-24 14:01:1837import * as UI from '../ui/ui.js';
38
Andres Olivaresc51c18a2020-10-21 02:48:4439import {KeybindsSettingsTab} from './KeybindsSettingsTab.js'; // eslint-disable-line no-unused-vars
40
vidortegc1aeb632020-10-22 02:59:3341export const UIStrings = {
42 /**
43 *@description Name of the Settings view
44 */
45 settings: 'Settings',
46 /**
47 *@description Text for keyboard shortcuts
48 */
49 shortcuts: 'Shortcuts',
50 /**
51 *@description Text in Settings Screen of the Settings
52 */
53 preferences: 'Preferences',
54 /**
55 *@description Text of button in Settings Screen of the Settings
56 */
57 restoreDefaultsAndReload: 'Restore defaults and reload',
58 /**
59 *@description Text in Settings Screen of the Settings
60 */
61 experiments: 'Experiments',
62 /**
63 *@description Message shown in the experiments panel to warn users about any possible unstable features.
64 */
65 theseExperimentsCouldBeUnstable:
66 'These experiments could be unstable or unreliable and may require you to restart DevTools.',
67 /**
68 *@description Message text content in Settings Screen of the Settings
69 */
70 theseExperimentsAreParticularly: 'These experiments are particularly unstable. Enable at your own risk.',
71 /**
72 *@description Warning text content in Settings Screen of the Settings
73 */
74 warning: 'WARNING:',
75 /**
76 *@description Message to display if a setting change requires a reload of DevTools
77 */
78 oneOrMoreSettingsHaveChanged: 'One or more settings have changed which requires a reload to take effect.',
79};
80const str_ = i18n.i18n.registerUIStrings('settings/SettingsScreen.js', UIStrings);
81const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
82
Tim van der Lipped87271d2020-09-28 15:17:0683/** @type {!SettingsScreen} */
84let settingsScreenInstance;
85
Blink Reformat4c46d092018-04-07 15:32:3786/**
Tim van der Lippe66684e92020-01-24 14:01:1887 * @implements {UI.View.ViewLocationResolver}
Blink Reformat4c46d092018-04-07 15:32:3788 * @unrestricted
89 */
Tim van der Lippe66684e92020-01-24 14:01:1890export class SettingsScreen extends UI.Widget.VBox {
Tim van der Lipped87271d2020-09-28 15:17:0691 /**
92 * @private
93 */
Blink Reformat4c46d092018-04-07 15:32:3794 constructor() {
95 super(true);
Jack Franklin71519f82020-11-03 12:08:5996 this.registerRequiredCSS('settings/settingsScreen.css', {enableLegacyPatching: true});
Blink Reformat4c46d092018-04-07 15:32:3797
Blink Reformat4c46d092018-04-07 15:32:3798 this.contentElement.classList.add('settings-window-main');
99 this.contentElement.classList.add('vbox');
100
Andres Olivaresc51c18a2020-10-21 02:48:44101 const settingsLabelElement = document.createElement('div');
Tim van der Lippe66684e92020-01-24 14:01:18102 const settingsTitleElement =
103 UI.Utils.createShadowRootWithCoreStyles(settingsLabelElement, 'settings/settingsScreen.css')
104 .createChild('div', 'settings-window-title');
John Emaub970e562019-06-05 01:17:27105
106 UI.ARIAUtils.markAsHeading(settingsTitleElement, 1);
vidortegc1aeb632020-10-22 02:59:33107 settingsTitleElement.textContent = i18nString(UIStrings.settings);
Blink Reformat4c46d092018-04-07 15:32:37108
Paul Lewis75c7d0d2020-03-19 12:17:26109 this._tabbedLocation = UI.ViewManager.ViewManager.instance().createTabbedLocation(
Brian Cui4fef3cd2020-02-11 01:05:55110 () => SettingsScreen._revealSettingsScreen(), 'settings-view');
Blink Reformat4c46d092018-04-07 15:32:37111 const tabbedPane = this._tabbedLocation.tabbedPane();
Tim van der Lippe66684e92020-01-24 14:01:18112 tabbedPane.leftToolbar().appendToolbarItem(new UI.Toolbar.ToolbarItem(settingsLabelElement));
Blink Reformat4c46d092018-04-07 15:32:37113 tabbedPane.setShrinkableTabs(false);
114 tabbedPane.makeVerticalTabLayout();
Andres Olivaresc51c18a2020-10-21 02:48:44115 const keyBindsView = UI.ViewManager.ViewManager.instance().view('keybinds');
116 if (keyBindsView) {
117 keyBindsView.widget().then(widget => {
118 this._keybindsTab = /** @type {!KeybindsSettingsTab} */ (widget);
119 });
120 }
Blink Reformat4c46d092018-04-07 15:32:37121 tabbedPane.show(this.contentElement);
Brian Cui4fef3cd2020-02-11 01:05:55122 tabbedPane.selectTab('preferences');
123 tabbedPane.addEventListener(UI.TabbedPane.Events.TabInvoked, this._tabInvoked, this);
124 this._reportTabOnReveal = false;
Blink Reformat4c46d092018-04-07 15:32:37125 }
126
127 /**
Tim van der Lipped87271d2020-09-28 15:17:06128 * @param {{forceNew: ?boolean}} opts
129 */
130 static instance(opts = {forceNew: null}) {
131 const {forceNew} = opts;
132 if (!settingsScreenInstance || forceNew) {
133 settingsScreenInstance = new SettingsScreen();
134 }
135
136 return settingsScreenInstance;
137 }
138
139 /**
Brian Cui4fef3cd2020-02-11 01:05:55140 * @return {!SettingsScreen}
Blink Reformat4c46d092018-04-07 15:32:37141 */
Brian Cui4fef3cd2020-02-11 01:05:55142 static _revealSettingsScreen() {
Tim van der Lipped87271d2020-09-28 15:17:06143 const settingsScreen = SettingsScreen.instance();
Tim van der Lippe1d6e57a2019-09-30 11:55:34144 if (settingsScreen.isShowing()) {
Brian Cui4fef3cd2020-02-11 01:05:55145 return settingsScreen;
Tim van der Lippe1d6e57a2019-09-30 11:55:34146 }
Brian Cui4fef3cd2020-02-11 01:05:55147
148 settingsScreen._reportTabOnReveal = true;
Tim van der Lippe66684e92020-01-24 14:01:18149 const dialog = new UI.Dialog.Dialog();
Chandani Shrestha08469b82019-10-02 17:22:55150 dialog.contentElement.tabIndex = -1;
Blink Reformat4c46d092018-04-07 15:32:37151 dialog.addCloseButton();
Brian Cui8fdb1482019-12-04 21:41:46152 dialog.setOutsideClickCallback(() => {});
153 dialog.setPointerEventsBehavior(UI.GlassPane.PointerEventsBehavior.PierceGlassPane);
154 dialog.setOutsideTabIndexBehavior(UI.Dialog.OutsideTabIndexBehavior.PreserveMainViewTabIndex);
Blink Reformat4c46d092018-04-07 15:32:37155 settingsScreen.show(dialog.contentElement);
Jack Lynchca3683d2020-09-30 22:54:57156 dialog.setEscapeKeyCallback(settingsScreen._onEscapeKeyPressed.bind(settingsScreen));
Andres Olivaresc51c18a2020-10-21 02:48:44157
158 // UI.Dialog extends GlassPane and overrides the `show` method with a wider
159 // accepted type. However, TypeScript uses the supertype declaration to
160 // determine the full type, which requires a `!Document`.
161 // @ts-ignore
Blink Reformat4c46d092018-04-07 15:32:37162 dialog.show();
Jack Lynch85edfc82020-03-09 18:11:13163
Brian Cui4fef3cd2020-02-11 01:05:55164 return settingsScreen;
165 }
166
167 /**
Andres Olivaresc51c18a2020-10-21 02:48:44168 * @param {!ShowSettingsScreenOptions=} options
Brian Cui4fef3cd2020-02-11 01:05:55169 */
Andres Olivaresc51c18a2020-10-21 02:48:44170 static async _showSettingsScreen(options = {name: undefined, focusTabHeader: undefined}) {
Brian Cui4fef3cd2020-02-11 01:05:55171 const {name, focusTabHeader} = options;
172 const settingsScreen = SettingsScreen._revealSettingsScreen();
173
174 settingsScreen._selectTab(name || 'preferences');
Brian Cui55d00af2020-04-09 18:45:40175 const tabbedPane = settingsScreen._tabbedLocation.tabbedPane();
176 await tabbedPane.waitForTabElementUpdate();
Jack Lynch85edfc82020-03-09 18:11:13177 if (focusTabHeader) {
Jack Lynch85edfc82020-03-09 18:11:13178 tabbedPane.focusSelectedTabHeader();
Brian Cui55d00af2020-04-09 18:45:40179 } else {
180 tabbedPane.focus();
Jack Lynch85edfc82020-03-09 18:11:13181 }
Blink Reformat4c46d092018-04-07 15:32:37182 }
183
184 /**
185 * @override
186 * @param {string} locationName
Tim van der Lippe66684e92020-01-24 14:01:18187 * @return {?UI.View.ViewLocation}
Blink Reformat4c46d092018-04-07 15:32:37188 */
189 resolveLocation(locationName) {
190 return this._tabbedLocation;
191 }
192
193 /**
194 * @param {string} name
195 */
196 _selectTab(name) {
Brian Cui4fef3cd2020-02-11 01:05:55197 this._tabbedLocation.tabbedPane().selectTab(name, /* userGesture */ true);
198 }
199
200 /**
201 * @param {!Common.EventTarget.EventTargetEvent} event
202 */
203 _tabInvoked(event) {
204 const eventData = /** @type {!UI.TabbedPane.EventData} */ (event.data);
205 if (!eventData.isUserGesture) {
206 return;
207 }
208
209 const prevTabId = eventData.prevTabId;
210 const tabId = eventData.tabId;
211 if (!this._reportTabOnReveal && prevTabId && prevTabId === tabId) {
212 return;
213 }
214
215 this._reportTabOnReveal = false;
216 this._reportSettingsPanelShown(tabId);
217 }
218
219 /**
220 * @param {string} tabId
221 */
222 _reportSettingsPanelShown(tabId) {
vidortegc1aeb632020-10-22 02:59:33223 if (tabId === i18nString(UIStrings.shortcuts)) {
Brian Cui4fef3cd2020-02-11 01:05:55224 Host.userMetrics.settingsPanelShown('shortcuts');
225 return;
226 }
227
228 Host.userMetrics.settingsPanelShown(tabId);
Blink Reformat4c46d092018-04-07 15:32:37229 }
Jack Lynchca3683d2020-09-30 22:54:57230
231 /**
232 * @param {!Event} event
233 */
234 _onEscapeKeyPressed(event) {
235 if (this._tabbedLocation.tabbedPane().selectedTabId === 'keybinds' && this._keybindsTab) {
236 this._keybindsTab.onEscapeKeyPressed(event);
237 }
238 }
Paul Lewis5d4133e2019-11-27 13:06:01239}
Blink Reformat4c46d092018-04-07 15:32:37240
241/**
242 * @unrestricted
243 */
Tim van der Lippe66684e92020-01-24 14:01:18244class SettingsTab extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:37245 /**
246 * @param {string} name
247 * @param {string=} id
248 */
249 constructor(name, id) {
250 super();
251 this.element.classList.add('settings-tab-container');
Tim van der Lippe1d6e57a2019-09-30 11:55:34252 if (id) {
Blink Reformat4c46d092018-04-07 15:32:37253 this.element.id = id;
Tim van der Lippe1d6e57a2019-09-30 11:55:34254 }
Blink Reformat4c46d092018-04-07 15:32:37255 const header = this.element.createChild('header');
Sigurd Schneider23c52972020-10-13 09:31:14256 UI.UIUtils.createTextChild(header.createChild('h1'), name);
Blink Reformat4c46d092018-04-07 15:32:37257 this.containerElement = this.element.createChild('div', 'settings-container-wrapper')
258 .createChild('div', 'settings-tab settings-content settings-container');
259 }
260
261 /**
262 * @param {string=} name
263 * @return {!Element}
264 */
265 _appendSection(name) {
266 const block = this.containerElement.createChild('div', 'settings-block');
Chandani Shrestha83bd7c92019-06-11 21:21:59267 if (name) {
268 UI.ARIAUtils.markAsGroup(block);
269 const title = block.createChild('div', 'settings-section-title');
270 title.textContent = name;
271 UI.ARIAUtils.markAsHeading(title, 2);
Joel Einbindereaef6162019-07-15 17:42:55272 UI.ARIAUtils.setAccessibleName(block, name);
Chandani Shrestha83bd7c92019-06-11 21:21:59273 }
Blink Reformat4c46d092018-04-07 15:32:37274 return block;
275 }
Paul Lewis5d4133e2019-11-27 13:06:01276}
Blink Reformat4c46d092018-04-07 15:32:37277
278/**
279 * @unrestricted
280 */
Paul Lewis5d4133e2019-11-27 13:06:01281export class GenericSettingsTab extends SettingsTab {
Blink Reformat4c46d092018-04-07 15:32:37282 constructor() {
vidortegc1aeb632020-10-22 02:59:33283 super(i18nString(UIStrings.preferences), 'preferences-tab-content');
Blink Reformat4c46d092018-04-07 15:32:37284
285 /** @const */
Alex Rudenko4bcabeb2020-05-06 08:43:56286 const explicitSectionOrder = [
287 '', 'Appearance', 'Sources', 'Elements', 'Network', 'Performance', 'Console', 'Extensions', 'Persistence',
288 'Debugger', 'Global'
289 ];
Brandon Goddard80d38182020-06-12 15:33:25290
Blink Reformat4c46d092018-04-07 15:32:37291 /** @type {!Map<string, !Element>} */
292 this._nameToSection = new Map();
Tim van der Lippe1d6e57a2019-09-30 11:55:34293 for (const sectionName of explicitSectionOrder) {
Alex Rudenko4bcabeb2020-05-06 08:43:56294 this._createSectionElement(sectionName);
Tim van der Lippe1d6e57a2019-09-30 11:55:34295 }
Tim van der Lippe7f2002c2020-09-28 14:54:01296 Root.Runtime.Runtime.instance().extensions('setting').forEach(this._addSetting.bind(this));
297 Root.Runtime.Runtime.instance().extensions(UI.SettingsUI.SettingUI).forEach(this._addSettingUI.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37298
299 this._appendSection().appendChild(
vidortegc1aeb632020-10-22 02:59:33300 UI.UIUtils.createTextButton(i18nString(UIStrings.restoreDefaultsAndReload), restoreAndReload));
Blink Reformat4c46d092018-04-07 15:32:37301
302 function restoreAndReload() {
Paul Lewis2d7d65c2020-03-16 17:26:30303 Common.Settings.Settings.instance().clearAll();
Tim van der Lippe66684e92020-01-24 14:01:18304 Components.Reload.reload();
Blink Reformat4c46d092018-04-07 15:32:37305 }
306 }
307
308 /**
Tim van der Lippe99e59b82019-09-30 20:00:59309 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37310 * @return {boolean}
311 */
312 static isSettingVisible(extension) {
313 const descriptor = extension.descriptor();
Tim van der Lippe1d6e57a2019-09-30 11:55:34314 if (!('title' in descriptor)) {
Blink Reformat4c46d092018-04-07 15:32:37315 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34316 }
317 if (!('category' in descriptor)) {
Blink Reformat4c46d092018-04-07 15:32:37318 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34319 }
Blink Reformat4c46d092018-04-07 15:32:37320 return true;
321 }
322
323 /**
Tim van der Lippe99e59b82019-09-30 20:00:59324 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37325 */
326 _addSetting(extension) {
Paul Lewis5d4133e2019-11-27 13:06:01327 if (!GenericSettingsTab.isSettingVisible(extension)) {
Blink Reformat4c46d092018-04-07 15:32:37328 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34329 }
Andres Olivaresc51c18a2020-10-21 02:48:44330 const extensionCategory = extension.descriptor()['category'];
331 if (!extensionCategory) {
332 return;
333 }
334 const sectionElement = this._sectionElement(extensionCategory);
Alex Rudenko4bcabeb2020-05-06 08:43:56335 if (!sectionElement) {
336 return;
337 }
Paul Lewis2d7d65c2020-03-16 17:26:30338 const setting = Common.Settings.Settings.instance().moduleSetting(extension.descriptor()['settingName']);
Blink Reformat4c46d092018-04-07 15:32:37339 const settingControl = UI.SettingsUI.createControlForSetting(setting);
Tim van der Lippe1d6e57a2019-09-30 11:55:34340 if (settingControl) {
Blink Reformat4c46d092018-04-07 15:32:37341 sectionElement.appendChild(settingControl);
Tim van der Lippe1d6e57a2019-09-30 11:55:34342 }
Blink Reformat4c46d092018-04-07 15:32:37343 }
344
345 /**
Tim van der Lippe99e59b82019-09-30 20:00:59346 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37347 */
348 _addSettingUI(extension) {
349 const descriptor = extension.descriptor();
350 const sectionName = descriptor['category'] || '';
351 extension.instance().then(appendCustomSetting.bind(this));
352
353 /**
354 * @param {!Object} object
Tim van der Lippe1ebfc502020-01-15 13:45:09355 * @this {GenericSettingsTab}
Blink Reformat4c46d092018-04-07 15:32:37356 */
357 function appendCustomSetting(object) {
Tim van der Lippe66684e92020-01-24 14:01:18358 const settingUI = /** @type {!UI.SettingsUI.SettingUI} */ (object);
Blink Reformat4c46d092018-04-07 15:32:37359 const element = settingUI.settingElement();
Tim van der Lippe1d6e57a2019-09-30 11:55:34360 if (element) {
Alex Rudenko4bcabeb2020-05-06 08:43:56361 let sectionElement = this._sectionElement(sectionName);
362 if (!sectionElement) {
363 sectionElement = this._createSectionElement(sectionName);
364 }
365 sectionElement.appendChild(element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34366 }
Blink Reformat4c46d092018-04-07 15:32:37367 }
368 }
369
370 /**
371 * @param {string} sectionName
372 * @return {!Element}
373 */
Alex Rudenko4bcabeb2020-05-06 08:43:56374 _createSectionElement(sectionName) {
vidortegc1aeb632020-10-22 02:59:33375 const uiSectionName = sectionName && i18nString(sectionName);
Alex Rudenko4bcabeb2020-05-06 08:43:56376 const sectionElement = this._appendSection(uiSectionName);
377 this._nameToSection.set(sectionName, sectionElement);
Blink Reformat4c46d092018-04-07 15:32:37378 return sectionElement;
379 }
Alex Rudenko4bcabeb2020-05-06 08:43:56380
381 /**
382 * @param {string} sectionName
383 * @return {?Element}
384 */
385 _sectionElement(sectionName) {
386 return this._nameToSection.get(sectionName) || null;
387 }
Paul Lewis5d4133e2019-11-27 13:06:01388}
Blink Reformat4c46d092018-04-07 15:32:37389
390/**
391 * @unrestricted
392 */
Paul Lewis5d4133e2019-11-27 13:06:01393export class ExperimentsSettingsTab extends SettingsTab {
Blink Reformat4c46d092018-04-07 15:32:37394 constructor() {
vidortegc1aeb632020-10-22 02:59:33395 super(i18nString(UIStrings.experiments), 'experiments-tab-content');
Blink Reformat4c46d092018-04-07 15:32:37396
Yang Guo33e8f6f2020-02-06 11:50:29397 const experiments = Root.Runtime.experiments.allConfigurableExperiments().sort();
398 const unstableExperiments = experiments.filter(e => e.unstable);
399 const stableExperiments = experiments.filter(e => !e.unstable);
400 if (stableExperiments.length) {
Blink Reformat4c46d092018-04-07 15:32:37401 const experimentsSection = this._appendSection();
vidortegc1aeb632020-10-22 02:59:33402 const warningMessage = i18nString(UIStrings.theseExperimentsCouldBeUnstable);
Yang Guo33e8f6f2020-02-06 11:50:29403 experimentsSection.appendChild(this._createExperimentsWarningSubsection(warningMessage));
404 for (const experiment of stableExperiments) {
405 experimentsSection.appendChild(this._createExperimentCheckbox(experiment));
406 }
407 }
408 if (unstableExperiments.length) {
409 const experimentsSection = this._appendSection();
vidortegc1aeb632020-10-22 02:59:33410 const warningMessage = i18nString(UIStrings.theseExperimentsAreParticularly);
Yang Guo33e8f6f2020-02-06 11:50:29411 experimentsSection.appendChild(this._createExperimentsWarningSubsection(warningMessage));
412 for (const experiment of unstableExperiments) {
413 experimentsSection.appendChild(this._createExperimentCheckbox(experiment));
Tim van der Lippe1d6e57a2019-09-30 11:55:34414 }
Blink Reformat4c46d092018-04-07 15:32:37415 }
416 }
417
418 /**
Yang Guo33e8f6f2020-02-06 11:50:29419 * @param {string} warningMessage
Blink Reformat4c46d092018-04-07 15:32:37420 * @return {!Element} element
421 */
Yang Guo33e8f6f2020-02-06 11:50:29422 _createExperimentsWarningSubsection(warningMessage) {
Andres Olivaresc51c18a2020-10-21 02:48:44423 const subsection = document.createElement('div');
Blink Reformat4c46d092018-04-07 15:32:37424 const warning = subsection.createChild('span', 'settings-experiments-warning-subsection-warning');
vidortegc1aeb632020-10-22 02:59:33425 warning.textContent = i18nString(UIStrings.warning);
Sigurd Schneider23c52972020-10-13 09:31:14426 UI.UIUtils.createTextChild(subsection, ' ');
Blink Reformat4c46d092018-04-07 15:32:37427 const message = subsection.createChild('span', 'settings-experiments-warning-subsection-message');
Yang Guo33e8f6f2020-02-06 11:50:29428 message.textContent = warningMessage;
Blink Reformat4c46d092018-04-07 15:32:37429 return subsection;
430 }
431
Andres Olivaresc51c18a2020-10-21 02:48:44432 /**
433 * @param {*} experiment
434 */
Blink Reformat4c46d092018-04-07 15:32:37435 _createExperimentCheckbox(experiment) {
vidortegc1aeb632020-10-22 02:59:33436 const label = UI.UIUtils.CheckboxLabel.create(i18nString(experiment.title), experiment.isEnabled());
Blink Reformat4c46d092018-04-07 15:32:37437 const input = label.checkboxElement;
438 input.name = experiment.name;
439 function listener() {
440 experiment.setEnabled(input.checked);
Brandon Goddard413d1722020-08-10 17:51:26441 Host.userMetrics.experimentChanged(experiment.name, experiment.isEnabled());
Rob Pavezac32568d2020-07-13 16:18:18442 UI.InspectorView.InspectorView.instance().displayReloadRequiredWarning(
vidortegc1aeb632020-10-22 02:59:33443 i18nString(UIStrings.oneOrMoreSettingsHaveChanged));
Blink Reformat4c46d092018-04-07 15:32:37444 }
445 input.addEventListener('click', listener, false);
446
Andres Olivaresc51c18a2020-10-21 02:48:44447 const p = document.createElement('p');
Yang Guo33e8f6f2020-02-06 11:50:29448 p.className = experiment.unstable && !experiment.isEnabled() ? 'settings-experiment-unstable' : '';
Blink Reformat4c46d092018-04-07 15:32:37449 p.appendChild(label);
450 return p;
451 }
Paul Lewis5d4133e2019-11-27 13:06:01452}
Blink Reformat4c46d092018-04-07 15:32:37453
454/**
Tim van der Lippe66684e92020-01-24 14:01:18455 * @implements {UI.ActionDelegate.ActionDelegate}
Blink Reformat4c46d092018-04-07 15:32:37456 * @unrestricted
457 */
Paul Lewis5d4133e2019-11-27 13:06:01458export class ActionDelegate {
Blink Reformat4c46d092018-04-07 15:32:37459 /**
460 * @override
Tim van der Lippe66684e92020-01-24 14:01:18461 * @param {!UI.Context.Context} context
Blink Reformat4c46d092018-04-07 15:32:37462 * @param {string} actionId
463 * @return {boolean}
464 */
465 handleAction(context, actionId) {
Blink Reformat4c46d092018-04-07 15:32:37466 switch (actionId) {
467 case 'settings.show':
Andres Olivaresc51c18a2020-10-21 02:48:44468 SettingsScreen._showSettingsScreen(/** @type {!ShowSettingsScreenOptions}*/ ({focusTabHeader: true}));
Blink Reformat4c46d092018-04-07 15:32:37469 return true;
470 case 'settings.documentation':
Tim van der Lippe66684e92020-01-24 14:01:18471 Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(
Wolfgang Beyer6190ec82020-03-09 15:06:33472 UI.UIUtils.addReferrerToURL('https://developers.google.com/web/tools/chrome-devtools/'));
Blink Reformat4c46d092018-04-07 15:32:37473 return true;
474 case 'settings.shortcuts':
Jack Lynchd77d4ca2020-10-16 18:27:15475 SettingsScreen._showSettingsScreen({name: 'keybinds', focusTabHeader: true});
Blink Reformat4c46d092018-04-07 15:32:37476 return true;
477 }
478 return false;
479 }
Paul Lewis5d4133e2019-11-27 13:06:01480}
Blink Reformat4c46d092018-04-07 15:32:37481
482/**
Tim van der Lippe66684e92020-01-24 14:01:18483 * @implements {Common.Revealer.Revealer}
Blink Reformat4c46d092018-04-07 15:32:37484 * @unrestricted
485 */
Paul Lewis5d4133e2019-11-27 13:06:01486export class Revealer {
Blink Reformat4c46d092018-04-07 15:32:37487 /**
488 * @override
489 * @param {!Object} object
Andres Olivaresc51c18a2020-10-21 02:48:44490 * @return {!Promise<void>}
Blink Reformat4c46d092018-04-07 15:32:37491 */
492 reveal(object) {
Tim van der Lippe66684e92020-01-24 14:01:18493 console.assert(object instanceof Common.Settings.Setting);
Andres Olivaresc51c18a2020-10-21 02:48:44494 const setting = /** @type {!Common.Settings.Setting<*>} */ (object);
Blink Reformat4c46d092018-04-07 15:32:37495 let success = false;
496
Tim van der Lippe7f2002c2020-09-28 14:54:01497 Root.Runtime.Runtime.instance().extensions('setting').forEach(revealModuleSetting);
498 Root.Runtime.Runtime.instance().extensions(UI.SettingsUI.SettingUI).forEach(revealSettingUI);
499 Root.Runtime.Runtime.instance().extensions('view').forEach(revealSettingsView);
Blink Reformat4c46d092018-04-07 15:32:37500
501 return success ? Promise.resolve() : Promise.reject();
502
503 /**
Tim van der Lippe99e59b82019-09-30 20:00:59504 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37505 */
506 function revealModuleSetting(extension) {
Paul Lewis5d4133e2019-11-27 13:06:01507 if (!GenericSettingsTab.isSettingVisible(extension)) {
Blink Reformat4c46d092018-04-07 15:32:37508 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34509 }
Blink Reformat4c46d092018-04-07 15:32:37510 if (extension.descriptor()['settingName'] === setting.name) {
Tim van der Lippe66684e92020-01-24 14:01:18511 Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront();
Paul Lewis5d4133e2019-11-27 13:06:01512 SettingsScreen._showSettingsScreen();
Blink Reformat4c46d092018-04-07 15:32:37513 success = true;
514 }
515 }
516
517 /**
Tim van der Lippe99e59b82019-09-30 20:00:59518 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37519 */
520 function revealSettingUI(extension) {
521 const settings = extension.descriptor()['settings'];
522 if (settings && settings.indexOf(setting.name) !== -1) {
Tim van der Lippe66684e92020-01-24 14:01:18523 Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront();
Paul Lewis5d4133e2019-11-27 13:06:01524 SettingsScreen._showSettingsScreen();
Blink Reformat4c46d092018-04-07 15:32:37525 success = true;
526 }
527 }
528
529 /**
Tim van der Lippe99e59b82019-09-30 20:00:59530 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37531 */
532 function revealSettingsView(extension) {
533 const location = extension.descriptor()['location'];
Tim van der Lippe1d6e57a2019-09-30 11:55:34534 if (location !== 'settings-view') {
Blink Reformat4c46d092018-04-07 15:32:37535 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34536 }
Andres Olivaresc51c18a2020-10-21 02:48:44537 const descriptor = extension.descriptor();
538 const settings = descriptor['settings'];
Blink Reformat4c46d092018-04-07 15:32:37539 if (settings && settings.indexOf(setting.name) !== -1) {
Tim van der Lippe66684e92020-01-24 14:01:18540 Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront();
Andres Olivaresc51c18a2020-10-21 02:48:44541 SettingsScreen._showSettingsScreen(
542 /** @type {!ShowSettingsScreenOptions}*/ ({name: extension.descriptor()['id']}));
Blink Reformat4c46d092018-04-07 15:32:37543 success = true;
544 }
545 }
546 }
Paul Lewis5d4133e2019-11-27 13:06:01547}
Andres Olivaresc51c18a2020-10-21 02:48:44548
549/**
550 * @typedef {{
551 * name: (string|undefined),
552 * focusTabHeader: (boolean|undefined)
553 * }}
554 */
555// @ts-ignore typedef
556export let ShowSettingsScreenOptions;