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