blob: e4ef0bd3f8e9743043a78e3bded7fb115f3d6446 [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
31import * as Common from '../common/common.js';
32import * as Components from '../components/components.js';
33import * as Host from '../host/host.js';
34import * as UI from '../ui/ui.js';
35
Blink Reformat4c46d092018-04-07 15:32:3736/**
Tim van der Lippe66684e92020-01-24 14:01:1837 * @implements {UI.View.ViewLocationResolver}
Blink Reformat4c46d092018-04-07 15:32:3738 * @unrestricted
39 */
Tim van der Lippe66684e92020-01-24 14:01:1840export class SettingsScreen extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:3741 constructor() {
42 super(true);
43 this.registerRequiredCSS('settings/settingsScreen.css');
44
Blink Reformat4c46d092018-04-07 15:32:3745 this.contentElement.classList.add('settings-window-main');
46 this.contentElement.classList.add('vbox');
47
48 const settingsLabelElement = createElement('div');
Tim van der Lippe66684e92020-01-24 14:01:1849 const settingsTitleElement =
50 UI.Utils.createShadowRootWithCoreStyles(settingsLabelElement, 'settings/settingsScreen.css')
51 .createChild('div', 'settings-window-title');
John Emaub970e562019-06-05 01:17:2752
53 UI.ARIAUtils.markAsHeading(settingsTitleElement, 1);
54 settingsTitleElement.textContent = ls`Settings`;
Blink Reformat4c46d092018-04-07 15:32:3755
Paul Lewis75c7d0d2020-03-19 12:17:2656 this._tabbedLocation = UI.ViewManager.ViewManager.instance().createTabbedLocation(
Brian Cui4fef3cd2020-02-11 01:05:5557 () => SettingsScreen._revealSettingsScreen(), 'settings-view');
Blink Reformat4c46d092018-04-07 15:32:3758 const tabbedPane = this._tabbedLocation.tabbedPane();
Tim van der Lippe66684e92020-01-24 14:01:1859 tabbedPane.leftToolbar().appendToolbarItem(new UI.Toolbar.ToolbarItem(settingsLabelElement));
Blink Reformat4c46d092018-04-07 15:32:3760 tabbedPane.setShrinkableTabs(false);
61 tabbedPane.makeVerticalTabLayout();
Brian Cui4fef3cd2020-02-11 01:05:5562
Jack Lynch575e9fb2020-03-26 22:20:5163 if (!Root.Runtime.experiments.isEnabled('customKeyboardShortcuts')) {
64 const shortcutsView = new UI.View.SimpleView(ls`Shortcuts`);
65 self.UI.shortcutsScreen.createShortcutsTabView().show(shortcutsView.element);
66 this._tabbedLocation.appendView(shortcutsView);
67 }
Blink Reformat4c46d092018-04-07 15:32:3768 tabbedPane.show(this.contentElement);
Brian Cui4fef3cd2020-02-11 01:05:5569 tabbedPane.selectTab('preferences');
70 tabbedPane.addEventListener(UI.TabbedPane.Events.TabInvoked, this._tabInvoked, this);
71 this._reportTabOnReveal = false;
Blink Reformat4c46d092018-04-07 15:32:3772 }
73
74 /**
Brian Cui4fef3cd2020-02-11 01:05:5575 * @return {!SettingsScreen}
Blink Reformat4c46d092018-04-07 15:32:3776 */
Brian Cui4fef3cd2020-02-11 01:05:5577 static _revealSettingsScreen() {
78 /** @type {!SettingsScreen} */
79 const settingsScreen = self.runtime.sharedInstance(SettingsScreen);
Tim van der Lippe1d6e57a2019-09-30 11:55:3480 if (settingsScreen.isShowing()) {
Brian Cui4fef3cd2020-02-11 01:05:5581 return settingsScreen;
Tim van der Lippe1d6e57a2019-09-30 11:55:3482 }
Brian Cui4fef3cd2020-02-11 01:05:5583
84 settingsScreen._reportTabOnReveal = true;
Tim van der Lippe66684e92020-01-24 14:01:1885 const dialog = new UI.Dialog.Dialog();
Chandani Shrestha08469b82019-10-02 17:22:5586 dialog.contentElement.tabIndex = -1;
Blink Reformat4c46d092018-04-07 15:32:3787 dialog.addCloseButton();
Brian Cui8fdb1482019-12-04 21:41:4688 dialog.setOutsideClickCallback(() => {});
89 dialog.setPointerEventsBehavior(UI.GlassPane.PointerEventsBehavior.PierceGlassPane);
90 dialog.setOutsideTabIndexBehavior(UI.Dialog.OutsideTabIndexBehavior.PreserveMainViewTabIndex);
Blink Reformat4c46d092018-04-07 15:32:3791 settingsScreen.show(dialog.contentElement);
92 dialog.show();
Jack Lynch85edfc82020-03-09 18:11:1393
Brian Cui4fef3cd2020-02-11 01:05:5594 return settingsScreen;
95 }
96
97 /**
98 * @param {{name: (string|undefined), focusTabHeader: (boolean|undefined)}=} options
99 */
100 static async _showSettingsScreen(options = {}) {
101 const {name, focusTabHeader} = options;
102 const settingsScreen = SettingsScreen._revealSettingsScreen();
103
104 settingsScreen._selectTab(name || 'preferences');
Brian Cui55d00af2020-04-09 18:45:40105 const tabbedPane = settingsScreen._tabbedLocation.tabbedPane();
106 await tabbedPane.waitForTabElementUpdate();
Jack Lynch85edfc82020-03-09 18:11:13107 if (focusTabHeader) {
Jack Lynch85edfc82020-03-09 18:11:13108 tabbedPane.focusSelectedTabHeader();
Brian Cui55d00af2020-04-09 18:45:40109 } else {
110 tabbedPane.focus();
Jack Lynch85edfc82020-03-09 18:11:13111 }
Blink Reformat4c46d092018-04-07 15:32:37112 }
113
114 /**
115 * @override
116 * @param {string} locationName
Tim van der Lippe66684e92020-01-24 14:01:18117 * @return {?UI.View.ViewLocation}
Blink Reformat4c46d092018-04-07 15:32:37118 */
119 resolveLocation(locationName) {
120 return this._tabbedLocation;
121 }
122
123 /**
124 * @param {string} name
125 */
126 _selectTab(name) {
Brian Cui4fef3cd2020-02-11 01:05:55127 this._tabbedLocation.tabbedPane().selectTab(name, /* userGesture */ true);
128 }
129
130 /**
131 * @param {!Common.EventTarget.EventTargetEvent} event
132 */
133 _tabInvoked(event) {
134 const eventData = /** @type {!UI.TabbedPane.EventData} */ (event.data);
135 if (!eventData.isUserGesture) {
136 return;
137 }
138
139 const prevTabId = eventData.prevTabId;
140 const tabId = eventData.tabId;
141 if (!this._reportTabOnReveal && prevTabId && prevTabId === tabId) {
142 return;
143 }
144
145 this._reportTabOnReveal = false;
146 this._reportSettingsPanelShown(tabId);
147 }
148
149 /**
150 * @param {string} tabId
151 */
152 _reportSettingsPanelShown(tabId) {
153 if (tabId === ls`Shortcuts`) {
154 Host.userMetrics.settingsPanelShown('shortcuts');
155 return;
156 }
157
158 Host.userMetrics.settingsPanelShown(tabId);
Blink Reformat4c46d092018-04-07 15:32:37159 }
Paul Lewis5d4133e2019-11-27 13:06:01160}
Blink Reformat4c46d092018-04-07 15:32:37161
162/**
163 * @unrestricted
164 */
Tim van der Lippe66684e92020-01-24 14:01:18165class SettingsTab extends UI.Widget.VBox {
Blink Reformat4c46d092018-04-07 15:32:37166 /**
167 * @param {string} name
168 * @param {string=} id
169 */
170 constructor(name, id) {
171 super();
172 this.element.classList.add('settings-tab-container');
Tim van der Lippe1d6e57a2019-09-30 11:55:34173 if (id) {
Blink Reformat4c46d092018-04-07 15:32:37174 this.element.id = id;
Tim van der Lippe1d6e57a2019-09-30 11:55:34175 }
Blink Reformat4c46d092018-04-07 15:32:37176 const header = this.element.createChild('header');
Chandani Shrestha83bd7c92019-06-11 21:21:59177 header.createChild('h1').createTextChild(name);
Blink Reformat4c46d092018-04-07 15:32:37178 this.containerElement = this.element.createChild('div', 'settings-container-wrapper')
179 .createChild('div', 'settings-tab settings-content settings-container');
180 }
181
182 /**
183 * @param {string=} name
184 * @return {!Element}
185 */
186 _appendSection(name) {
187 const block = this.containerElement.createChild('div', 'settings-block');
Chandani Shrestha83bd7c92019-06-11 21:21:59188 if (name) {
189 UI.ARIAUtils.markAsGroup(block);
190 const title = block.createChild('div', 'settings-section-title');
191 title.textContent = name;
192 UI.ARIAUtils.markAsHeading(title, 2);
Joel Einbindereaef6162019-07-15 17:42:55193 UI.ARIAUtils.setAccessibleName(block, name);
Chandani Shrestha83bd7c92019-06-11 21:21:59194 }
Blink Reformat4c46d092018-04-07 15:32:37195 return block;
196 }
Paul Lewis5d4133e2019-11-27 13:06:01197}
Blink Reformat4c46d092018-04-07 15:32:37198
199/**
200 * @unrestricted
201 */
Paul Lewis5d4133e2019-11-27 13:06:01202export class GenericSettingsTab extends SettingsTab {
Blink Reformat4c46d092018-04-07 15:32:37203 constructor() {
Tim van der Lippe66684e92020-01-24 14:01:18204 super(Common.UIString.UIString('Preferences'), 'preferences-tab-content');
Blink Reformat4c46d092018-04-07 15:32:37205
206 /** @const */
Alex Rudenko4bcabeb2020-05-06 08:43:56207 const explicitSectionOrder = [
208 '', 'Appearance', 'Sources', 'Elements', 'Network', 'Performance', 'Console', 'Extensions', 'Persistence',
209 'Debugger', 'Global'
210 ];
Brandon Goddard80d38182020-06-12 15:33:25211
212 // Sections only available if their corresponding experiment is enabled
213 /** @type {!Array<{name: string, experiment: string}>} */
214 const experimentalSections = [{name: 'Grid', experiment: 'cssGridFeatures'}];
215
216
Blink Reformat4c46d092018-04-07 15:32:37217 /** @type {!Map<string, !Element>} */
218 this._nameToSection = new Map();
Tim van der Lippe1d6e57a2019-09-30 11:55:34219 for (const sectionName of explicitSectionOrder) {
Alex Rudenko4bcabeb2020-05-06 08:43:56220 this._createSectionElement(sectionName);
Tim van der Lippe1d6e57a2019-09-30 11:55:34221 }
Brandon Goddard80d38182020-06-12 15:33:25222 for (const section of experimentalSections) {
223 if (Root.Runtime.experiments.isEnabled(section.experiment)) {
224 this._createSectionElement(section.name);
225 }
226 }
Blink Reformat4c46d092018-04-07 15:32:37227 self.runtime.extensions('setting').forEach(this._addSetting.bind(this));
Tim van der Lippe66684e92020-01-24 14:01:18228 self.runtime.extensions(UI.SettingsUI.SettingUI).forEach(this._addSettingUI.bind(this));
Blink Reformat4c46d092018-04-07 15:32:37229
230 this._appendSection().appendChild(
Mike Jackson60a0e9d2020-03-24 18:57:41231 UI.UIUtils.createTextButton(Common.UIString.UIString('Restore defaults and reload'), restoreAndReload));
Blink Reformat4c46d092018-04-07 15:32:37232
233 function restoreAndReload() {
Paul Lewis2d7d65c2020-03-16 17:26:30234 Common.Settings.Settings.instance().clearAll();
Tim van der Lippe66684e92020-01-24 14:01:18235 Components.Reload.reload();
Blink Reformat4c46d092018-04-07 15:32:37236 }
237 }
238
239 /**
Tim van der Lippe99e59b82019-09-30 20:00:59240 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37241 * @return {boolean}
242 */
243 static isSettingVisible(extension) {
244 const descriptor = extension.descriptor();
Tim van der Lippe1d6e57a2019-09-30 11:55:34245 if (!('title' in descriptor)) {
Blink Reformat4c46d092018-04-07 15:32:37246 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34247 }
248 if (!('category' in descriptor)) {
Blink Reformat4c46d092018-04-07 15:32:37249 return false;
Tim van der Lippe1d6e57a2019-09-30 11:55:34250 }
Blink Reformat4c46d092018-04-07 15:32:37251 return true;
252 }
253
254 /**
Tim van der Lippe99e59b82019-09-30 20:00:59255 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37256 */
257 _addSetting(extension) {
Paul Lewis5d4133e2019-11-27 13:06:01258 if (!GenericSettingsTab.isSettingVisible(extension)) {
Blink Reformat4c46d092018-04-07 15:32:37259 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34260 }
Blink Reformat4c46d092018-04-07 15:32:37261 const sectionElement = this._sectionElement(extension.descriptor()['category']);
Alex Rudenko4bcabeb2020-05-06 08:43:56262 if (!sectionElement) {
263 return;
264 }
Paul Lewis2d7d65c2020-03-16 17:26:30265 const setting = Common.Settings.Settings.instance().moduleSetting(extension.descriptor()['settingName']);
Blink Reformat4c46d092018-04-07 15:32:37266 const settingControl = UI.SettingsUI.createControlForSetting(setting);
Tim van der Lippe1d6e57a2019-09-30 11:55:34267 if (settingControl) {
Blink Reformat4c46d092018-04-07 15:32:37268 sectionElement.appendChild(settingControl);
Tim van der Lippe1d6e57a2019-09-30 11:55:34269 }
Blink Reformat4c46d092018-04-07 15:32:37270 }
271
272 /**
Tim van der Lippe99e59b82019-09-30 20:00:59273 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37274 */
275 _addSettingUI(extension) {
276 const descriptor = extension.descriptor();
277 const sectionName = descriptor['category'] || '';
278 extension.instance().then(appendCustomSetting.bind(this));
279
280 /**
281 * @param {!Object} object
Tim van der Lippe1ebfc502020-01-15 13:45:09282 * @this {GenericSettingsTab}
Blink Reformat4c46d092018-04-07 15:32:37283 */
284 function appendCustomSetting(object) {
Tim van der Lippe66684e92020-01-24 14:01:18285 const settingUI = /** @type {!UI.SettingsUI.SettingUI} */ (object);
Blink Reformat4c46d092018-04-07 15:32:37286 const element = settingUI.settingElement();
Tim van der Lippe1d6e57a2019-09-30 11:55:34287 if (element) {
Alex Rudenko4bcabeb2020-05-06 08:43:56288 let sectionElement = this._sectionElement(sectionName);
289 if (!sectionElement) {
290 sectionElement = this._createSectionElement(sectionName);
291 }
292 sectionElement.appendChild(element);
Tim van der Lippe1d6e57a2019-09-30 11:55:34293 }
Blink Reformat4c46d092018-04-07 15:32:37294 }
295 }
296
297 /**
298 * @param {string} sectionName
299 * @return {!Element}
300 */
Alex Rudenko4bcabeb2020-05-06 08:43:56301 _createSectionElement(sectionName) {
302 const uiSectionName = sectionName && Common.UIString.UIString(sectionName);
303 const sectionElement = this._appendSection(uiSectionName);
304 this._nameToSection.set(sectionName, sectionElement);
Blink Reformat4c46d092018-04-07 15:32:37305 return sectionElement;
306 }
Alex Rudenko4bcabeb2020-05-06 08:43:56307
308 /**
309 * @param {string} sectionName
310 * @return {?Element}
311 */
312 _sectionElement(sectionName) {
313 return this._nameToSection.get(sectionName) || null;
314 }
Paul Lewis5d4133e2019-11-27 13:06:01315}
Blink Reformat4c46d092018-04-07 15:32:37316
317/**
318 * @unrestricted
319 */
Paul Lewis5d4133e2019-11-27 13:06:01320export class ExperimentsSettingsTab extends SettingsTab {
Blink Reformat4c46d092018-04-07 15:32:37321 constructor() {
Tim van der Lippe66684e92020-01-24 14:01:18322 super(Common.UIString.UIString('Experiments'), 'experiments-tab-content');
Blink Reformat4c46d092018-04-07 15:32:37323
Yang Guo33e8f6f2020-02-06 11:50:29324 const experiments = Root.Runtime.experiments.allConfigurableExperiments().sort();
325 const unstableExperiments = experiments.filter(e => e.unstable);
326 const stableExperiments = experiments.filter(e => !e.unstable);
327 if (stableExperiments.length) {
Blink Reformat4c46d092018-04-07 15:32:37328 const experimentsSection = this._appendSection();
Yang Guo33e8f6f2020-02-06 11:50:29329 const warningMessage = Common.UIString.UIString('These experiments could be dangerous and may require restart.');
330 experimentsSection.appendChild(this._createExperimentsWarningSubsection(warningMessage));
331 for (const experiment of stableExperiments) {
332 experimentsSection.appendChild(this._createExperimentCheckbox(experiment));
333 }
334 }
335 if (unstableExperiments.length) {
336 const experimentsSection = this._appendSection();
337 const warningMessage =
338 Common.UIString.UIString('These experiments are particularly unstable. Enable at your own risk.');
339 experimentsSection.appendChild(this._createExperimentsWarningSubsection(warningMessage));
340 for (const experiment of unstableExperiments) {
341 experimentsSection.appendChild(this._createExperimentCheckbox(experiment));
Tim van der Lippe1d6e57a2019-09-30 11:55:34342 }
Blink Reformat4c46d092018-04-07 15:32:37343 }
344 }
345
346 /**
Yang Guo33e8f6f2020-02-06 11:50:29347 * @param {string} warningMessage
Blink Reformat4c46d092018-04-07 15:32:37348 * @return {!Element} element
349 */
Yang Guo33e8f6f2020-02-06 11:50:29350 _createExperimentsWarningSubsection(warningMessage) {
Blink Reformat4c46d092018-04-07 15:32:37351 const subsection = createElement('div');
352 const warning = subsection.createChild('span', 'settings-experiments-warning-subsection-warning');
Tim van der Lippe66684e92020-01-24 14:01:18353 warning.textContent = Common.UIString.UIString('WARNING:');
Blink Reformat4c46d092018-04-07 15:32:37354 subsection.createTextChild(' ');
355 const message = subsection.createChild('span', 'settings-experiments-warning-subsection-message');
Yang Guo33e8f6f2020-02-06 11:50:29356 message.textContent = warningMessage;
Blink Reformat4c46d092018-04-07 15:32:37357 return subsection;
358 }
359
360 _createExperimentCheckbox(experiment) {
Tim van der Lippe66684e92020-01-24 14:01:18361 const label = UI.UIUtils.CheckboxLabel.create(Common.UIString.UIString(experiment.title), experiment.isEnabled());
Blink Reformat4c46d092018-04-07 15:32:37362 const input = label.checkboxElement;
363 input.name = experiment.name;
364 function listener() {
365 experiment.setEnabled(input.checked);
366 }
367 input.addEventListener('click', listener, false);
368
369 const p = createElement('p');
Yang Guo33e8f6f2020-02-06 11:50:29370 p.className = experiment.unstable && !experiment.isEnabled() ? 'settings-experiment-unstable' : '';
Blink Reformat4c46d092018-04-07 15:32:37371 p.appendChild(label);
372 return p;
373 }
Paul Lewis5d4133e2019-11-27 13:06:01374}
Blink Reformat4c46d092018-04-07 15:32:37375
376/**
Tim van der Lippe66684e92020-01-24 14:01:18377 * @implements {UI.ActionDelegate.ActionDelegate}
Blink Reformat4c46d092018-04-07 15:32:37378 * @unrestricted
379 */
Paul Lewis5d4133e2019-11-27 13:06:01380export class ActionDelegate {
Blink Reformat4c46d092018-04-07 15:32:37381 /**
382 * @override
Tim van der Lippe66684e92020-01-24 14:01:18383 * @param {!UI.Context.Context} context
Blink Reformat4c46d092018-04-07 15:32:37384 * @param {string} actionId
385 * @return {boolean}
386 */
387 handleAction(context, actionId) {
Jack Lynch575e9fb2020-03-26 22:20:51388 let screen;
Blink Reformat4c46d092018-04-07 15:32:37389 switch (actionId) {
390 case 'settings.show':
Jack Lynch85edfc82020-03-09 18:11:13391 SettingsScreen._showSettingsScreen({focusTabHeader: true});
Blink Reformat4c46d092018-04-07 15:32:37392 return true;
393 case 'settings.documentation':
Tim van der Lippe66684e92020-01-24 14:01:18394 Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(
Wolfgang Beyer6190ec82020-03-09 15:06:33395 UI.UIUtils.addReferrerToURL('https://developers.google.com/web/tools/chrome-devtools/'));
Blink Reformat4c46d092018-04-07 15:32:37396 return true;
397 case 'settings.shortcuts':
Brian Cui4fef3cd2020-02-11 01:05:55398 Host.userMetrics.actionTaken(Host.UserMetrics.Action.SettingsOpenedFromMenu);
Jack Lynch575e9fb2020-03-26 22:20:51399 screen = {name: ls`Shortcuts`, focusTabHeader: true};
400 if (Root.Runtime.experiments.isEnabled('customKeyboardShortcuts')) {
401 screen = {name: 'keybinds', focusTabHeader: true};
402 }
403 SettingsScreen._showSettingsScreen(screen);
Blink Reformat4c46d092018-04-07 15:32:37404 return true;
405 }
406 return false;
407 }
Paul Lewis5d4133e2019-11-27 13:06:01408}
Blink Reformat4c46d092018-04-07 15:32:37409
410/**
Tim van der Lippe66684e92020-01-24 14:01:18411 * @implements {Common.Revealer.Revealer}
Blink Reformat4c46d092018-04-07 15:32:37412 * @unrestricted
413 */
Paul Lewis5d4133e2019-11-27 13:06:01414export class Revealer {
Blink Reformat4c46d092018-04-07 15:32:37415 /**
416 * @override
417 * @param {!Object} object
418 * @return {!Promise}
419 */
420 reveal(object) {
Tim van der Lippe66684e92020-01-24 14:01:18421 console.assert(object instanceof Common.Settings.Setting);
422 const setting = /** @type {!Common.Settings.Setting} */ (object);
Blink Reformat4c46d092018-04-07 15:32:37423 let success = false;
424
425 self.runtime.extensions('setting').forEach(revealModuleSetting);
Tim van der Lippe66684e92020-01-24 14:01:18426 self.runtime.extensions(UI.SettingsUI.SettingUI).forEach(revealSettingUI);
Blink Reformat4c46d092018-04-07 15:32:37427 self.runtime.extensions('view').forEach(revealSettingsView);
428
429 return success ? Promise.resolve() : Promise.reject();
430
431 /**
Tim van der Lippe99e59b82019-09-30 20:00:59432 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37433 */
434 function revealModuleSetting(extension) {
Paul Lewis5d4133e2019-11-27 13:06:01435 if (!GenericSettingsTab.isSettingVisible(extension)) {
Blink Reformat4c46d092018-04-07 15:32:37436 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34437 }
Blink Reformat4c46d092018-04-07 15:32:37438 if (extension.descriptor()['settingName'] === setting.name) {
Tim van der Lippe66684e92020-01-24 14:01:18439 Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront();
Paul Lewis5d4133e2019-11-27 13:06:01440 SettingsScreen._showSettingsScreen();
Blink Reformat4c46d092018-04-07 15:32:37441 success = true;
442 }
443 }
444
445 /**
Tim van der Lippe99e59b82019-09-30 20:00:59446 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37447 */
448 function revealSettingUI(extension) {
449 const settings = extension.descriptor()['settings'];
450 if (settings && settings.indexOf(setting.name) !== -1) {
Tim van der Lippe66684e92020-01-24 14:01:18451 Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront();
Paul Lewis5d4133e2019-11-27 13:06:01452 SettingsScreen._showSettingsScreen();
Blink Reformat4c46d092018-04-07 15:32:37453 success = true;
454 }
455 }
456
457 /**
Tim van der Lippe99e59b82019-09-30 20:00:59458 * @param {!Root.Runtime.Extension} extension
Blink Reformat4c46d092018-04-07 15:32:37459 */
460 function revealSettingsView(extension) {
461 const location = extension.descriptor()['location'];
Tim van der Lippe1d6e57a2019-09-30 11:55:34462 if (location !== 'settings-view') {
Blink Reformat4c46d092018-04-07 15:32:37463 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34464 }
Blink Reformat4c46d092018-04-07 15:32:37465 const settings = extension.descriptor()['settings'];
466 if (settings && settings.indexOf(setting.name) !== -1) {
Tim van der Lippe66684e92020-01-24 14:01:18467 Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront();
Jack Lynch85edfc82020-03-09 18:11:13468 SettingsScreen._showSettingsScreen({name: extension.descriptor()['id']});
Blink Reformat4c46d092018-04-07 15:32:37469 success = true;
470 }
471 }
472 }
Paul Lewis5d4133e2019-11-27 13:06:01473}