blob: b9608d84c45c4ef05d33f68c12bf3c1f435b68bd [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371// 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
5/**
6 * @implements {Common.Runnable}
7 */
Paul Lewis7b9a9182019-12-03 14:09:038export class InspectorMainImpl extends Common.Object {
Blink Reformat4c46d092018-04-07 15:32:379 /**
10 * @override
11 */
Pavel Feldman07ef9722018-12-13 23:52:2212 async run() {
13 let firstCall = true;
14 await SDK.initMainConnection(async () => {
Tim van der Lippe99e59b82019-09-30 20:00:5915 const type = Root.Runtime.queryParam('v8only') ? SDK.Target.Type.Node : SDK.Target.Type.Frame;
16 const waitForDebuggerInPage = type === SDK.Target.Type.Frame && Root.Runtime.queryParam('panel') === 'sources';
Paul Lewis4ae5f4f2020-01-23 10:19:3317 const target = self.SDK.targetManager.createTarget(
18 'main', Common.UIString('Main'), type, null, undefined, waitForDebuggerInPage);
Pavel Feldman07ef9722018-12-13 23:52:2219
20 // Only resume target during the first connection,
21 // subsequent connections are due to connection hand-over,
22 // there is no need to pause in debugger.
Tim van der Lippe1d6e57a2019-09-30 11:55:3423 if (!firstCall) {
Pavel Feldman07ef9722018-12-13 23:52:2224 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:3425 }
Pavel Feldman07ef9722018-12-13 23:52:2226 firstCall = false;
27
28 if (waitForDebuggerInPage) {
29 const debuggerModel = target.model(SDK.DebuggerModel);
Tim van der Lippe1d6e57a2019-09-30 11:55:3430 if (!debuggerModel.isReadyToPause()) {
Pavel Feldman07ef9722018-12-13 23:52:2231 await debuggerModel.once(SDK.DebuggerModel.Events.DebuggerIsReadyToPause);
Tim van der Lippe1d6e57a2019-09-30 11:55:3432 }
Pavel Feldman07ef9722018-12-13 23:52:2233 debuggerModel.pause();
34 }
35
Dmitry Gozman99d7a6c2018-11-12 17:55:1136 target.runtimeAgent().runIfWaitingForDebugger();
37 }, Components.TargetDetachedDialog.webSocketConnectionLost);
Blink Reformat4c46d092018-04-07 15:32:3738
Paul Lewis7b9a9182019-12-03 14:09:0339 new SourcesPanelIndicator();
Tim van der Lippe078c7af2020-01-10 14:44:0140 new BackendSettingsSync();
Blink Reformat4c46d092018-04-07 15:32:3741 new MobileThrottling.NetworkPanelIndicator();
42
Tim van der Lippe50cfa9b2019-10-01 10:40:5843 Host.InspectorFrontendHost.events.addEventListener(
44 Host.InspectorFrontendHostAPI.Events.ReloadInspectedPage, event => {
45 const hard = /** @type {boolean} */ (event.data);
46 SDK.ResourceTreeModel.reloadAllPages(hard);
47 });
Blink Reformat4c46d092018-04-07 15:32:3748 }
Paul Lewis7b9a9182019-12-03 14:09:0349}
Blink Reformat4c46d092018-04-07 15:32:3750
51/**
52 * @implements {UI.ActionDelegate}
53 * @unrestricted
54 */
Paul Lewis7b9a9182019-12-03 14:09:0355export class ReloadActionDelegate {
Blink Reformat4c46d092018-04-07 15:32:3756 /**
57 * @override
58 * @param {!UI.Context} context
59 * @param {string} actionId
60 * @return {boolean}
61 */
62 handleAction(context, actionId) {
63 switch (actionId) {
64 case 'inspector_main.reload':
65 SDK.ResourceTreeModel.reloadAllPages(false);
66 return true;
67 case 'inspector_main.hard-reload':
68 SDK.ResourceTreeModel.reloadAllPages(true);
69 return true;
70 }
71 return false;
72 }
Paul Lewis7b9a9182019-12-03 14:09:0373}
Blink Reformat4c46d092018-04-07 15:32:3774
75/**
76 * @implements {UI.ActionDelegate}
77 * @unrestricted
78 */
Paul Lewis7b9a9182019-12-03 14:09:0379export class FocusDebuggeeActionDelegate {
Blink Reformat4c46d092018-04-07 15:32:3780 /**
81 * @override
82 * @param {!UI.Context} context
83 * @param {string} actionId
84 * @return {boolean}
85 */
86 handleAction(context, actionId) {
Paul Lewis4ae5f4f2020-01-23 10:19:3387 self.SDK.targetManager.mainTarget().pageAgent().bringToFront();
Blink Reformat4c46d092018-04-07 15:32:3788 return true;
89 }
Paul Lewis7b9a9182019-12-03 14:09:0390}
Blink Reformat4c46d092018-04-07 15:32:3791
92/**
93 * @implements {UI.ToolbarItem.Provider}
94 */
Paul Lewis7b9a9182019-12-03 14:09:0395export class NodeIndicator {
Blink Reformat4c46d092018-04-07 15:32:3796 constructor() {
97 const element = createElement('div');
98 const shadowRoot = UI.createShadowRootWithCoreStyles(element, 'inspector_main/nodeIcon.css');
99 this._element = shadowRoot.createChild('div', 'node-icon');
Tim van der Lippe50cfa9b2019-10-01 10:40:58100 element.addEventListener('click', () => Host.InspectorFrontendHost.openNodeFrontend(), false);
Blink Reformat4c46d092018-04-07 15:32:37101 this._button = new UI.ToolbarItem(element);
102 this._button.setTitle(Common.UIString('Open dedicated DevTools for Node.js'));
Paul Lewis4ae5f4f2020-01-23 10:19:33103 self.SDK.targetManager.addEventListener(
Blink Reformat4c46d092018-04-07 15:32:37104 SDK.TargetManager.Events.AvailableTargetsChanged,
105 event => this._update(/** @type {!Array<!Protocol.Target.TargetInfo>} */ (event.data)));
106 this._button.setVisible(false);
107 this._update([]);
108 }
109
110 /**
111 * @param {!Array<!Protocol.Target.TargetInfo>} targetInfos
112 */
113 _update(targetInfos) {
114 const hasNode = !!targetInfos.find(target => target.type === 'node' && !target.attached);
115 this._element.classList.toggle('inactive', !hasNode);
Tim van der Lippe1d6e57a2019-09-30 11:55:34116 if (hasNode) {
Blink Reformat4c46d092018-04-07 15:32:37117 this._button.setVisible(true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34118 }
Blink Reformat4c46d092018-04-07 15:32:37119 }
120
121 /**
122 * @override
123 * @return {?UI.ToolbarItem}
124 */
125 item() {
126 return this._button;
127 }
Paul Lewis7b9a9182019-12-03 14:09:03128}
Blink Reformat4c46d092018-04-07 15:32:37129
130/**
131 * @unrestricted
132 */
Paul Lewis7b9a9182019-12-03 14:09:03133export class SourcesPanelIndicator {
Blink Reformat4c46d092018-04-07 15:32:37134 constructor() {
Paul Lewis4b64b3f2020-01-23 11:41:20135 self.Common.settings.moduleSetting('javaScriptDisabled').addChangeListener(javaScriptDisabledChanged);
Blink Reformat4c46d092018-04-07 15:32:37136 javaScriptDisabledChanged();
137
138 function javaScriptDisabledChanged() {
139 let icon = null;
Paul Lewis4b64b3f2020-01-23 11:41:20140 const javaScriptDisabled = self.Common.settings.moduleSetting('javaScriptDisabled').get();
Blink Reformat4c46d092018-04-07 15:32:37141 if (javaScriptDisabled) {
142 icon = UI.Icon.create('smallicon-warning');
143 icon.title = Common.UIString('JavaScript is disabled');
144 }
Paul Lewis0a7c6b62020-01-23 16:16:22145 self.UI.inspectorView.setPanelIcon('sources', icon);
Blink Reformat4c46d092018-04-07 15:32:37146 }
147 }
Paul Lewis7b9a9182019-12-03 14:09:03148}
Blink Reformat4c46d092018-04-07 15:32:37149
150/**
Blink Reformat4c46d092018-04-07 15:32:37151 * @implements {SDK.TargetManager.Observer}
152 * @unrestricted
153 */
Paul Lewis7b9a9182019-12-03 14:09:03154export class BackendSettingsSync {
Blink Reformat4c46d092018-04-07 15:32:37155 constructor() {
Paul Lewis6bcdb182020-01-23 11:08:05156 this._autoAttachSetting = self.Common.settings.moduleSetting('autoAttachToCreatedPages');
Blink Reformat4c46d092018-04-07 15:32:37157 this._autoAttachSetting.addChangeListener(this._updateAutoAttach, this);
158 this._updateAutoAttach();
159
Paul Lewis6bcdb182020-01-23 11:08:05160 this._adBlockEnabledSetting = self.Common.settings.moduleSetting('network.adBlockingEnabled');
Blink Reformat4c46d092018-04-07 15:32:37161 this._adBlockEnabledSetting.addChangeListener(this._update, this);
162
Paul Lewis6bcdb182020-01-23 11:08:05163 this._emulatePageFocusSetting = self.Common.settings.moduleSetting('emulatePageFocus');
Joel Einbinder09a34e32018-09-11 21:49:05164 this._emulatePageFocusSetting.addChangeListener(this._update, this);
165
Paul Lewis4ae5f4f2020-01-23 10:19:33166 self.SDK.targetManager.observeTargets(this);
Blink Reformat4c46d092018-04-07 15:32:37167 }
168
169 /**
170 * @param {!SDK.Target} target
171 */
172 _updateTarget(target) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34173 if (target.type() !== SDK.Target.Type.Frame || target.parentTarget()) {
Joel Einbinder09a34e32018-09-11 21:49:05174 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34175 }
Joel Einbinder09a34e32018-09-11 21:49:05176 target.pageAgent().setAdBlockingEnabled(this._adBlockEnabledSetting.get());
177 target.emulationAgent().setFocusEmulationEnabled(this._emulatePageFocusSetting.get());
Blink Reformat4c46d092018-04-07 15:32:37178 }
179
180 _updateAutoAttach() {
Tim van der Lippe50cfa9b2019-10-01 10:40:58181 Host.InspectorFrontendHost.setOpenNewWindowForPopups(this._autoAttachSetting.get());
Blink Reformat4c46d092018-04-07 15:32:37182 }
183
184 _update() {
Paul Lewis4ae5f4f2020-01-23 10:19:33185 for (const target of self.SDK.targetManager.targets()) {
Dmitry Gozman08dbcb62018-11-01 16:15:05186 this._updateTarget(target);
Tim van der Lippe1d6e57a2019-09-30 11:55:34187 }
Blink Reformat4c46d092018-04-07 15:32:37188 }
189
190 /**
191 * @param {!SDK.Target} target
192 * @override
193 */
194 targetAdded(target) {
195 this._updateTarget(target);
196 }
197
198 /**
199 * @param {!SDK.Target} target
200 * @override
201 */
202 targetRemoved(target) {
203 }
Paul Lewis7b9a9182019-12-03 14:09:03204}
Blink Reformat4c46d092018-04-07 15:32:37205
206SDK.ChildTargetManager.install();