blob: 5ac2f2378bc424d3002c783634e24a9857f9eef9 [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(
Alexei Filippov52efd4d2018-07-06 07:55:26148 ['colorContrastRatio', 'stepIntoAsync', 'oopifInlineDOM', 'consoleBelowPrompt', 'timelineTracingJSProfile']);
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) {
Joel Einbindera66e5bf2018-05-31 01:26:37386 if (!event.handled)
387 UI.shortcutRegistry.handleShortcut(event);
Blink Reformat4c46d092018-04-07 15:32:37388 }
389
390 /**
391 * @param {!Event} event
392 */
393 _redispatchClipboardEvent(event) {
394 const eventCopy = new CustomEvent('clipboard-' + event.type, {bubbles: true});
395 eventCopy['original'] = event;
396 const document = event.target && event.target.ownerDocument;
397 const target = document ? document.deepActiveElement() : null;
398 if (target)
399 target.dispatchEvent(eventCopy);
400 if (eventCopy.handled)
401 event.preventDefault();
402 }
403
404 _contextMenuEventFired(event) {
405 if (event.handled || event.target.classList.contains('popup-glasspane'))
406 event.preventDefault();
407 }
408
409 /**
410 * @param {!Document} document
411 */
412 _addMainEventListeners(document) {
413 document.addEventListener('keydown', this._postDocumentKeyDown.bind(this), false);
414 document.addEventListener('beforecopy', this._redispatchClipboardEvent.bind(this), true);
415 document.addEventListener('copy', this._redispatchClipboardEvent.bind(this), false);
416 document.addEventListener('cut', this._redispatchClipboardEvent.bind(this), false);
417 document.addEventListener('paste', this._redispatchClipboardEvent.bind(this), false);
418 document.addEventListener('contextmenu', this._contextMenuEventFired.bind(this), true);
419 }
420
421 _onSuspendStateChanged() {
422 const suspended = SDK.targetManager.allTargetsSuspended();
423 UI.inspectorView.onSuspendStateChanged(suspended);
424 }
425};
426
427/**
428 * @implements {UI.ActionDelegate}
429 * @unrestricted
430 */
431Main.Main.ZoomActionDelegate = class {
432 /**
433 * @override
434 * @param {!UI.Context} context
435 * @param {string} actionId
436 * @return {boolean}
437 */
438 handleAction(context, actionId) {
439 if (InspectorFrontendHost.isHostedMode())
440 return false;
441
442 switch (actionId) {
443 case 'main.zoom-in':
444 InspectorFrontendHost.zoomIn();
445 return true;
446 case 'main.zoom-out':
447 InspectorFrontendHost.zoomOut();
448 return true;
449 case 'main.zoom-reset':
450 InspectorFrontendHost.resetZoom();
451 return true;
452 }
453 return false;
454 }
455};
456
457/**
458 * @implements {UI.ActionDelegate}
459 * @unrestricted
460 */
461Main.Main.SearchActionDelegate = class {
462 /**
463 * @override
464 * @param {!UI.Context} context
465 * @param {string} actionId
466 * @return {boolean}
467 * @suppressGlobalPropertiesCheck
468 */
469 handleAction(context, actionId) {
470 const searchableView = UI.SearchableView.fromElement(document.deepActiveElement()) ||
471 UI.inspectorView.currentPanelDeprecated().searchableView();
472 if (!searchableView)
473 return false;
474 switch (actionId) {
475 case 'main.search-in-panel.find':
476 return searchableView.handleFindShortcut();
477 case 'main.search-in-panel.cancel':
478 return searchableView.handleCancelSearchShortcut();
479 case 'main.search-in-panel.find-next':
480 return searchableView.handleFindNextShortcut();
481 case 'main.search-in-panel.find-previous':
482 return searchableView.handleFindPreviousShortcut();
483 }
484 return false;
485 }
486};
487
488/**
489 * @implements {UI.ToolbarItem.Provider}
490 */
491Main.Main.MainMenuItem = class {
492 constructor() {
493 this._item = new UI.ToolbarMenuButton(this._handleContextMenu.bind(this), true);
494 this._item.setTitle(Common.UIString('Customize and control DevTools'));
495 }
496
497 /**
498 * @override
499 * @return {?UI.ToolbarItem}
500 */
501 item() {
502 return this._item;
503 }
504
505 /**
506 * @param {!UI.ContextMenu} contextMenu
507 */
508 _handleContextMenu(contextMenu) {
509 if (Components.dockController.canDock()) {
510 const dockItemElement = createElementWithClass('div', 'flex-centered flex-auto');
511 const titleElement = dockItemElement.createChild('span', 'flex-auto');
512 titleElement.textContent = Common.UIString('Dock side');
513 const toggleDockSideShorcuts = UI.shortcutRegistry.shortcutDescriptorsForAction('main.toggle-dock');
514 titleElement.title = Common.UIString(
515 'Placement of DevTools relative to the page. (%s to restore last position)', toggleDockSideShorcuts[0].name);
516 dockItemElement.appendChild(titleElement);
517 const dockItemToolbar = new UI.Toolbar('', dockItemElement);
518 dockItemToolbar.makeBlueOnHover();
519 const undock = new UI.ToolbarToggle(Common.UIString('Undock into separate window'), 'largeicon-undock');
520 const bottom = new UI.ToolbarToggle(Common.UIString('Dock to bottom'), 'largeicon-dock-to-bottom');
521 const right = new UI.ToolbarToggle(Common.UIString('Dock to right'), 'largeicon-dock-to-right');
522 const left = new UI.ToolbarToggle(Common.UIString('Dock to left'), 'largeicon-dock-to-left');
523 undock.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
524 bottom.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
525 right.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
526 left.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
527 undock.addEventListener(
528 UI.ToolbarButton.Events.MouseUp, setDockSide.bind(null, Components.DockController.State.Undocked));
529 bottom.addEventListener(
530 UI.ToolbarButton.Events.MouseUp, setDockSide.bind(null, Components.DockController.State.DockedToBottom));
531 right.addEventListener(
532 UI.ToolbarButton.Events.MouseUp, setDockSide.bind(null, Components.DockController.State.DockedToRight));
533 left.addEventListener(
534 UI.ToolbarButton.Events.MouseUp, setDockSide.bind(null, Components.DockController.State.DockedToLeft));
535 undock.setToggled(Components.dockController.dockSide() === Components.DockController.State.Undocked);
536 bottom.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToBottom);
537 right.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToRight);
538 left.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToLeft);
539 dockItemToolbar.appendToolbarItem(undock);
540 dockItemToolbar.appendToolbarItem(left);
541 dockItemToolbar.appendToolbarItem(bottom);
542 dockItemToolbar.appendToolbarItem(right);
543 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 &&
555 SDK.targetManager.mainTarget() && SDK.targetManager.mainTarget().hasBrowserCapability())
556 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) => {
609 Protocol.InspectorBackend.sendRawMessageForTesting(method, params, (err, ...results) => {
610 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();