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