Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 5 | import * as Common from '../common/common.js'; |
| 6 | import * as Components from '../components/components.js'; |
| 7 | import * as Host from '../host/host.js'; |
| 8 | import * as MobileThrottling from '../mobile_throttling/mobile_throttling.js'; |
| 9 | import * as SDK from '../sdk/sdk.js'; |
| 10 | import * as UI from '../ui/ui.js'; |
| 11 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 12 | /** |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 13 | * @implements {Common.Runnable.Runnable} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 14 | */ |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 15 | export class InspectorMainImpl extends Common.ObjectWrapper.ObjectWrapper { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 16 | /** |
| 17 | * @override |
| 18 | */ |
Pavel Feldman | 07ef972 | 2018-12-13 23:52:22 | [diff] [blame] | 19 | async run() { |
| 20 | let firstCall = true; |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 21 | await SDK.Connections.initMainConnection(async () => { |
| 22 | const type = Root.Runtime.queryParam('v8only') ? SDK.SDKModel.Type.Node : SDK.SDKModel.Type.Frame; |
| 23 | const waitForDebuggerInPage = type === SDK.SDKModel.Type.Frame && Root.Runtime.queryParam('panel') === 'sources'; |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 24 | const target = self.SDK.targetManager.createTarget( |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 25 | 'main', Common.UIString.UIString('Main'), type, null, undefined, waitForDebuggerInPage); |
Pavel Feldman | 07ef972 | 2018-12-13 23:52:22 | [diff] [blame] | 26 | |
| 27 | // Only resume target during the first connection, |
| 28 | // subsequent connections are due to connection hand-over, |
| 29 | // there is no need to pause in debugger. |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 30 | if (!firstCall) { |
Pavel Feldman | 07ef972 | 2018-12-13 23:52:22 | [diff] [blame] | 31 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 32 | } |
Pavel Feldman | 07ef972 | 2018-12-13 23:52:22 | [diff] [blame] | 33 | firstCall = false; |
| 34 | |
| 35 | if (waitForDebuggerInPage) { |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 36 | const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 37 | if (!debuggerModel.isReadyToPause()) { |
Pavel Feldman | 07ef972 | 2018-12-13 23:52:22 | [diff] [blame] | 38 | await debuggerModel.once(SDK.DebuggerModel.Events.DebuggerIsReadyToPause); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 39 | } |
Pavel Feldman | 07ef972 | 2018-12-13 23:52:22 | [diff] [blame] | 40 | debuggerModel.pause(); |
| 41 | } |
| 42 | |
Dmitry Gozman | 99d7a6c | 2018-11-12 17:55:11 | [diff] [blame] | 43 | target.runtimeAgent().runIfWaitingForDebugger(); |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 44 | }, Components.TargetDetachedDialog.TargetDetachedDialog.webSocketConnectionLost); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 45 | |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 46 | new SourcesPanelIndicator(); |
Tim van der Lippe | 078c7af | 2020-01-10 14:44:01 | [diff] [blame] | 47 | new BackendSettingsSync(); |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 48 | new MobileThrottling.NetworkPanelIndicator.NetworkPanelIndicator(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 49 | |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 50 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.events.addEventListener( |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 51 | Host.InspectorFrontendHostAPI.Events.ReloadInspectedPage, event => { |
| 52 | const hard = /** @type {boolean} */ (event.data); |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 53 | SDK.ResourceTreeModel.ResourceTreeModel.reloadAllPages(hard); |
Tim van der Lippe | 50cfa9b | 2019-10-01 10:40:58 | [diff] [blame] | 54 | }); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 55 | } |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 56 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 57 | |
| 58 | /** |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 59 | * @implements {UI.ActionDelegate.ActionDelegate} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 60 | * @unrestricted |
| 61 | */ |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 62 | export class ReloadActionDelegate { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 63 | /** |
| 64 | * @override |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 65 | * @param {!UI.Context.Context} context |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 66 | * @param {string} actionId |
| 67 | * @return {boolean} |
| 68 | */ |
| 69 | handleAction(context, actionId) { |
| 70 | switch (actionId) { |
| 71 | case 'inspector_main.reload': |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 72 | SDK.ResourceTreeModel.ResourceTreeModel.reloadAllPages(false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 73 | return true; |
| 74 | case 'inspector_main.hard-reload': |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 75 | SDK.ResourceTreeModel.ResourceTreeModel.reloadAllPages(true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 76 | return true; |
| 77 | } |
| 78 | return false; |
| 79 | } |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 80 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 81 | |
| 82 | /** |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 83 | * @implements {UI.ActionDelegate.ActionDelegate} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 84 | * @unrestricted |
| 85 | */ |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 86 | export class FocusDebuggeeActionDelegate { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 87 | /** |
| 88 | * @override |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 89 | * @param {!UI.Context.Context} context |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 90 | * @param {string} actionId |
| 91 | * @return {boolean} |
| 92 | */ |
| 93 | handleAction(context, actionId) { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 94 | self.SDK.targetManager.mainTarget().pageAgent().bringToFront(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 95 | return true; |
| 96 | } |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 97 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 98 | |
| 99 | /** |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 100 | * @implements {UI.Toolbar.Provider} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 101 | */ |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 102 | export class NodeIndicator { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 103 | constructor() { |
| 104 | const element = createElement('div'); |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 105 | const shadowRoot = UI.Utils.createShadowRootWithCoreStyles(element, 'inspector_main/nodeIcon.css'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 106 | this._element = shadowRoot.createChild('div', 'node-icon'); |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 107 | element.addEventListener( |
| 108 | 'click', () => Host.InspectorFrontendHost.InspectorFrontendHostInstance.openNodeFrontend(), false); |
| 109 | this._button = new UI.Toolbar.ToolbarItem(element); |
| 110 | this._button.setTitle(Common.UIString.UIString('Open dedicated DevTools for Node.js')); |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 111 | self.SDK.targetManager.addEventListener( |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 112 | SDK.SDKModel.Events.AvailableTargetsChanged, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 113 | event => this._update(/** @type {!Array<!Protocol.Target.TargetInfo>} */ (event.data))); |
| 114 | this._button.setVisible(false); |
| 115 | this._update([]); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * @param {!Array<!Protocol.Target.TargetInfo>} targetInfos |
| 120 | */ |
| 121 | _update(targetInfos) { |
| 122 | const hasNode = !!targetInfos.find(target => target.type === 'node' && !target.attached); |
| 123 | this._element.classList.toggle('inactive', !hasNode); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 124 | if (hasNode) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 125 | this._button.setVisible(true); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 126 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /** |
| 130 | * @override |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 131 | * @return {?UI.Toolbar.ToolbarItem} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 132 | */ |
| 133 | item() { |
| 134 | return this._button; |
| 135 | } |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 136 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * @unrestricted |
| 140 | */ |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 141 | export class SourcesPanelIndicator { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 142 | constructor() { |
Paul Lewis | 4b64b3f | 2020-01-23 11:41:20 | [diff] [blame] | 143 | self.Common.settings.moduleSetting('javaScriptDisabled').addChangeListener(javaScriptDisabledChanged); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 144 | javaScriptDisabledChanged(); |
| 145 | |
| 146 | function javaScriptDisabledChanged() { |
| 147 | let icon = null; |
Paul Lewis | 4b64b3f | 2020-01-23 11:41:20 | [diff] [blame] | 148 | const javaScriptDisabled = self.Common.settings.moduleSetting('javaScriptDisabled').get(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 149 | if (javaScriptDisabled) { |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 150 | icon = UI.Icon.Icon.create('smallicon-warning'); |
| 151 | icon.title = Common.UIString.UIString('JavaScript is disabled'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 152 | } |
Paul Lewis | 0a7c6b6 | 2020-01-23 16:16:22 | [diff] [blame] | 153 | self.UI.inspectorView.setPanelIcon('sources', icon); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 154 | } |
| 155 | } |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 156 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 157 | |
| 158 | /** |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 159 | * @implements {SDK.SDKModel.Observer} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 160 | * @unrestricted |
| 161 | */ |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 162 | export class BackendSettingsSync { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 163 | constructor() { |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 164 | this._autoAttachSetting = self.Common.settings.moduleSetting('autoAttachToCreatedPages'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 165 | this._autoAttachSetting.addChangeListener(this._updateAutoAttach, this); |
| 166 | this._updateAutoAttach(); |
| 167 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 168 | this._adBlockEnabledSetting = self.Common.settings.moduleSetting('network.adBlockingEnabled'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 169 | this._adBlockEnabledSetting.addChangeListener(this._update, this); |
| 170 | |
Paul Lewis | 6bcdb18 | 2020-01-23 11:08:05 | [diff] [blame] | 171 | this._emulatePageFocusSetting = self.Common.settings.moduleSetting('emulatePageFocus'); |
Joel Einbinder | 09a34e3 | 2018-09-11 21:49:05 | [diff] [blame] | 172 | this._emulatePageFocusSetting.addChangeListener(this._update, this); |
| 173 | |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 174 | self.SDK.targetManager.observeTargets(this); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /** |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 178 | * @param {!SDK.SDKModel.Target} target |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 179 | */ |
| 180 | _updateTarget(target) { |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 181 | if (target.type() !== SDK.SDKModel.Type.Frame || target.parentTarget()) { |
Joel Einbinder | 09a34e3 | 2018-09-11 21:49:05 | [diff] [blame] | 182 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 183 | } |
Joel Einbinder | 09a34e3 | 2018-09-11 21:49:05 | [diff] [blame] | 184 | target.pageAgent().setAdBlockingEnabled(this._adBlockEnabledSetting.get()); |
| 185 | target.emulationAgent().setFocusEmulationEnabled(this._emulatePageFocusSetting.get()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | _updateAutoAttach() { |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 189 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.setOpenNewWindowForPopups(this._autoAttachSetting.get()); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | _update() { |
Paul Lewis | 4ae5f4f | 2020-01-23 10:19:33 | [diff] [blame] | 193 | for (const target of self.SDK.targetManager.targets()) { |
Dmitry Gozman | 08dbcb6 | 2018-11-01 16:15:05 | [diff] [blame] | 194 | this._updateTarget(target); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 195 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /** |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 199 | * @param {!SDK.SDKModel.Target} target |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 200 | * @override |
| 201 | */ |
| 202 | targetAdded(target) { |
| 203 | this._updateTarget(target); |
| 204 | } |
| 205 | |
| 206 | /** |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 207 | * @param {!SDK.SDKModel.Target} target |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 208 | * @override |
| 209 | */ |
| 210 | targetRemoved(target) { |
| 211 | } |
Paul Lewis | 7b9a918 | 2019-12-03 14:09:03 | [diff] [blame] | 212 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 213 | |
Tim van der Lippe | 76e32b1 | 2020-01-24 16:21:00 | [diff] [blame^] | 214 | SDK.ChildTargetManager.ChildTargetManager.install(); |