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