Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/SourcesPanel.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26
27 /** 26 /**
28 * @constructor
29 * @extends {WebInspector.Panel}
30 * @implements {WebInspector.ContextMenu.Provider} 27 * @implements {WebInspector.ContextMenu.Provider}
31 * @implements {WebInspector.TargetManager.Observer} 28 * @implements {WebInspector.TargetManager.Observer}
32 * @implements {WebInspector.ViewLocationResolver} 29 * @implements {WebInspector.ViewLocationResolver}
30 * @unrestricted
33 */ 31 */
34 WebInspector.SourcesPanel = function() 32 WebInspector.SourcesPanel = class extends WebInspector.Panel {
35 { 33 constructor() {
36 WebInspector.Panel.call(this, "sources"); 34 super('sources');
37 WebInspector.SourcesPanel._instance = this; 35 WebInspector.SourcesPanel._instance = this;
38 this.registerRequiredCSS("sources/sourcesPanel.css"); 36 this.registerRequiredCSS('sources/sourcesPanel.css');
39 new WebInspector.DropTarget(this.element, [WebInspector.DropTarget.Types.Fil es], WebInspector.UIString("Drop workspace folder here"), this._handleDrop.bind( this)); 37 new WebInspector.DropTarget(
38 this.element, [WebInspector.DropTarget.Types.Files], WebInspector.UIStri ng('Drop workspace folder here'),
39 this._handleDrop.bind(this));
40 40
41 this._workspace = WebInspector.workspace; 41 this._workspace = WebInspector.workspace;
42 this._networkMapping = WebInspector.networkMapping; 42 this._networkMapping = WebInspector.networkMapping;
43 43
44 this._runSnippetAction = /** @type {!WebInspector.Action }*/ (WebInspector.a ctionRegistry.action("debugger.run-snippet")); 44 this._runSnippetAction =
45 this._togglePauseAction = /** @type {!WebInspector.Action }*/ (WebInspector. actionRegistry.action("debugger.toggle-pause")); 45 /** @type {!WebInspector.Action }*/ (WebInspector.actionRegistry.action( 'debugger.run-snippet'));
46 this._stepOverAction = /** @type {!WebInspector.Action }*/ (WebInspector.act ionRegistry.action("debugger.step-over")); 46 this._togglePauseAction =
47 this._stepIntoAction = /** @type {!WebInspector.Action }*/ (WebInspector.act ionRegistry.action("debugger.step-into")); 47 /** @type {!WebInspector.Action }*/ (WebInspector.actionRegistry.action( 'debugger.toggle-pause'));
48 this._stepOutAction = /** @type {!WebInspector.Action }*/ (WebInspector.acti onRegistry.action("debugger.step-out")); 48 this._stepOverAction =
49 this._toggleBreakpointsActiveAction = /** @type {!WebInspector.Action }*/ (W ebInspector.actionRegistry.action("debugger.toggle-breakpoints-active")); 49 /** @type {!WebInspector.Action }*/ (WebInspector.actionRegistry.action( 'debugger.step-over'));
50 this._stepIntoAction =
51 /** @type {!WebInspector.Action }*/ (WebInspector.actionRegistry.action( 'debugger.step-into'));
52 this._stepOutAction = /** @type {!WebInspector.Action }*/ (WebInspector.acti onRegistry.action('debugger.step-out'));
53 this._toggleBreakpointsActiveAction =
54 /** @type {!WebInspector.Action }*/ (WebInspector.actionRegistry.action( 'debugger.toggle-breakpoints-active'));
50 55
51 this._debugToolbar = this._createDebugToolbar(); 56 this._debugToolbar = this._createDebugToolbar();
52 this._debugToolbarDrawer = this._createDebugToolbarDrawer(); 57 this._debugToolbarDrawer = this._createDebugToolbarDrawer();
53 this._debuggerPausedMessage = new WebInspector.DebuggerPausedMessage(); 58 this._debuggerPausedMessage = new WebInspector.DebuggerPausedMessage();
54 59
55 const initialDebugSidebarWidth = 225; 60 const initialDebugSidebarWidth = 225;
56 this._splitWidget = new WebInspector.SplitWidget(true, true, "sourcesPanelSp litViewState", initialDebugSidebarWidth); 61 this._splitWidget =
62 new WebInspector.SplitWidget(true, true, 'sourcesPanelSplitViewState', i nitialDebugSidebarWidth);
57 this._splitWidget.enableShowModeSaving(); 63 this._splitWidget.enableShowModeSaving();
58 this._splitWidget.show(this.element); 64 this._splitWidget.show(this.element);
59 65
60 // Create scripts navigator 66 // Create scripts navigator
61 const initialNavigatorWidth = 225; 67 const initialNavigatorWidth = 225;
62 this.editorView = new WebInspector.SplitWidget(true, false, "sourcesPanelNav igatorSplitViewState", initialNavigatorWidth); 68 this.editorView =
69 new WebInspector.SplitWidget(true, false, 'sourcesPanelNavigatorSplitVie wState', initialNavigatorWidth);
63 this.editorView.enableShowModeSaving(); 70 this.editorView.enableShowModeSaving();
64 this.editorView.element.tabIndex = 0; 71 this.editorView.element.tabIndex = 0;
65 this._splitWidget.setMainWidget(this.editorView); 72 this._splitWidget.setMainWidget(this.editorView);
66 73
67 // Create navigator tabbed pane with toolbar. 74 // Create navigator tabbed pane with toolbar.
68 this._navigatorTabbedLocation = WebInspector.viewManager.createTabbedLocatio n(this._revealNavigatorSidebar.bind(this), "navigator-view", true); 75 this._navigatorTabbedLocation =
76 WebInspector.viewManager.createTabbedLocation(this._revealNavigatorSideb ar.bind(this), 'navigator-view', true);
69 var tabbedPane = this._navigatorTabbedLocation.tabbedPane(); 77 var tabbedPane = this._navigatorTabbedLocation.tabbedPane();
70 tabbedPane.setMinimumSize(100, 25); 78 tabbedPane.setMinimumSize(100, 25);
71 tabbedPane.element.classList.add("navigator-tabbed-pane"); 79 tabbedPane.element.classList.add('navigator-tabbed-pane');
72 var navigatorMenuButton = new WebInspector.ToolbarMenuButton(this._populateN avigatorMenu.bind(this), true); 80 var navigatorMenuButton = new WebInspector.ToolbarMenuButton(this._populateN avigatorMenu.bind(this), true);
73 navigatorMenuButton.setTitle(WebInspector.UIString("More options")); 81 navigatorMenuButton.setTitle(WebInspector.UIString('More options'));
74 tabbedPane.rightToolbar().appendToolbarItem(navigatorMenuButton); 82 tabbedPane.rightToolbar().appendToolbarItem(navigatorMenuButton);
75 this.editorView.setSidebarWidget(tabbedPane); 83 this.editorView.setSidebarWidget(tabbedPane);
76 84
77 this._sourcesView = new WebInspector.SourcesView(); 85 this._sourcesView = new WebInspector.SourcesView();
78 this._sourcesView.addEventListener(WebInspector.SourcesView.Events.EditorSel ected, this._editorSelected.bind(this)); 86 this._sourcesView.addEventListener(WebInspector.SourcesView.Events.EditorSel ected, this._editorSelected.bind(this));
79 this._sourcesView.addEventListener(WebInspector.SourcesView.Events.EditorClo sed, this._editorClosed.bind(this)); 87 this._sourcesView.addEventListener(WebInspector.SourcesView.Events.EditorClo sed, this._editorClosed.bind(this));
80 this._sourcesView.registerShortcuts(this.registerShortcuts.bind(this)); 88 this._sourcesView.registerShortcuts(this.registerShortcuts.bind(this));
81 89
82 this._toggleNavigatorSidebarButton = this.editorView.createShowHideSidebarBu tton("navigator"); 90 this._toggleNavigatorSidebarButton = this.editorView.createShowHideSidebarBu tton('navigator');
83 this._toggleDebuggerSidebarButton = this._splitWidget.createShowHideSidebarB utton("debugger"); 91 this._toggleDebuggerSidebarButton = this._splitWidget.createShowHideSidebarB utton('debugger');
84 this.editorView.setMainWidget(this._sourcesView); 92 this.editorView.setMainWidget(this._sourcesView);
85 this._editorChanged(this._sourcesView.currentUISourceCode()); 93 this._editorChanged(this._sourcesView.currentUISourceCode());
86 94
87 this._threadsSidebarPane = null; 95 this._threadsSidebarPane = null;
88 this._watchSidebarPane = /** @type {!WebInspector.View} */ (WebInspector.vie wManager.view("sources.watch")); 96 this._watchSidebarPane = /** @type {!WebInspector.View} */ (WebInspector.vie wManager.view('sources.watch'));
89 // TODO: Force installing listeners from the model, not the UI. 97 // TODO: Force installing listeners from the model, not the UI.
90 self.runtime.sharedInstance(WebInspector.XHRBreakpointsSidebarPane); 98 self.runtime.sharedInstance(WebInspector.XHRBreakpointsSidebarPane);
91 this._callstackPane = self.runtime.sharedInstance(WebInspector.CallStackSide barPane); 99 this._callstackPane = self.runtime.sharedInstance(WebInspector.CallStackSide barPane);
92 this._callstackPane.registerShortcuts(this.registerShortcuts.bind(this)); 100 this._callstackPane.registerShortcuts(this.registerShortcuts.bind(this));
93 101
94 WebInspector.moduleSetting("sidebarPosition").addChangeListener(this._update SidebarPosition.bind(this)); 102 WebInspector.moduleSetting('sidebarPosition').addChangeListener(this._update SidebarPosition.bind(this));
95 this._updateSidebarPosition(); 103 this._updateSidebarPosition();
96 104
97 this._updateDebuggerButtonsAndStatus(); 105 this._updateDebuggerButtonsAndStatus();
98 this._pauseOnExceptionEnabledChanged(); 106 this._pauseOnExceptionEnabledChanged();
99 WebInspector.moduleSetting("pauseOnExceptionEnabled").addChangeListener(this ._pauseOnExceptionEnabledChanged, this); 107 WebInspector.moduleSetting('pauseOnExceptionEnabled').addChangeListener(this ._pauseOnExceptionEnabledChanged, this);
100 108
101 this._liveLocationPool = new WebInspector.LiveLocationPool(); 109 this._liveLocationPool = new WebInspector.LiveLocationPool();
102 110
103 this._setTarget(WebInspector.context.flavor(WebInspector.Target)); 111 this._setTarget(WebInspector.context.flavor(WebInspector.Target));
104 WebInspector.breakpointManager.addEventListener(WebInspector.BreakpointManag er.Events.BreakpointsActiveStateChanged, this._breakpointsActiveStateChanged, th is); 112 WebInspector.breakpointManager.addEventListener(
113 WebInspector.BreakpointManager.Events.BreakpointsActiveStateChanged, thi s._breakpointsActiveStateChanged, this);
105 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._onCu rrentTargetChanged, this); 114 WebInspector.context.addFlavorChangeListener(WebInspector.Target, this._onCu rrentTargetChanged, this);
106 WebInspector.context.addFlavorChangeListener(WebInspector.DebuggerModel.Call Frame, this._callFrameChanged, this); 115 WebInspector.context.addFlavorChangeListener(WebInspector.DebuggerModel.Call Frame, this._callFrameChanged, this);
107 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerWasEnabled, this._debuggerWasEnabled, this ); 116 WebInspector.targetManager.addModelListener(
108 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this); 117 WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.DebuggerWa sEnabled, this._debuggerWasEnabled,
109 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this); 118 this);
110 WebInspector.targetManager.addModelListener(WebInspector.DebuggerModel, WebI nspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this); 119 WebInspector.targetManager.addModelListener(
120 WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.DebuggerPa used, this._debuggerPaused, this);
121 WebInspector.targetManager.addModelListener(
122 WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.DebuggerRe sumed, this._debuggerResumed, this);
123 WebInspector.targetManager.addModelListener(
124 WebInspector.DebuggerModel, WebInspector.DebuggerModel.Events.GlobalObje ctCleared, this._debuggerReset, this);
111 new WebInspector.WorkspaceMappingTip(this, this._workspace); 125 new WebInspector.WorkspaceMappingTip(this, this._workspace);
112 WebInspector.extensionServer.addEventListener(WebInspector.ExtensionServer.E vents.SidebarPaneAdded, this._extensionSidebarPaneAdded, this); 126 WebInspector.extensionServer.addEventListener(
127 WebInspector.ExtensionServer.Events.SidebarPaneAdded, this._extensionSid ebarPaneAdded, this);
113 WebInspector.DataSaverInfobar.maybeShowInPanel(this); 128 WebInspector.DataSaverInfobar.maybeShowInPanel(this);
114 WebInspector.targetManager.observeTargets(this); 129 WebInspector.targetManager.observeTargets(this);
115 }; 130 }
116 131
117 WebInspector.SourcesPanel._lastModificationTimeout = 200; 132 /**
118 133 * @return {!WebInspector.SourcesPanel}
119 WebInspector.SourcesPanel.minToolbarWidth = 215; 134 */
120 135 static instance() {
121 WebInspector.SourcesPanel.prototype = {
122 /**
123 * @override
124 * @param {!WebInspector.Target} target
125 */
126 targetAdded: function(target)
127 {
128 var hasThreads = WebInspector.targetManager.targets(WebInspector.Target. Capability.JS).length > 1;
129 if (hasThreads && !this._threadsSidebarPane) {
130 this._threadsSidebarPane = /** @type {!WebInspector.View} */ (WebIns pector.viewManager.view("sources.threads"));
131 if (this._sidebarPaneStack) {
132 this._sidebarPaneStack.showView(this._threadsSidebarPane, this._ splitWidget.isVertical() ? this._watchSidebarPane : this._callstackPane);
133 }
134 }
135 },
136
137 /**
138 * @override
139 * @param {!WebInspector.Target} target
140 */
141 targetRemoved: function(target)
142 {
143 },
144
145 /**
146 * @param {?WebInspector.Target} target
147 */
148 _setTarget: function(target)
149 {
150 if (!target)
151 return;
152 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target);
153 if (!debuggerModel)
154 return;
155
156 if (debuggerModel.isPaused()) {
157 this._showDebuggerPausedDetails(/** @type {!WebInspector.DebuggerPau sedDetails} */ (debuggerModel.debuggerPausedDetails()));
158 } else {
159 this._paused = false;
160 this._clearInterface();
161 this._toggleDebuggerSidebarButton.setEnabled(true);
162 }
163 },
164
165 /**
166 * @param {!WebInspector.Event} event
167 */
168 _onCurrentTargetChanged: function(event)
169 {
170 var target = /** @type {?WebInspector.Target} */ (event.data);
171 this._setTarget(target);
172 },
173 /**
174 * @return {boolean}
175 */
176 paused: function()
177 {
178 return this._paused;
179 },
180
181 wasShown: function()
182 {
183 WebInspector.context.setFlavor(WebInspector.SourcesPanel, this);
184 WebInspector.Panel.prototype.wasShown.call(this);
185 var wrapper = WebInspector.SourcesPanel.WrapperView._instance;
186 if (wrapper && wrapper.isShowing()) {
187 WebInspector.inspectorView.setDrawerMinimized(true);
188 WebInspector.SourcesPanel.updateResizerAndSidebarButtons(this);
189 }
190 this.editorView.setMainWidget(this._sourcesView);
191 },
192
193 willHide: function()
194 {
195 WebInspector.Panel.prototype.willHide.call(this);
196 WebInspector.context.setFlavor(WebInspector.SourcesPanel, null);
197 if (WebInspector.SourcesPanel.WrapperView.isShowing()) {
198 WebInspector.SourcesPanel.WrapperView._instance._showViewInWrapper() ;
199 WebInspector.inspectorView.setDrawerMinimized(false);
200 WebInspector.SourcesPanel.updateResizerAndSidebarButtons(this);
201 }
202 },
203
204 /**
205 * @override
206 * @param {string} locationName
207 * @return {?WebInspector.ViewLocation}
208 */
209 resolveLocation: function(locationName)
210 {
211 if (locationName === "sources-sidebar")
212 return this._sidebarPaneStack;
213 else
214 return this._navigatorTabbedLocation;
215 },
216
217 /**
218 * @return {boolean}
219 */
220 _ensureSourcesViewVisible: function()
221 {
222 if (WebInspector.SourcesPanel.WrapperView.isShowing())
223 return true;
224 if (!WebInspector.inspectorView.canSelectPanel("sources"))
225 return false;
226 WebInspector.viewManager.showView("sources");
227 return true;
228 },
229
230 onResize: function()
231 {
232 if (WebInspector.moduleSetting("sidebarPosition").get() === "auto")
233 this.element.window().requestAnimationFrame(this._updateSidebarPosit ion.bind(this)); // Do not force layout.
234 },
235
236 /**
237 * @override
238 * @return {!WebInspector.SearchableView}
239 */
240 searchableView: function()
241 {
242 return this._sourcesView.searchableView();
243 },
244
245 /**
246 * @param {!WebInspector.Event} event
247 */
248 _debuggerPaused: function(event)
249 {
250 var details = /** @type {!WebInspector.DebuggerPausedDetails} */ (event. data);
251 if (!this._paused)
252 this._setAsCurrentPanel();
253
254 if (WebInspector.context.flavor(WebInspector.Target) === details.target( ))
255 this._showDebuggerPausedDetails(details);
256 else if (!this._paused)
257 WebInspector.context.setFlavor(WebInspector.Target, details.target() );
258 },
259
260 /**
261 * @param {!WebInspector.DebuggerPausedDetails} details
262 */
263 _showDebuggerPausedDetails: function(details)
264 {
265 this._paused = true;
266 this._updateDebuggerButtonsAndStatus();
267 WebInspector.context.setFlavor(WebInspector.DebuggerPausedDetails, detai ls);
268 this._toggleDebuggerSidebarButton.setEnabled(false);
269 window.focus();
270 InspectorFrontendHost.bringToFront();
271 },
272
273 /**
274 * @param {!WebInspector.Event} event
275 */
276 _debuggerResumed: function(event)
277 {
278 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.t arget);
279 var target = debuggerModel.target();
280 if (WebInspector.context.flavor(WebInspector.Target) !== target)
281 return;
282 this._paused = false;
283 this._clearInterface();
284 this._toggleDebuggerSidebarButton.setEnabled(true);
285 this._switchToPausedTargetTimeout = setTimeout(this._switchToPausedTarge t.bind(this, debuggerModel), 500);
286 },
287
288 /**
289 * @param {!WebInspector.Event} event
290 */
291 _debuggerWasEnabled: function(event)
292 {
293 var target = /** @type {!WebInspector.Target} */ (event.target.target() );
294 if (WebInspector.context.flavor(WebInspector.Target) !== target)
295 return;
296
297 this._updateDebuggerButtonsAndStatus();
298 },
299
300 /**
301 * @param {!WebInspector.Event} event
302 */
303 _debuggerReset: function(event)
304 {
305 this._debuggerResumed(event);
306 },
307
308 /**
309 * @return {!WebInspector.Widget}
310 */
311 get visibleView()
312 {
313 return this._sourcesView.visibleView();
314 },
315
316 /**
317 * @param {!WebInspector.UISourceCode} uiSourceCode
318 * @param {number=} lineNumber 0-based
319 * @param {number=} columnNumber
320 * @param {boolean=} omitFocus
321 */
322 showUISourceCode: function(uiSourceCode, lineNumber, columnNumber, omitFocus )
323 {
324 if (omitFocus) {
325 var wrapperShowing = WebInspector.SourcesPanel.WrapperView._instance && WebInspector.SourcesPanel.WrapperView._instance.isShowing();
326 if (!this.isShowing() && !wrapperShowing)
327 return;
328 } else {
329 this._showEditor();
330 }
331 this._sourcesView.showSourceLocation(uiSourceCode, lineNumber, columnNum ber, omitFocus);
332 },
333
334 _showEditor: function()
335 {
336 if (WebInspector.SourcesPanel.WrapperView._instance && WebInspector.Sour cesPanel.WrapperView._instance.isShowing())
337 return;
338 this._setAsCurrentPanel();
339 },
340
341 /**
342 * @param {!WebInspector.UILocation} uiLocation
343 * @param {boolean=} omitFocus
344 */
345 showUILocation: function(uiLocation, omitFocus)
346 {
347 this.showUISourceCode(uiLocation.uiSourceCode, uiLocation.lineNumber, ui Location.columnNumber, omitFocus);
348 },
349
350 /**
351 * @param {!WebInspector.UISourceCode} uiSourceCode
352 * @param {boolean=} skipReveal
353 */
354 _revealInNavigator: function(uiSourceCode, skipReveal)
355 {
356 var binding = WebInspector.persistence.binding(uiSourceCode);
357 if (binding && binding.network === uiSourceCode)
358 uiSourceCode = binding.fileSystem;
359
360 var extensions = self.runtime.extensions(WebInspector.NavigatorView);
361 Promise.all(extensions.map(extension => extension.instance())).then(filt erNavigators.bind(this));
362
363 /**
364 * @this {WebInspector.SourcesPanel}
365 * @param {!Array.<!Object>} objects
366 */
367 function filterNavigators(objects)
368 {
369 for (var i = 0; i < objects.length; ++i) {
370 var navigatorView = /** @type {!WebInspector.NavigatorView} */ ( objects[i]);
371 var viewId = extensions[i].descriptor()["viewId"];
372 if (navigatorView.accept(uiSourceCode)) {
373 navigatorView.revealUISourceCode(uiSourceCode, true);
374 if (skipReveal)
375 this._navigatorTabbedLocation.tabbedPane().selectTab(vie wId);
376 else
377 WebInspector.viewManager.showView(viewId);
378 }
379 }
380 }
381 },
382
383 /**
384 * @param {!WebInspector.ContextMenu} contextMenu
385 */
386 _populateNavigatorMenu: function(contextMenu)
387 {
388 var groupByFolderSetting = WebInspector.moduleSetting("navigatorGroupByF older");
389 contextMenu.appendItemsAtLocation("navigatorMenu");
390 contextMenu.appendSeparator();
391 contextMenu.appendCheckboxItem(WebInspector.UIString("Group by folder"), () => groupByFolderSetting.set(!groupByFolderSetting.get()), groupByFolderSetti ng.get());
392 },
393
394 /**
395 * @param {boolean} ignoreExecutionLineEvents
396 */
397 setIgnoreExecutionLineEvents: function(ignoreExecutionLineEvents)
398 {
399 this._ignoreExecutionLineEvents = ignoreExecutionLineEvents;
400 },
401
402 updateLastModificationTime: function()
403 {
404 this._lastModificationTime = window.performance.now();
405 },
406
407 /**
408 * @param {!WebInspector.LiveLocation} liveLocation
409 */
410 _executionLineChanged: function(liveLocation)
411 {
412 var uiLocation = liveLocation.uiLocation();
413 if (!uiLocation)
414 return;
415 this._sourcesView.clearCurrentExecutionLine();
416 this._sourcesView.setExecutionLocation(uiLocation);
417 if (window.performance.now() - this._lastModificationTime < WebInspector .SourcesPanel._lastModificationTimeout)
418 return;
419 this._sourcesView.showSourceLocation(uiLocation.uiSourceCode, uiLocation .lineNumber, uiLocation.columnNumber, undefined, true);
420 },
421
422 _lastModificationTimeoutPassedForTest: function()
423 {
424 WebInspector.SourcesPanel._lastModificationTimeout = Number.MIN_VALUE;
425 },
426
427 _updateLastModificationTimeForTest: function()
428 {
429 WebInspector.SourcesPanel._lastModificationTimeout = Number.MAX_VALUE;
430 },
431
432 _callFrameChanged: function()
433 {
434 var callFrame = WebInspector.context.flavor(WebInspector.DebuggerModel.C allFrame);
435 if (!callFrame)
436 return;
437 if (this._executionLineLocation)
438 this._executionLineLocation.dispose();
439 this._executionLineLocation = WebInspector.debuggerWorkspaceBinding.crea teCallFrameLiveLocation(callFrame.location(), this._executionLineChanged.bind(th is), this._liveLocationPool);
440 },
441
442 _pauseOnExceptionEnabledChanged: function()
443 {
444 var enabled = WebInspector.moduleSetting("pauseOnExceptionEnabled").get( );
445 this._pauseOnExceptionButton.setToggled(enabled);
446 this._pauseOnExceptionButton.setTitle(WebInspector.UIString(enabled ? "D on't pause on exceptions" : "Pause on exceptions"));
447 this._debugToolbarDrawer.classList.toggle("expanded", enabled);
448 },
449
450 _updateDebuggerButtonsAndStatus: function()
451 {
452 var currentTarget = WebInspector.context.flavor(WebInspector.Target);
453 var currentDebuggerModel = WebInspector.DebuggerModel.fromTarget(current Target);
454 if (!currentDebuggerModel) {
455 this._togglePauseAction.setEnabled(false);
456 this._stepOverAction.setEnabled(false);
457 this._stepIntoAction.setEnabled(false);
458 this._stepOutAction.setEnabled(false);
459 } else if (this._paused) {
460 this._togglePauseAction.setToggled(true);
461 this._togglePauseAction.setEnabled(true);
462 this._stepOverAction.setEnabled(true);
463 this._stepIntoAction.setEnabled(true);
464 this._stepOutAction.setEnabled(true);
465 } else {
466 this._togglePauseAction.setToggled(false);
467 this._togglePauseAction.setEnabled(!currentDebuggerModel.isPausing() );
468 this._stepOverAction.setEnabled(false);
469 this._stepIntoAction.setEnabled(false);
470 this._stepOutAction.setEnabled(false);
471 }
472
473 var details = currentDebuggerModel ? currentDebuggerModel.debuggerPaused Details() : null;
474 this._debuggerPausedMessage.render(details, WebInspector.debuggerWorkspa ceBinding, WebInspector.breakpointManager);
475 },
476
477 _clearInterface: function()
478 {
479 this._sourcesView.clearCurrentExecutionLine();
480 this._updateDebuggerButtonsAndStatus();
481 WebInspector.context.setFlavor(WebInspector.DebuggerPausedDetails, null) ;
482
483 if (this._switchToPausedTargetTimeout)
484 clearTimeout(this._switchToPausedTargetTimeout);
485 this._liveLocationPool.disposeAll();
486 },
487
488 /**
489 * @param {!WebInspector.DebuggerModel} debuggerModel
490 */
491 _switchToPausedTarget: function(debuggerModel)
492 {
493 delete this._switchToPausedTargetTimeout;
494 if (this._paused)
495 return;
496 var target = WebInspector.context.flavor(WebInspector.Target);
497 if (debuggerModel.isPaused())
498 return;
499 var debuggerModels = WebInspector.DebuggerModel.instances();
500 for (var i = 0; i < debuggerModels.length; ++i) {
501 if (debuggerModels[i].isPaused()) {
502 WebInspector.context.setFlavor(WebInspector.Target, debuggerMode ls[i].target());
503 break;
504 }
505 }
506 },
507
508 _togglePauseOnExceptions: function()
509 {
510 WebInspector.moduleSetting("pauseOnExceptionEnabled").set(!this._pauseOn ExceptionButton.toggled());
511 },
512
513 /**
514 * @return {boolean}
515 */
516 _runSnippet: function()
517 {
518 var uiSourceCode = this._sourcesView.currentUISourceCode();
519 if (uiSourceCode.project().type() !== WebInspector.projectTypes.Snippets )
520 return false;
521
522 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E xecutionContext);
523 if (!currentExecutionContext)
524 return false;
525
526 WebInspector.scriptSnippetModel.evaluateScriptSnippet(currentExecutionCo ntext, uiSourceCode);
527 return true;
528 },
529
530 /**
531 * @param {!WebInspector.Event} event
532 */
533 _editorSelected: function(event)
534 {
535 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data );
536 this._editorChanged(uiSourceCode);
537 if (this.editorView.mainWidget() && WebInspector.moduleSetting("autoReve alInNavigator").get())
538 this._revealInNavigator(uiSourceCode, true);
539 },
540
541 /**
542 * @param {!WebInspector.Event} event
543 */
544 _editorClosed: function(event)
545 {
546 var wasSelected = /** @type {boolean} */ (event.data.wasSelected);
547 if (wasSelected)
548 this._editorChanged(null);
549 },
550
551 /**
552 * @param {?WebInspector.UISourceCode} uiSourceCode
553 */
554 _editorChanged: function(uiSourceCode)
555 {
556 var isSnippet = uiSourceCode && uiSourceCode.project().type() === WebIns pector.projectTypes.Snippets;
557 this._runSnippetButton.setVisible(isSnippet);
558 },
559
560 /**
561 * @return {boolean}
562 */
563 _togglePause: function()
564 {
565 var target = WebInspector.context.flavor(WebInspector.Target);
566 if (!target)
567 return true;
568 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target);
569 if (!debuggerModel)
570 return true;
571
572 if (this._paused) {
573 this._paused = false;
574 debuggerModel.resume();
575 } else {
576 // Make sure pauses didn't stick skipped.
577 debuggerModel.pause();
578 }
579
580 this._clearInterface();
581 return true;
582 },
583
584 /**
585 * @return {?WebInspector.DebuggerModel}
586 */
587 _prepareToResume: function()
588 {
589 if (!this._paused)
590 return null;
591
592 this._paused = false;
593
594 this._clearInterface();
595 var target = WebInspector.context.flavor(WebInspector.Target);
596 return target ? WebInspector.DebuggerModel.fromTarget(target) : null;
597 },
598
599 /**
600 * @return {boolean}
601 */
602 _longResume: function()
603 {
604 var debuggerModel = this._prepareToResume();
605 if (!debuggerModel)
606 return true;
607
608 debuggerModel.skipAllPausesUntilReloadOrTimeout(500);
609 debuggerModel.resume();
610 return true;
611 },
612
613 /**
614 * @return {boolean}
615 */
616 _stepOver: function()
617 {
618 var debuggerModel = this._prepareToResume();
619 if (!debuggerModel)
620 return true;
621
622 debuggerModel.stepOver();
623 return true;
624 },
625
626 /**
627 * @return {boolean}
628 */
629 _stepInto: function()
630 {
631 var debuggerModel = this._prepareToResume();
632 if (!debuggerModel)
633 return true;
634
635 debuggerModel.stepInto();
636 return true;
637 },
638
639 /**
640 * @return {boolean}
641 */
642 _stepOut: function()
643 {
644 var debuggerModel = this._prepareToResume();
645 if (!debuggerModel)
646 return true;
647
648 debuggerModel.stepOut();
649 return true;
650 },
651
652 /**
653 * @param {!WebInspector.UILocation} uiLocation
654 */
655 _continueToLocation: function(uiLocation)
656 {
657 var executionContext = WebInspector.context.flavor(WebInspector.Executio nContext);
658 if (!executionContext)
659 return;
660
661 // Always use 0 column.
662 var rawLocation = WebInspector.debuggerWorkspaceBinding.uiLocationToRawL ocation(executionContext.target(), uiLocation.uiSourceCode, uiLocation.lineNumbe r, 0);
663 if (!rawLocation)
664 return;
665
666 if (!this._prepareToResume())
667 return;
668
669 rawLocation.continueToLocation();
670 },
671
672 _toggleBreakpointsActive: function()
673 {
674 WebInspector.breakpointManager.setBreakpointsActive(!WebInspector.breakp ointManager.breakpointsActive());
675 },
676
677 _breakpointsActiveStateChanged: function(event)
678 {
679 var active = event.data;
680 this._toggleBreakpointsActiveAction.setToggled(!active);
681 this._sourcesView.toggleBreakpointsActiveState(active);
682 },
683
684 /**
685 * @return {!WebInspector.Toolbar}
686 */
687 _createDebugToolbar: function()
688 {
689 var debugToolbar = new WebInspector.Toolbar("scripts-debug-toolbar");
690
691 this._runSnippetButton = WebInspector.Toolbar.createActionButton(this._r unSnippetAction);
692 debugToolbar.appendToolbarItem(this._runSnippetButton);
693 this._runSnippetButton.setVisible(false);
694
695 var longResumeButton = new WebInspector.ToolbarButton(WebInspector.UIStr ing("Resume with all pauses blocked for 500 ms"), "play-toolbar-item");
696 longResumeButton.addEventListener("click", this._longResume.bind(this), this);
697 debugToolbar.appendToolbarItem(WebInspector.Toolbar.createActionButton(t his._togglePauseAction, [longResumeButton], []));
698
699 debugToolbar.appendToolbarItem(WebInspector.Toolbar.createActionButton(t his._stepOverAction));
700 debugToolbar.appendToolbarItem(WebInspector.Toolbar.createActionButton(t his._stepIntoAction));
701 debugToolbar.appendToolbarItem(WebInspector.Toolbar.createActionButton(t his._stepOutAction));
702 debugToolbar.appendSeparator();
703 debugToolbar.appendToolbarItem(WebInspector.Toolbar.createActionButton(t his._toggleBreakpointsActiveAction));
704
705 this._pauseOnExceptionButton = new WebInspector.ToolbarToggle("", "pause -on-exceptions-toolbar-item");
706 this._pauseOnExceptionButton.addEventListener("click", this._togglePause OnExceptions, this);
707 debugToolbar.appendToolbarItem(this._pauseOnExceptionButton);
708
709 debugToolbar.appendSeparator();
710 debugToolbar.appendToolbarItem(new WebInspector.ToolbarCheckbox(WebInspe ctor.UIString("Async"), WebInspector.UIString("Capture async stack traces"), Web Inspector.moduleSetting("enableAsyncStackTraces")));
711
712 return debugToolbar;
713 },
714
715 _createDebugToolbarDrawer: function()
716 {
717 var debugToolbarDrawer = createElementWithClass("div", "scripts-debug-to olbar-drawer");
718
719 var label = WebInspector.UIString("Pause On Caught Exceptions");
720 var setting = WebInspector.moduleSetting("pauseOnCaughtException");
721 debugToolbarDrawer.appendChild(WebInspector.SettingsUI.createSettingChec kbox(label, setting, true));
722
723 return debugToolbarDrawer;
724 },
725
726 /**
727 * @param {!WebInspector.UISourceCode} uiSourceCode
728 */
729 _showLocalHistory: function(uiSourceCode)
730 {
731 WebInspector.RevisionHistoryView.showHistory(uiSourceCode);
732 },
733
734 /**
735 * @override
736 * @param {!Event} event
737 * @param {!WebInspector.ContextMenu} contextMenu
738 * @param {!Object} target
739 */
740 appendApplicableItems: function(event, contextMenu, target)
741 {
742 this._appendUISourceCodeItems(event, contextMenu, target);
743 this._appendUISourceCodeFrameItems(event, contextMenu, target);
744 this.appendUILocationItems(contextMenu, target);
745 this._appendRemoteObjectItems(contextMenu, target);
746 this._appendNetworkRequestItems(contextMenu, target);
747 },
748
749 /**
750 * @param {!WebInspector.UISourceCode} uiSourceCode
751 */
752 mapFileSystemToNetwork: function(uiSourceCode)
753 {
754 WebInspector.SelectUISourceCodeForProjectTypesDialog.show(uiSourceCode.n ame(), [WebInspector.projectTypes.Network, WebInspector.projectTypes.ContentScri pts], mapFileSystemToNetwork.bind(this));
755
756 /**
757 * @param {?WebInspector.UISourceCode} networkUISourceCode
758 * @this {WebInspector.SourcesPanel}
759 */
760 function mapFileSystemToNetwork(networkUISourceCode)
761 {
762 if (!networkUISourceCode)
763 return;
764 this._networkMapping.addMapping(networkUISourceCode, uiSourceCode);
765 }
766 },
767
768 /**
769 * @param {!WebInspector.UISourceCode} networkUISourceCode
770 */
771 mapNetworkToFileSystem: function(networkUISourceCode)
772 {
773 WebInspector.SelectUISourceCodeForProjectTypesDialog.show(networkUISourc eCode.name(), [WebInspector.projectTypes.FileSystem], mapNetworkToFileSystem.bin d(this));
774
775 /**
776 * @param {?WebInspector.UISourceCode} uiSourceCode
777 * @this {WebInspector.SourcesPanel}
778 */
779 function mapNetworkToFileSystem(uiSourceCode)
780 {
781 if (!uiSourceCode)
782 return;
783 this._networkMapping.addMapping(networkUISourceCode, uiSourceCode);
784 }
785 },
786
787 /**
788 * @param {!WebInspector.UISourceCode} uiSourceCode
789 */
790 _removeNetworkMapping: function(uiSourceCode)
791 {
792 this._networkMapping.removeMapping(uiSourceCode);
793 },
794
795 /**
796 * @param {!WebInspector.ContextMenu} contextMenu
797 * @param {!WebInspector.UISourceCode} uiSourceCode
798 */
799 _appendUISourceCodeMappingItems: function(contextMenu, uiSourceCode)
800 {
801 WebInspector.NavigatorView.appendAddFolderItem(contextMenu);
802
803 if (Runtime.experiments.isEnabled("persistence2"))
804 return;
805 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSyst em) {
806 var binding = WebInspector.persistence.binding(uiSourceCode);
807 if (!binding)
808 contextMenu.appendItem(WebInspector.UIString.capitalize("Map to ^network ^resource\u2026"), this.mapFileSystemToNetwork.bind(this, uiSourceCode) );
809 else
810 contextMenu.appendItem(WebInspector.UIString.capitalize("Remove ^network ^mapping"), this._removeNetworkMapping.bind(this, binding.network));
811 }
812
813 /**
814 * @param {!WebInspector.Project} project
815 */
816 function filterProject(project)
817 {
818 return project.type() === WebInspector.projectTypes.FileSystem;
819 }
820
821 if (uiSourceCode.project().type() === WebInspector.projectTypes.Network || uiSourceCode.project().type() === WebInspector.projectTypes.ContentScripts) {
822 if (!this._workspace.projects().filter(filterProject).length)
823 return;
824 if (this._networkMapping.uiSourceCodeForURLForAnyTarget(uiSourceCode .url()) === uiSourceCode)
825 contextMenu.appendItem(WebInspector.UIString.capitalize("Map to ^file ^system ^resource\u2026"), this.mapNetworkToFileSystem.bind(this, uiSource Code));
826 }
827 },
828
829 /**
830 * @param {!Event} event
831 * @param {!WebInspector.ContextMenu} contextMenu
832 * @param {!Object} target
833 */
834 _appendUISourceCodeItems: function(event, contextMenu, target)
835 {
836 if (!(target instanceof WebInspector.UISourceCode))
837 return;
838
839 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (target);
840 var projectType = uiSourceCode.project().type();
841
842 if (projectType !== WebInspector.projectTypes.Debugger && !event.target. isSelfOrDescendant(this._navigatorTabbedLocation.widget().element)) {
843 contextMenu.appendItem(WebInspector.UIString.capitalize("Reveal in ^ navigator"), this._handleContextMenuReveal.bind(this, uiSourceCode));
844 contextMenu.appendSeparator();
845 }
846 this._appendUISourceCodeMappingItems(contextMenu, uiSourceCode);
847 if (projectType !== WebInspector.projectTypes.FileSystem)
848 contextMenu.appendItem(WebInspector.UIString.capitalize("Local ^modi fications\u2026"), this._showLocalHistory.bind(this, uiSourceCode));
849 },
850
851 /**
852 * @param {!Event} event
853 * @param {!WebInspector.ContextMenu} contextMenu
854 * @param {!Object} target
855 */
856 _appendUISourceCodeFrameItems: function(event, contextMenu, target)
857 {
858 if (!(target instanceof WebInspector.UISourceCodeFrame))
859 return;
860 contextMenu.appendAction("debugger.evaluate-selection");
861 },
862
863 /**
864 * @param {!WebInspector.ContextMenu} contextMenu
865 * @param {!Object} object
866 */
867 appendUILocationItems: function(contextMenu, object)
868 {
869 if (!(object instanceof WebInspector.UILocation))
870 return;
871 var uiLocation = /** @type {!WebInspector.UILocation} */ (object);
872 var uiSourceCode = uiLocation.uiSourceCode;
873 var projectType = uiSourceCode.project().type();
874
875 var contentType = uiSourceCode.contentType();
876 if (contentType.hasScripts()) {
877 var target = WebInspector.context.flavor(WebInspector.Target);
878 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target);
879 if (debuggerModel && debuggerModel.isPaused())
880 contextMenu.appendItem(WebInspector.UIString.capitalize("Continu e to ^here"), this._continueToLocation.bind(this, uiLocation));
881 }
882
883 if (contentType.hasScripts() && projectType !== WebInspector.projectType s.Snippets)
884 this._callstackPane.appendBlackboxURLContextMenuItems(contextMenu, u iSourceCode);
885 },
886
887 /**
888 * @param {!WebInspector.UISourceCode} uiSourceCode
889 */
890 _handleContextMenuReveal: function(uiSourceCode)
891 {
892 this.editorView.showBoth();
893 this._revealInNavigator(uiSourceCode);
894 },
895
896 /**
897 * @param {!WebInspector.ContextMenu} contextMenu
898 * @param {!Object} target
899 */
900 _appendRemoteObjectItems: function(contextMenu, target)
901 {
902 if (!(target instanceof WebInspector.RemoteObject))
903 return;
904 var remoteObject = /** @type {!WebInspector.RemoteObject} */ (target);
905 contextMenu.appendItem(WebInspector.UIString.capitalize("Store as ^globa l ^variable"), this._saveToTempVariable.bind(this, remoteObject));
906 if (remoteObject.type === "function")
907 contextMenu.appendItem(WebInspector.UIString.capitalize("Show ^funct ion ^definition"), this._showFunctionDefinition.bind(this, remoteObject));
908 },
909
910 /**
911 * @param {!WebInspector.ContextMenu} contextMenu
912 * @param {!Object} target
913 */
914 _appendNetworkRequestItems: function(contextMenu, target)
915 {
916 if (!(target instanceof WebInspector.NetworkRequest))
917 return;
918 var request = /** @type {!WebInspector.NetworkRequest} */ (target);
919 var uiSourceCode = this._networkMapping.uiSourceCodeForURLForAnyTarget(r equest.url);
920 if (!uiSourceCode)
921 return;
922 var openText = WebInspector.UIString.capitalize("Open in Sources ^panel" );
923 contextMenu.appendItem(openText, this.showUILocation.bind(this, uiSource Code.uiLocation(0, 0)));
924 },
925
926 /**
927 * @param {!WebInspector.RemoteObject} remoteObject
928 */
929 _saveToTempVariable: function(remoteObject)
930 {
931 var currentExecutionContext = WebInspector.context.flavor(WebInspector.E xecutionContext);
932 if (!currentExecutionContext)
933 return;
934
935 currentExecutionContext.globalObject("", false, didGetGlobalObject);
936 /**
937 * @param {?WebInspector.RemoteObject} global
938 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails
939 */
940 function didGetGlobalObject(global, exceptionDetails)
941 {
942 /**
943 * @suppressReceiverCheck
944 * @this {Window}
945 */
946 function remoteFunction(value)
947 {
948 var prefix = "temp";
949 var index = 1;
950 while ((prefix + index) in this)
951 ++index;
952 var name = prefix + index;
953 this[name] = value;
954 return name;
955 }
956
957 if (!!exceptionDetails || !global)
958 failedToSave(global);
959 else
960 global.callFunction(remoteFunction, [WebInspector.RemoteObject.t oCallArgument(remoteObject)], didSave.bind(null, global));
961 }
962
963 /**
964 * @param {!WebInspector.RemoteObject} global
965 * @param {?WebInspector.RemoteObject} result
966 * @param {boolean=} wasThrown
967 */
968 function didSave(global, result, wasThrown)
969 {
970 global.release();
971 if (wasThrown || !result || result.type !== "string")
972 failedToSave(result);
973 else
974 WebInspector.ConsoleModel.evaluateCommandInConsole(/** @type {!W ebInspector.ExecutionContext} */ (currentExecutionContext), result.value);
975 }
976
977 /**
978 * @param {?WebInspector.RemoteObject} result
979 */
980 function failedToSave(result)
981 {
982 var message = WebInspector.UIString("Failed to save to temp variable .");
983 if (result) {
984 message += " " + result.description;
985 result.release();
986 }
987 WebInspector.console.error(message);
988 }
989 },
990
991 /**
992 * @param {!WebInspector.RemoteObject} remoteObject
993 */
994 _showFunctionDefinition: function(remoteObject)
995 {
996 remoteObject.debuggerModel().functionDetailsPromise(remoteObject).then(t his._didGetFunctionDetails.bind(this));
997 },
998
999 /**
1000 * @param {?{location: ?WebInspector.DebuggerModel.Location}} response
1001 */
1002 _didGetFunctionDetails: function(response)
1003 {
1004 if (!response || !response.location)
1005 return;
1006
1007 var location = response.location;
1008 if (!location)
1009 return;
1010
1011 var uiLocation = WebInspector.debuggerWorkspaceBinding.rawLocationToUILo cation(location);
1012 if (uiLocation)
1013 this.showUILocation(uiLocation);
1014 },
1015
1016 showGoToSourceDialog: function()
1017 {
1018 this._sourcesView.showOpenResourceDialog();
1019 },
1020
1021 _revealNavigatorSidebar: function()
1022 {
1023 this._setAsCurrentPanel();
1024 this.editorView.showBoth(true);
1025 },
1026
1027 _revealDebuggerSidebar: function()
1028 {
1029 this._setAsCurrentPanel();
1030 this._splitWidget.showBoth(true);
1031 },
1032
1033 _updateSidebarPosition: function()
1034 {
1035 var vertically;
1036 var position = WebInspector.moduleSetting("sidebarPosition").get();
1037 if (position === "right")
1038 vertically = false;
1039 else if (position === "bottom")
1040 vertically = true;
1041 else
1042 vertically = WebInspector.inspectorView.element.offsetWidth < 680;
1043
1044 if (this.sidebarPaneView && vertically === !this._splitWidget.isVertical ())
1045 return;
1046
1047 if (this.sidebarPaneView && this.sidebarPaneView.shouldHideOnDetach())
1048 return; // We can't reparent extension iframes.
1049
1050 if (this.sidebarPaneView)
1051 this.sidebarPaneView.detach();
1052
1053 this._splitWidget.setVertical(!vertically);
1054 this._splitWidget.element.classList.toggle("sources-split-view-vertical" , vertically);
1055
1056 WebInspector.SourcesPanel.updateResizerAndSidebarButtons(this);
1057
1058 // Create vertical box with stack.
1059 var vbox = new WebInspector.VBox();
1060 vbox.element.appendChild(this._debugToolbarDrawer);
1061 vbox.setMinimumAndPreferredSizes(25, 25, WebInspector.SourcesPanel.minTo olbarWidth, 100);
1062 this._sidebarPaneStack = WebInspector.viewManager.createStackLocation(th is._revealDebuggerSidebar.bind(this));
1063 this._sidebarPaneStack.widget().element.classList.add("overflow-auto");
1064 this._sidebarPaneStack.widget().show(vbox.element);
1065 this._sidebarPaneStack.widget().element.appendChild(this._debuggerPaused Message.element());
1066 vbox.element.appendChild(this._debugToolbar.element);
1067
1068 if (this._threadsSidebarPane)
1069 this._sidebarPaneStack.showView(this._threadsSidebarPane);
1070
1071 if (!vertically)
1072 this._sidebarPaneStack.appendView(this._watchSidebarPane);
1073
1074 this._sidebarPaneStack.showView(this._callstackPane);
1075 var jsBreakpoints = /** @type {!WebInspector.View} */ (WebInspector.view Manager.view("sources.jsBreakpoints"));
1076 var scopeChainView = /** @type {!WebInspector.View} */ (WebInspector.vie wManager.view("sources.scopeChain"));
1077
1078 if (!vertically) {
1079 // Populate the rest of the stack.
1080 this._sidebarPaneStack.showView(scopeChainView);
1081 this._sidebarPaneStack.showView(jsBreakpoints);
1082 this._extensionSidebarPanesContainer = this._sidebarPaneStack;
1083 this.sidebarPaneView = vbox;
1084 } else {
1085 var splitWidget = new WebInspector.SplitWidget(true, true, "sourcesP anelDebuggerSidebarSplitViewState", 0.5);
1086 splitWidget.setMainWidget(vbox);
1087
1088 // Populate the left stack.
1089 this._sidebarPaneStack.showView(jsBreakpoints);
1090
1091 var tabbedLocation = WebInspector.viewManager.createTabbedLocation(t his._revealDebuggerSidebar.bind(this));
1092 splitWidget.setSidebarWidget(tabbedLocation.tabbedPane());
1093 tabbedLocation.appendView(scopeChainView);
1094 tabbedLocation.appendView(this._watchSidebarPane);
1095 this._extensionSidebarPanesContainer = tabbedLocation;
1096 this.sidebarPaneView = splitWidget;
1097 }
1098
1099 this._sidebarPaneStack.appendApplicableItems("sources-sidebar");
1100 var extensionSidebarPanes = WebInspector.extensionServer.sidebarPanes();
1101 for (var i = 0; i < extensionSidebarPanes.length; ++i)
1102 this._addExtensionSidebarPane(extensionSidebarPanes[i]);
1103
1104 this._splitWidget.setSidebarWidget(this.sidebarPaneView);
1105 },
1106
1107 /**
1108 * @return {!Promise}
1109 */
1110 _setAsCurrentPanel: function()
1111 {
1112 return WebInspector.viewManager.showView("sources");
1113 },
1114
1115 /**
1116 * @param {!WebInspector.Event} event
1117 */
1118 _extensionSidebarPaneAdded: function(event)
1119 {
1120 var pane = /** @type {!WebInspector.ExtensionSidebarPane} */ (event.data );
1121 this._addExtensionSidebarPane(pane);
1122 },
1123
1124 /**
1125 * @param {!WebInspector.ExtensionSidebarPane} pane
1126 */
1127 _addExtensionSidebarPane: function(pane)
1128 {
1129 if (pane.panelName() === this.name)
1130 this._extensionSidebarPanesContainer.appendView(pane);
1131 },
1132
1133 /**
1134 * @return {!WebInspector.SourcesView}
1135 */
1136 sourcesView: function()
1137 {
1138 return this._sourcesView;
1139 },
1140
1141 /**
1142 * @param {!DataTransfer} dataTransfer
1143 */
1144 _handleDrop: function(dataTransfer)
1145 {
1146 var items = dataTransfer.items;
1147 if (!items.length)
1148 return;
1149 var entry = items[0].webkitGetAsEntry();
1150 if (!entry.isDirectory)
1151 return;
1152 InspectorFrontendHost.upgradeDraggedFileSystemPermissions(entry.filesyst em);
1153 },
1154
1155 __proto__: WebInspector.Panel.prototype
1156 };
1157
1158 /**
1159 * @constructor
1160 * @implements {WebInspector.Revealer}
1161 */
1162 WebInspector.SourcesPanel.UILocationRevealer = function()
1163 {
1164 };
1165
1166 WebInspector.SourcesPanel.UILocationRevealer.prototype = {
1167 /**
1168 * @override
1169 * @param {!Object} uiLocation
1170 * @param {boolean=} omitFocus
1171 * @return {!Promise}
1172 */
1173 reveal: function(uiLocation, omitFocus)
1174 {
1175 if (!(uiLocation instanceof WebInspector.UILocation))
1176 return Promise.reject(new Error("Internal error: not a ui location") );
1177 WebInspector.SourcesPanel.instance().showUILocation(uiLocation, omitFocu s);
1178 return Promise.resolve();
1179 }
1180 };
1181
1182 /**
1183 * @constructor
1184 * @implements {WebInspector.Revealer}
1185 */
1186 WebInspector.SourcesPanel.DebuggerLocationRevealer = function()
1187 {
1188 };
1189
1190 WebInspector.SourcesPanel.DebuggerLocationRevealer.prototype = {
1191 /**
1192 * @override
1193 * @param {!Object} rawLocation
1194 * @param {boolean=} omitFocus
1195 * @return {!Promise}
1196 */
1197 reveal: function(rawLocation, omitFocus)
1198 {
1199 if (!(rawLocation instanceof WebInspector.DebuggerModel.Location))
1200 return Promise.reject(new Error("Internal error: not a debugger loca tion"));
1201 WebInspector.SourcesPanel.instance().showUILocation(WebInspector.debugge rWorkspaceBinding.rawLocationToUILocation(rawLocation), omitFocus);
1202 return Promise.resolve();
1203 }
1204 };
1205
1206 /**
1207 * @constructor
1208 * @implements {WebInspector.Revealer}
1209 */
1210 WebInspector.SourcesPanel.UISourceCodeRevealer = function()
1211 {
1212 };
1213
1214 WebInspector.SourcesPanel.UISourceCodeRevealer.prototype = {
1215 /**
1216 * @override
1217 * @param {!Object} uiSourceCode
1218 * @param {boolean=} omitFocus
1219 * @return {!Promise}
1220 */
1221 reveal: function(uiSourceCode, omitFocus)
1222 {
1223 if (!(uiSourceCode instanceof WebInspector.UISourceCode))
1224 return Promise.reject(new Error("Internal error: not a ui source cod e"));
1225 WebInspector.SourcesPanel.instance().showUISourceCode(uiSourceCode, unde fined, undefined, omitFocus);
1226 return Promise.resolve();
1227 }
1228 };
1229
1230 /**
1231 * @constructor
1232 * @implements {WebInspector.Revealer}
1233 */
1234 WebInspector.SourcesPanel.DebuggerPausedDetailsRevealer = function()
1235 {
1236 };
1237
1238 WebInspector.SourcesPanel.DebuggerPausedDetailsRevealer.prototype = {
1239 /**
1240 * @override
1241 * @param {!Object} object
1242 * @return {!Promise}
1243 */
1244 reveal: function(object)
1245 {
1246 return WebInspector.SourcesPanel.instance()._setAsCurrentPanel();
1247 }
1248 };
1249
1250 /**
1251 * @constructor
1252 * @implements {WebInspector.ActionDelegate}
1253 */
1254 WebInspector.SourcesPanel.RevealingActionDelegate = function() {};
1255
1256 WebInspector.SourcesPanel.RevealingActionDelegate.prototype = {
1257 /**
1258 * @override
1259 * @param {!WebInspector.Context} context
1260 * @param {string} actionId
1261 * @return {boolean}
1262 */
1263 handleAction: function(context, actionId)
1264 {
1265 var panel = WebInspector.SourcesPanel.instance();
1266 if (!panel._ensureSourcesViewVisible())
1267 return false;
1268 switch (actionId) {
1269 case "debugger.toggle-pause":
1270 panel._togglePause();
1271 return true;
1272 case "sources.go-to-source":
1273 panel.showGoToSourceDialog();
1274 return true;
1275 }
1276 return false;
1277 }
1278 };
1279
1280 /**
1281 * @constructor
1282 * @implements {WebInspector.ActionDelegate}
1283 */
1284 WebInspector.SourcesPanel.DebuggingActionDelegate = function()
1285 {
1286 };
1287
1288 WebInspector.SourcesPanel.DebuggingActionDelegate.prototype = {
1289 /**
1290 * @override
1291 * @param {!WebInspector.Context} context
1292 * @param {string} actionId
1293 * @return {boolean}
1294 */
1295 handleAction: function(context, actionId)
1296 {
1297 var panel = WebInspector.SourcesPanel.instance();
1298 switch (actionId) {
1299 case "debugger.step-over":
1300 panel._stepOver();
1301 return true;
1302 case "debugger.step-into":
1303 panel._stepInto();
1304 return true;
1305 case "debugger.step-out":
1306 panel._stepOut();
1307 return true;
1308 case "debugger.run-snippet":
1309 panel._runSnippet();
1310 return true;
1311 case "debugger.toggle-breakpoints-active":
1312 panel._toggleBreakpointsActive();
1313 return true;
1314 case "debugger.evaluate-selection":
1315 var frame = WebInspector.context.flavor(WebInspector.UISourceCodeFra me);
1316 if (frame) {
1317 var text = frame.textEditor.text(frame.textEditor.selection());
1318 var executionContext = WebInspector.context.flavor(WebInspector. ExecutionContext);
1319 if (executionContext)
1320 WebInspector.ConsoleModel.evaluateCommandInConsole(execution Context, text);
1321 }
1322 return true;
1323 }
1324 return false;
1325 }
1326 };
1327
1328 /**
1329 * @return {!WebInspector.SourcesPanel}
1330 */
1331 WebInspector.SourcesPanel.instance = function()
1332 {
1333 if (WebInspector.SourcesPanel._instance) 136 if (WebInspector.SourcesPanel._instance)
1334 return WebInspector.SourcesPanel._instance; 137 return WebInspector.SourcesPanel._instance;
1335 return /** @type {!WebInspector.SourcesPanel} */ (self.runtime.sharedInstanc e(WebInspector.SourcesPanel)); 138 return /** @type {!WebInspector.SourcesPanel} */ (self.runtime.sharedInstanc e(WebInspector.SourcesPanel));
1336 }; 139 }
1337 140
1338 /** 141 /**
1339 * @param {!WebInspector.SourcesPanel} panel 142 * @param {!WebInspector.SourcesPanel} panel
1340 */ 143 */
1341 WebInspector.SourcesPanel.updateResizerAndSidebarButtons = function(panel) 144 static updateResizerAndSidebarButtons(panel) {
1342 {
1343 panel._sourcesView.leftToolbar().removeToolbarItems(); 145 panel._sourcesView.leftToolbar().removeToolbarItems();
1344 panel._sourcesView.rightToolbar().removeToolbarItems(); 146 panel._sourcesView.rightToolbar().removeToolbarItems();
1345 panel._sourcesView.bottomToolbar().removeToolbarItems(); 147 panel._sourcesView.bottomToolbar().removeToolbarItems();
1346 var isInWrapper = WebInspector.SourcesPanel.WrapperView.isShowing() && !WebI nspector.inspectorView.isDrawerMinimized(); 148 var isInWrapper =
149 WebInspector.SourcesPanel.WrapperView.isShowing() && !WebInspector.inspe ctorView.isDrawerMinimized();
1347 if (panel._splitWidget.isVertical() || isInWrapper) 150 if (panel._splitWidget.isVertical() || isInWrapper)
1348 panel._splitWidget.uninstallResizer(panel._sourcesView.toolbarContainerE lement()); 151 panel._splitWidget.uninstallResizer(panel._sourcesView.toolbarContainerEle ment());
1349 else 152 else
1350 panel._splitWidget.installResizer(panel._sourcesView.toolbarContainerEle ment()); 153 panel._splitWidget.installResizer(panel._sourcesView.toolbarContainerEleme nt());
1351 if (!isInWrapper) { 154 if (!isInWrapper) {
1352 panel._sourcesView.leftToolbar().appendToolbarItem(panel._toggleNavigato rSidebarButton); 155 panel._sourcesView.leftToolbar().appendToolbarItem(panel._toggleNavigatorS idebarButton);
1353 if (panel._splitWidget.isVertical()) 156 if (panel._splitWidget.isVertical())
1354 panel._sourcesView.rightToolbar().appendToolbarItem(panel._toggleDeb uggerSidebarButton); 157 panel._sourcesView.rightToolbar().appendToolbarItem(panel._toggleDebugge rSidebarButton);
1355 else 158 else
1356 panel._sourcesView.bottomToolbar().appendToolbarItem(panel._toggleDe buggerSidebarButton); 159 panel._sourcesView.bottomToolbar().appendToolbarItem(panel._toggleDebugg erSidebarButton);
1357 } 160 }
161 }
162
163 /**
164 * @override
165 * @param {!WebInspector.Target} target
166 */
167 targetAdded(target) {
168 var hasThreads = WebInspector.targetManager.targets(WebInspector.Target.Capa bility.JS).length > 1;
169 if (hasThreads && !this._threadsSidebarPane) {
170 this._threadsSidebarPane = /** @type {!WebInspector.View} */ (WebInspector .viewManager.view('sources.threads'));
171 if (this._sidebarPaneStack) {
172 this._sidebarPaneStack.showView(
173 this._threadsSidebarPane, this._splitWidget.isVertical() ? this._wat chSidebarPane : this._callstackPane);
174 }
175 }
176 }
177
178 /**
179 * @override
180 * @param {!WebInspector.Target} target
181 */
182 targetRemoved(target) {
183 }
184
185 /**
186 * @param {?WebInspector.Target} target
187 */
188 _setTarget(target) {
189 if (!target)
190 return;
191 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target);
192 if (!debuggerModel)
193 return;
194
195 if (debuggerModel.isPaused()) {
196 this._showDebuggerPausedDetails(
197 /** @type {!WebInspector.DebuggerPausedDetails} */ (debuggerModel.debu ggerPausedDetails()));
198 } else {
199 this._paused = false;
200 this._clearInterface();
201 this._toggleDebuggerSidebarButton.setEnabled(true);
202 }
203 }
204
205 /**
206 * @param {!WebInspector.Event} event
207 */
208 _onCurrentTargetChanged(event) {
209 var target = /** @type {?WebInspector.Target} */ (event.data);
210 this._setTarget(target);
211 }
212 /**
213 * @return {boolean}
214 */
215 paused() {
216 return this._paused;
217 }
218
219 /**
220 * @override
221 */
222 wasShown() {
223 WebInspector.context.setFlavor(WebInspector.SourcesPanel, this);
224 super.wasShown();
225 var wrapper = WebInspector.SourcesPanel.WrapperView._instance;
226 if (wrapper && wrapper.isShowing()) {
227 WebInspector.inspectorView.setDrawerMinimized(true);
228 WebInspector.SourcesPanel.updateResizerAndSidebarButtons(this);
229 }
230 this.editorView.setMainWidget(this._sourcesView);
231 }
232
233 /**
234 * @override
235 */
236 willHide() {
237 super.willHide();
238 WebInspector.context.setFlavor(WebInspector.SourcesPanel, null);
239 if (WebInspector.SourcesPanel.WrapperView.isShowing()) {
240 WebInspector.SourcesPanel.WrapperView._instance._showViewInWrapper();
241 WebInspector.inspectorView.setDrawerMinimized(false);
242 WebInspector.SourcesPanel.updateResizerAndSidebarButtons(this);
243 }
244 }
245
246 /**
247 * @override
248 * @param {string} locationName
249 * @return {?WebInspector.ViewLocation}
250 */
251 resolveLocation(locationName) {
252 if (locationName === 'sources-sidebar')
253 return this._sidebarPaneStack;
254 else
255 return this._navigatorTabbedLocation;
256 }
257
258 /**
259 * @return {boolean}
260 */
261 _ensureSourcesViewVisible() {
262 if (WebInspector.SourcesPanel.WrapperView.isShowing())
263 return true;
264 if (!WebInspector.inspectorView.canSelectPanel('sources'))
265 return false;
266 WebInspector.viewManager.showView('sources');
267 return true;
268 }
269
270 /**
271 * @override
272 */
273 onResize() {
274 if (WebInspector.moduleSetting('sidebarPosition').get() === 'auto')
275 this.element.window().requestAnimationFrame(this._updateSidebarPosition.bi nd(this)); // Do not force layout.
276 }
277
278 /**
279 * @override
280 * @return {!WebInspector.SearchableView}
281 */
282 searchableView() {
283 return this._sourcesView.searchableView();
284 }
285
286 /**
287 * @param {!WebInspector.Event} event
288 */
289 _debuggerPaused(event) {
290 var details = /** @type {!WebInspector.DebuggerPausedDetails} */ (event.data );
291 if (!this._paused)
292 this._setAsCurrentPanel();
293
294 if (WebInspector.context.flavor(WebInspector.Target) === details.target())
295 this._showDebuggerPausedDetails(details);
296 else if (!this._paused)
297 WebInspector.context.setFlavor(WebInspector.Target, details.target());
298 }
299
300 /**
301 * @param {!WebInspector.DebuggerPausedDetails} details
302 */
303 _showDebuggerPausedDetails(details) {
304 this._paused = true;
305 this._updateDebuggerButtonsAndStatus();
306 WebInspector.context.setFlavor(WebInspector.DebuggerPausedDetails, details);
307 this._toggleDebuggerSidebarButton.setEnabled(false);
308 window.focus();
309 InspectorFrontendHost.bringToFront();
310 }
311
312 /**
313 * @param {!WebInspector.Event} event
314 */
315 _debuggerResumed(event) {
316 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (event.target );
317 var target = debuggerModel.target();
318 if (WebInspector.context.flavor(WebInspector.Target) !== target)
319 return;
320 this._paused = false;
321 this._clearInterface();
322 this._toggleDebuggerSidebarButton.setEnabled(true);
323 this._switchToPausedTargetTimeout = setTimeout(this._switchToPausedTarget.bi nd(this, debuggerModel), 500);
324 }
325
326 /**
327 * @param {!WebInspector.Event} event
328 */
329 _debuggerWasEnabled(event) {
330 var target = /** @type {!WebInspector.Target} */ (event.target.target());
331 if (WebInspector.context.flavor(WebInspector.Target) !== target)
332 return;
333
334 this._updateDebuggerButtonsAndStatus();
335 }
336
337 /**
338 * @param {!WebInspector.Event} event
339 */
340 _debuggerReset(event) {
341 this._debuggerResumed(event);
342 }
343
344 /**
345 * @return {?WebInspector.Widget}
346 */
347 get visibleView() {
348 return this._sourcesView.visibleView();
349 }
350
351 /**
352 * @param {!WebInspector.UISourceCode} uiSourceCode
353 * @param {number=} lineNumber 0-based
354 * @param {number=} columnNumber
355 * @param {boolean=} omitFocus
356 */
357 showUISourceCode(uiSourceCode, lineNumber, columnNumber, omitFocus) {
358 if (omitFocus) {
359 var wrapperShowing = WebInspector.SourcesPanel.WrapperView._instance &&
360 WebInspector.SourcesPanel.WrapperView._instance.isShowing();
361 if (!this.isShowing() && !wrapperShowing)
362 return;
363 } else {
364 this._showEditor();
365 }
366 this._sourcesView.showSourceLocation(uiSourceCode, lineNumber, columnNumber, omitFocus);
367 }
368
369 _showEditor() {
370 if (WebInspector.SourcesPanel.WrapperView._instance && WebInspector.SourcesP anel.WrapperView._instance.isShowing())
371 return;
372 this._setAsCurrentPanel();
373 }
374
375 /**
376 * @param {!WebInspector.UILocation} uiLocation
377 * @param {boolean=} omitFocus
378 */
379 showUILocation(uiLocation, omitFocus) {
380 this.showUISourceCode(uiLocation.uiSourceCode, uiLocation.lineNumber, uiLoca tion.columnNumber, omitFocus);
381 }
382
383 /**
384 * @param {!WebInspector.UISourceCode} uiSourceCode
385 * @param {boolean=} skipReveal
386 */
387 _revealInNavigator(uiSourceCode, skipReveal) {
388 var binding = WebInspector.persistence.binding(uiSourceCode);
389 if (binding && binding.network === uiSourceCode)
390 uiSourceCode = binding.fileSystem;
391
392 var extensions = self.runtime.extensions(WebInspector.NavigatorView);
393 Promise.all(extensions.map(extension => extension.instance())).then(filterNa vigators.bind(this));
394
395 /**
396 * @this {WebInspector.SourcesPanel}
397 * @param {!Array.<!Object>} objects
398 */
399 function filterNavigators(objects) {
400 for (var i = 0; i < objects.length; ++i) {
401 var navigatorView = /** @type {!WebInspector.NavigatorView} */ (objects[ i]);
402 var viewId = extensions[i].descriptor()['viewId'];
403 if (navigatorView.accept(uiSourceCode)) {
404 navigatorView.revealUISourceCode(uiSourceCode, true);
405 if (skipReveal)
406 this._navigatorTabbedLocation.tabbedPane().selectTab(viewId);
407 else
408 WebInspector.viewManager.showView(viewId);
409 }
410 }
411 }
412 }
413
414 /**
415 * @param {!WebInspector.ContextMenu} contextMenu
416 */
417 _populateNavigatorMenu(contextMenu) {
418 var groupByFolderSetting = WebInspector.moduleSetting('navigatorGroupByFolde r');
419 contextMenu.appendItemsAtLocation('navigatorMenu');
420 contextMenu.appendSeparator();
421 contextMenu.appendCheckboxItem(
422 WebInspector.UIString('Group by folder'), () => groupByFolderSetting.set (!groupByFolderSetting.get()),
423 groupByFolderSetting.get());
424 }
425
426 /**
427 * @param {boolean} ignoreExecutionLineEvents
428 */
429 setIgnoreExecutionLineEvents(ignoreExecutionLineEvents) {
430 this._ignoreExecutionLineEvents = ignoreExecutionLineEvents;
431 }
432
433 updateLastModificationTime() {
434 this._lastModificationTime = window.performance.now();
435 }
436
437 /**
438 * @param {!WebInspector.LiveLocation} liveLocation
439 */
440 _executionLineChanged(liveLocation) {
441 var uiLocation = liveLocation.uiLocation();
442 if (!uiLocation)
443 return;
444 this._sourcesView.clearCurrentExecutionLine();
445 this._sourcesView.setExecutionLocation(uiLocation);
446 if (window.performance.now() - this._lastModificationTime < WebInspector.Sou rcesPanel._lastModificationTimeout)
447 return;
448 this._sourcesView.showSourceLocation(
449 uiLocation.uiSourceCode, uiLocation.lineNumber, uiLocation.columnNumber, undefined, true);
450 }
451
452 _lastModificationTimeoutPassedForTest() {
453 WebInspector.SourcesPanel._lastModificationTimeout = Number.MIN_VALUE;
454 }
455
456 _updateLastModificationTimeForTest() {
457 WebInspector.SourcesPanel._lastModificationTimeout = Number.MAX_VALUE;
458 }
459
460 _callFrameChanged() {
461 var callFrame = WebInspector.context.flavor(WebInspector.DebuggerModel.CallF rame);
462 if (!callFrame)
463 return;
464 if (this._executionLineLocation)
465 this._executionLineLocation.dispose();
466 this._executionLineLocation = WebInspector.debuggerWorkspaceBinding.createCa llFrameLiveLocation(
467 callFrame.location(), this._executionLineChanged.bind(this), this._liveL ocationPool);
468 }
469
470 _pauseOnExceptionEnabledChanged() {
471 var enabled = WebInspector.moduleSetting('pauseOnExceptionEnabled').get();
472 this._pauseOnExceptionButton.setToggled(enabled);
473 this._pauseOnExceptionButton.setTitle(
474 WebInspector.UIString(enabled ? 'Don\'t pause on exceptions' : 'Pause on exceptions'));
475 this._debugToolbarDrawer.classList.toggle('expanded', enabled);
476 }
477
478 _updateDebuggerButtonsAndStatus() {
479 var currentTarget = WebInspector.context.flavor(WebInspector.Target);
480 var currentDebuggerModel = WebInspector.DebuggerModel.fromTarget(currentTarg et);
481 if (!currentDebuggerModel) {
482 this._togglePauseAction.setEnabled(false);
483 this._stepOverAction.setEnabled(false);
484 this._stepIntoAction.setEnabled(false);
485 this._stepOutAction.setEnabled(false);
486 } else if (this._paused) {
487 this._togglePauseAction.setToggled(true);
488 this._togglePauseAction.setEnabled(true);
489 this._stepOverAction.setEnabled(true);
490 this._stepIntoAction.setEnabled(true);
491 this._stepOutAction.setEnabled(true);
492 } else {
493 this._togglePauseAction.setToggled(false);
494 this._togglePauseAction.setEnabled(!currentDebuggerModel.isPausing());
495 this._stepOverAction.setEnabled(false);
496 this._stepIntoAction.setEnabled(false);
497 this._stepOutAction.setEnabled(false);
498 }
499
500 var details = currentDebuggerModel ? currentDebuggerModel.debuggerPausedDeta ils() : null;
501 this._debuggerPausedMessage.render(details, WebInspector.debuggerWorkspaceBi nding, WebInspector.breakpointManager);
502 }
503
504 _clearInterface() {
505 this._sourcesView.clearCurrentExecutionLine();
506 this._updateDebuggerButtonsAndStatus();
507 WebInspector.context.setFlavor(WebInspector.DebuggerPausedDetails, null);
508
509 if (this._switchToPausedTargetTimeout)
510 clearTimeout(this._switchToPausedTargetTimeout);
511 this._liveLocationPool.disposeAll();
512 }
513
514 /**
515 * @param {!WebInspector.DebuggerModel} debuggerModel
516 */
517 _switchToPausedTarget(debuggerModel) {
518 delete this._switchToPausedTargetTimeout;
519 if (this._paused)
520 return;
521 var target = WebInspector.context.flavor(WebInspector.Target);
522 if (debuggerModel.isPaused())
523 return;
524 var debuggerModels = WebInspector.DebuggerModel.instances();
525 for (var i = 0; i < debuggerModels.length; ++i) {
526 if (debuggerModels[i].isPaused()) {
527 WebInspector.context.setFlavor(WebInspector.Target, debuggerModels[i].ta rget());
528 break;
529 }
530 }
531 }
532
533 _togglePauseOnExceptions() {
534 WebInspector.moduleSetting('pauseOnExceptionEnabled').set(!this._pauseOnExce ptionButton.toggled());
535 }
536
537 /**
538 * @return {boolean}
539 */
540 _runSnippet() {
541 var uiSourceCode = this._sourcesView.currentUISourceCode();
542 if (uiSourceCode.project().type() !== WebInspector.projectTypes.Snippets)
543 return false;
544
545 var currentExecutionContext = WebInspector.context.flavor(WebInspector.Execu tionContext);
546 if (!currentExecutionContext)
547 return false;
548
549 WebInspector.scriptSnippetModel.evaluateScriptSnippet(currentExecutionContex t, uiSourceCode);
550 return true;
551 }
552
553 /**
554 * @param {!WebInspector.Event} event
555 */
556 _editorSelected(event) {
557 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data);
558 this._editorChanged(uiSourceCode);
559 if (this.editorView.mainWidget() && WebInspector.moduleSetting('autoRevealIn Navigator').get())
560 this._revealInNavigator(uiSourceCode, true);
561 }
562
563 /**
564 * @param {!WebInspector.Event} event
565 */
566 _editorClosed(event) {
567 var wasSelected = /** @type {boolean} */ (event.data.wasSelected);
568 if (wasSelected)
569 this._editorChanged(null);
570 }
571
572 /**
573 * @param {?WebInspector.UISourceCode} uiSourceCode
574 */
575 _editorChanged(uiSourceCode) {
576 var isSnippet = uiSourceCode && uiSourceCode.project().type() === WebInspect or.projectTypes.Snippets;
577 this._runSnippetButton.setVisible(isSnippet);
578 }
579
580 /**
581 * @return {boolean}
582 */
583 _togglePause() {
584 var target = WebInspector.context.flavor(WebInspector.Target);
585 if (!target)
586 return true;
587 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target);
588 if (!debuggerModel)
589 return true;
590
591 if (this._paused) {
592 this._paused = false;
593 debuggerModel.resume();
594 } else {
595 // Make sure pauses didn't stick skipped.
596 debuggerModel.pause();
597 }
598
599 this._clearInterface();
600 return true;
601 }
602
603 /**
604 * @return {?WebInspector.DebuggerModel}
605 */
606 _prepareToResume() {
607 if (!this._paused)
608 return null;
609
610 this._paused = false;
611
612 this._clearInterface();
613 var target = WebInspector.context.flavor(WebInspector.Target);
614 return target ? WebInspector.DebuggerModel.fromTarget(target) : null;
615 }
616
617 /**
618 * @return {boolean}
619 */
620 _longResume() {
621 var debuggerModel = this._prepareToResume();
622 if (!debuggerModel)
623 return true;
624
625 debuggerModel.skipAllPausesUntilReloadOrTimeout(500);
626 debuggerModel.resume();
627 return true;
628 }
629
630 /**
631 * @return {boolean}
632 */
633 _stepOver() {
634 var debuggerModel = this._prepareToResume();
635 if (!debuggerModel)
636 return true;
637
638 debuggerModel.stepOver();
639 return true;
640 }
641
642 /**
643 * @return {boolean}
644 */
645 _stepInto() {
646 var debuggerModel = this._prepareToResume();
647 if (!debuggerModel)
648 return true;
649
650 debuggerModel.stepInto();
651 return true;
652 }
653
654 /**
655 * @return {boolean}
656 */
657 _stepOut() {
658 var debuggerModel = this._prepareToResume();
659 if (!debuggerModel)
660 return true;
661
662 debuggerModel.stepOut();
663 return true;
664 }
665
666 /**
667 * @param {!WebInspector.UILocation} uiLocation
668 */
669 _continueToLocation(uiLocation) {
670 var executionContext = WebInspector.context.flavor(WebInspector.ExecutionCon text);
671 if (!executionContext)
672 return;
673
674 // Always use 0 column.
675 var rawLocation = WebInspector.debuggerWorkspaceBinding.uiLocationToRawLocat ion(
676 executionContext.target(), uiLocation.uiSourceCode, uiLocation.lineNumbe r, 0);
677 if (!rawLocation)
678 return;
679
680 if (!this._prepareToResume())
681 return;
682
683 rawLocation.continueToLocation();
684 }
685
686 _toggleBreakpointsActive() {
687 WebInspector.breakpointManager.setBreakpointsActive(!WebInspector.breakpoint Manager.breakpointsActive());
688 }
689
690 _breakpointsActiveStateChanged(event) {
691 var active = event.data;
692 this._toggleBreakpointsActiveAction.setToggled(!active);
693 this._sourcesView.toggleBreakpointsActiveState(active);
694 }
695
696 /**
697 * @return {!WebInspector.Toolbar}
698 */
699 _createDebugToolbar() {
700 var debugToolbar = new WebInspector.Toolbar('scripts-debug-toolbar');
701
702 this._runSnippetButton = WebInspector.Toolbar.createActionButton(this._runSn ippetAction);
703 debugToolbar.appendToolbarItem(this._runSnippetButton);
704 this._runSnippetButton.setVisible(false);
705
706 var longResumeButton = new WebInspector.ToolbarButton(
707 WebInspector.UIString('Resume with all pauses blocked for 500 ms'), 'pla y-toolbar-item');
708 longResumeButton.addEventListener('click', this._longResume.bind(this), this );
709 debugToolbar.appendToolbarItem(
710 WebInspector.Toolbar.createActionButton(this._togglePauseAction, [longRe sumeButton], []));
711
712 debugToolbar.appendToolbarItem(WebInspector.Toolbar.createActionButton(this. _stepOverAction));
713 debugToolbar.appendToolbarItem(WebInspector.Toolbar.createActionButton(this. _stepIntoAction));
714 debugToolbar.appendToolbarItem(WebInspector.Toolbar.createActionButton(this. _stepOutAction));
715 debugToolbar.appendSeparator();
716 debugToolbar.appendToolbarItem(WebInspector.Toolbar.createActionButton(this. _toggleBreakpointsActiveAction));
717
718 this._pauseOnExceptionButton = new WebInspector.ToolbarToggle('', 'pause-on- exceptions-toolbar-item');
719 this._pauseOnExceptionButton.addEventListener('click', this._togglePauseOnEx ceptions, this);
720 debugToolbar.appendToolbarItem(this._pauseOnExceptionButton);
721
722 debugToolbar.appendSeparator();
723 debugToolbar.appendToolbarItem(new WebInspector.ToolbarCheckbox(
724 WebInspector.UIString('Async'), WebInspector.UIString('Capture async sta ck traces'),
725 WebInspector.moduleSetting('enableAsyncStackTraces')));
726
727 return debugToolbar;
728 }
729
730 _createDebugToolbarDrawer() {
731 var debugToolbarDrawer = createElementWithClass('div', 'scripts-debug-toolba r-drawer');
732
733 var label = WebInspector.UIString('Pause On Caught Exceptions');
734 var setting = WebInspector.moduleSetting('pauseOnCaughtException');
735 debugToolbarDrawer.appendChild(WebInspector.SettingsUI.createSettingCheckbox (label, setting, true));
736
737 return debugToolbarDrawer;
738 }
739
740 /**
741 * @param {!WebInspector.UISourceCode} uiSourceCode
742 */
743 _showLocalHistory(uiSourceCode) {
744 WebInspector.RevisionHistoryView.showHistory(uiSourceCode);
745 }
746
747 /**
748 * @override
749 * @param {!Event} event
750 * @param {!WebInspector.ContextMenu} contextMenu
751 * @param {!Object} target
752 */
753 appendApplicableItems(event, contextMenu, target) {
754 this._appendUISourceCodeItems(event, contextMenu, target);
755 this._appendUISourceCodeFrameItems(event, contextMenu, target);
756 this.appendUILocationItems(contextMenu, target);
757 this._appendRemoteObjectItems(contextMenu, target);
758 this._appendNetworkRequestItems(contextMenu, target);
759 }
760
761 /**
762 * @param {!WebInspector.UISourceCode} uiSourceCode
763 */
764 mapFileSystemToNetwork(uiSourceCode) {
765 WebInspector.SelectUISourceCodeForProjectTypesDialog.show(
766 uiSourceCode.name(), [WebInspector.projectTypes.Network, WebInspector.pr ojectTypes.ContentScripts],
767 mapFileSystemToNetwork.bind(this));
768
769 /**
770 * @param {?WebInspector.UISourceCode} networkUISourceCode
771 * @this {WebInspector.SourcesPanel}
772 */
773 function mapFileSystemToNetwork(networkUISourceCode) {
774 if (!networkUISourceCode)
775 return;
776 this._networkMapping.addMapping(networkUISourceCode, uiSourceCode);
777 }
778 }
779
780 /**
781 * @param {!WebInspector.UISourceCode} networkUISourceCode
782 */
783 mapNetworkToFileSystem(networkUISourceCode) {
784 WebInspector.SelectUISourceCodeForProjectTypesDialog.show(
785 networkUISourceCode.name(), [WebInspector.projectTypes.FileSystem], mapN etworkToFileSystem.bind(this));
786
787 /**
788 * @param {?WebInspector.UISourceCode} uiSourceCode
789 * @this {WebInspector.SourcesPanel}
790 */
791 function mapNetworkToFileSystem(uiSourceCode) {
792 if (!uiSourceCode)
793 return;
794 this._networkMapping.addMapping(networkUISourceCode, uiSourceCode);
795 }
796 }
797
798 /**
799 * @param {!WebInspector.UISourceCode} uiSourceCode
800 */
801 _removeNetworkMapping(uiSourceCode) {
802 this._networkMapping.removeMapping(uiSourceCode);
803 }
804
805 /**
806 * @param {!WebInspector.ContextMenu} contextMenu
807 * @param {!WebInspector.UISourceCode} uiSourceCode
808 */
809 _appendUISourceCodeMappingItems(contextMenu, uiSourceCode) {
810 WebInspector.NavigatorView.appendAddFolderItem(contextMenu);
811
812 if (Runtime.experiments.isEnabled('persistence2'))
813 return;
814 if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSystem) {
815 var binding = WebInspector.persistence.binding(uiSourceCode);
816 if (!binding)
817 contextMenu.appendItem(
818 WebInspector.UIString.capitalize('Map to ^network ^resource\u2026'),
819 this.mapFileSystemToNetwork.bind(this, uiSourceCode));
820 else
821 contextMenu.appendItem(
822 WebInspector.UIString.capitalize('Remove ^network ^mapping'),
823 this._removeNetworkMapping.bind(this, binding.network));
824 }
825
826 /**
827 * @param {!WebInspector.Project} project
828 */
829 function filterProject(project) {
830 return project.type() === WebInspector.projectTypes.FileSystem;
831 }
832
833 if (uiSourceCode.project().type() === WebInspector.projectTypes.Network ||
834 uiSourceCode.project().type() === WebInspector.projectTypes.ContentScrip ts) {
835 if (!this._workspace.projects().filter(filterProject).length)
836 return;
837 if (this._networkMapping.uiSourceCodeForURLForAnyTarget(uiSourceCode.url() ) === uiSourceCode)
838 contextMenu.appendItem(
839 WebInspector.UIString.capitalize('Map to ^file ^system ^resource\u20 26'),
840 this.mapNetworkToFileSystem.bind(this, uiSourceCode));
841 }
842 }
843
844 /**
845 * @param {!Event} event
846 * @param {!WebInspector.ContextMenu} contextMenu
847 * @param {!Object} target
848 */
849 _appendUISourceCodeItems(event, contextMenu, target) {
850 if (!(target instanceof WebInspector.UISourceCode))
851 return;
852
853 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (target);
854 var projectType = uiSourceCode.project().type();
855
856 if (projectType !== WebInspector.projectTypes.Debugger &&
857 !event.target.isSelfOrDescendant(this._navigatorTabbedLocation.widget(). element)) {
858 contextMenu.appendItem(
859 WebInspector.UIString.capitalize('Reveal in ^navigator'),
860 this._handleContextMenuReveal.bind(this, uiSourceCode));
861 contextMenu.appendSeparator();
862 }
863 this._appendUISourceCodeMappingItems(contextMenu, uiSourceCode);
864 if (projectType !== WebInspector.projectTypes.FileSystem)
865 contextMenu.appendItem(
866 WebInspector.UIString.capitalize('Local ^modifications\u2026'),
867 this._showLocalHistory.bind(this, uiSourceCode));
868 }
869
870 /**
871 * @param {!Event} event
872 * @param {!WebInspector.ContextMenu} contextMenu
873 * @param {!Object} target
874 */
875 _appendUISourceCodeFrameItems(event, contextMenu, target) {
876 if (!(target instanceof WebInspector.UISourceCodeFrame))
877 return;
878 contextMenu.appendAction('debugger.evaluate-selection');
879 }
880
881 /**
882 * @param {!WebInspector.ContextMenu} contextMenu
883 * @param {!Object} object
884 */
885 appendUILocationItems(contextMenu, object) {
886 if (!(object instanceof WebInspector.UILocation))
887 return;
888 var uiLocation = /** @type {!WebInspector.UILocation} */ (object);
889 var uiSourceCode = uiLocation.uiSourceCode;
890 var projectType = uiSourceCode.project().type();
891
892 var contentType = uiSourceCode.contentType();
893 if (contentType.hasScripts()) {
894 var target = WebInspector.context.flavor(WebInspector.Target);
895 var debuggerModel = WebInspector.DebuggerModel.fromTarget(target);
896 if (debuggerModel && debuggerModel.isPaused())
897 contextMenu.appendItem(
898 WebInspector.UIString.capitalize('Continue to ^here'), this._continu eToLocation.bind(this, uiLocation));
899 }
900
901 if (contentType.hasScripts() && projectType !== WebInspector.projectTypes.Sn ippets)
902 this._callstackPane.appendBlackboxURLContextMenuItems(contextMenu, uiSourc eCode);
903 }
904
905 /**
906 * @param {!WebInspector.UISourceCode} uiSourceCode
907 */
908 _handleContextMenuReveal(uiSourceCode) {
909 this.editorView.showBoth();
910 this._revealInNavigator(uiSourceCode);
911 }
912
913 /**
914 * @param {!WebInspector.ContextMenu} contextMenu
915 * @param {!Object} target
916 */
917 _appendRemoteObjectItems(contextMenu, target) {
918 if (!(target instanceof WebInspector.RemoteObject))
919 return;
920 var remoteObject = /** @type {!WebInspector.RemoteObject} */ (target);
921 contextMenu.appendItem(
922 WebInspector.UIString.capitalize('Store as ^global ^variable'),
923 this._saveToTempVariable.bind(this, remoteObject));
924 if (remoteObject.type === 'function')
925 contextMenu.appendItem(
926 WebInspector.UIString.capitalize('Show ^function ^definition'),
927 this._showFunctionDefinition.bind(this, remoteObject));
928 }
929
930 /**
931 * @param {!WebInspector.ContextMenu} contextMenu
932 * @param {!Object} target
933 */
934 _appendNetworkRequestItems(contextMenu, target) {
935 if (!(target instanceof WebInspector.NetworkRequest))
936 return;
937 var request = /** @type {!WebInspector.NetworkRequest} */ (target);
938 var uiSourceCode = this._networkMapping.uiSourceCodeForURLForAnyTarget(reque st.url);
939 if (!uiSourceCode)
940 return;
941 var openText = WebInspector.UIString.capitalize('Open in Sources ^panel');
942 contextMenu.appendItem(openText, this.showUILocation.bind(this, uiSourceCode .uiLocation(0, 0)));
943 }
944
945 /**
946 * @param {!WebInspector.RemoteObject} remoteObject
947 */
948 _saveToTempVariable(remoteObject) {
949 var currentExecutionContext = WebInspector.context.flavor(WebInspector.Execu tionContext);
950 if (!currentExecutionContext)
951 return;
952
953 currentExecutionContext.globalObject('', false, didGetGlobalObject);
954 /**
955 * @param {?WebInspector.RemoteObject} global
956 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails
957 */
958 function didGetGlobalObject(global, exceptionDetails) {
959 /**
960 * @suppressReceiverCheck
961 * @this {Window}
962 */
963 function remoteFunction(value) {
964 var prefix = 'temp';
965 var index = 1;
966 while ((prefix + index) in this)
967 ++index;
968 var name = prefix + index;
969 this[name] = value;
970 return name;
971 }
972
973 if (!!exceptionDetails || !global)
974 failedToSave(global);
975 else
976 global.callFunction(
977 remoteFunction, [WebInspector.RemoteObject.toCallArgument(remoteObje ct)], didSave.bind(null, global));
978 }
979
980 /**
981 * @param {!WebInspector.RemoteObject} global
982 * @param {?WebInspector.RemoteObject} result
983 * @param {boolean=} wasThrown
984 */
985 function didSave(global, result, wasThrown) {
986 global.release();
987 if (wasThrown || !result || result.type !== 'string')
988 failedToSave(result);
989 else
990 WebInspector.ConsoleModel.evaluateCommandInConsole(
991 /** @type {!WebInspector.ExecutionContext} */ (currentExecutionConte xt), result.value);
992 }
993
994 /**
995 * @param {?WebInspector.RemoteObject} result
996 */
997 function failedToSave(result) {
998 var message = WebInspector.UIString('Failed to save to temp variable.');
999 if (result) {
1000 message += ' ' + result.description;
1001 result.release();
1002 }
1003 WebInspector.console.error(message);
1004 }
1005 }
1006
1007 /**
1008 * @param {!WebInspector.RemoteObject} remoteObject
1009 */
1010 _showFunctionDefinition(remoteObject) {
1011 remoteObject.debuggerModel().functionDetailsPromise(remoteObject).then(this. _didGetFunctionDetails.bind(this));
1012 }
1013
1014 /**
1015 * @param {?{location: ?WebInspector.DebuggerModel.Location}} response
1016 */
1017 _didGetFunctionDetails(response) {
1018 if (!response || !response.location)
1019 return;
1020
1021 var location = response.location;
1022 if (!location)
1023 return;
1024
1025 var uiLocation = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocati on(location);
1026 if (uiLocation)
1027 this.showUILocation(uiLocation);
1028 }
1029
1030 showGoToSourceDialog() {
1031 this._sourcesView.showOpenResourceDialog();
1032 }
1033
1034 _revealNavigatorSidebar() {
1035 this._setAsCurrentPanel();
1036 this.editorView.showBoth(true);
1037 }
1038
1039 _revealDebuggerSidebar() {
1040 this._setAsCurrentPanel();
1041 this._splitWidget.showBoth(true);
1042 }
1043
1044 _updateSidebarPosition() {
1045 var vertically;
1046 var position = WebInspector.moduleSetting('sidebarPosition').get();
1047 if (position === 'right')
1048 vertically = false;
1049 else if (position === 'bottom')
1050 vertically = true;
1051 else
1052 vertically = WebInspector.inspectorView.element.offsetWidth < 680;
1053
1054 if (this.sidebarPaneView && vertically === !this._splitWidget.isVertical())
1055 return;
1056
1057 if (this.sidebarPaneView && this.sidebarPaneView.shouldHideOnDetach())
1058 return; // We can't reparent extension iframes.
1059
1060 if (this.sidebarPaneView)
1061 this.sidebarPaneView.detach();
1062
1063 this._splitWidget.setVertical(!vertically);
1064 this._splitWidget.element.classList.toggle('sources-split-view-vertical', ve rtically);
1065
1066 WebInspector.SourcesPanel.updateResizerAndSidebarButtons(this);
1067
1068 // Create vertical box with stack.
1069 var vbox = new WebInspector.VBox();
1070 vbox.element.appendChild(this._debugToolbarDrawer);
1071 vbox.setMinimumAndPreferredSizes(25, 25, WebInspector.SourcesPanel.minToolba rWidth, 100);
1072 this._sidebarPaneStack = WebInspector.viewManager.createStackLocation(this._ revealDebuggerSidebar.bind(this));
1073 this._sidebarPaneStack.widget().element.classList.add('overflow-auto');
1074 this._sidebarPaneStack.widget().show(vbox.element);
1075 this._sidebarPaneStack.widget().element.appendChild(this._debuggerPausedMess age.element());
1076 vbox.element.appendChild(this._debugToolbar.element);
1077
1078 if (this._threadsSidebarPane)
1079 this._sidebarPaneStack.showView(this._threadsSidebarPane);
1080
1081 if (!vertically)
1082 this._sidebarPaneStack.appendView(this._watchSidebarPane);
1083
1084 this._sidebarPaneStack.showView(this._callstackPane);
1085 var jsBreakpoints = /** @type {!WebInspector.View} */ (WebInspector.viewMana ger.view('sources.jsBreakpoints'));
1086 var scopeChainView = /** @type {!WebInspector.View} */ (WebInspector.viewMan ager.view('sources.scopeChain'));
1087
1088 if (!vertically) {
1089 // Populate the rest of the stack.
1090 this._sidebarPaneStack.showView(scopeChainView);
1091 this._sidebarPaneStack.showView(jsBreakpoints);
1092 this._extensionSidebarPanesContainer = this._sidebarPaneStack;
1093 this.sidebarPaneView = vbox;
1094 } else {
1095 var splitWidget = new WebInspector.SplitWidget(true, true, 'sourcesPanelDe buggerSidebarSplitViewState', 0.5);
1096 splitWidget.setMainWidget(vbox);
1097
1098 // Populate the left stack.
1099 this._sidebarPaneStack.showView(jsBreakpoints);
1100
1101 var tabbedLocation = WebInspector.viewManager.createTabbedLocation(this._r evealDebuggerSidebar.bind(this));
1102 splitWidget.setSidebarWidget(tabbedLocation.tabbedPane());
1103 tabbedLocation.appendView(scopeChainView);
1104 tabbedLocation.appendView(this._watchSidebarPane);
1105 this._extensionSidebarPanesContainer = tabbedLocation;
1106 this.sidebarPaneView = splitWidget;
1107 }
1108
1109 this._sidebarPaneStack.appendApplicableItems('sources-sidebar');
1110 var extensionSidebarPanes = WebInspector.extensionServer.sidebarPanes();
1111 for (var i = 0; i < extensionSidebarPanes.length; ++i)
1112 this._addExtensionSidebarPane(extensionSidebarPanes[i]);
1113
1114 this._splitWidget.setSidebarWidget(this.sidebarPaneView);
1115 }
1116
1117 /**
1118 * @return {!Promise}
1119 */
1120 _setAsCurrentPanel() {
1121 return WebInspector.viewManager.showView('sources');
1122 }
1123
1124 /**
1125 * @param {!WebInspector.Event} event
1126 */
1127 _extensionSidebarPaneAdded(event) {
1128 var pane = /** @type {!WebInspector.ExtensionSidebarPane} */ (event.data);
1129 this._addExtensionSidebarPane(pane);
1130 }
1131
1132 /**
1133 * @param {!WebInspector.ExtensionSidebarPane} pane
1134 */
1135 _addExtensionSidebarPane(pane) {
1136 if (pane.panelName() === this.name)
1137 this._extensionSidebarPanesContainer.appendView(pane);
1138 }
1139
1140 /**
1141 * @return {!WebInspector.SourcesView}
1142 */
1143 sourcesView() {
1144 return this._sourcesView;
1145 }
1146
1147 /**
1148 * @param {!DataTransfer} dataTransfer
1149 */
1150 _handleDrop(dataTransfer) {
1151 var items = dataTransfer.items;
1152 if (!items.length)
1153 return;
1154 var entry = items[0].webkitGetAsEntry();
1155 if (!entry.isDirectory)
1156 return;
1157 InspectorFrontendHost.upgradeDraggedFileSystemPermissions(entry.filesystem);
1158 }
1358 }; 1159 };
1359 1160
1161 WebInspector.SourcesPanel._lastModificationTimeout = 200;
1162
1163 WebInspector.SourcesPanel.minToolbarWidth = 215;
1164
1360 /** 1165 /**
1361 * @constructor 1166 * @implements {WebInspector.Revealer}
1362 * @extends {WebInspector.VBox} 1167 * @unrestricted
1363 */ 1168 */
1364 WebInspector.SourcesPanel.WrapperView = function() 1169 WebInspector.SourcesPanel.UILocationRevealer = class {
1365 { 1170 /**
1366 WebInspector.VBox.call(this); 1171 * @override
1367 this.element.classList.add("sources-view-wrapper"); 1172 * @param {!Object} uiLocation
1173 * @param {boolean=} omitFocus
1174 * @return {!Promise}
1175 */
1176 reveal(uiLocation, omitFocus) {
1177 if (!(uiLocation instanceof WebInspector.UILocation))
1178 return Promise.reject(new Error('Internal error: not a ui location'));
1179 WebInspector.SourcesPanel.instance().showUILocation(uiLocation, omitFocus);
1180 return Promise.resolve();
1181 }
1182 };
1183
1184 /**
1185 * @implements {WebInspector.Revealer}
1186 * @unrestricted
1187 */
1188 WebInspector.SourcesPanel.DebuggerLocationRevealer = class {
1189 /**
1190 * @override
1191 * @param {!Object} rawLocation
1192 * @param {boolean=} omitFocus
1193 * @return {!Promise}
1194 */
1195 reveal(rawLocation, omitFocus) {
1196 if (!(rawLocation instanceof WebInspector.DebuggerModel.Location))
1197 return Promise.reject(new Error('Internal error: not a debugger location') );
1198 WebInspector.SourcesPanel.instance().showUILocation(
1199 WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(rawLocatio n), omitFocus);
1200 return Promise.resolve();
1201 }
1202 };
1203
1204 /**
1205 * @implements {WebInspector.Revealer}
1206 * @unrestricted
1207 */
1208 WebInspector.SourcesPanel.UISourceCodeRevealer = class {
1209 /**
1210 * @override
1211 * @param {!Object} uiSourceCode
1212 * @param {boolean=} omitFocus
1213 * @return {!Promise}
1214 */
1215 reveal(uiSourceCode, omitFocus) {
1216 if (!(uiSourceCode instanceof WebInspector.UISourceCode))
1217 return Promise.reject(new Error('Internal error: not a ui source code'));
1218 WebInspector.SourcesPanel.instance().showUISourceCode(uiSourceCode, undefine d, undefined, omitFocus);
1219 return Promise.resolve();
1220 }
1221 };
1222
1223 /**
1224 * @implements {WebInspector.Revealer}
1225 * @unrestricted
1226 */
1227 WebInspector.SourcesPanel.DebuggerPausedDetailsRevealer = class {
1228 /**
1229 * @override
1230 * @param {!Object} object
1231 * @return {!Promise}
1232 */
1233 reveal(object) {
1234 return WebInspector.SourcesPanel.instance()._setAsCurrentPanel();
1235 }
1236 };
1237
1238 /**
1239 * @implements {WebInspector.ActionDelegate}
1240 * @unrestricted
1241 */
1242 WebInspector.SourcesPanel.RevealingActionDelegate = class {
1243 /**
1244 * @override
1245 * @param {!WebInspector.Context} context
1246 * @param {string} actionId
1247 * @return {boolean}
1248 */
1249 handleAction(context, actionId) {
1250 var panel = WebInspector.SourcesPanel.instance();
1251 if (!panel._ensureSourcesViewVisible())
1252 return false;
1253 switch (actionId) {
1254 case 'debugger.toggle-pause':
1255 panel._togglePause();
1256 return true;
1257 case 'sources.go-to-source':
1258 panel.showGoToSourceDialog();
1259 return true;
1260 }
1261 return false;
1262 }
1263 };
1264
1265 /**
1266 * @implements {WebInspector.ActionDelegate}
1267 * @unrestricted
1268 */
1269 WebInspector.SourcesPanel.DebuggingActionDelegate = class {
1270 /**
1271 * @override
1272 * @param {!WebInspector.Context} context
1273 * @param {string} actionId
1274 * @return {boolean}
1275 */
1276 handleAction(context, actionId) {
1277 var panel = WebInspector.SourcesPanel.instance();
1278 switch (actionId) {
1279 case 'debugger.step-over':
1280 panel._stepOver();
1281 return true;
1282 case 'debugger.step-into':
1283 panel._stepInto();
1284 return true;
1285 case 'debugger.step-out':
1286 panel._stepOut();
1287 return true;
1288 case 'debugger.run-snippet':
1289 panel._runSnippet();
1290 return true;
1291 case 'debugger.toggle-breakpoints-active':
1292 panel._toggleBreakpointsActive();
1293 return true;
1294 case 'debugger.evaluate-selection':
1295 var frame = WebInspector.context.flavor(WebInspector.UISourceCodeFrame);
1296 if (frame) {
1297 var text = frame.textEditor.text(frame.textEditor.selection());
1298 var executionContext = WebInspector.context.flavor(WebInspector.Execut ionContext);
1299 if (executionContext)
1300 WebInspector.ConsoleModel.evaluateCommandInConsole(executionContext, text);
1301 }
1302 return true;
1303 }
1304 return false;
1305 }
1306 };
1307
1308
1309 /**
1310 * @unrestricted
1311 */
1312 WebInspector.SourcesPanel.WrapperView = class extends WebInspector.VBox {
1313 constructor() {
1314 super();
1315 this.element.classList.add('sources-view-wrapper');
1368 WebInspector.SourcesPanel.WrapperView._instance = this; 1316 WebInspector.SourcesPanel.WrapperView._instance = this;
1369 this._view = WebInspector.SourcesPanel.instance()._sourcesView; 1317 this._view = WebInspector.SourcesPanel.instance()._sourcesView;
1318 }
1319
1320 /**
1321 * @return {boolean}
1322 */
1323 static isShowing() {
1324 return !!WebInspector.SourcesPanel.WrapperView._instance &&
1325 WebInspector.SourcesPanel.WrapperView._instance.isShowing();
1326 }
1327
1328 /**
1329 * @override
1330 */
1331 wasShown() {
1332 if (!WebInspector.SourcesPanel.instance().isShowing())
1333 this._showViewInWrapper();
1334 else
1335 WebInspector.inspectorView.setDrawerMinimized(true);
1336 WebInspector.SourcesPanel.updateResizerAndSidebarButtons(WebInspector.Source sPanel.instance());
1337 }
1338
1339 /**
1340 * @override
1341 */
1342 willHide() {
1343 WebInspector.inspectorView.setDrawerMinimized(false);
1344 setImmediate(() => WebInspector.SourcesPanel.updateResizerAndSidebarButtons( WebInspector.SourcesPanel.instance()));
1345 }
1346
1347 _showViewInWrapper() {
1348 this._view.show(this.element);
1349 }
1370 }; 1350 };
1371 1351
1372 WebInspector.SourcesPanel.WrapperView.prototype = { 1352
1373 wasShown: function()
1374 {
1375 if (!WebInspector.SourcesPanel.instance().isShowing())
1376 this._showViewInWrapper();
1377 else
1378 WebInspector.inspectorView.setDrawerMinimized(true);
1379 WebInspector.SourcesPanel.updateResizerAndSidebarButtons(WebInspector.So urcesPanel.instance());
1380 },
1381
1382 willHide: function()
1383 {
1384 WebInspector.inspectorView.setDrawerMinimized(false);
1385 setImmediate(() => WebInspector.SourcesPanel.updateResizerAndSidebarButt ons(WebInspector.SourcesPanel.instance()));
1386 },
1387
1388 _showViewInWrapper: function()
1389 {
1390 this._view.show(this.element);
1391 },
1392
1393 __proto__: WebInspector.VBox.prototype
1394 };
1395
1396 /**
1397 * @return {boolean}
1398 */
1399 WebInspector.SourcesPanel.WrapperView.isShowing = function()
1400 {
1401 return !!WebInspector.SourcesPanel.WrapperView._instance && WebInspector.Sou rcesPanel.WrapperView._instance.isShowing();
1402 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698