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