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