blob: 7db4a5b178d7cf58cac03273e54e9537eabcb457 [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
Tim van der Lippe76e32b12020-01-24 16:21:005import * as Common from '../common/common.js';
6import * as Components from '../components/components.js';
7import * as Host from '../host/host.js';
8import * as MobileThrottling from '../mobile_throttling/mobile_throttling.js';
Tim van der Lippe56c953d2020-11-13 14:07:459import * as Root from '../root/root.js';
Tim van der Lippe76e32b12020-01-24 16:21:0010import * as SDK from '../sdk/sdk.js';
11import * as UI from '../ui/ui.js';
12
Blink Reformat4c46d092018-04-07 15:32:3713/**
Tim van der Lippe76e32b12020-01-24 16:21:0014 * @implements {Common.Runnable.Runnable}
Blink Reformat4c46d092018-04-07 15:32:3715 */
Tim van der Lippe76e32b12020-01-24 16:21:0016export class InspectorMainImpl extends Common.ObjectWrapper.ObjectWrapper {
Blink Reformat4c46d092018-04-07 15:32:3717 /**
18 * @override
19 */
Pavel Feldman07ef9722018-12-13 23:52:2220 async run() {
21 let firstCall = true;
Tim van der Lippe76e32b12020-01-24 16:21:0022 await SDK.Connections.initMainConnection(async () => {
Tim van der Lippe56c953d2020-11-13 14:07:4523 const type = Root.Runtime.Runtime.queryParam('v8only') ? SDK.SDKModel.Type.Node : SDK.SDKModel.Type.Frame;
24 const waitForDebuggerInPage =
25 type === SDK.SDKModel.Type.Frame && Root.Runtime.Runtime.queryParam('panel') === 'sources';
Paul Lewisdaac1062020-03-05 14:37:1026 const target = SDK.SDKModel.TargetManager.instance().createTarget(
Tim van der Lippe76e32b12020-01-24 16:21:0027 'main', Common.UIString.UIString('Main'), type, null, undefined, waitForDebuggerInPage);
Pavel Feldman07ef9722018-12-13 23:52:2228
29 // Only resume target during the first connection,
30 // subsequent connections are due to connection hand-over,
31 // there is no need to pause in debugger.
Tim van der Lippe1d6e57a2019-09-30 11:55:3432 if (!firstCall) {
Pavel Feldman07ef9722018-12-13 23:52:2233 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:3434 }
Pavel Feldman07ef9722018-12-13 23:52:2235 firstCall = false;
36
37 if (waitForDebuggerInPage) {
Tim van der Lippe76e32b12020-01-24 16:21:0038 const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel);
Tim van der Lippe56c953d2020-11-13 14:07:4539 if (debuggerModel) {
40 if (!debuggerModel.isReadyToPause()) {
41 await debuggerModel.once(SDK.DebuggerModel.Events.DebuggerIsReadyToPause);
42 }
43 debuggerModel.pause();
Tim van der Lippe1d6e57a2019-09-30 11:55:3444 }
Pavel Feldman07ef9722018-12-13 23:52:2245 }
46
Tim van der Lippe56c953d2020-11-13 14:07:4547 await target.runtimeAgent().invoke_runIfWaitingForDebugger();
Tim van der Lippe76e32b12020-01-24 16:21:0048 }, Components.TargetDetachedDialog.TargetDetachedDialog.webSocketConnectionLost);
Blink Reformat4c46d092018-04-07 15:32:3749
Paul Lewis7b9a9182019-12-03 14:09:0350 new SourcesPanelIndicator();
Tim van der Lippe078c7af2020-01-10 14:44:0151 new BackendSettingsSync();
Tim van der Lippe76e32b12020-01-24 16:21:0052 new MobileThrottling.NetworkPanelIndicator.NetworkPanelIndicator();
Blink Reformat4c46d092018-04-07 15:32:3753
Tim van der Lippe76e32b12020-01-24 16:21:0054 Host.InspectorFrontendHost.InspectorFrontendHostInstance.events.addEventListener(
Tim van der Lippe50cfa9b2019-10-01 10:40:5855 Host.InspectorFrontendHostAPI.Events.ReloadInspectedPage, event => {
56 const hard = /** @type {boolean} */ (event.data);
Tim van der Lippe76e32b12020-01-24 16:21:0057 SDK.ResourceTreeModel.ResourceTreeModel.reloadAllPages(hard);
Tim van der Lippe50cfa9b2019-10-01 10:40:5858 });
Blink Reformat4c46d092018-04-07 15:32:3759 }
Paul Lewis7b9a9182019-12-03 14:09:0360}
Blink Reformat4c46d092018-04-07 15:32:3761
62/**
Andres Olivares6ff6d042020-11-17 14:31:5763 * @implements {UI.ActionRegistration.ActionDelegate}
Blink Reformat4c46d092018-04-07 15:32:3764 * @unrestricted
65 */
Paul Lewis7b9a9182019-12-03 14:09:0366export class ReloadActionDelegate {
Blink Reformat4c46d092018-04-07 15:32:3767 /**
68 * @override
Tim van der Lippe76e32b12020-01-24 16:21:0069 * @param {!UI.Context.Context} context
Blink Reformat4c46d092018-04-07 15:32:3770 * @param {string} actionId
71 * @return {boolean}
72 */
73 handleAction(context, actionId) {
74 switch (actionId) {
75 case 'inspector_main.reload':
Tim van der Lippe76e32b12020-01-24 16:21:0076 SDK.ResourceTreeModel.ResourceTreeModel.reloadAllPages(false);
Blink Reformat4c46d092018-04-07 15:32:3777 return true;
78 case 'inspector_main.hard-reload':
Tim van der Lippe76e32b12020-01-24 16:21:0079 SDK.ResourceTreeModel.ResourceTreeModel.reloadAllPages(true);
Blink Reformat4c46d092018-04-07 15:32:3780 return true;
81 }
82 return false;
83 }
Paul Lewis7b9a9182019-12-03 14:09:0384}
Blink Reformat4c46d092018-04-07 15:32:3785
86/**
Andres Olivares6ff6d042020-11-17 14:31:5787 * @implements {UI.ActionRegistration.ActionDelegate}
Blink Reformat4c46d092018-04-07 15:32:3788 * @unrestricted
89 */
Paul Lewis7b9a9182019-12-03 14:09:0390export class FocusDebuggeeActionDelegate {
Blink Reformat4c46d092018-04-07 15:32:3791 /**
92 * @override
Tim van der Lippe76e32b12020-01-24 16:21:0093 * @param {!UI.Context.Context} context
Blink Reformat4c46d092018-04-07 15:32:3794 * @param {string} actionId
95 * @return {boolean}
96 */
97 handleAction(context, actionId) {
Tim van der Lippe56c953d2020-11-13 14:07:4598 const mainTarget = SDK.SDKModel.TargetManager.instance().mainTarget();
99 if (!mainTarget) {
100 return false;
101 }
102 mainTarget.pageAgent().invoke_bringToFront();
Blink Reformat4c46d092018-04-07 15:32:37103 return true;
104 }
Paul Lewis7b9a9182019-12-03 14:09:03105}
Blink Reformat4c46d092018-04-07 15:32:37106
107/**
Tim van der Lippe76e32b12020-01-24 16:21:00108 * @implements {UI.Toolbar.Provider}
Blink Reformat4c46d092018-04-07 15:32:37109 */
Paul Lewis7b9a9182019-12-03 14:09:03110export class NodeIndicator {
Blink Reformat4c46d092018-04-07 15:32:37111 constructor() {
Tim van der Lippe56c953d2020-11-13 14:07:45112 const element = document.createElement('div');
Jack Franklin8ce2d8d2020-11-04 10:44:25113 const shadowRoot = UI.Utils.createShadowRootWithCoreStyles(
114 element, {cssFile: 'inspector_main/nodeIcon.css', enableLegacyPatching: true, delegatesFocus: undefined});
Blink Reformat4c46d092018-04-07 15:32:37115 this._element = shadowRoot.createChild('div', 'node-icon');
Tim van der Lippe76e32b12020-01-24 16:21:00116 element.addEventListener(
117 'click', () => Host.InspectorFrontendHost.InspectorFrontendHostInstance.openNodeFrontend(), false);
118 this._button = new UI.Toolbar.ToolbarItem(element);
119 this._button.setTitle(Common.UIString.UIString('Open dedicated DevTools for Node.js'));
Paul Lewisdaac1062020-03-05 14:37:10120 SDK.SDKModel.TargetManager.instance().addEventListener(
Tim van der Lippe76e32b12020-01-24 16:21:00121 SDK.SDKModel.Events.AvailableTargetsChanged,
Blink Reformat4c46d092018-04-07 15:32:37122 event => this._update(/** @type {!Array<!Protocol.Target.TargetInfo>} */ (event.data)));
123 this._button.setVisible(false);
124 this._update([]);
125 }
126
127 /**
128 * @param {!Array<!Protocol.Target.TargetInfo>} targetInfos
129 */
130 _update(targetInfos) {
131 const hasNode = !!targetInfos.find(target => target.type === 'node' && !target.attached);
132 this._element.classList.toggle('inactive', !hasNode);
Tim van der Lippe1d6e57a2019-09-30 11:55:34133 if (hasNode) {
Blink Reformat4c46d092018-04-07 15:32:37134 this._button.setVisible(true);
Tim van der Lippe1d6e57a2019-09-30 11:55:34135 }
Blink Reformat4c46d092018-04-07 15:32:37136 }
137
138 /**
139 * @override
Tim van der Lippe76e32b12020-01-24 16:21:00140 * @return {?UI.Toolbar.ToolbarItem}
Blink Reformat4c46d092018-04-07 15:32:37141 */
142 item() {
143 return this._button;
144 }
Paul Lewis7b9a9182019-12-03 14:09:03145}
Blink Reformat4c46d092018-04-07 15:32:37146
147/**
148 * @unrestricted
149 */
Paul Lewis7b9a9182019-12-03 14:09:03150export class SourcesPanelIndicator {
Blink Reformat4c46d092018-04-07 15:32:37151 constructor() {
Paul Lewis2d7d65c2020-03-16 17:26:30152 Common.Settings.Settings.instance()
153 .moduleSetting('javaScriptDisabled')
154 .addChangeListener(javaScriptDisabledChanged);
Blink Reformat4c46d092018-04-07 15:32:37155 javaScriptDisabledChanged();
156
157 function javaScriptDisabledChanged() {
158 let icon = null;
Paul Lewis2d7d65c2020-03-16 17:26:30159 const javaScriptDisabled = Common.Settings.Settings.instance().moduleSetting('javaScriptDisabled').get();
Blink Reformat4c46d092018-04-07 15:32:37160 if (javaScriptDisabled) {
Tim van der Lippe76e32b12020-01-24 16:21:00161 icon = UI.Icon.Icon.create('smallicon-warning');
162 icon.title = Common.UIString.UIString('JavaScript is disabled');
Blink Reformat4c46d092018-04-07 15:32:37163 }
Tim van der Lippe80d82652020-08-27 13:53:44164 UI.InspectorView.InspectorView.instance().setPanelIcon('sources', icon);
Blink Reformat4c46d092018-04-07 15:32:37165 }
166 }
Paul Lewis7b9a9182019-12-03 14:09:03167}
Blink Reformat4c46d092018-04-07 15:32:37168
169/**
Tim van der Lippe76e32b12020-01-24 16:21:00170 * @implements {SDK.SDKModel.Observer}
Blink Reformat4c46d092018-04-07 15:32:37171 * @unrestricted
172 */
Paul Lewis7b9a9182019-12-03 14:09:03173export class BackendSettingsSync {
Blink Reformat4c46d092018-04-07 15:32:37174 constructor() {
Paul Lewis2d7d65c2020-03-16 17:26:30175 this._autoAttachSetting = Common.Settings.Settings.instance().moduleSetting('autoAttachToCreatedPages');
Blink Reformat4c46d092018-04-07 15:32:37176 this._autoAttachSetting.addChangeListener(this._updateAutoAttach, this);
177 this._updateAutoAttach();
178
Paul Lewis2d7d65c2020-03-16 17:26:30179 this._adBlockEnabledSetting = Common.Settings.Settings.instance().moduleSetting('network.adBlockingEnabled');
Blink Reformat4c46d092018-04-07 15:32:37180 this._adBlockEnabledSetting.addChangeListener(this._update, this);
181
Paul Lewis2d7d65c2020-03-16 17:26:30182 this._emulatePageFocusSetting = Common.Settings.Settings.instance().moduleSetting('emulatePageFocus');
Joel Einbinder09a34e32018-09-11 21:49:05183 this._emulatePageFocusSetting.addChangeListener(this._update, this);
184
Paul Lewisdaac1062020-03-05 14:37:10185 SDK.SDKModel.TargetManager.instance().observeTargets(this);
Blink Reformat4c46d092018-04-07 15:32:37186 }
187
188 /**
Tim van der Lippe76e32b12020-01-24 16:21:00189 * @param {!SDK.SDKModel.Target} target
Blink Reformat4c46d092018-04-07 15:32:37190 */
191 _updateTarget(target) {
Tim van der Lippe76e32b12020-01-24 16:21:00192 if (target.type() !== SDK.SDKModel.Type.Frame || target.parentTarget()) {
Joel Einbinder09a34e32018-09-11 21:49:05193 return;
Tim van der Lippe1d6e57a2019-09-30 11:55:34194 }
Tim van der Lippe56c953d2020-11-13 14:07:45195 target.pageAgent().invoke_setAdBlockingEnabled({enabled: this._adBlockEnabledSetting.get()});
196 target.emulationAgent().invoke_setFocusEmulationEnabled({enabled: this._emulatePageFocusSetting.get()});
Blink Reformat4c46d092018-04-07 15:32:37197 }
198
199 _updateAutoAttach() {
Tim van der Lippe76e32b12020-01-24 16:21:00200 Host.InspectorFrontendHost.InspectorFrontendHostInstance.setOpenNewWindowForPopups(this._autoAttachSetting.get());
Blink Reformat4c46d092018-04-07 15:32:37201 }
202
203 _update() {
Paul Lewisdaac1062020-03-05 14:37:10204 for (const target of SDK.SDKModel.TargetManager.instance().targets()) {
Dmitry Gozman08dbcb62018-11-01 16:15:05205 this._updateTarget(target);
Tim van der Lippe1d6e57a2019-09-30 11:55:34206 }
Blink Reformat4c46d092018-04-07 15:32:37207 }
208
209 /**
Tim van der Lippe76e32b12020-01-24 16:21:00210 * @param {!SDK.SDKModel.Target} target
Blink Reformat4c46d092018-04-07 15:32:37211 * @override
212 */
213 targetAdded(target) {
214 this._updateTarget(target);
215 }
216
217 /**
Tim van der Lippe76e32b12020-01-24 16:21:00218 * @param {!SDK.SDKModel.Target} target
Blink Reformat4c46d092018-04-07 15:32:37219 * @override
220 */
221 targetRemoved(target) {
222 }
Paul Lewis7b9a9182019-12-03 14:09:03223}
Blink Reformat4c46d092018-04-07 15:32:37224
Tim van der Lippe76e32b12020-01-24 16:21:00225SDK.ChildTargetManager.ChildTargetManager.install();