blob: 3d3214e46de55a7c2967d7df51adefb952f7bf51 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Matt Lilek ([email protected]).
4 * Copyright (C) 2009 Joseph Pecoraro
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * @unrestricted
33 */
34Main.Main = class {
35 /**
36 * @suppressGlobalPropertiesCheck
37 */
38 constructor() {
39 Main.Main._instanceForTest = this;
40 runOnWindowLoad(this._loaded.bind(this));
41 }
42
43 /**
44 * @param {string} label
45 */
46 static time(label) {
47 if (Host.isUnderTest())
48 return;
49 console.time(label);
50 }
51
52 /**
53 * @param {string} label
54 */
55 static timeEnd(label) {
56 if (Host.isUnderTest())
57 return;
58 console.timeEnd(label);
59 }
60
61 async _loaded() {
62 console.timeStamp('Main._loaded');
Pavel Feldman63e89eb2018-11-25 05:47:0963 await Runtime.appStarted();
Blink Reformat4c46d092018-04-07 15:32:3764 Runtime.setPlatform(Host.platform());
65 InspectorFrontendHost.getPreferences(this._gotPreferences.bind(this));
66 }
67
68 /**
69 * @param {!Object<string, string>} prefs
70 */
71 _gotPreferences(prefs) {
72 console.timeStamp('Main._gotPreferences');
73 if (Host.isUnderTest(prefs))
74 self.runtime.useTestBase();
75 this._createSettings(prefs);
76 this._createAppUI();
77 }
78
79 /**
80 * @param {!Object<string, string>} prefs
81 * Note: this function is called from testSettings in Tests.js.
82 */
83 _createSettings(prefs) {
84 this._initializeExperiments();
85 let storagePrefix = '';
86 if (Host.isCustomDevtoolsFrontend())
87 storagePrefix = '__custom__';
88 else if (!Runtime.queryParam('can_dock') && !!Runtime.queryParam('debugFrontend') && !Host.isUnderTest())
89 storagePrefix = '__bundled__';
90
91 let localStorage;
92 if (!Host.isUnderTest() && window.localStorage) {
93 localStorage = new Common.SettingsStorage(
94 window.localStorage, undefined, undefined, () => window.localStorage.clear(), storagePrefix);
95 } else {
96 localStorage = new Common.SettingsStorage({}, undefined, undefined, undefined, storagePrefix);
97 }
98 const globalStorage = new Common.SettingsStorage(
99 prefs, InspectorFrontendHost.setPreference, InspectorFrontendHost.removePreference,
100 InspectorFrontendHost.clearPreferences, storagePrefix);
101 Common.settings = new Common.Settings(globalStorage, localStorage);
102 if (!Host.isUnderTest())
103 new Common.VersionController().updateVersion();
104 }
105
106 _initializeExperiments() {
107 // Keep this sorted alphabetically: both keys and values.
108 Runtime.experiments.register('applyCustomStylesheet', 'Allow custom UI themes');
Rayan Kanso8fe8ee22019-03-04 14:58:46109 Runtime.experiments.register('backgroundServices', 'Background web platform feature events', true);
Blink Reformat4c46d092018-04-07 15:32:37110 Runtime.experiments.register('blackboxJSFramesOnTimeline', 'Blackbox JavaScript frames on Timeline', true);
Blink Reformat4c46d092018-04-07 15:32:37111 Runtime.experiments.register('emptySourceMapAutoStepping', 'Empty sourcemap auto-stepping');
112 Runtime.experiments.register('inputEventsOnTimelineOverview', 'Input events on Timeline overview', true);
113 Runtime.experiments.register('nativeHeapProfiler', 'Native memory sampling heap profiler', true);
Blink Reformat4c46d092018-04-07 15:32:37114 Runtime.experiments.register('protocolMonitor', 'Protocol Monitor');
Alexei Filippov6d2eb592018-10-25 21:48:56115 Runtime.experiments.register('samplingHeapProfilerTimeline', 'Sampling heap profiler timeline', true);
Blink Reformat4c46d092018-04-07 15:32:37116 Runtime.experiments.register('sourceDiff', 'Source diff');
Joel Einbinderd7595c72018-05-15 17:41:54117 Runtime.experiments.register('sourcesPrettyPrint', 'Automatically pretty print in the Sources Panel');
Pavel Feldmanc9060ea2018-04-30 04:42:18118 Runtime.experiments.register('splitInDrawer', 'Split in drawer', true);
Blink Reformat4c46d092018-04-07 15:32:37119 Runtime.experiments.register('terminalInDrawer', 'Terminal in drawer', true);
120
121 // Timeline
122 Runtime.experiments.register('timelineEventInitiators', 'Timeline: event initiators');
123 Runtime.experiments.register('timelineFlowEvents', 'Timeline: flow events', true);
124 Runtime.experiments.register('timelineInvalidationTracking', 'Timeline: invalidation tracking', true);
Blink Reformat4c46d092018-04-07 15:32:37125 Runtime.experiments.register('timelineShowAllEvents', 'Timeline: show all events', true);
Blink Reformat4c46d092018-04-07 15:32:37126 Runtime.experiments.register('timelineV8RuntimeCallStats', 'Timeline: V8 Runtime Call Stats on Timeline', true);
Alexei Filippov57ccafb2018-08-14 20:59:05127 Runtime.experiments.register('timelineWebGL', 'Timeline: WebGL-based flamechart');
Blink Reformat4c46d092018-04-07 15:32:37128
129 Runtime.experiments.cleanUpStaleExperiments();
Pavel Feldmandb310912019-01-30 00:31:20130 Runtime.experiments.setDefaultExperiments([]);
Blink Reformat4c46d092018-04-07 15:32:37131 }
132
133 /**
134 * @suppressGlobalPropertiesCheck
135 */
136 async _createAppUI() {
137 Main.Main.time('Main._createAppUI');
138
139 UI.viewManager = new UI.ViewManager();
140
141 // Request filesystems early, we won't create connections until callback is fired. Things will happen in parallel.
142 Persistence.isolatedFileSystemManager = new Persistence.IsolatedFileSystemManager();
143
144 const themeSetting = Common.settings.createSetting('uiTheme', 'default');
145 UI.initializeUIUtils(document, themeSetting);
146 themeSetting.addChangeListener(Components.reload.bind(Components));
147
148 UI.installComponentRootStyles(/** @type {!Element} */ (document.body));
149
150 this._addMainEventListeners(document);
151
152 const canDock = !!Runtime.queryParam('can_dock');
153 UI.zoomManager = new UI.ZoomManager(window, InspectorFrontendHost);
154 UI.inspectorView = UI.InspectorView.instance();
155 UI.ContextMenu.initialize();
156 UI.ContextMenu.installHandler(document);
157 UI.Tooltip.installHandler(document);
158 Components.dockController = new Components.DockController(canDock);
159 SDK.consoleModel = new SDK.ConsoleModel();
160 SDK.multitargetNetworkManager = new SDK.MultitargetNetworkManager();
161 SDK.domDebuggerManager = new SDK.DOMDebuggerManager();
162 SDK.targetManager.addEventListener(
163 SDK.TargetManager.Events.SuspendStateChanged, this._onSuspendStateChanged.bind(this));
164
165 UI.shortcutsScreen = new UI.ShortcutsScreen();
166 // set order of some sections explicitly
167 UI.shortcutsScreen.section(Common.UIString('Elements Panel'));
168 UI.shortcutsScreen.section(Common.UIString('Styles Pane'));
169 UI.shortcutsScreen.section(Common.UIString('Debugger'));
170 UI.shortcutsScreen.section(Common.UIString('Console'));
171
172 Workspace.fileManager = new Workspace.FileManager();
173 Workspace.workspace = new Workspace.Workspace();
174
175 Bindings.networkProjectManager = new Bindings.NetworkProjectManager();
176 Bindings.resourceMapping = new Bindings.ResourceMapping(SDK.targetManager, Workspace.workspace);
177 new Bindings.PresentationConsoleMessageManager();
178 Bindings.cssWorkspaceBinding = new Bindings.CSSWorkspaceBinding(SDK.targetManager, Workspace.workspace);
179 Bindings.debuggerWorkspaceBinding = new Bindings.DebuggerWorkspaceBinding(SDK.targetManager, Workspace.workspace);
180 Bindings.breakpointManager =
181 new Bindings.BreakpointManager(Workspace.workspace, SDK.targetManager, Bindings.debuggerWorkspaceBinding);
182 Extensions.extensionServer = new Extensions.ExtensionServer();
183
184 new Persistence.FileSystemWorkspaceBinding(Persistence.isolatedFileSystemManager, Workspace.workspace);
185 Persistence.persistence = new Persistence.Persistence(Workspace.workspace, Bindings.breakpointManager);
186 Persistence.networkPersistenceManager = new Persistence.NetworkPersistenceManager(Workspace.workspace);
187
188 new Main.ExecutionContextSelector(SDK.targetManager, UI.context);
189 Bindings.blackboxManager = new Bindings.BlackboxManager(Bindings.debuggerWorkspaceBinding);
190
191 new Main.Main.PauseListener();
192
193 UI.actionRegistry = new UI.ActionRegistry();
194 UI.shortcutRegistry = new UI.ShortcutRegistry(UI.actionRegistry, document);
195 UI.ShortcutsScreen.registerShortcuts();
196 this._registerForwardedShortcuts();
197 this._registerMessageSinkListener();
198
199 Main.Main.timeEnd('Main._createAppUI');
200 this._showAppUI(await self.runtime.extension(Common.AppProvider).instance());
201 }
202
203 /**
204 * @param {!Object} appProvider
205 * @suppressGlobalPropertiesCheck
206 */
207 _showAppUI(appProvider) {
208 Main.Main.time('Main._showAppUI');
209 const app = /** @type {!Common.AppProvider} */ (appProvider).createApp();
210 // It is important to kick controller lifetime after apps are instantiated.
211 Components.dockController.initialize();
212 app.presentUI(document);
213
214 const toggleSearchNodeAction = UI.actionRegistry.action('elements.toggle-element-search');
215 // TODO: we should not access actions from other modules.
216 if (toggleSearchNodeAction) {
217 InspectorFrontendHost.events.addEventListener(
218 InspectorFrontendHostAPI.Events.EnterInspectElementMode,
219 toggleSearchNodeAction.execute.bind(toggleSearchNodeAction), this);
220 }
221 InspectorFrontendHost.events.addEventListener(
222 InspectorFrontendHostAPI.Events.RevealSourceLine, this._revealSourceLine, this);
223
224 UI.inspectorView.createToolbars();
225 InspectorFrontendHost.loadCompleted();
226
227 const extensions = self.runtime.extensions(Common.QueryParamHandler);
228 for (const extension of extensions) {
229 const value = Runtime.queryParam(extension.descriptor()['name']);
230 if (value !== null)
231 extension.instance().then(handleQueryParam.bind(null, value));
232 }
233
234 /**
235 * @param {string} value
236 * @param {!Common.QueryParamHandler} handler
237 */
238 function handleQueryParam(value, handler) {
239 handler.handleQueryParam(value);
240 }
241
242 // Allow UI cycles to repaint prior to creating connection.
243 setTimeout(this._initializeTarget.bind(this), 0);
244 Main.Main.timeEnd('Main._showAppUI');
245 }
246
247 async _initializeTarget() {
248 Main.Main.time('Main._initializeTarget');
249 const instances =
250 await Promise.all(self.runtime.extensions('early-initialization').map(extension => extension.instance()));
251 for (const instance of instances)
Pavel Feldman07ef9722018-12-13 23:52:22252 await /** @type {!Common.Runnable} */ (instance).run();
Blink Reformat4c46d092018-04-07 15:32:37253 // Used for browser tests.
254 InspectorFrontendHost.readyForTest();
255 // Asynchronously run the extensions.
256 setTimeout(this._lateInitialization.bind(this), 100);
257 Main.Main.timeEnd('Main._initializeTarget');
258 }
259
260 _lateInitialization() {
261 Main.Main.time('Main._lateInitialization');
262 this._registerShortcuts();
263 Extensions.extensionServer.initializeExtensions();
264 if (!Host.isUnderTest()) {
265 for (const extension of self.runtime.extensions('late-initialization'))
266 extension.instance().then(instance => (/** @type {!Common.Runnable} */ (instance)).run());
267 }
268 Main.Main.timeEnd('Main._lateInitialization');
269 }
270
271 _registerForwardedShortcuts() {
272 /** @const */ const forwardedActions = [
273 'main.toggle-dock', 'debugger.toggle-breakpoints-active', 'debugger.toggle-pause', 'commandMenu.show',
274 'console.show'
275 ];
276 const actionKeys =
277 UI.shortcutRegistry.keysForActions(forwardedActions).map(UI.KeyboardShortcut.keyCodeAndModifiersFromKey);
278 InspectorFrontendHost.setWhitelistedShortcuts(JSON.stringify(actionKeys));
279 }
280
281 _registerMessageSinkListener() {
282 Common.console.addEventListener(Common.Console.Events.MessageAdded, messageAdded);
283
284 /**
285 * @param {!Common.Event} event
286 */
287 function messageAdded(event) {
288 const message = /** @type {!Common.Console.Message} */ (event.data);
289 if (message.show)
290 Common.console.show();
291 }
292 }
293
294 /**
295 * @param {!Common.Event} event
296 */
297 _revealSourceLine(event) {
298 const url = /** @type {string} */ (event.data['url']);
299 const lineNumber = /** @type {number} */ (event.data['lineNumber']);
300 const columnNumber = /** @type {number} */ (event.data['columnNumber']);
301
302 const uiSourceCode = Workspace.workspace.uiSourceCodeForURL(url);
303 if (uiSourceCode) {
304 Common.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber));
305 return;
306 }
307
308 /**
309 * @param {!Common.Event} event
310 */
311 function listener(event) {
312 const uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
313 if (uiSourceCode.url() === url) {
314 Common.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber));
315 Workspace.workspace.removeEventListener(Workspace.Workspace.Events.UISourceCodeAdded, listener);
316 }
317 }
318
319 Workspace.workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAdded, listener);
320 }
321
322 _registerShortcuts() {
323 const shortcut = UI.KeyboardShortcut;
324 const section = UI.shortcutsScreen.section(Common.UIString('All Panels'));
325 let keys = [
326 shortcut.makeDescriptor('[', shortcut.Modifiers.CtrlOrMeta),
327 shortcut.makeDescriptor(']', shortcut.Modifiers.CtrlOrMeta)
328 ];
329 section.addRelatedKeys(keys, Common.UIString('Go to the panel to the left/right'));
330
331 const toggleConsoleLabel = Common.UIString('Show console');
332 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Tilde, shortcut.Modifiers.Ctrl), toggleConsoleLabel);
333 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Esc), Common.UIString('Toggle drawer'));
334 if (Components.dockController.canDock()) {
335 section.addKey(
336 shortcut.makeDescriptor('M', shortcut.Modifiers.CtrlOrMeta | shortcut.Modifiers.Shift),
337 Common.UIString('Toggle device mode'));
338 section.addKey(
339 shortcut.makeDescriptor('D', shortcut.Modifiers.CtrlOrMeta | shortcut.Modifiers.Shift),
340 Common.UIString('Toggle dock side'));
341 }
342 section.addKey(shortcut.makeDescriptor('f', shortcut.Modifiers.CtrlOrMeta), Common.UIString('Search'));
343
344 const advancedSearchShortcutModifier = Host.isMac() ?
345 UI.KeyboardShortcut.Modifiers.Meta | UI.KeyboardShortcut.Modifiers.Alt :
346 UI.KeyboardShortcut.Modifiers.Ctrl | UI.KeyboardShortcut.Modifiers.Shift;
347 const advancedSearchShortcut = shortcut.makeDescriptor('f', advancedSearchShortcutModifier);
348 section.addKey(advancedSearchShortcut, Common.UIString('Search across all sources'));
349
350 const inspectElementModeShortcuts =
351 UI.shortcutRegistry.shortcutDescriptorsForAction('elements.toggle-element-search');
352 if (inspectElementModeShortcuts.length)
353 section.addKey(inspectElementModeShortcuts[0], Common.UIString('Select node to inspect'));
354
355 const openResourceShortcut = UI.KeyboardShortcut.makeDescriptor('p', UI.KeyboardShortcut.Modifiers.CtrlOrMeta);
356 section.addKey(openResourceShortcut, Common.UIString('Go to source'));
357
358 if (Host.isMac()) {
359 keys = [
360 shortcut.makeDescriptor('g', shortcut.Modifiers.Meta),
361 shortcut.makeDescriptor('g', shortcut.Modifiers.Meta | shortcut.Modifiers.Shift)
362 ];
363 section.addRelatedKeys(keys, Common.UIString('Find next/previous'));
364 }
365 }
366
367 _postDocumentKeyDown(event) {
Joel Einbindera66e5bf2018-05-31 01:26:37368 if (!event.handled)
369 UI.shortcutRegistry.handleShortcut(event);
Blink Reformat4c46d092018-04-07 15:32:37370 }
371
372 /**
373 * @param {!Event} event
374 */
375 _redispatchClipboardEvent(event) {
376 const eventCopy = new CustomEvent('clipboard-' + event.type, {bubbles: true});
377 eventCopy['original'] = event;
378 const document = event.target && event.target.ownerDocument;
379 const target = document ? document.deepActiveElement() : null;
380 if (target)
381 target.dispatchEvent(eventCopy);
382 if (eventCopy.handled)
383 event.preventDefault();
384 }
385
386 _contextMenuEventFired(event) {
387 if (event.handled || event.target.classList.contains('popup-glasspane'))
388 event.preventDefault();
389 }
390
391 /**
392 * @param {!Document} document
393 */
394 _addMainEventListeners(document) {
395 document.addEventListener('keydown', this._postDocumentKeyDown.bind(this), false);
396 document.addEventListener('beforecopy', this._redispatchClipboardEvent.bind(this), true);
397 document.addEventListener('copy', this._redispatchClipboardEvent.bind(this), false);
398 document.addEventListener('cut', this._redispatchClipboardEvent.bind(this), false);
399 document.addEventListener('paste', this._redispatchClipboardEvent.bind(this), false);
400 document.addEventListener('contextmenu', this._contextMenuEventFired.bind(this), true);
401 }
402
403 _onSuspendStateChanged() {
404 const suspended = SDK.targetManager.allTargetsSuspended();
405 UI.inspectorView.onSuspendStateChanged(suspended);
406 }
407};
408
409/**
410 * @implements {UI.ActionDelegate}
411 * @unrestricted
412 */
413Main.Main.ZoomActionDelegate = class {
414 /**
415 * @override
416 * @param {!UI.Context} context
417 * @param {string} actionId
418 * @return {boolean}
419 */
420 handleAction(context, actionId) {
421 if (InspectorFrontendHost.isHostedMode())
422 return false;
423
424 switch (actionId) {
425 case 'main.zoom-in':
426 InspectorFrontendHost.zoomIn();
427 return true;
428 case 'main.zoom-out':
429 InspectorFrontendHost.zoomOut();
430 return true;
431 case 'main.zoom-reset':
432 InspectorFrontendHost.resetZoom();
433 return true;
434 }
435 return false;
436 }
437};
438
439/**
440 * @implements {UI.ActionDelegate}
441 * @unrestricted
442 */
443Main.Main.SearchActionDelegate = class {
444 /**
445 * @override
446 * @param {!UI.Context} context
447 * @param {string} actionId
448 * @return {boolean}
449 * @suppressGlobalPropertiesCheck
450 */
451 handleAction(context, actionId) {
452 const searchableView = UI.SearchableView.fromElement(document.deepActiveElement()) ||
453 UI.inspectorView.currentPanelDeprecated().searchableView();
454 if (!searchableView)
455 return false;
456 switch (actionId) {
457 case 'main.search-in-panel.find':
458 return searchableView.handleFindShortcut();
459 case 'main.search-in-panel.cancel':
460 return searchableView.handleCancelSearchShortcut();
461 case 'main.search-in-panel.find-next':
462 return searchableView.handleFindNextShortcut();
463 case 'main.search-in-panel.find-previous':
464 return searchableView.handleFindPreviousShortcut();
465 }
466 return false;
467 }
468};
469
470/**
471 * @implements {UI.ToolbarItem.Provider}
472 */
473Main.Main.MainMenuItem = class {
474 constructor() {
475 this._item = new UI.ToolbarMenuButton(this._handleContextMenu.bind(this), true);
476 this._item.setTitle(Common.UIString('Customize and control DevTools'));
477 }
478
479 /**
480 * @override
481 * @return {?UI.ToolbarItem}
482 */
483 item() {
484 return this._item;
485 }
486
487 /**
488 * @param {!UI.ContextMenu} contextMenu
489 */
490 _handleContextMenu(contextMenu) {
491 if (Components.dockController.canDock()) {
492 const dockItemElement = createElementWithClass('div', 'flex-centered flex-auto');
Joel Einbinder57b9fad2019-02-08 23:31:35493 dockItemElement.tabIndex = -1;
Blink Reformat4c46d092018-04-07 15:32:37494 const titleElement = dockItemElement.createChild('span', 'flex-auto');
495 titleElement.textContent = Common.UIString('Dock side');
496 const toggleDockSideShorcuts = UI.shortcutRegistry.shortcutDescriptorsForAction('main.toggle-dock');
497 titleElement.title = Common.UIString(
498 'Placement of DevTools relative to the page. (%s to restore last position)', toggleDockSideShorcuts[0].name);
499 dockItemElement.appendChild(titleElement);
500 const dockItemToolbar = new UI.Toolbar('', dockItemElement);
Joel Einbinder9a6bead2018-08-06 18:02:35501 if (Host.isMac() && !UI.themeSupport.hasTheme())
502 dockItemToolbar.makeBlueOnHover();
Blink Reformat4c46d092018-04-07 15:32:37503 const undock = new UI.ToolbarToggle(Common.UIString('Undock into separate window'), 'largeicon-undock');
504 const bottom = new UI.ToolbarToggle(Common.UIString('Dock to bottom'), 'largeicon-dock-to-bottom');
505 const right = new UI.ToolbarToggle(Common.UIString('Dock to right'), 'largeicon-dock-to-right');
506 const left = new UI.ToolbarToggle(Common.UIString('Dock to left'), 'largeicon-dock-to-left');
507 undock.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
508 bottom.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
509 right.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
510 left.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
511 undock.addEventListener(
Joel Einbinder57b9fad2019-02-08 23:31:35512 UI.ToolbarButton.Events.Click, setDockSide.bind(null, Components.DockController.State.Undocked));
Blink Reformat4c46d092018-04-07 15:32:37513 bottom.addEventListener(
Joel Einbinder57b9fad2019-02-08 23:31:35514 UI.ToolbarButton.Events.Click, setDockSide.bind(null, Components.DockController.State.DockedToBottom));
Blink Reformat4c46d092018-04-07 15:32:37515 right.addEventListener(
Joel Einbinder57b9fad2019-02-08 23:31:35516 UI.ToolbarButton.Events.Click, setDockSide.bind(null, Components.DockController.State.DockedToRight));
Blink Reformat4c46d092018-04-07 15:32:37517 left.addEventListener(
Joel Einbinder57b9fad2019-02-08 23:31:35518 UI.ToolbarButton.Events.Click, setDockSide.bind(null, Components.DockController.State.DockedToLeft));
Blink Reformat4c46d092018-04-07 15:32:37519 undock.setToggled(Components.dockController.dockSide() === Components.DockController.State.Undocked);
520 bottom.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToBottom);
521 right.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToRight);
522 left.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToLeft);
523 dockItemToolbar.appendToolbarItem(undock);
524 dockItemToolbar.appendToolbarItem(left);
525 dockItemToolbar.appendToolbarItem(bottom);
526 dockItemToolbar.appendToolbarItem(right);
Joel Einbinder57b9fad2019-02-08 23:31:35527 dockItemElement.addEventListener('keydown', event => {
528 let dir = 0;
529 if (event.key === 'ArrowLeft')
530 dir = -1;
531 else if (event.key === 'ArrowRight')
532 dir = 1;
533 else
534 return;
535
536 const buttons = [undock, left, bottom, right];
537 let index = buttons.findIndex(button => button.element.hasFocus());
538 index = Number.constrain(index + dir, 0, buttons.length - 1);
539
540 buttons[index].element.focus();
541 event.consume(true);
542 });
Blink Reformat4c46d092018-04-07 15:32:37543 contextMenu.headerSection().appendCustomItem(dockItemElement);
544 }
545
546 /**
547 * @param {string} side
548 */
549 function setDockSide(side) {
550 Components.dockController.setDockSide(side);
551 contextMenu.discard();
552 }
553
554 if (Components.dockController.dockSide() === Components.DockController.State.Undocked &&
Dmitry Gozmanb24fcc22018-10-31 23:42:42555 SDK.targetManager.mainTarget() && SDK.targetManager.mainTarget().type() === SDK.Target.Type.Frame)
Blink Reformat4c46d092018-04-07 15:32:37556 contextMenu.defaultSection().appendAction('inspector_main.focus-debuggee', Common.UIString('Focus debuggee'));
557
558 contextMenu.defaultSection().appendAction(
559 'main.toggle-drawer',
560 UI.inspectorView.drawerVisible() ? Common.UIString('Hide console drawer') :
561 Common.UIString('Show console drawer'));
562 contextMenu.appendItemsAtLocation('mainMenu');
563 const moreTools = contextMenu.defaultSection().appendSubMenuItem(Common.UIString('More tools'));
564 const extensions = self.runtime.extensions('view', undefined, true);
565 for (const extension of extensions) {
566 const descriptor = extension.descriptor();
567 if (descriptor['persistence'] !== 'closeable')
568 continue;
569 if (descriptor['location'] !== 'drawer-view' && descriptor['location'] !== 'panel')
570 continue;
571 moreTools.defaultSection().appendItem(
572 extension.title(), UI.viewManager.showView.bind(UI.viewManager, descriptor['id']));
573 }
574
575 const helpSubMenu = contextMenu.footerSection().appendSubMenuItem(Common.UIString('Help'));
576 helpSubMenu.appendItemsAtLocation('mainMenuHelp');
577 }
578};
579
580/**
581 * @unrestricted
582 */
583Main.Main.PauseListener = class {
584 constructor() {
585 SDK.targetManager.addModelListener(
586 SDK.DebuggerModel, SDK.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
587 }
588
589 /**
590 * @param {!Common.Event} event
591 */
592 _debuggerPaused(event) {
593 SDK.targetManager.removeModelListener(
594 SDK.DebuggerModel, SDK.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
595 const debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data);
596 const debuggerPausedDetails = debuggerModel.debuggerPausedDetails();
597 UI.context.setFlavor(SDK.Target, debuggerModel.target());
598 Common.Revealer.reveal(debuggerPausedDetails);
599 }
600};
601
602/**
603 * @param {string} method
604 * @param {?Object} params
605 * @return {!Promise}
606 */
607Main.sendOverProtocol = function(method, params) {
608 return new Promise((resolve, reject) => {
Dmitry Gozman99d7a6c2018-11-12 17:55:11609 Protocol.test.sendRawMessage(method, params, (err, ...results) => {
Blink Reformat4c46d092018-04-07 15:32:37610 if (err)
611 return reject(err);
612 return resolve(results);
613 });
614 });
615};
616
617/**
618 * @implements {UI.ActionDelegate}
619 * @unrestricted
620 */
621Main.ReloadActionDelegate = class {
622 /**
623 * @override
624 * @param {!UI.Context} context
625 * @param {string} actionId
626 * @return {boolean}
627 */
628 handleAction(context, actionId) {
629 switch (actionId) {
630 case 'main.debug-reload':
631 Components.reload();
632 return true;
633 }
634 return false;
635 }
636};
637
638new Main.Main();