Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 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 Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 30 | |
| 31 | import * as Common from '../common/common.js'; |
| 32 | import * as Components from '../components/components.js'; |
| 33 | import * as Host from '../host/host.js'; |
| 34 | import * as UI from '../ui/ui.js'; |
| 35 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 36 | /** |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 37 | * @implements {UI.View.ViewLocationResolver} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 38 | * @unrestricted |
| 39 | */ |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 40 | export class SettingsScreen extends UI.Widget.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 41 | constructor() { |
| 42 | super(true); |
| 43 | this.registerRequiredCSS('settings/settingsScreen.css'); |
| 44 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 45 | this.contentElement.classList.add('settings-window-main'); |
| 46 | this.contentElement.classList.add('vbox'); |
| 47 | |
| 48 | const settingsLabelElement = createElement('div'); |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 49 | const settingsTitleElement = |
| 50 | UI.Utils.createShadowRootWithCoreStyles(settingsLabelElement, 'settings/settingsScreen.css') |
| 51 | .createChild('div', 'settings-window-title'); |
John Emau | b970e56 | 2019-06-05 01:17:27 | [diff] [blame] | 52 | |
| 53 | UI.ARIAUtils.markAsHeading(settingsTitleElement, 1); |
| 54 | settingsTitleElement.textContent = ls`Settings`; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 55 | |
Paul Lewis | 75c7d0d | 2020-03-19 12:17:26 | [diff] [blame] | 56 | this._tabbedLocation = UI.ViewManager.ViewManager.instance().createTabbedLocation( |
Brian Cui | 4fef3cd | 2020-02-11 01:05:55 | [diff] [blame] | 57 | () => SettingsScreen._revealSettingsScreen(), 'settings-view'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 58 | const tabbedPane = this._tabbedLocation.tabbedPane(); |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 59 | tabbedPane.leftToolbar().appendToolbarItem(new UI.Toolbar.ToolbarItem(settingsLabelElement)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 60 | tabbedPane.setShrinkableTabs(false); |
| 61 | tabbedPane.makeVerticalTabLayout(); |
Brian Cui | 4fef3cd | 2020-02-11 01:05:55 | [diff] [blame] | 62 | |
Jack Lynch | 575e9fb | 2020-03-26 22:20:51 | [diff] [blame] | 63 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 68 | tabbedPane.show(this.contentElement); |
Brian Cui | 4fef3cd | 2020-02-11 01:05:55 | [diff] [blame] | 69 | tabbedPane.selectTab('preferences'); |
| 70 | tabbedPane.addEventListener(UI.TabbedPane.Events.TabInvoked, this._tabInvoked, this); |
| 71 | this._reportTabOnReveal = false; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /** |
Brian Cui | 4fef3cd | 2020-02-11 01:05:55 | [diff] [blame] | 75 | * @return {!SettingsScreen} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 76 | */ |
Brian Cui | 4fef3cd | 2020-02-11 01:05:55 | [diff] [blame] | 77 | static _revealSettingsScreen() { |
| 78 | /** @type {!SettingsScreen} */ |
| 79 | const settingsScreen = self.runtime.sharedInstance(SettingsScreen); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 80 | if (settingsScreen.isShowing()) { |
Brian Cui | 4fef3cd | 2020-02-11 01:05:55 | [diff] [blame] | 81 | return settingsScreen; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 82 | } |
Brian Cui | 4fef3cd | 2020-02-11 01:05:55 | [diff] [blame] | 83 | |
| 84 | settingsScreen._reportTabOnReveal = true; |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 85 | const dialog = new UI.Dialog.Dialog(); |
Chandani Shrestha | 08469b8 | 2019-10-02 17:22:55 | [diff] [blame] | 86 | dialog.contentElement.tabIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 87 | dialog.addCloseButton(); |
Brian Cui | 8fdb148 | 2019-12-04 21:41:46 | [diff] [blame] | 88 | dialog.setOutsideClickCallback(() => {}); |
| 89 | dialog.setPointerEventsBehavior(UI.GlassPane.PointerEventsBehavior.PierceGlassPane); |
| 90 | dialog.setOutsideTabIndexBehavior(UI.Dialog.OutsideTabIndexBehavior.PreserveMainViewTabIndex); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 91 | settingsScreen.show(dialog.contentElement); |
| 92 | dialog.show(); |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 93 | |
Brian Cui | 4fef3cd | 2020-02-11 01:05:55 | [diff] [blame] | 94 | 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 Cui | 55d00af | 2020-04-09 18:45:40 | [diff] [blame] | 105 | const tabbedPane = settingsScreen._tabbedLocation.tabbedPane(); |
| 106 | await tabbedPane.waitForTabElementUpdate(); |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 107 | if (focusTabHeader) { |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 108 | tabbedPane.focusSelectedTabHeader(); |
Brian Cui | 55d00af | 2020-04-09 18:45:40 | [diff] [blame] | 109 | } else { |
| 110 | tabbedPane.focus(); |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 111 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** |
| 115 | * @override |
| 116 | * @param {string} locationName |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 117 | * @return {?UI.View.ViewLocation} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 118 | */ |
| 119 | resolveLocation(locationName) { |
| 120 | return this._tabbedLocation; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @param {string} name |
| 125 | */ |
| 126 | _selectTab(name) { |
Brian Cui | 4fef3cd | 2020-02-11 01:05:55 | [diff] [blame] | 127 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 159 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 160 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * @unrestricted |
| 164 | */ |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 165 | class SettingsTab extends UI.Widget.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 166 | /** |
| 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 173 | if (id) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 174 | this.element.id = id; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 175 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 176 | const header = this.element.createChild('header'); |
Chandani Shrestha | 83bd7c9 | 2019-06-11 21:21:59 | [diff] [blame] | 177 | header.createChild('h1').createTextChild(name); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 178 | 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 Shrestha | 83bd7c9 | 2019-06-11 21:21:59 | [diff] [blame] | 188 | 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 Einbinder | eaef616 | 2019-07-15 17:42:55 | [diff] [blame] | 193 | UI.ARIAUtils.setAccessibleName(block, name); |
Chandani Shrestha | 83bd7c9 | 2019-06-11 21:21:59 | [diff] [blame] | 194 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 195 | return block; |
| 196 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 197 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 198 | |
| 199 | /** |
| 200 | * @unrestricted |
| 201 | */ |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 202 | export class GenericSettingsTab extends SettingsTab { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 203 | constructor() { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 204 | super(Common.UIString.UIString('Preferences'), 'preferences-tab-content'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 205 | |
| 206 | /** @const */ |
Alex Rudenko | 4bcabeb | 2020-05-06 08:43:56 | [diff] [blame] | 207 | const explicitSectionOrder = [ |
| 208 | '', 'Appearance', 'Sources', 'Elements', 'Network', 'Performance', 'Console', 'Extensions', 'Persistence', |
| 209 | 'Debugger', 'Global' |
| 210 | ]; |
Brandon Goddard | 80d3818 | 2020-06-12 15:33:25 | [diff] [blame^] | 211 | |
| 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 217 | /** @type {!Map<string, !Element>} */ |
| 218 | this._nameToSection = new Map(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 219 | for (const sectionName of explicitSectionOrder) { |
Alex Rudenko | 4bcabeb | 2020-05-06 08:43:56 | [diff] [blame] | 220 | this._createSectionElement(sectionName); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 221 | } |
Brandon Goddard | 80d3818 | 2020-06-12 15:33:25 | [diff] [blame^] | 222 | for (const section of experimentalSections) { |
| 223 | if (Root.Runtime.experiments.isEnabled(section.experiment)) { |
| 224 | this._createSectionElement(section.name); |
| 225 | } |
| 226 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 227 | self.runtime.extensions('setting').forEach(this._addSetting.bind(this)); |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 228 | self.runtime.extensions(UI.SettingsUI.SettingUI).forEach(this._addSettingUI.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 229 | |
| 230 | this._appendSection().appendChild( |
Mike Jackson | 60a0e9d | 2020-03-24 18:57:41 | [diff] [blame] | 231 | UI.UIUtils.createTextButton(Common.UIString.UIString('Restore defaults and reload'), restoreAndReload)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 232 | |
| 233 | function restoreAndReload() { |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame] | 234 | Common.Settings.Settings.instance().clearAll(); |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 235 | Components.Reload.reload(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
| 239 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 240 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 241 | * @return {boolean} |
| 242 | */ |
| 243 | static isSettingVisible(extension) { |
| 244 | const descriptor = extension.descriptor(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 245 | if (!('title' in descriptor)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 246 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 247 | } |
| 248 | if (!('category' in descriptor)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 249 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 250 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 251 | return true; |
| 252 | } |
| 253 | |
| 254 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 255 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 256 | */ |
| 257 | _addSetting(extension) { |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 258 | if (!GenericSettingsTab.isSettingVisible(extension)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 259 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 260 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 261 | const sectionElement = this._sectionElement(extension.descriptor()['category']); |
Alex Rudenko | 4bcabeb | 2020-05-06 08:43:56 | [diff] [blame] | 262 | if (!sectionElement) { |
| 263 | return; |
| 264 | } |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame] | 265 | const setting = Common.Settings.Settings.instance().moduleSetting(extension.descriptor()['settingName']); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 266 | const settingControl = UI.SettingsUI.createControlForSetting(setting); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 267 | if (settingControl) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 268 | sectionElement.appendChild(settingControl); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 269 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 273 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 274 | */ |
| 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 Lippe | 1ebfc50 | 2020-01-15 13:45:09 | [diff] [blame] | 282 | * @this {GenericSettingsTab} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 283 | */ |
| 284 | function appendCustomSetting(object) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 285 | const settingUI = /** @type {!UI.SettingsUI.SettingUI} */ (object); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 286 | const element = settingUI.settingElement(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 287 | if (element) { |
Alex Rudenko | 4bcabeb | 2020-05-06 08:43:56 | [diff] [blame] | 288 | let sectionElement = this._sectionElement(sectionName); |
| 289 | if (!sectionElement) { |
| 290 | sectionElement = this._createSectionElement(sectionName); |
| 291 | } |
| 292 | sectionElement.appendChild(element); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 293 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
| 297 | /** |
| 298 | * @param {string} sectionName |
| 299 | * @return {!Element} |
| 300 | */ |
Alex Rudenko | 4bcabeb | 2020-05-06 08:43:56 | [diff] [blame] | 301 | _createSectionElement(sectionName) { |
| 302 | const uiSectionName = sectionName && Common.UIString.UIString(sectionName); |
| 303 | const sectionElement = this._appendSection(uiSectionName); |
| 304 | this._nameToSection.set(sectionName, sectionElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 305 | return sectionElement; |
| 306 | } |
Alex Rudenko | 4bcabeb | 2020-05-06 08:43:56 | [diff] [blame] | 307 | |
| 308 | /** |
| 309 | * @param {string} sectionName |
| 310 | * @return {?Element} |
| 311 | */ |
| 312 | _sectionElement(sectionName) { |
| 313 | return this._nameToSection.get(sectionName) || null; |
| 314 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 315 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 316 | |
| 317 | /** |
| 318 | * @unrestricted |
| 319 | */ |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 320 | export class ExperimentsSettingsTab extends SettingsTab { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 321 | constructor() { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 322 | super(Common.UIString.UIString('Experiments'), 'experiments-tab-content'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 323 | |
Yang Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 324 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 328 | const experimentsSection = this._appendSection(); |
Yang Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 329 | 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 Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 342 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
| 346 | /** |
Yang Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 347 | * @param {string} warningMessage |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 348 | * @return {!Element} element |
| 349 | */ |
Yang Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 350 | _createExperimentsWarningSubsection(warningMessage) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 351 | const subsection = createElement('div'); |
| 352 | const warning = subsection.createChild('span', 'settings-experiments-warning-subsection-warning'); |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 353 | warning.textContent = Common.UIString.UIString('WARNING:'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 354 | subsection.createTextChild(' '); |
| 355 | const message = subsection.createChild('span', 'settings-experiments-warning-subsection-message'); |
Yang Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 356 | message.textContent = warningMessage; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 357 | return subsection; |
| 358 | } |
| 359 | |
| 360 | _createExperimentCheckbox(experiment) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 361 | const label = UI.UIUtils.CheckboxLabel.create(Common.UIString.UIString(experiment.title), experiment.isEnabled()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 362 | 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 Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 370 | p.className = experiment.unstable && !experiment.isEnabled() ? 'settings-experiment-unstable' : ''; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 371 | p.appendChild(label); |
| 372 | return p; |
| 373 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 374 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 375 | |
| 376 | /** |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 377 | * @implements {UI.ActionDelegate.ActionDelegate} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 378 | * @unrestricted |
| 379 | */ |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 380 | export class ActionDelegate { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 381 | /** |
| 382 | * @override |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 383 | * @param {!UI.Context.Context} context |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 384 | * @param {string} actionId |
| 385 | * @return {boolean} |
| 386 | */ |
| 387 | handleAction(context, actionId) { |
Jack Lynch | 575e9fb | 2020-03-26 22:20:51 | [diff] [blame] | 388 | let screen; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 389 | switch (actionId) { |
| 390 | case 'settings.show': |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 391 | SettingsScreen._showSettingsScreen({focusTabHeader: true}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 392 | return true; |
| 393 | case 'settings.documentation': |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 394 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab( |
Wolfgang Beyer | 6190ec8 | 2020-03-09 15:06:33 | [diff] [blame] | 395 | UI.UIUtils.addReferrerToURL('https://developers.google.com/web/tools/chrome-devtools/')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 396 | return true; |
| 397 | case 'settings.shortcuts': |
Brian Cui | 4fef3cd | 2020-02-11 01:05:55 | [diff] [blame] | 398 | Host.userMetrics.actionTaken(Host.UserMetrics.Action.SettingsOpenedFromMenu); |
Jack Lynch | 575e9fb | 2020-03-26 22:20:51 | [diff] [blame] | 399 | 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 Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 404 | return true; |
| 405 | } |
| 406 | return false; |
| 407 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 408 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 409 | |
| 410 | /** |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 411 | * @implements {Common.Revealer.Revealer} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 412 | * @unrestricted |
| 413 | */ |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 414 | export class Revealer { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 415 | /** |
| 416 | * @override |
| 417 | * @param {!Object} object |
| 418 | * @return {!Promise} |
| 419 | */ |
| 420 | reveal(object) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 421 | console.assert(object instanceof Common.Settings.Setting); |
| 422 | const setting = /** @type {!Common.Settings.Setting} */ (object); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 423 | let success = false; |
| 424 | |
| 425 | self.runtime.extensions('setting').forEach(revealModuleSetting); |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 426 | self.runtime.extensions(UI.SettingsUI.SettingUI).forEach(revealSettingUI); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 427 | self.runtime.extensions('view').forEach(revealSettingsView); |
| 428 | |
| 429 | return success ? Promise.resolve() : Promise.reject(); |
| 430 | |
| 431 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 432 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 433 | */ |
| 434 | function revealModuleSetting(extension) { |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 435 | if (!GenericSettingsTab.isSettingVisible(extension)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 436 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 437 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 438 | if (extension.descriptor()['settingName'] === setting.name) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 439 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront(); |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 440 | SettingsScreen._showSettingsScreen(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 441 | success = true; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 446 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 447 | */ |
| 448 | function revealSettingUI(extension) { |
| 449 | const settings = extension.descriptor()['settings']; |
| 450 | if (settings && settings.indexOf(setting.name) !== -1) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 451 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront(); |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 452 | SettingsScreen._showSettingsScreen(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 453 | success = true; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 458 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 459 | */ |
| 460 | function revealSettingsView(extension) { |
| 461 | const location = extension.descriptor()['location']; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 462 | if (location !== 'settings-view') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 463 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 464 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 465 | const settings = extension.descriptor()['settings']; |
| 466 | if (settings && settings.indexOf(setting.name) !== -1) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 467 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront(); |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 468 | SettingsScreen._showSettingsScreen({name: extension.descriptor()['id']}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 469 | success = true; |
| 470 | } |
| 471 | } |
| 472 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 473 | } |