blob: 97d6ae0304e6ec7fbad2561602a67ea0d8fefed7 [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 */
8InspectorMain.InspectorMain = class 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 () => {
Dmitry Gozman99d7a6c2018-11-12 17:55:1115 const type = Runtime.queryParam('v8only') ? SDK.Target.Type.Node : SDK.Target.Type.Frame;
Pavel Feldman07ef9722018-12-13 23:52:2216 const waitForDebuggerInPage = type === SDK.Target.Type.Frame && Runtime.queryParam('panel') === 'sources';
17 const target =
18 SDK.targetManager.createTarget('main', Common.UIString('Main'), type, null, undefined, waitForDebuggerInPage);
19
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.
23 if (!firstCall)
24 return;
25 firstCall = false;
26
27 if (waitForDebuggerInPage) {
28 const debuggerModel = target.model(SDK.DebuggerModel);
29 if (!debuggerModel.isReadyToPause())
30 await debuggerModel.once(SDK.DebuggerModel.Events.DebuggerIsReadyToPause);
31 debuggerModel.pause();
32 }
33
Dmitry Gozman99d7a6c2018-11-12 17:55:1134 target.runtimeAgent().runIfWaitingForDebugger();
35 }, Components.TargetDetachedDialog.webSocketConnectionLost);
Blink Reformat4c46d092018-04-07 15:32:3736
37 new InspectorMain.InspectedNodeRevealer();
38 new InspectorMain.SourcesPanelIndicator();
39 new InspectorMain.BackendSettingsSync();
40 new MobileThrottling.NetworkPanelIndicator();
41
42 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.ReloadInspectedPage, event => {
43 const hard = /** @type {boolean} */ (event.data);
44 SDK.ResourceTreeModel.reloadAllPages(hard);
45 });
46 }
Blink Reformat4c46d092018-04-07 15:32:3747};
48
49/**
50 * @implements {UI.ActionDelegate}
51 * @unrestricted
52 */
53InspectorMain.ReloadActionDelegate = class {
54 /**
55 * @override
56 * @param {!UI.Context} context
57 * @param {string} actionId
58 * @return {boolean}
59 */
60 handleAction(context, actionId) {
61 switch (actionId) {
62 case 'inspector_main.reload':
63 SDK.ResourceTreeModel.reloadAllPages(false);
64 return true;
65 case 'inspector_main.hard-reload':
66 SDK.ResourceTreeModel.reloadAllPages(true);
67 return true;
68 }
69 return false;
70 }
71};
72
73/**
74 * @implements {UI.ActionDelegate}
75 * @unrestricted
76 */
77InspectorMain.FocusDebuggeeActionDelegate = class {
78 /**
79 * @override
80 * @param {!UI.Context} context
81 * @param {string} actionId
82 * @return {boolean}
83 */
84 handleAction(context, actionId) {
85 SDK.targetManager.mainTarget().pageAgent().bringToFront();
86 return true;
87 }
88};
89
90/**
91 * @implements {UI.ToolbarItem.Provider}
92 */
93InspectorMain.NodeIndicator = class {
94 constructor() {
95 const element = createElement('div');
96 const shadowRoot = UI.createShadowRootWithCoreStyles(element, 'inspector_main/nodeIcon.css');
97 this._element = shadowRoot.createChild('div', 'node-icon');
98 element.addEventListener('click', () => InspectorFrontendHost.openNodeFrontend(), false);
99 this._button = new UI.ToolbarItem(element);
100 this._button.setTitle(Common.UIString('Open dedicated DevTools for Node.js'));
101 SDK.targetManager.addEventListener(
102 SDK.TargetManager.Events.AvailableTargetsChanged,
103 event => this._update(/** @type {!Array<!Protocol.Target.TargetInfo>} */ (event.data)));
104 this._button.setVisible(false);
105 this._update([]);
106 }
107
108 /**
109 * @param {!Array<!Protocol.Target.TargetInfo>} targetInfos
110 */
111 _update(targetInfos) {
112 const hasNode = !!targetInfos.find(target => target.type === 'node' && !target.attached);
113 this._element.classList.toggle('inactive', !hasNode);
114 if (hasNode)
115 this._button.setVisible(true);
116 }
117
118 /**
119 * @override
120 * @return {?UI.ToolbarItem}
121 */
122 item() {
123 return this._button;
124 }
125};
126
127/**
128 * @unrestricted
129 */
130InspectorMain.SourcesPanelIndicator = class {
131 constructor() {
132 Common.moduleSetting('javaScriptDisabled').addChangeListener(javaScriptDisabledChanged);
133 javaScriptDisabledChanged();
134
135 function javaScriptDisabledChanged() {
136 let icon = null;
137 const javaScriptDisabled = Common.moduleSetting('javaScriptDisabled').get();
138 if (javaScriptDisabled) {
139 icon = UI.Icon.create('smallicon-warning');
140 icon.title = Common.UIString('JavaScript is disabled');
141 }
142 UI.inspectorView.setPanelIcon('sources', icon);
143 }
144 }
145};
146
147/**
148 * @unrestricted
149 */
150InspectorMain.InspectedNodeRevealer = class {
151 constructor() {
152 SDK.targetManager.addModelListener(
153 SDK.OverlayModel, SDK.OverlayModel.Events.InspectNodeRequested, this._inspectNode, this);
154 }
155
156 /**
157 * @param {!Common.Event} event
158 */
159 _inspectNode(event) {
160 const deferredNode = /** @type {!SDK.DeferredDOMNode} */ (event.data);
161 Common.Revealer.reveal(deferredNode);
162 }
163};
164
165/**
166 * @implements {SDK.TargetManager.Observer}
167 * @unrestricted
168 */
169InspectorMain.BackendSettingsSync = class {
170 constructor() {
171 this._autoAttachSetting = Common.settings.moduleSetting('autoAttachToCreatedPages');
172 this._autoAttachSetting.addChangeListener(this._updateAutoAttach, this);
173 this._updateAutoAttach();
174
175 this._adBlockEnabledSetting = Common.settings.moduleSetting('network.adBlockingEnabled');
176 this._adBlockEnabledSetting.addChangeListener(this._update, this);
177
Joel Einbinder09a34e32018-09-11 21:49:05178 this._emulatePageFocusSetting = Common.settings.moduleSetting('emulatePageFocus');
179 this._emulatePageFocusSetting.addChangeListener(this._update, this);
180
Dmitry Gozman08dbcb62018-11-01 16:15:05181 SDK.targetManager.observeTargets(this);
Blink Reformat4c46d092018-04-07 15:32:37182 }
183
184 /**
185 * @param {!SDK.Target} target
186 */
187 _updateTarget(target) {
Dmitry Gozmanb24fcc22018-10-31 23:42:42188 if (target.type() !== SDK.Target.Type.Frame || target.parentTarget())
Joel Einbinder09a34e32018-09-11 21:49:05189 return;
190 target.pageAgent().setAdBlockingEnabled(this._adBlockEnabledSetting.get());
191 target.emulationAgent().setFocusEmulationEnabled(this._emulatePageFocusSetting.get());
Blink Reformat4c46d092018-04-07 15:32:37192 }
193
194 _updateAutoAttach() {
195 InspectorFrontendHost.setOpenNewWindowForPopups(this._autoAttachSetting.get());
196 }
197
198 _update() {
Dmitry Gozman08dbcb62018-11-01 16:15:05199 for (const target of SDK.targetManager.targets())
200 this._updateTarget(target);
Blink Reformat4c46d092018-04-07 15:32:37201 }
202
203 /**
204 * @param {!SDK.Target} target
205 * @override
206 */
207 targetAdded(target) {
208 this._updateTarget(target);
209 }
210
211 /**
212 * @param {!SDK.Target} target
213 * @override
214 */
215 targetRemoved(target) {
216 }
217};
218
219SDK.ChildTargetManager.install();