blob: 642849355eefb345ff7fe66b9d39e34e1f09f5f9 [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');
63 await Runtime.runtimeReady();
64 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');
109 Runtime.experiments.register('blackboxJSFramesOnTimeline', 'Blackbox JavaScript frames on Timeline', true);
110 Runtime.experiments.register('colorContrastRatio', 'Color contrast ratio line in color picker', true);
Erik Luo241ee492018-05-05 06:00:35111 Runtime.experiments.register('consoleBelowPrompt', 'Eager evaluation');
Blink Reformat4c46d092018-04-07 15:32:37112 Runtime.experiments.register('emptySourceMapAutoStepping', 'Empty sourcemap auto-stepping');
113 Runtime.experiments.register('inputEventsOnTimelineOverview', 'Input events on Timeline overview', true);
114 Runtime.experiments.register('nativeHeapProfiler', 'Native memory sampling heap profiler', true);
115 Runtime.experiments.register('networkSearch', 'Network search');
116 Runtime.experiments.register('oopifInlineDOM', 'OOPIF: inline DOM ', true);
117 Runtime.experiments.register('protocolMonitor', 'Protocol Monitor');
118 Runtime.experiments.register('sourceDiff', 'Source diff');
Joel Einbinderd7595c72018-05-15 17:41:54119 Runtime.experiments.register('sourcesPrettyPrint', 'Automatically pretty print in the Sources Panel');
Blink Reformat4c46d092018-04-07 15:32:37120 Runtime.experiments.register(
121 'stepIntoAsync', 'Introduce separate step action, stepInto becomes powerful enough to go inside async call');
Pavel Feldmanc9060ea2018-04-30 04:42:18122 Runtime.experiments.register('splitInDrawer', 'Split in drawer', true);
Blink Reformat4c46d092018-04-07 15:32:37123 Runtime.experiments.register('terminalInDrawer', 'Terminal in drawer', true);
124
125 // Timeline
126 Runtime.experiments.register('timelineEventInitiators', 'Timeline: event initiators');
127 Runtime.experiments.register('timelineFlowEvents', 'Timeline: flow events', true);
128 Runtime.experiments.register('timelineInvalidationTracking', 'Timeline: invalidation tracking', true);
129 Runtime.experiments.register('timelinePaintTimingMarkers', 'Timeline: paint timing markers', true);
130 Runtime.experiments.register('timelineShowAllEvents', 'Timeline: show all events', true);
Blink Reformat4c46d092018-04-07 15:32:37131 Runtime.experiments.register('timelineTracingJSProfile', 'Timeline: tracing based JS profiler', true);
132 Runtime.experiments.register('timelineV8RuntimeCallStats', 'Timeline: V8 Runtime Call Stats on Timeline', true);
133
134 Runtime.experiments.cleanUpStaleExperiments();
135
136 if (Host.isUnderTest()) {
137 const testPath = Runtime.queryParam('test');
138 // Enable experiments for testing.
139 if (testPath.indexOf('oopif/') !== -1)
140 Runtime.experiments.enableForTest('oopifInlineDOM');
141 if (testPath.indexOf('network/') !== -1)
142 Runtime.experiments.enableForTest('networkSearch');
Erik Luo0f7f85b2018-04-17 03:06:58143 if (testPath.indexOf('console/viewport-testing/') !== -1)
144 Runtime.experiments.enableForTest('consoleBelowPrompt');
Blink Reformat4c46d092018-04-07 15:32:37145 }
146
Erik Luo6f5c1112018-05-08 08:59:22147 Runtime.experiments.setDefaultExperiments(
148 ['colorContrastRatio', 'stepIntoAsync', 'oopifInlineDOM', 'consoleBelowPrompt']);
Blink Reformat4c46d092018-04-07 15:32:37149 }
150
151 /**
152 * @suppressGlobalPropertiesCheck
153 */
154 async _createAppUI() {
155 Main.Main.time('Main._createAppUI');
156
157 UI.viewManager = new UI.ViewManager();
158
159 // Request filesystems early, we won't create connections until callback is fired. Things will happen in parallel.
160 Persistence.isolatedFileSystemManager = new Persistence.IsolatedFileSystemManager();
161
162 const themeSetting = Common.settings.createSetting('uiTheme', 'default');
163 UI.initializeUIUtils(document, themeSetting);
164 themeSetting.addChangeListener(Components.reload.bind(Components));
165
166 UI.installComponentRootStyles(/** @type {!Element} */ (document.body));
167
168 this._addMainEventListeners(document);
169
170 const canDock = !!Runtime.queryParam('can_dock');
171 UI.zoomManager = new UI.ZoomManager(window, InspectorFrontendHost);
172 UI.inspectorView = UI.InspectorView.instance();
173 UI.ContextMenu.initialize();
174 UI.ContextMenu.installHandler(document);
175 UI.Tooltip.installHandler(document);
176 Components.dockController = new Components.DockController(canDock);
177 SDK.consoleModel = new SDK.ConsoleModel();
178 SDK.multitargetNetworkManager = new SDK.MultitargetNetworkManager();
179 SDK.domDebuggerManager = new SDK.DOMDebuggerManager();
180 SDK.targetManager.addEventListener(
181 SDK.TargetManager.Events.SuspendStateChanged, this._onSuspendStateChanged.bind(this));
182
183 UI.shortcutsScreen = new UI.ShortcutsScreen();
184 // set order of some sections explicitly
185 UI.shortcutsScreen.section(Common.UIString('Elements Panel'));
186 UI.shortcutsScreen.section(Common.UIString('Styles Pane'));
187 UI.shortcutsScreen.section(Common.UIString('Debugger'));
188 UI.shortcutsScreen.section(Common.UIString('Console'));
189
190 Workspace.fileManager = new Workspace.FileManager();
191 Workspace.workspace = new Workspace.Workspace();
192
193 Bindings.networkProjectManager = new Bindings.NetworkProjectManager();
194 Bindings.resourceMapping = new Bindings.ResourceMapping(SDK.targetManager, Workspace.workspace);
195 new Bindings.PresentationConsoleMessageManager();
196 Bindings.cssWorkspaceBinding = new Bindings.CSSWorkspaceBinding(SDK.targetManager, Workspace.workspace);
197 Bindings.debuggerWorkspaceBinding = new Bindings.DebuggerWorkspaceBinding(SDK.targetManager, Workspace.workspace);
198 Bindings.breakpointManager =
199 new Bindings.BreakpointManager(Workspace.workspace, SDK.targetManager, Bindings.debuggerWorkspaceBinding);
200 Extensions.extensionServer = new Extensions.ExtensionServer();
201
202 new Persistence.FileSystemWorkspaceBinding(Persistence.isolatedFileSystemManager, Workspace.workspace);
203 Persistence.persistence = new Persistence.Persistence(Workspace.workspace, Bindings.breakpointManager);
204 Persistence.networkPersistenceManager = new Persistence.NetworkPersistenceManager(Workspace.workspace);
205
206 new Main.ExecutionContextSelector(SDK.targetManager, UI.context);
207 Bindings.blackboxManager = new Bindings.BlackboxManager(Bindings.debuggerWorkspaceBinding);
208
209 new Main.Main.PauseListener();
210
211 UI.actionRegistry = new UI.ActionRegistry();
212 UI.shortcutRegistry = new UI.ShortcutRegistry(UI.actionRegistry, document);
213 UI.ShortcutsScreen.registerShortcuts();
214 this._registerForwardedShortcuts();
215 this._registerMessageSinkListener();
216
217 Main.Main.timeEnd('Main._createAppUI');
218 this._showAppUI(await self.runtime.extension(Common.AppProvider).instance());
219 }
220
221 /**
222 * @param {!Object} appProvider
223 * @suppressGlobalPropertiesCheck
224 */
225 _showAppUI(appProvider) {
226 Main.Main.time('Main._showAppUI');
227 const app = /** @type {!Common.AppProvider} */ (appProvider).createApp();
228 // It is important to kick controller lifetime after apps are instantiated.
229 Components.dockController.initialize();
230 app.presentUI(document);
231
232 const toggleSearchNodeAction = UI.actionRegistry.action('elements.toggle-element-search');
233 // TODO: we should not access actions from other modules.
234 if (toggleSearchNodeAction) {
235 InspectorFrontendHost.events.addEventListener(
236 InspectorFrontendHostAPI.Events.EnterInspectElementMode,
237 toggleSearchNodeAction.execute.bind(toggleSearchNodeAction), this);
238 }
239 InspectorFrontendHost.events.addEventListener(
240 InspectorFrontendHostAPI.Events.RevealSourceLine, this._revealSourceLine, this);
241
242 UI.inspectorView.createToolbars();
243 InspectorFrontendHost.loadCompleted();
244
245 const extensions = self.runtime.extensions(Common.QueryParamHandler);
246 for (const extension of extensions) {
247 const value = Runtime.queryParam(extension.descriptor()['name']);
248 if (value !== null)
249 extension.instance().then(handleQueryParam.bind(null, value));
250 }
251
252 /**
253 * @param {string} value
254 * @param {!Common.QueryParamHandler} handler
255 */
256 function handleQueryParam(value, handler) {
257 handler.handleQueryParam(value);
258 }
259
260 // Allow UI cycles to repaint prior to creating connection.
261 setTimeout(this._initializeTarget.bind(this), 0);
262 Main.Main.timeEnd('Main._showAppUI');
263 }
264
265 async _initializeTarget() {
266 Main.Main.time('Main._initializeTarget');
267 const instances =
268 await Promise.all(self.runtime.extensions('early-initialization').map(extension => extension.instance()));
269 for (const instance of instances)
270 /** @type {!Common.Runnable} */ (instance).run();
271 // Used for browser tests.
272 InspectorFrontendHost.readyForTest();
273 // Asynchronously run the extensions.
274 setTimeout(this._lateInitialization.bind(this), 100);
275 Main.Main.timeEnd('Main._initializeTarget');
276 }
277
278 _lateInitialization() {
279 Main.Main.time('Main._lateInitialization');
280 this._registerShortcuts();
281 Extensions.extensionServer.initializeExtensions();
282 if (!Host.isUnderTest()) {
283 for (const extension of self.runtime.extensions('late-initialization'))
284 extension.instance().then(instance => (/** @type {!Common.Runnable} */ (instance)).run());
285 }
286 Main.Main.timeEnd('Main._lateInitialization');
287 }
288
289 _registerForwardedShortcuts() {
290 /** @const */ const forwardedActions = [
291 'main.toggle-dock', 'debugger.toggle-breakpoints-active', 'debugger.toggle-pause', 'commandMenu.show',
292 'console.show'
293 ];
294 const actionKeys =
295 UI.shortcutRegistry.keysForActions(forwardedActions).map(UI.KeyboardShortcut.keyCodeAndModifiersFromKey);
296 InspectorFrontendHost.setWhitelistedShortcuts(JSON.stringify(actionKeys));
297 }
298
299 _registerMessageSinkListener() {
300 Common.console.addEventListener(Common.Console.Events.MessageAdded, messageAdded);
301
302 /**
303 * @param {!Common.Event} event
304 */
305 function messageAdded(event) {
306 const message = /** @type {!Common.Console.Message} */ (event.data);
307 if (message.show)
308 Common.console.show();
309 }
310 }
311
312 /**
313 * @param {!Common.Event} event
314 */
315 _revealSourceLine(event) {
316 const url = /** @type {string} */ (event.data['url']);
317 const lineNumber = /** @type {number} */ (event.data['lineNumber']);
318 const columnNumber = /** @type {number} */ (event.data['columnNumber']);
319
320 const uiSourceCode = Workspace.workspace.uiSourceCodeForURL(url);
321 if (uiSourceCode) {
322 Common.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber));
323 return;
324 }
325
326 /**
327 * @param {!Common.Event} event
328 */
329 function listener(event) {
330 const uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
331 if (uiSourceCode.url() === url) {
332 Common.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber));
333 Workspace.workspace.removeEventListener(Workspace.Workspace.Events.UISourceCodeAdded, listener);
334 }
335 }
336
337 Workspace.workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAdded, listener);
338 }
339
340 _registerShortcuts() {
341 const shortcut = UI.KeyboardShortcut;
342 const section = UI.shortcutsScreen.section(Common.UIString('All Panels'));
343 let keys = [
344 shortcut.makeDescriptor('[', shortcut.Modifiers.CtrlOrMeta),
345 shortcut.makeDescriptor(']', shortcut.Modifiers.CtrlOrMeta)
346 ];
347 section.addRelatedKeys(keys, Common.UIString('Go to the panel to the left/right'));
348
349 const toggleConsoleLabel = Common.UIString('Show console');
350 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Tilde, shortcut.Modifiers.Ctrl), toggleConsoleLabel);
351 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Esc), Common.UIString('Toggle drawer'));
352 if (Components.dockController.canDock()) {
353 section.addKey(
354 shortcut.makeDescriptor('M', shortcut.Modifiers.CtrlOrMeta | shortcut.Modifiers.Shift),
355 Common.UIString('Toggle device mode'));
356 section.addKey(
357 shortcut.makeDescriptor('D', shortcut.Modifiers.CtrlOrMeta | shortcut.Modifiers.Shift),
358 Common.UIString('Toggle dock side'));
359 }
360 section.addKey(shortcut.makeDescriptor('f', shortcut.Modifiers.CtrlOrMeta), Common.UIString('Search'));
361
362 const advancedSearchShortcutModifier = Host.isMac() ?
363 UI.KeyboardShortcut.Modifiers.Meta | UI.KeyboardShortcut.Modifiers.Alt :
364 UI.KeyboardShortcut.Modifiers.Ctrl | UI.KeyboardShortcut.Modifiers.Shift;
365 const advancedSearchShortcut = shortcut.makeDescriptor('f', advancedSearchShortcutModifier);
366 section.addKey(advancedSearchShortcut, Common.UIString('Search across all sources'));
367
368 const inspectElementModeShortcuts =
369 UI.shortcutRegistry.shortcutDescriptorsForAction('elements.toggle-element-search');
370 if (inspectElementModeShortcuts.length)
371 section.addKey(inspectElementModeShortcuts[0], Common.UIString('Select node to inspect'));
372
373 const openResourceShortcut = UI.KeyboardShortcut.makeDescriptor('p', UI.KeyboardShortcut.Modifiers.CtrlOrMeta);
374 section.addKey(openResourceShortcut, Common.UIString('Go to source'));
375
376 if (Host.isMac()) {
377 keys = [
378 shortcut.makeDescriptor('g', shortcut.Modifiers.Meta),
379 shortcut.makeDescriptor('g', shortcut.Modifiers.Meta | shortcut.Modifiers.Shift)
380 ];
381 section.addRelatedKeys(keys, Common.UIString('Find next/previous'));
382 }
383 }
384
385 _postDocumentKeyDown(event) {
386 if (event.handled)
387 return;
388
Pavel Feldmane7367752018-05-07 20:41:34389 if (!UI.Dialog.hasInstance() && UI.inspectorView.currentPanelDeprecated() &&
390 UI.inspectorView.currentPanelDeprecated().hasFocus()) {
Blink Reformat4c46d092018-04-07 15:32:37391 UI.inspectorView.currentPanelDeprecated().handleShortcut(event);
392 if (event.handled) {
393 event.consume(true);
394 return;
395 }
396 }
397
398 UI.shortcutRegistry.handleShortcut(event);
399 }
400
401 /**
402 * @param {!Event} event
403 */
404 _redispatchClipboardEvent(event) {
405 const eventCopy = new CustomEvent('clipboard-' + event.type, {bubbles: true});
406 eventCopy['original'] = event;
407 const document = event.target && event.target.ownerDocument;
408 const target = document ? document.deepActiveElement() : null;
409 if (target)
410 target.dispatchEvent(eventCopy);
411 if (eventCopy.handled)
412 event.preventDefault();
413 }
414
415 _contextMenuEventFired(event) {
416 if (event.handled || event.target.classList.contains('popup-glasspane'))
417 event.preventDefault();
418 }
419
420 /**
421 * @param {!Document} document
422 */
423 _addMainEventListeners(document) {
424 document.addEventListener('keydown', this._postDocumentKeyDown.bind(this), false);
425 document.addEventListener('beforecopy', this._redispatchClipboardEvent.bind(this), true);
426 document.addEventListener('copy', this._redispatchClipboardEvent.bind(this), false);
427 document.addEventListener('cut', this._redispatchClipboardEvent.bind(this), false);
428 document.addEventListener('paste', this._redispatchClipboardEvent.bind(this), false);
429 document.addEventListener('contextmenu', this._contextMenuEventFired.bind(this), true);
430 }
431
432 _onSuspendStateChanged() {
433 const suspended = SDK.targetManager.allTargetsSuspended();
434 UI.inspectorView.onSuspendStateChanged(suspended);
435 }
436};
437
438/**
439 * @implements {UI.ActionDelegate}
440 * @unrestricted
441 */
442Main.Main.ZoomActionDelegate = class {
443 /**
444 * @override
445 * @param {!UI.Context} context
446 * @param {string} actionId
447 * @return {boolean}
448 */
449 handleAction(context, actionId) {
450 if (InspectorFrontendHost.isHostedMode())
451 return false;
452
453 switch (actionId) {
454 case 'main.zoom-in':
455 InspectorFrontendHost.zoomIn();
456 return true;
457 case 'main.zoom-out':
458 InspectorFrontendHost.zoomOut();
459 return true;
460 case 'main.zoom-reset':
461 InspectorFrontendHost.resetZoom();
462 return true;
463 }
464 return false;
465 }
466};
467
468/**
469 * @implements {UI.ActionDelegate}
470 * @unrestricted
471 */
472Main.Main.SearchActionDelegate = class {
473 /**
474 * @override
475 * @param {!UI.Context} context
476 * @param {string} actionId
477 * @return {boolean}
478 * @suppressGlobalPropertiesCheck
479 */
480 handleAction(context, actionId) {
481 const searchableView = UI.SearchableView.fromElement(document.deepActiveElement()) ||
482 UI.inspectorView.currentPanelDeprecated().searchableView();
483 if (!searchableView)
484 return false;
485 switch (actionId) {
486 case 'main.search-in-panel.find':
487 return searchableView.handleFindShortcut();
488 case 'main.search-in-panel.cancel':
489 return searchableView.handleCancelSearchShortcut();
490 case 'main.search-in-panel.find-next':
491 return searchableView.handleFindNextShortcut();
492 case 'main.search-in-panel.find-previous':
493 return searchableView.handleFindPreviousShortcut();
494 }
495 return false;
496 }
497};
498
499/**
500 * @implements {UI.ToolbarItem.Provider}
501 */
502Main.Main.MainMenuItem = class {
503 constructor() {
504 this._item = new UI.ToolbarMenuButton(this._handleContextMenu.bind(this), true);
505 this._item.setTitle(Common.UIString('Customize and control DevTools'));
506 }
507
508 /**
509 * @override
510 * @return {?UI.ToolbarItem}
511 */
512 item() {
513 return this._item;
514 }
515
516 /**
517 * @param {!UI.ContextMenu} contextMenu
518 */
519 _handleContextMenu(contextMenu) {
520 if (Components.dockController.canDock()) {
521 const dockItemElement = createElementWithClass('div', 'flex-centered flex-auto');
522 const titleElement = dockItemElement.createChild('span', 'flex-auto');
523 titleElement.textContent = Common.UIString('Dock side');
524 const toggleDockSideShorcuts = UI.shortcutRegistry.shortcutDescriptorsForAction('main.toggle-dock');
525 titleElement.title = Common.UIString(
526 'Placement of DevTools relative to the page. (%s to restore last position)', toggleDockSideShorcuts[0].name);
527 dockItemElement.appendChild(titleElement);
528 const dockItemToolbar = new UI.Toolbar('', dockItemElement);
529 dockItemToolbar.makeBlueOnHover();
530 const undock = new UI.ToolbarToggle(Common.UIString('Undock into separate window'), 'largeicon-undock');
531 const bottom = new UI.ToolbarToggle(Common.UIString('Dock to bottom'), 'largeicon-dock-to-bottom');
532 const right = new UI.ToolbarToggle(Common.UIString('Dock to right'), 'largeicon-dock-to-right');
533 const left = new UI.ToolbarToggle(Common.UIString('Dock to left'), 'largeicon-dock-to-left');
534 undock.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
535 bottom.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
536 right.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
537 left.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
538 undock.addEventListener(
539 UI.ToolbarButton.Events.MouseUp, setDockSide.bind(null, Components.DockController.State.Undocked));
540 bottom.addEventListener(
541 UI.ToolbarButton.Events.MouseUp, setDockSide.bind(null, Components.DockController.State.DockedToBottom));
542 right.addEventListener(
543 UI.ToolbarButton.Events.MouseUp, setDockSide.bind(null, Components.DockController.State.DockedToRight));
544 left.addEventListener(
545 UI.ToolbarButton.Events.MouseUp, setDockSide.bind(null, Components.DockController.State.DockedToLeft));
546 undock.setToggled(Components.dockController.dockSide() === Components.DockController.State.Undocked);
547 bottom.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToBottom);
548 right.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToRight);
549 left.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToLeft);
550 dockItemToolbar.appendToolbarItem(undock);
551 dockItemToolbar.appendToolbarItem(left);
552 dockItemToolbar.appendToolbarItem(bottom);
553 dockItemToolbar.appendToolbarItem(right);
554 contextMenu.headerSection().appendCustomItem(dockItemElement);
555 }
556
557 /**
558 * @param {string} side
559 */
560 function setDockSide(side) {
561 Components.dockController.setDockSide(side);
562 contextMenu.discard();
563 }
564
565 if (Components.dockController.dockSide() === Components.DockController.State.Undocked &&
566 SDK.targetManager.mainTarget() && SDK.targetManager.mainTarget().hasBrowserCapability())
567 contextMenu.defaultSection().appendAction('inspector_main.focus-debuggee', Common.UIString('Focus debuggee'));
568
569 contextMenu.defaultSection().appendAction(
570 'main.toggle-drawer',
571 UI.inspectorView.drawerVisible() ? Common.UIString('Hide console drawer') :
572 Common.UIString('Show console drawer'));
573 contextMenu.appendItemsAtLocation('mainMenu');
574 const moreTools = contextMenu.defaultSection().appendSubMenuItem(Common.UIString('More tools'));
575 const extensions = self.runtime.extensions('view', undefined, true);
576 for (const extension of extensions) {
577 const descriptor = extension.descriptor();
578 if (descriptor['persistence'] !== 'closeable')
579 continue;
580 if (descriptor['location'] !== 'drawer-view' && descriptor['location'] !== 'panel')
581 continue;
582 moreTools.defaultSection().appendItem(
583 extension.title(), UI.viewManager.showView.bind(UI.viewManager, descriptor['id']));
584 }
585
586 const helpSubMenu = contextMenu.footerSection().appendSubMenuItem(Common.UIString('Help'));
587 helpSubMenu.appendItemsAtLocation('mainMenuHelp');
588 }
589};
590
591/**
592 * @unrestricted
593 */
594Main.Main.PauseListener = class {
595 constructor() {
596 SDK.targetManager.addModelListener(
597 SDK.DebuggerModel, SDK.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
598 }
599
600 /**
601 * @param {!Common.Event} event
602 */
603 _debuggerPaused(event) {
604 SDK.targetManager.removeModelListener(
605 SDK.DebuggerModel, SDK.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
606 const debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data);
607 const debuggerPausedDetails = debuggerModel.debuggerPausedDetails();
608 UI.context.setFlavor(SDK.Target, debuggerModel.target());
609 Common.Revealer.reveal(debuggerPausedDetails);
610 }
611};
612
613/**
614 * @param {string} method
615 * @param {?Object} params
616 * @return {!Promise}
617 */
618Main.sendOverProtocol = function(method, params) {
619 return new Promise((resolve, reject) => {
620 Protocol.InspectorBackend.sendRawMessageForTesting(method, params, (err, ...results) => {
621 if (err)
622 return reject(err);
623 return resolve(results);
624 });
625 });
626};
627
628/**
629 * @implements {UI.ActionDelegate}
630 * @unrestricted
631 */
632Main.ReloadActionDelegate = class {
633 /**
634 * @override
635 * @param {!UI.Context} context
636 * @param {string} actionId
637 * @return {boolean}
638 */
639 handleAction(context, actionId) {
640 switch (actionId) {
641 case 'main.debug-reload':
642 Components.reload();
643 return true;
644 }
645 return false;
646 }
647};
648
649new Main.Main();