blob: 53e24c0adc3cce33663a942b7e4e510af8706a9e [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Matt Lilek ([email protected]).
4 * Copyright (C) 2009 Joseph Pecoraro
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * @unrestricted
33 */
34Main.Main = class {
35 /**
36 * @suppressGlobalPropertiesCheck
37 */
38 constructor() {
39 Main.Main._instanceForTest = this;
40 runOnWindowLoad(this._loaded.bind(this));
41 }
42
43 /**
44 * @param {string} label
45 */
46 static time(label) {
47 if (Host.isUnderTest())
48 return;
49 console.time(label);
50 }
51
52 /**
53 * @param {string} label
54 */
55 static timeEnd(label) {
56 if (Host.isUnderTest())
57 return;
58 console.timeEnd(label);
59 }
60
61 async _loaded() {
62 console.timeStamp('Main._loaded');
Pavel Feldman63e89eb2018-11-25 05:47:0963 await Runtime.appStarted();
Blink Reformat4c46d092018-04-07 15:32:3764 Runtime.setPlatform(Host.platform());
65 InspectorFrontendHost.getPreferences(this._gotPreferences.bind(this));
66 }
67
68 /**
69 * @param {!Object<string, string>} prefs
70 */
71 _gotPreferences(prefs) {
72 console.timeStamp('Main._gotPreferences');
73 if (Host.isUnderTest(prefs))
74 self.runtime.useTestBase();
75 this._createSettings(prefs);
76 this._createAppUI();
77 }
78
79 /**
80 * @param {!Object<string, string>} prefs
81 * Note: this function is called from testSettings in Tests.js.
82 */
83 _createSettings(prefs) {
84 this._initializeExperiments();
85 let storagePrefix = '';
86 if (Host.isCustomDevtoolsFrontend())
87 storagePrefix = '__custom__';
88 else if (!Runtime.queryParam('can_dock') && !!Runtime.queryParam('debugFrontend') && !Host.isUnderTest())
89 storagePrefix = '__bundled__';
90
91 let localStorage;
92 if (!Host.isUnderTest() && window.localStorage) {
93 localStorage = new Common.SettingsStorage(
94 window.localStorage, undefined, undefined, () => window.localStorage.clear(), storagePrefix);
95 } else {
96 localStorage = new Common.SettingsStorage({}, undefined, undefined, undefined, storagePrefix);
97 }
98 const globalStorage = new Common.SettingsStorage(
99 prefs, InspectorFrontendHost.setPreference, InspectorFrontendHost.removePreference,
100 InspectorFrontendHost.clearPreferences, storagePrefix);
101 Common.settings = new Common.Settings(globalStorage, localStorage);
102 if (!Host.isUnderTest())
103 new Common.VersionController().updateVersion();
104 }
105
106 _initializeExperiments() {
107 // Keep this sorted alphabetically: both keys and values.
108 Runtime.experiments.register('applyCustomStylesheet', 'Allow custom UI themes');
Alexei Filippovfdfefe02019-03-09 00:33:24109 Runtime.experiments.register('sourcesPrettyPrint', 'Automatically pretty print in the Sources Panel');
Rayan Kanso8fe8ee22019-03-04 14:58:46110 Runtime.experiments.register('backgroundServices', 'Background web platform feature events', true);
Blink Reformat4c46d092018-04-07 15:32:37111 Runtime.experiments.register('blackboxJSFramesOnTimeline', 'Blackbox JavaScript frames on Timeline', true);
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);
Alexei Filippovfdfefe02019-03-09 00:33:24114 Runtime.experiments.register('liveHeapProfile', 'Live heap profile', true);
Blink Reformat4c46d092018-04-07 15:32:37115 Runtime.experiments.register('nativeHeapProfiler', 'Native memory sampling heap profiler', true);
Blink Reformat4c46d092018-04-07 15:32:37116 Runtime.experiments.register('protocolMonitor', 'Protocol Monitor');
Alexei Filippov6d2eb592018-10-25 21:48:56117 Runtime.experiments.register('samplingHeapProfilerTimeline', 'Sampling heap profiler timeline', true);
Blink Reformat4c46d092018-04-07 15:32:37118 Runtime.experiments.register('sourceDiff', 'Source diff');
Pavel Feldmanc9060ea2018-04-30 04:42:18119 Runtime.experiments.register('splitInDrawer', 'Split in drawer', true);
Blink Reformat4c46d092018-04-07 15:32:37120 Runtime.experiments.register('terminalInDrawer', 'Terminal in drawer', true);
121
122 // Timeline
123 Runtime.experiments.register('timelineEventInitiators', 'Timeline: event initiators');
124 Runtime.experiments.register('timelineFlowEvents', 'Timeline: flow events', true);
125 Runtime.experiments.register('timelineInvalidationTracking', 'Timeline: invalidation tracking', true);
Blink Reformat4c46d092018-04-07 15:32:37126 Runtime.experiments.register('timelineShowAllEvents', 'Timeline: show all events', true);
Blink Reformat4c46d092018-04-07 15:32:37127 Runtime.experiments.register('timelineV8RuntimeCallStats', 'Timeline: V8 Runtime Call Stats on Timeline', true);
Alexei Filippov57ccafb2018-08-14 20:59:05128 Runtime.experiments.register('timelineWebGL', 'Timeline: WebGL-based flamechart');
Blink Reformat4c46d092018-04-07 15:32:37129
130 Runtime.experiments.cleanUpStaleExperiments();
Pavel Feldmandb310912019-01-30 00:31:20131 Runtime.experiments.setDefaultExperiments([]);
Alexei Filippovfdfefe02019-03-09 00:33:24132
133 if (Host.isUnderTest() && Runtime.queryParam('test').includes('live-line-level-heap-profile.js'))
134 Runtime.experiments.enableForTest('liveHeapProfile');
Blink Reformat4c46d092018-04-07 15:32:37135 }
136
137 /**
138 * @suppressGlobalPropertiesCheck
139 */
140 async _createAppUI() {
141 Main.Main.time('Main._createAppUI');
142
143 UI.viewManager = new UI.ViewManager();
144
145 // Request filesystems early, we won't create connections until callback is fired. Things will happen in parallel.
146 Persistence.isolatedFileSystemManager = new Persistence.IsolatedFileSystemManager();
147
148 const themeSetting = Common.settings.createSetting('uiTheme', 'default');
149 UI.initializeUIUtils(document, themeSetting);
150 themeSetting.addChangeListener(Components.reload.bind(Components));
151
152 UI.installComponentRootStyles(/** @type {!Element} */ (document.body));
153
154 this._addMainEventListeners(document);
155
156 const canDock = !!Runtime.queryParam('can_dock');
157 UI.zoomManager = new UI.ZoomManager(window, InspectorFrontendHost);
158 UI.inspectorView = UI.InspectorView.instance();
159 UI.ContextMenu.initialize();
160 UI.ContextMenu.installHandler(document);
161 UI.Tooltip.installHandler(document);
162 Components.dockController = new Components.DockController(canDock);
163 SDK.consoleModel = new SDK.ConsoleModel();
164 SDK.multitargetNetworkManager = new SDK.MultitargetNetworkManager();
165 SDK.domDebuggerManager = new SDK.DOMDebuggerManager();
166 SDK.targetManager.addEventListener(
167 SDK.TargetManager.Events.SuspendStateChanged, this._onSuspendStateChanged.bind(this));
168
169 UI.shortcutsScreen = new UI.ShortcutsScreen();
170 // set order of some sections explicitly
171 UI.shortcutsScreen.section(Common.UIString('Elements Panel'));
172 UI.shortcutsScreen.section(Common.UIString('Styles Pane'));
173 UI.shortcutsScreen.section(Common.UIString('Debugger'));
174 UI.shortcutsScreen.section(Common.UIString('Console'));
175
176 Workspace.fileManager = new Workspace.FileManager();
177 Workspace.workspace = new Workspace.Workspace();
178
179 Bindings.networkProjectManager = new Bindings.NetworkProjectManager();
180 Bindings.resourceMapping = new Bindings.ResourceMapping(SDK.targetManager, Workspace.workspace);
181 new Bindings.PresentationConsoleMessageManager();
182 Bindings.cssWorkspaceBinding = new Bindings.CSSWorkspaceBinding(SDK.targetManager, Workspace.workspace);
183 Bindings.debuggerWorkspaceBinding = new Bindings.DebuggerWorkspaceBinding(SDK.targetManager, Workspace.workspace);
184 Bindings.breakpointManager =
185 new Bindings.BreakpointManager(Workspace.workspace, SDK.targetManager, Bindings.debuggerWorkspaceBinding);
186 Extensions.extensionServer = new Extensions.ExtensionServer();
187
188 new Persistence.FileSystemWorkspaceBinding(Persistence.isolatedFileSystemManager, Workspace.workspace);
189 Persistence.persistence = new Persistence.Persistence(Workspace.workspace, Bindings.breakpointManager);
190 Persistence.networkPersistenceManager = new Persistence.NetworkPersistenceManager(Workspace.workspace);
191
192 new Main.ExecutionContextSelector(SDK.targetManager, UI.context);
193 Bindings.blackboxManager = new Bindings.BlackboxManager(Bindings.debuggerWorkspaceBinding);
194
195 new Main.Main.PauseListener();
196
197 UI.actionRegistry = new UI.ActionRegistry();
198 UI.shortcutRegistry = new UI.ShortcutRegistry(UI.actionRegistry, document);
199 UI.ShortcutsScreen.registerShortcuts();
200 this._registerForwardedShortcuts();
201 this._registerMessageSinkListener();
202
203 Main.Main.timeEnd('Main._createAppUI');
204 this._showAppUI(await self.runtime.extension(Common.AppProvider).instance());
205 }
206
207 /**
208 * @param {!Object} appProvider
209 * @suppressGlobalPropertiesCheck
210 */
211 _showAppUI(appProvider) {
212 Main.Main.time('Main._showAppUI');
213 const app = /** @type {!Common.AppProvider} */ (appProvider).createApp();
214 // It is important to kick controller lifetime after apps are instantiated.
215 Components.dockController.initialize();
216 app.presentUI(document);
217
218 const toggleSearchNodeAction = UI.actionRegistry.action('elements.toggle-element-search');
219 // TODO: we should not access actions from other modules.
220 if (toggleSearchNodeAction) {
221 InspectorFrontendHost.events.addEventListener(
222 InspectorFrontendHostAPI.Events.EnterInspectElementMode,
223 toggleSearchNodeAction.execute.bind(toggleSearchNodeAction), this);
224 }
225 InspectorFrontendHost.events.addEventListener(
226 InspectorFrontendHostAPI.Events.RevealSourceLine, this._revealSourceLine, this);
227
228 UI.inspectorView.createToolbars();
229 InspectorFrontendHost.loadCompleted();
230
231 const extensions = self.runtime.extensions(Common.QueryParamHandler);
232 for (const extension of extensions) {
233 const value = Runtime.queryParam(extension.descriptor()['name']);
234 if (value !== null)
235 extension.instance().then(handleQueryParam.bind(null, value));
236 }
237
238 /**
239 * @param {string} value
240 * @param {!Common.QueryParamHandler} handler
241 */
242 function handleQueryParam(value, handler) {
243 handler.handleQueryParam(value);
244 }
245
246 // Allow UI cycles to repaint prior to creating connection.
247 setTimeout(this._initializeTarget.bind(this), 0);
248 Main.Main.timeEnd('Main._showAppUI');
249 }
250
251 async _initializeTarget() {
252 Main.Main.time('Main._initializeTarget');
253 const instances =
254 await Promise.all(self.runtime.extensions('early-initialization').map(extension => extension.instance()));
255 for (const instance of instances)
Pavel Feldman07ef9722018-12-13 23:52:22256 await /** @type {!Common.Runnable} */ (instance).run();
Blink Reformat4c46d092018-04-07 15:32:37257 // Used for browser tests.
258 InspectorFrontendHost.readyForTest();
259 // Asynchronously run the extensions.
260 setTimeout(this._lateInitialization.bind(this), 100);
261 Main.Main.timeEnd('Main._initializeTarget');
262 }
263
264 _lateInitialization() {
265 Main.Main.time('Main._lateInitialization');
266 this._registerShortcuts();
267 Extensions.extensionServer.initializeExtensions();
Alexei Filippovfdfefe02019-03-09 00:33:24268 for (const extension of self.runtime.extensions('late-initialization'))
269 extension.instance().then(instance => (/** @type {!Common.Runnable} */ (instance)).run());
Blink Reformat4c46d092018-04-07 15:32:37270 Main.Main.timeEnd('Main._lateInitialization');
271 }
272
273 _registerForwardedShortcuts() {
274 /** @const */ const forwardedActions = [
275 'main.toggle-dock', 'debugger.toggle-breakpoints-active', 'debugger.toggle-pause', 'commandMenu.show',
276 'console.show'
277 ];
278 const actionKeys =
279 UI.shortcutRegistry.keysForActions(forwardedActions).map(UI.KeyboardShortcut.keyCodeAndModifiersFromKey);
280 InspectorFrontendHost.setWhitelistedShortcuts(JSON.stringify(actionKeys));
281 }
282
283 _registerMessageSinkListener() {
284 Common.console.addEventListener(Common.Console.Events.MessageAdded, messageAdded);
285
286 /**
287 * @param {!Common.Event} event
288 */
289 function messageAdded(event) {
290 const message = /** @type {!Common.Console.Message} */ (event.data);
291 if (message.show)
292 Common.console.show();
293 }
294 }
295
296 /**
297 * @param {!Common.Event} event
298 */
299 _revealSourceLine(event) {
300 const url = /** @type {string} */ (event.data['url']);
301 const lineNumber = /** @type {number} */ (event.data['lineNumber']);
302 const columnNumber = /** @type {number} */ (event.data['columnNumber']);
303
304 const uiSourceCode = Workspace.workspace.uiSourceCodeForURL(url);
305 if (uiSourceCode) {
306 Common.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber));
307 return;
308 }
309
310 /**
311 * @param {!Common.Event} event
312 */
313 function listener(event) {
314 const uiSourceCode = /** @type {!Workspace.UISourceCode} */ (event.data);
315 if (uiSourceCode.url() === url) {
316 Common.Revealer.reveal(uiSourceCode.uiLocation(lineNumber, columnNumber));
317 Workspace.workspace.removeEventListener(Workspace.Workspace.Events.UISourceCodeAdded, listener);
318 }
319 }
320
321 Workspace.workspace.addEventListener(Workspace.Workspace.Events.UISourceCodeAdded, listener);
322 }
323
324 _registerShortcuts() {
325 const shortcut = UI.KeyboardShortcut;
326 const section = UI.shortcutsScreen.section(Common.UIString('All Panels'));
327 let keys = [
328 shortcut.makeDescriptor('[', shortcut.Modifiers.CtrlOrMeta),
329 shortcut.makeDescriptor(']', shortcut.Modifiers.CtrlOrMeta)
330 ];
331 section.addRelatedKeys(keys, Common.UIString('Go to the panel to the left/right'));
332
333 const toggleConsoleLabel = Common.UIString('Show console');
334 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Tilde, shortcut.Modifiers.Ctrl), toggleConsoleLabel);
335 section.addKey(shortcut.makeDescriptor(shortcut.Keys.Esc), Common.UIString('Toggle drawer'));
336 if (Components.dockController.canDock()) {
337 section.addKey(
338 shortcut.makeDescriptor('M', shortcut.Modifiers.CtrlOrMeta | shortcut.Modifiers.Shift),
339 Common.UIString('Toggle device mode'));
340 section.addKey(
341 shortcut.makeDescriptor('D', shortcut.Modifiers.CtrlOrMeta | shortcut.Modifiers.Shift),
342 Common.UIString('Toggle dock side'));
343 }
344 section.addKey(shortcut.makeDescriptor('f', shortcut.Modifiers.CtrlOrMeta), Common.UIString('Search'));
345
346 const advancedSearchShortcutModifier = Host.isMac() ?
347 UI.KeyboardShortcut.Modifiers.Meta | UI.KeyboardShortcut.Modifiers.Alt :
348 UI.KeyboardShortcut.Modifiers.Ctrl | UI.KeyboardShortcut.Modifiers.Shift;
349 const advancedSearchShortcut = shortcut.makeDescriptor('f', advancedSearchShortcutModifier);
350 section.addKey(advancedSearchShortcut, Common.UIString('Search across all sources'));
351
352 const inspectElementModeShortcuts =
353 UI.shortcutRegistry.shortcutDescriptorsForAction('elements.toggle-element-search');
354 if (inspectElementModeShortcuts.length)
355 section.addKey(inspectElementModeShortcuts[0], Common.UIString('Select node to inspect'));
356
357 const openResourceShortcut = UI.KeyboardShortcut.makeDescriptor('p', UI.KeyboardShortcut.Modifiers.CtrlOrMeta);
358 section.addKey(openResourceShortcut, Common.UIString('Go to source'));
359
360 if (Host.isMac()) {
361 keys = [
362 shortcut.makeDescriptor('g', shortcut.Modifiers.Meta),
363 shortcut.makeDescriptor('g', shortcut.Modifiers.Meta | shortcut.Modifiers.Shift)
364 ];
365 section.addRelatedKeys(keys, Common.UIString('Find next/previous'));
366 }
367 }
368
369 _postDocumentKeyDown(event) {
Joel Einbindera66e5bf2018-05-31 01:26:37370 if (!event.handled)
371 UI.shortcutRegistry.handleShortcut(event);
Blink Reformat4c46d092018-04-07 15:32:37372 }
373
374 /**
375 * @param {!Event} event
376 */
377 _redispatchClipboardEvent(event) {
378 const eventCopy = new CustomEvent('clipboard-' + event.type, {bubbles: true});
379 eventCopy['original'] = event;
380 const document = event.target && event.target.ownerDocument;
381 const target = document ? document.deepActiveElement() : null;
382 if (target)
383 target.dispatchEvent(eventCopy);
384 if (eventCopy.handled)
385 event.preventDefault();
386 }
387
388 _contextMenuEventFired(event) {
389 if (event.handled || event.target.classList.contains('popup-glasspane'))
390 event.preventDefault();
391 }
392
393 /**
394 * @param {!Document} document
395 */
396 _addMainEventListeners(document) {
397 document.addEventListener('keydown', this._postDocumentKeyDown.bind(this), false);
398 document.addEventListener('beforecopy', this._redispatchClipboardEvent.bind(this), true);
399 document.addEventListener('copy', this._redispatchClipboardEvent.bind(this), false);
400 document.addEventListener('cut', this._redispatchClipboardEvent.bind(this), false);
401 document.addEventListener('paste', this._redispatchClipboardEvent.bind(this), false);
402 document.addEventListener('contextmenu', this._contextMenuEventFired.bind(this), true);
403 }
404
405 _onSuspendStateChanged() {
406 const suspended = SDK.targetManager.allTargetsSuspended();
407 UI.inspectorView.onSuspendStateChanged(suspended);
408 }
409};
410
411/**
412 * @implements {UI.ActionDelegate}
413 * @unrestricted
414 */
415Main.Main.ZoomActionDelegate = class {
416 /**
417 * @override
418 * @param {!UI.Context} context
419 * @param {string} actionId
420 * @return {boolean}
421 */
422 handleAction(context, actionId) {
423 if (InspectorFrontendHost.isHostedMode())
424 return false;
425
426 switch (actionId) {
427 case 'main.zoom-in':
428 InspectorFrontendHost.zoomIn();
429 return true;
430 case 'main.zoom-out':
431 InspectorFrontendHost.zoomOut();
432 return true;
433 case 'main.zoom-reset':
434 InspectorFrontendHost.resetZoom();
435 return true;
436 }
437 return false;
438 }
439};
440
441/**
442 * @implements {UI.ActionDelegate}
443 * @unrestricted
444 */
445Main.Main.SearchActionDelegate = class {
446 /**
447 * @override
448 * @param {!UI.Context} context
449 * @param {string} actionId
450 * @return {boolean}
451 * @suppressGlobalPropertiesCheck
452 */
453 handleAction(context, actionId) {
454 const searchableView = UI.SearchableView.fromElement(document.deepActiveElement()) ||
455 UI.inspectorView.currentPanelDeprecated().searchableView();
456 if (!searchableView)
457 return false;
458 switch (actionId) {
459 case 'main.search-in-panel.find':
460 return searchableView.handleFindShortcut();
461 case 'main.search-in-panel.cancel':
462 return searchableView.handleCancelSearchShortcut();
463 case 'main.search-in-panel.find-next':
464 return searchableView.handleFindNextShortcut();
465 case 'main.search-in-panel.find-previous':
466 return searchableView.handleFindPreviousShortcut();
467 }
468 return false;
469 }
470};
471
472/**
473 * @implements {UI.ToolbarItem.Provider}
474 */
475Main.Main.MainMenuItem = class {
476 constructor() {
477 this._item = new UI.ToolbarMenuButton(this._handleContextMenu.bind(this), true);
478 this._item.setTitle(Common.UIString('Customize and control DevTools'));
479 }
480
481 /**
482 * @override
483 * @return {?UI.ToolbarItem}
484 */
485 item() {
486 return this._item;
487 }
488
489 /**
490 * @param {!UI.ContextMenu} contextMenu
491 */
492 _handleContextMenu(contextMenu) {
493 if (Components.dockController.canDock()) {
494 const dockItemElement = createElementWithClass('div', 'flex-centered flex-auto');
Joel Einbinder57b9fad2019-02-08 23:31:35495 dockItemElement.tabIndex = -1;
Blink Reformat4c46d092018-04-07 15:32:37496 const titleElement = dockItemElement.createChild('span', 'flex-auto');
497 titleElement.textContent = Common.UIString('Dock side');
498 const toggleDockSideShorcuts = UI.shortcutRegistry.shortcutDescriptorsForAction('main.toggle-dock');
499 titleElement.title = Common.UIString(
500 'Placement of DevTools relative to the page. (%s to restore last position)', toggleDockSideShorcuts[0].name);
501 dockItemElement.appendChild(titleElement);
502 const dockItemToolbar = new UI.Toolbar('', dockItemElement);
Joel Einbinder9a6bead2018-08-06 18:02:35503 if (Host.isMac() && !UI.themeSupport.hasTheme())
504 dockItemToolbar.makeBlueOnHover();
Blink Reformat4c46d092018-04-07 15:32:37505 const undock = new UI.ToolbarToggle(Common.UIString('Undock into separate window'), 'largeicon-undock');
506 const bottom = new UI.ToolbarToggle(Common.UIString('Dock to bottom'), 'largeicon-dock-to-bottom');
507 const right = new UI.ToolbarToggle(Common.UIString('Dock to right'), 'largeicon-dock-to-right');
508 const left = new UI.ToolbarToggle(Common.UIString('Dock to left'), 'largeicon-dock-to-left');
509 undock.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
510 bottom.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
511 right.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
512 left.addEventListener(UI.ToolbarButton.Events.MouseDown, event => event.data.consume());
513 undock.addEventListener(
Joel Einbinder57b9fad2019-02-08 23:31:35514 UI.ToolbarButton.Events.Click, setDockSide.bind(null, Components.DockController.State.Undocked));
Blink Reformat4c46d092018-04-07 15:32:37515 bottom.addEventListener(
Joel Einbinder57b9fad2019-02-08 23:31:35516 UI.ToolbarButton.Events.Click, setDockSide.bind(null, Components.DockController.State.DockedToBottom));
Blink Reformat4c46d092018-04-07 15:32:37517 right.addEventListener(
Joel Einbinder57b9fad2019-02-08 23:31:35518 UI.ToolbarButton.Events.Click, setDockSide.bind(null, Components.DockController.State.DockedToRight));
Blink Reformat4c46d092018-04-07 15:32:37519 left.addEventListener(
Joel Einbinder57b9fad2019-02-08 23:31:35520 UI.ToolbarButton.Events.Click, setDockSide.bind(null, Components.DockController.State.DockedToLeft));
Blink Reformat4c46d092018-04-07 15:32:37521 undock.setToggled(Components.dockController.dockSide() === Components.DockController.State.Undocked);
522 bottom.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToBottom);
523 right.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToRight);
524 left.setToggled(Components.dockController.dockSide() === Components.DockController.State.DockedToLeft);
525 dockItemToolbar.appendToolbarItem(undock);
526 dockItemToolbar.appendToolbarItem(left);
527 dockItemToolbar.appendToolbarItem(bottom);
528 dockItemToolbar.appendToolbarItem(right);
Joel Einbinder57b9fad2019-02-08 23:31:35529 dockItemElement.addEventListener('keydown', event => {
530 let dir = 0;
531 if (event.key === 'ArrowLeft')
532 dir = -1;
533 else if (event.key === 'ArrowRight')
534 dir = 1;
535 else
536 return;
537
538 const buttons = [undock, left, bottom, right];
539 let index = buttons.findIndex(button => button.element.hasFocus());
540 index = Number.constrain(index + dir, 0, buttons.length - 1);
541
542 buttons[index].element.focus();
543 event.consume(true);
544 });
Blink Reformat4c46d092018-04-07 15:32:37545 contextMenu.headerSection().appendCustomItem(dockItemElement);
546 }
547
548 /**
549 * @param {string} side
550 */
551 function setDockSide(side) {
552 Components.dockController.setDockSide(side);
553 contextMenu.discard();
554 }
555
556 if (Components.dockController.dockSide() === Components.DockController.State.Undocked &&
Dmitry Gozmanb24fcc22018-10-31 23:42:42557 SDK.targetManager.mainTarget() && SDK.targetManager.mainTarget().type() === SDK.Target.Type.Frame)
Blink Reformat4c46d092018-04-07 15:32:37558 contextMenu.defaultSection().appendAction('inspector_main.focus-debuggee', Common.UIString('Focus debuggee'));
559
560 contextMenu.defaultSection().appendAction(
561 'main.toggle-drawer',
562 UI.inspectorView.drawerVisible() ? Common.UIString('Hide console drawer') :
563 Common.UIString('Show console drawer'));
564 contextMenu.appendItemsAtLocation('mainMenu');
565 const moreTools = contextMenu.defaultSection().appendSubMenuItem(Common.UIString('More tools'));
566 const extensions = self.runtime.extensions('view', undefined, true);
567 for (const extension of extensions) {
568 const descriptor = extension.descriptor();
569 if (descriptor['persistence'] !== 'closeable')
570 continue;
571 if (descriptor['location'] !== 'drawer-view' && descriptor['location'] !== 'panel')
572 continue;
573 moreTools.defaultSection().appendItem(
574 extension.title(), UI.viewManager.showView.bind(UI.viewManager, descriptor['id']));
575 }
576
577 const helpSubMenu = contextMenu.footerSection().appendSubMenuItem(Common.UIString('Help'));
578 helpSubMenu.appendItemsAtLocation('mainMenuHelp');
579 }
580};
581
582/**
583 * @unrestricted
584 */
585Main.Main.PauseListener = class {
586 constructor() {
587 SDK.targetManager.addModelListener(
588 SDK.DebuggerModel, SDK.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
589 }
590
591 /**
592 * @param {!Common.Event} event
593 */
594 _debuggerPaused(event) {
595 SDK.targetManager.removeModelListener(
596 SDK.DebuggerModel, SDK.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
597 const debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data);
598 const debuggerPausedDetails = debuggerModel.debuggerPausedDetails();
599 UI.context.setFlavor(SDK.Target, debuggerModel.target());
600 Common.Revealer.reveal(debuggerPausedDetails);
601 }
602};
603
604/**
605 * @param {string} method
606 * @param {?Object} params
607 * @return {!Promise}
608 */
609Main.sendOverProtocol = function(method, params) {
610 return new Promise((resolve, reject) => {
Dmitry Gozman99d7a6c2018-11-12 17:55:11611 Protocol.test.sendRawMessage(method, params, (err, ...results) => {
Blink Reformat4c46d092018-04-07 15:32:37612 if (err)
613 return reject(err);
614 return resolve(results);
615 });
616 });
617};
618
619/**
620 * @implements {UI.ActionDelegate}
621 * @unrestricted
622 */
623Main.ReloadActionDelegate = class {
624 /**
625 * @override
626 * @param {!UI.Context} context
627 * @param {string} actionId
628 * @return {boolean}
629 */
630 handleAction(context, actionId) {
631 switch (actionId) {
632 case 'main.debug-reload':
633 Components.reload();
634 return true;
635 }
636 return false;
637 }
638};
639
640new Main.Main();