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 | |
| 56 | this._tabbedLocation = |
Paul Lewis | 5099369 | 2020-01-23 15:22:26 | [diff] [blame] | 57 | self.UI.viewManager.createTabbedLocation(() => SettingsScreen._showSettingsScreen(), '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(); |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 62 | const shortcutsView = new UI.View.SimpleView(ls`Shortcuts`); |
| 63 | self.UI.shortcutsScreen.createShortcutsTabView().show(shortcutsView.element); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 64 | this._tabbedLocation.appendView(shortcutsView); |
| 65 | tabbedPane.show(this.contentElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 69 | * @param {{name: (string|undefined), focusTabHeader: (boolean|undefined)}=} options |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 70 | */ |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 71 | static async _showSettingsScreen(options = {}) { |
| 72 | const {name, focusTabHeader} = options; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 73 | const settingsScreen = |
Tim van der Lippe | 1ebfc50 | 2020-01-15 13:45:09 | [diff] [blame] | 74 | /** @type {!SettingsScreen} */ (self.runtime.sharedInstance(SettingsScreen)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 75 | if (settingsScreen.isShowing()) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 76 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 77 | } |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 78 | const dialog = new UI.Dialog.Dialog(); |
Chandani Shrestha | 08469b8 | 2019-10-02 17:22:55 | [diff] [blame] | 79 | dialog.contentElement.tabIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 80 | dialog.addCloseButton(); |
Brian Cui | 8fdb148 | 2019-12-04 21:41:46 | [diff] [blame] | 81 | dialog.setOutsideClickCallback(() => {}); |
| 82 | dialog.setPointerEventsBehavior(UI.GlassPane.PointerEventsBehavior.PierceGlassPane); |
| 83 | dialog.setOutsideTabIndexBehavior(UI.Dialog.OutsideTabIndexBehavior.PreserveMainViewTabIndex); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 84 | settingsScreen.show(dialog.contentElement); |
| 85 | dialog.show(); |
| 86 | settingsScreen._selectTab(name || 'preferences'); |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 87 | |
| 88 | if (focusTabHeader) { |
| 89 | const tabbedPane = settingsScreen._tabbedLocation.tabbedPane(); |
| 90 | await tabbedPane.waitForTabElementUpdate(); |
| 91 | tabbedPane.focusSelectedTabHeader(); |
| 92 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @override |
| 97 | * @param {string} locationName |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 98 | * @return {?UI.View.ViewLocation} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 99 | */ |
| 100 | resolveLocation(locationName) { |
| 101 | return this._tabbedLocation; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @param {string} name |
| 106 | */ |
| 107 | _selectTab(name) { |
Paul Lewis | 5099369 | 2020-01-23 15:22:26 | [diff] [blame] | 108 | self.UI.viewManager.showView(name); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 109 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 110 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * @unrestricted |
| 114 | */ |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 115 | class SettingsTab extends UI.Widget.VBox { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 116 | /** |
| 117 | * @param {string} name |
| 118 | * @param {string=} id |
| 119 | */ |
| 120 | constructor(name, id) { |
| 121 | super(); |
| 122 | this.element.classList.add('settings-tab-container'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 123 | if (id) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 124 | this.element.id = id; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 125 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 126 | const header = this.element.createChild('header'); |
Chandani Shrestha | 83bd7c9 | 2019-06-11 21:21:59 | [diff] [blame] | 127 | header.createChild('h1').createTextChild(name); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 128 | this.containerElement = this.element.createChild('div', 'settings-container-wrapper') |
| 129 | .createChild('div', 'settings-tab settings-content settings-container'); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * @param {string=} name |
| 134 | * @return {!Element} |
| 135 | */ |
| 136 | _appendSection(name) { |
| 137 | const block = this.containerElement.createChild('div', 'settings-block'); |
Chandani Shrestha | 83bd7c9 | 2019-06-11 21:21:59 | [diff] [blame] | 138 | if (name) { |
| 139 | UI.ARIAUtils.markAsGroup(block); |
| 140 | const title = block.createChild('div', 'settings-section-title'); |
| 141 | title.textContent = name; |
| 142 | UI.ARIAUtils.markAsHeading(title, 2); |
Joel Einbinder | eaef616 | 2019-07-15 17:42:55 | [diff] [blame] | 143 | UI.ARIAUtils.setAccessibleName(block, name); |
Chandani Shrestha | 83bd7c9 | 2019-06-11 21:21:59 | [diff] [blame] | 144 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 145 | return block; |
| 146 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 147 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * @unrestricted |
| 151 | */ |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 152 | export class GenericSettingsTab extends SettingsTab { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 153 | constructor() { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 154 | super(Common.UIString.UIString('Preferences'), 'preferences-tab-content'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 155 | |
| 156 | /** @const */ |
| 157 | const explicitSectionOrder = |
| 158 | ['', 'Appearance', 'Sources', 'Elements', 'Network', 'Performance', 'Console', 'Extensions']; |
| 159 | /** @type {!Map<string, !Element>} */ |
| 160 | this._nameToSection = new Map(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 161 | for (const sectionName of explicitSectionOrder) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 162 | this._sectionElement(sectionName); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 163 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 164 | self.runtime.extensions('setting').forEach(this._addSetting.bind(this)); |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 165 | self.runtime.extensions(UI.SettingsUI.SettingUI).forEach(this._addSettingUI.bind(this)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 166 | |
| 167 | this._appendSection().appendChild( |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 168 | UI.UIUtils.createTextButton(Common.UIString.UIString('Restore defaults and reload'), restoreAndReload)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 169 | |
| 170 | function restoreAndReload() { |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame^] | 171 | Common.Settings.Settings.instance().clearAll(); |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 172 | Components.Reload.reload(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
| 176 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 177 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 178 | * @return {boolean} |
| 179 | */ |
| 180 | static isSettingVisible(extension) { |
| 181 | const descriptor = extension.descriptor(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 182 | if (!('title' in descriptor)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 183 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 184 | } |
| 185 | if (!('category' in descriptor)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 186 | return false; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 187 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 188 | return true; |
| 189 | } |
| 190 | |
| 191 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 192 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 193 | */ |
| 194 | _addSetting(extension) { |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 195 | if (!GenericSettingsTab.isSettingVisible(extension)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 196 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 197 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 198 | const sectionElement = this._sectionElement(extension.descriptor()['category']); |
Paul Lewis | 2d7d65c | 2020-03-16 17:26:30 | [diff] [blame^] | 199 | const setting = Common.Settings.Settings.instance().moduleSetting(extension.descriptor()['settingName']); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 200 | const settingControl = UI.SettingsUI.createControlForSetting(setting); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 201 | if (settingControl) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 202 | sectionElement.appendChild(settingControl); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 203 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 207 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 208 | */ |
| 209 | _addSettingUI(extension) { |
| 210 | const descriptor = extension.descriptor(); |
| 211 | const sectionName = descriptor['category'] || ''; |
| 212 | extension.instance().then(appendCustomSetting.bind(this)); |
| 213 | |
| 214 | /** |
| 215 | * @param {!Object} object |
Tim van der Lippe | 1ebfc50 | 2020-01-15 13:45:09 | [diff] [blame] | 216 | * @this {GenericSettingsTab} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 217 | */ |
| 218 | function appendCustomSetting(object) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 219 | const settingUI = /** @type {!UI.SettingsUI.SettingUI} */ (object); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 220 | const element = settingUI.settingElement(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 221 | if (element) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 222 | this._sectionElement(sectionName).appendChild(element); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 223 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * @param {string} sectionName |
| 229 | * @return {!Element} |
| 230 | */ |
| 231 | _sectionElement(sectionName) { |
| 232 | let sectionElement = this._nameToSection.get(sectionName); |
| 233 | if (!sectionElement) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 234 | const uiSectionName = sectionName && Common.UIString.UIString(sectionName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 235 | sectionElement = this._appendSection(uiSectionName); |
| 236 | this._nameToSection.set(sectionName, sectionElement); |
| 237 | } |
| 238 | return sectionElement; |
| 239 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 240 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 241 | |
| 242 | /** |
| 243 | * @unrestricted |
| 244 | */ |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 245 | export class ExperimentsSettingsTab extends SettingsTab { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 246 | constructor() { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 247 | super(Common.UIString.UIString('Experiments'), 'experiments-tab-content'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 248 | |
Yang Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 249 | const experiments = Root.Runtime.experiments.allConfigurableExperiments().sort(); |
| 250 | const unstableExperiments = experiments.filter(e => e.unstable); |
| 251 | const stableExperiments = experiments.filter(e => !e.unstable); |
| 252 | if (stableExperiments.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 253 | const experimentsSection = this._appendSection(); |
Yang Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 254 | const warningMessage = Common.UIString.UIString('These experiments could be dangerous and may require restart.'); |
| 255 | experimentsSection.appendChild(this._createExperimentsWarningSubsection(warningMessage)); |
| 256 | for (const experiment of stableExperiments) { |
| 257 | experimentsSection.appendChild(this._createExperimentCheckbox(experiment)); |
| 258 | } |
| 259 | } |
| 260 | if (unstableExperiments.length) { |
| 261 | const experimentsSection = this._appendSection(); |
| 262 | const warningMessage = |
| 263 | Common.UIString.UIString('These experiments are particularly unstable. Enable at your own risk.'); |
| 264 | experimentsSection.appendChild(this._createExperimentsWarningSubsection(warningMessage)); |
| 265 | for (const experiment of unstableExperiments) { |
| 266 | experimentsSection.appendChild(this._createExperimentCheckbox(experiment)); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 267 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
| 271 | /** |
Yang Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 272 | * @param {string} warningMessage |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 273 | * @return {!Element} element |
| 274 | */ |
Yang Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 275 | _createExperimentsWarningSubsection(warningMessage) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 276 | const subsection = createElement('div'); |
| 277 | const warning = subsection.createChild('span', 'settings-experiments-warning-subsection-warning'); |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 278 | warning.textContent = Common.UIString.UIString('WARNING:'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 279 | subsection.createTextChild(' '); |
| 280 | const message = subsection.createChild('span', 'settings-experiments-warning-subsection-message'); |
Yang Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 281 | message.textContent = warningMessage; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 282 | return subsection; |
| 283 | } |
| 284 | |
| 285 | _createExperimentCheckbox(experiment) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 286 | const label = UI.UIUtils.CheckboxLabel.create(Common.UIString.UIString(experiment.title), experiment.isEnabled()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 287 | const input = label.checkboxElement; |
| 288 | input.name = experiment.name; |
| 289 | function listener() { |
| 290 | experiment.setEnabled(input.checked); |
| 291 | } |
| 292 | input.addEventListener('click', listener, false); |
| 293 | |
| 294 | const p = createElement('p'); |
Yang Guo | 33e8f6f | 2020-02-06 11:50:29 | [diff] [blame] | 295 | p.className = experiment.unstable && !experiment.isEnabled() ? 'settings-experiment-unstable' : ''; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 296 | p.appendChild(label); |
| 297 | return p; |
| 298 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 299 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 300 | |
| 301 | /** |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 302 | * @implements {UI.ActionDelegate.ActionDelegate} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 303 | * @unrestricted |
| 304 | */ |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 305 | export class ActionDelegate { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 306 | /** |
| 307 | * @override |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 308 | * @param {!UI.Context.Context} context |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 309 | * @param {string} actionId |
| 310 | * @return {boolean} |
| 311 | */ |
| 312 | handleAction(context, actionId) { |
| 313 | switch (actionId) { |
| 314 | case 'settings.show': |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 315 | SettingsScreen._showSettingsScreen({focusTabHeader: true}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 316 | return true; |
| 317 | case 'settings.documentation': |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 318 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab( |
Wolfgang Beyer | 6190ec8 | 2020-03-09 15:06:33 | [diff] [blame] | 319 | UI.UIUtils.addReferrerToURL('https://developers.google.com/web/tools/chrome-devtools/')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 320 | return true; |
| 321 | case 'settings.shortcuts': |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 322 | SettingsScreen._showSettingsScreen({name: ls`Shortcuts`, focusTabHeader: true}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 323 | return true; |
| 324 | } |
| 325 | return false; |
| 326 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 327 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 328 | |
| 329 | /** |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 330 | * @implements {Common.Revealer.Revealer} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 331 | * @unrestricted |
| 332 | */ |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 333 | export class Revealer { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 334 | /** |
| 335 | * @override |
| 336 | * @param {!Object} object |
| 337 | * @return {!Promise} |
| 338 | */ |
| 339 | reveal(object) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 340 | console.assert(object instanceof Common.Settings.Setting); |
| 341 | const setting = /** @type {!Common.Settings.Setting} */ (object); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 342 | let success = false; |
| 343 | |
| 344 | self.runtime.extensions('setting').forEach(revealModuleSetting); |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 345 | self.runtime.extensions(UI.SettingsUI.SettingUI).forEach(revealSettingUI); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 346 | self.runtime.extensions('view').forEach(revealSettingsView); |
| 347 | |
| 348 | return success ? Promise.resolve() : Promise.reject(); |
| 349 | |
| 350 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 351 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 352 | */ |
| 353 | function revealModuleSetting(extension) { |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 354 | if (!GenericSettingsTab.isSettingVisible(extension)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 355 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 356 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 357 | if (extension.descriptor()['settingName'] === setting.name) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 358 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront(); |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 359 | SettingsScreen._showSettingsScreen(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 360 | success = true; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 365 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 366 | */ |
| 367 | function revealSettingUI(extension) { |
| 368 | const settings = extension.descriptor()['settings']; |
| 369 | if (settings && settings.indexOf(setting.name) !== -1) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 370 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront(); |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 371 | SettingsScreen._showSettingsScreen(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 372 | success = true; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | /** |
Tim van der Lippe | 99e59b8 | 2019-09-30 20:00:59 | [diff] [blame] | 377 | * @param {!Root.Runtime.Extension} extension |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 378 | */ |
| 379 | function revealSettingsView(extension) { |
| 380 | const location = extension.descriptor()['location']; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 381 | if (location !== 'settings-view') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 382 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 383 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 384 | const settings = extension.descriptor()['settings']; |
| 385 | if (settings && settings.indexOf(setting.name) !== -1) { |
Tim van der Lippe | 66684e9 | 2020-01-24 14:01:18 | [diff] [blame] | 386 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.bringToFront(); |
Jack Lynch | 85edfc8 | 2020-03-09 18:11:13 | [diff] [blame] | 387 | SettingsScreen._showSettingsScreen({name: extension.descriptor()['id']}); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 388 | success = true; |
| 389 | } |
| 390 | } |
| 391 | } |
Paul Lewis | 5d4133e | 2019-11-27 13:06:01 | [diff] [blame] | 392 | } |