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