Web Inspector: Polish TabbedEditorContaner and ScriptsNavigator behavior.
[WebKit-https.git] / Source / WebCore / inspector / front-end / ScriptsPanel.js
1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  * Copyright (C) 2011 Google Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
25  */
26
27 importScript("BreakpointsSidebarPane.js");
28 importScript("CallStackSidebarPane.js");
29 importScript("FilteredItemSelectionDialog.js");
30 importScript("UISourceCodeFrame.js");
31 importScript("JavaScriptSourceFrame.js");
32 importScript("NavigatorOverlayController.js");
33 importScript("NavigatorView.js");
34 importScript("RevisionHistoryView.js");
35 importScript("ScopeChainSidebarPane.js");
36 importScript("ScriptsNavigator.js");
37 importScript("ScriptsSearchScope.js");
38 importScript("SnippetJavaScriptSourceFrame.js");
39 importScript("StyleSheetOutlineDialog.js");
40 importScript("TabbedEditorContainer.js");
41 importScript("WatchExpressionsSidebarPane.js");
42 importScript("WorkersSidebarPane.js");
43
44 /**
45  * @constructor
46  * @implements {WebInspector.TabbedEditorContainerDelegate}
47  * @implements {WebInspector.ContextMenu.Provider}
48  * @extends {WebInspector.Panel}
49  * @param {WebInspector.Workspace=} workspaceForTest
50  */
51 WebInspector.ScriptsPanel = function(workspaceForTest)
52 {
53     WebInspector.Panel.call(this, "scripts");
54     this.registerRequiredCSS("scriptsPanel.css");
55
56     WebInspector.settings.navigatorWasOnceHidden = WebInspector.settings.createSetting("navigatorWasOnceHidden", false);
57     WebInspector.settings.debuggerSidebarHidden = WebInspector.settings.createSetting("debuggerSidebarHidden", false);
58
59     this._workspace = workspaceForTest || WebInspector.workspace;
60
61     function viewGetter()
62     {
63         return this.visibleView;
64     }
65     WebInspector.GoToLineDialog.install(this, viewGetter.bind(this));
66
67     var helpSection = WebInspector.shortcutsScreen.section(WebInspector.UIString("Sources Panel"));
68     this.debugToolbar = this._createDebugToolbar();
69
70     const initialDebugSidebarWidth = 225;
71     const minimumDebugSidebarWidthPercent = 50;
72     this.createSidebarView(this.element, WebInspector.SidebarView.SidebarPosition.End, initialDebugSidebarWidth);
73     this.splitView.element.id = "scripts-split-view";
74     this.splitView.setMinimumSidebarWidth(Preferences.minScriptsSidebarWidth);
75     this.splitView.setMinimumMainWidthPercent(minimumDebugSidebarWidthPercent);
76
77     this.debugSidebarResizeWidgetElement = document.createElement("div");
78     this.debugSidebarResizeWidgetElement.id = "scripts-debug-sidebar-resizer-widget";
79     this.splitView.installResizer(this.debugSidebarResizeWidgetElement);
80
81     // Create scripts navigator
82     const initialNavigatorWidth = 225;
83     const minimumViewsContainerWidthPercent = 50;
84     this.editorView = new WebInspector.SidebarView(WebInspector.SidebarView.SidebarPosition.Start, "scriptsPanelNavigatorSidebarWidth", initialNavigatorWidth);
85     this.editorView.element.tabIndex = 0;
86
87     this.editorView.setMinimumSidebarWidth(Preferences.minScriptsSidebarWidth);
88     this.editorView.setMinimumMainWidthPercent(minimumViewsContainerWidthPercent);
89     this.editorView.show(this.splitView.mainElement);
90
91     this._navigator = new WebInspector.ScriptsNavigator();
92     this._navigator.view.show(this.editorView.sidebarElement);
93
94     this._editorContainer = new WebInspector.TabbedEditorContainer(this, "previouslyViewedFiles");
95     this._editorContainer.show(this.editorView.mainElement);
96
97     this._navigatorController = new WebInspector.NavigatorOverlayController(this.editorView, this._navigator.view, this._editorContainer.view);
98
99     this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.ScriptSelected, this._scriptSelected, this);
100     this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.SnippetCreationRequested, this._snippetCreationRequested, this);
101     this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.ItemRenamingRequested, this._itemRenamingRequested, this);
102     this._navigator.addEventListener(WebInspector.ScriptsNavigator.Events.FileRenamed, this._fileRenamed, this);
103
104     this._editorContainer.addEventListener(WebInspector.TabbedEditorContainer.Events.EditorSelected, this._editorSelected, this);
105     this._editorContainer.addEventListener(WebInspector.TabbedEditorContainer.Events.EditorClosed, this._editorClosed, this);
106
107     this.splitView.mainElement.appendChild(this.debugSidebarResizeWidgetElement);
108
109     this.sidebarPanes = {};
110     this.sidebarPanes.watchExpressions = new WebInspector.WatchExpressionsSidebarPane();
111     this.sidebarPanes.callstack = new WebInspector.CallStackSidebarPane();
112     this.sidebarPanes.scopechain = new WebInspector.ScopeChainSidebarPane();
113     this.sidebarPanes.jsBreakpoints = new WebInspector.JavaScriptBreakpointsSidebarPane(WebInspector.breakpointManager, this._showSourceLine.bind(this));
114     this.sidebarPanes.domBreakpoints = WebInspector.domBreakpointsSidebarPane.createProxy(this);
115     this.sidebarPanes.xhrBreakpoints = new WebInspector.XHRBreakpointsSidebarPane();
116     this.sidebarPanes.eventListenerBreakpoints = new WebInspector.EventListenerBreakpointsSidebarPane();
117
118     if (InspectorFrontendHost.canInspectWorkers() && !WebInspector.WorkerManager.isWorkerFrontend()) {
119         WorkerAgent.enable();
120         this.sidebarPanes.workerList = new WebInspector.WorkersSidebarPane(WebInspector.workerManager);
121     }
122
123     this.sidebarPanes.callstack.registerShortcuts(this.registerShortcuts.bind(this));
124     this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.EvaluateSelectionInConsole, this._evaluateSelectionInConsole.bind(this));
125     this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.GoToMember, this._showOutlineDialog.bind(this));
126     this.registerShortcuts(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.ToggleBreakpoint, this._toggleBreakpoint.bind(this));
127
128     var panelEnablerHeading = WebInspector.UIString("You need to enable debugging before you can use the Scripts panel.");
129     var panelEnablerDisclaimer = WebInspector.UIString("Enabling debugging will make scripts run slower.");
130     var panelEnablerButton = WebInspector.UIString("Enable Debugging");
131
132     this.panelEnablerView = new WebInspector.PanelEnablerView("scripts", panelEnablerHeading, panelEnablerDisclaimer, panelEnablerButton);
133     this.panelEnablerView.addEventListener("enable clicked", this._enableDebugging, this);
134
135     this.enableToggleButton = new WebInspector.StatusBarButton("", "enable-toggle-status-bar-item");
136     this.enableToggleButton.addEventListener("click", this._toggleDebugging, this);
137     if (!Capabilities.debuggerCausesRecompilation)
138         this.enableToggleButton.element.addStyleClass("hidden");
139
140     this._pauseOnExceptionButton = new WebInspector.StatusBarButton("", "scripts-pause-on-exceptions-status-bar-item", 3);
141     this._pauseOnExceptionButton.addEventListener("click", this._togglePauseOnExceptions, this);
142
143     this._toggleFormatSourceButton = new WebInspector.StatusBarButton(WebInspector.UIString("Pretty print"), "scripts-toggle-pretty-print-status-bar-item");
144     this._toggleFormatSourceButton.toggled = false;
145     this._toggleFormatSourceButton.addEventListener("click", this._toggleFormatSource, this);
146
147     this._scriptViewStatusBarItemsContainer = document.createElement("div");
148     this._scriptViewStatusBarItemsContainer.style.display = "inline-block";
149
150     this._installDebuggerSidebarController();
151
152     WebInspector.dockController.addEventListener(WebInspector.DockController.Events.DockSideChanged, this._dockSideChanged.bind(this));
153     WebInspector.settings.splitVerticallyWhenDockedToRight.addChangeListener(this._dockSideChanged.bind(this));
154     this._dockSideChanged();
155
156     this._sourceFramesByUISourceCode = new Map();
157     this._updateDebuggerButtons();
158     this._pauseOnExceptionStateChanged();
159     if (WebInspector.debuggerModel.isPaused())
160         this._debuggerPaused();
161
162     WebInspector.settings.pauseOnExceptionStateString.addChangeListener(this._pauseOnExceptionStateChanged, this);
163     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerWasEnabled, this._debuggerWasEnabled, this);
164     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerWasDisabled, this._debuggerWasDisabled, this);
165     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
166     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerResumed, this._debuggerResumed, this);
167     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.CallFrameSelected, this._callFrameSelected, this);
168     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ConsoleCommandEvaluatedInSelectedCallFrame, this._consoleCommandEvaluatedInSelectedCallFrame, this);
169     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ExecutionLineChanged, this._executionLineChanged, this);
170     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointsActiveStateChanged, this._breakpointsActiveStateChanged, this);
171
172     WebInspector.startBatchUpdate();
173     var uiSourceCodes = this._workspace.uiSourceCodes();
174     for (var i = 0; i < uiSourceCodes.length; ++i)
175         this._addUISourceCode(uiSourceCodes[i]);
176     WebInspector.endBatchUpdate();
177
178     this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, this._uiSourceCodeAdded, this);
179     this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, this._uiSourceCodeRemoved, this);
180     this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._projectWillReset.bind(this), this);
181     WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
182
183     WebInspector.advancedSearchController.registerSearchScope(new WebInspector.ScriptsSearchScope(this._workspace));
184 }
185
186 WebInspector.ScriptsPanel.prototype = {
187     get statusBarItems()
188     {
189         return [this.enableToggleButton.element, this._pauseOnExceptionButton.element, this._toggleFormatSourceButton.element, this._scriptViewStatusBarItemsContainer];
190     },
191
192     /**
193      * @return {?Element}
194      */
195     statusBarText: function()
196     {
197         var sourceFrame = this.visibleView;
198         return sourceFrame ? sourceFrame.statusBarText() : null;
199     },
200
201     defaultFocusedElement: function()
202     {
203         return this._editorContainer.view.defaultFocusedElement() || this._navigator.view.defaultFocusedElement();
204     },
205
206     get paused()
207     {
208         return this._paused;
209     },
210
211     wasShown: function()
212     {
213         WebInspector.Panel.prototype.wasShown.call(this);
214         this._navigatorController.wasShown();
215     },
216
217     willHide: function()
218     {
219         WebInspector.Panel.prototype.willHide.call(this);
220         WebInspector.closeViewInDrawer();
221     },
222
223     /**
224      * @param {WebInspector.Event} event
225      */
226     _uiSourceCodeAdded: function(event)
227     {
228         var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data);
229         this._addUISourceCode(uiSourceCode);
230     },
231
232     /**
233      * @param {WebInspector.UISourceCode} uiSourceCode
234      */
235     _addUISourceCode: function(uiSourceCode)
236     {
237         if (this._toggleFormatSourceButton.toggled)
238             uiSourceCode.setFormatted(true);
239         if (uiSourceCode.project().isServiceProject())
240             return;
241         this._navigator.addUISourceCode(uiSourceCode);
242         this._editorContainer.addUISourceCode(uiSourceCode);
243         // Replace debugger script-based uiSourceCode with a network-based one.
244         var currentUISourceCode = this._currentUISourceCode;
245         if (currentUISourceCode && currentUISourceCode.project().isServiceProject() && currentUISourceCode !== uiSourceCode && currentUISourceCode.url === uiSourceCode.url) {
246             this._showFile(uiSourceCode);
247             this._editorContainer.removeUISourceCode(currentUISourceCode);
248         }
249     },
250
251     _uiSourceCodeRemoved: function(event)
252     {
253         var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data);
254         this._removeUISourceCodes([uiSourceCode]);
255     },
256
257     /**
258      * @param {Array.<WebInspector.UISourceCode>} uiSourceCodes
259      */
260     _removeUISourceCodes: function(uiSourceCodes)
261     {
262         for (var i = 0; i < uiSourceCodes.length; ++i) {
263             this._navigator.removeUISourceCode(uiSourceCodes[i]);
264             this._removeSourceFrame(uiSourceCodes[i]);
265         }
266         this._editorContainer.removeUISourceCodes(uiSourceCodes);
267     },
268
269     _consoleCommandEvaluatedInSelectedCallFrame: function(event)
270     {
271         this.sidebarPanes.scopechain.update(WebInspector.debuggerModel.selectedCallFrame());
272     },
273
274     _debuggerPaused: function()
275     {
276         var details = WebInspector.debuggerModel.debuggerPausedDetails();
277
278         this._paused = true;
279         this._waitingToPause = false;
280         this._stepping = false;
281
282         this._updateDebuggerButtons();
283
284         WebInspector.inspectorView.setCurrentPanel(this);
285         this.sidebarPanes.callstack.update(details.callFrames);
286
287         if (details.reason === WebInspector.DebuggerModel.BreakReason.DOM) {
288             WebInspector.domBreakpointsSidebarPane.highlightBreakpoint(details.auxData);
289             function didCreateBreakpointHitStatusMessage(element)
290             {
291                 this.sidebarPanes.callstack.setStatus(element);
292             }
293             WebInspector.domBreakpointsSidebarPane.createBreakpointHitStatusMessage(details.auxData, didCreateBreakpointHitStatusMessage.bind(this));
294         } else if (details.reason === WebInspector.DebuggerModel.BreakReason.EventListener) {
295             var eventName = details.auxData.eventName;
296             this.sidebarPanes.eventListenerBreakpoints.highlightBreakpoint(details.auxData.eventName);
297             var eventNameForUI = WebInspector.EventListenerBreakpointsSidebarPane.eventNameForUI(eventName);
298             this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a \"%s\" Event Listener.", eventNameForUI));
299         } else if (details.reason === WebInspector.DebuggerModel.BreakReason.XHR) {
300             this.sidebarPanes.xhrBreakpoints.highlightBreakpoint(details.auxData["breakpointURL"]);
301             this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a XMLHttpRequest."));
302         } else if (details.reason === WebInspector.DebuggerModel.BreakReason.Exception)
303             this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on exception: '%s'.", details.auxData.description));
304         else if (details.reason === WebInspector.DebuggerModel.BreakReason.Assert)
305             this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on assertion."));
306         else if (details.reason === WebInspector.DebuggerModel.BreakReason.CSPViolation)
307             this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a script blocked due to Content Security Policy directive: \"%s\".", details.auxData["directiveText"]));
308         else {
309             function didGetUILocation(uiLocation)
310             {
311                 var breakpoint = WebInspector.breakpointManager.findBreakpoint(uiLocation.uiSourceCode, uiLocation.lineNumber);
312                 if (!breakpoint)
313                     return;
314                 this.sidebarPanes.jsBreakpoints.highlightBreakpoint(breakpoint);
315                 this.sidebarPanes.callstack.setStatus(WebInspector.UIString("Paused on a JavaScript breakpoint."));
316             }
317             if (details.callFrames.length) 
318                 details.callFrames[0].createLiveLocation(didGetUILocation.bind(this));
319             else
320                 console.warn("ScriptsPanel paused, but callFrames.length is zero."); // TODO remove this once we understand this case better
321         }
322
323         this._showDebuggerSidebar();
324         this._toggleDebuggerSidebarButton.setEnabled(false);
325         window.focus();
326         InspectorFrontendHost.bringToFront();
327     },
328
329     _debuggerResumed: function()
330     {
331         this._paused = false;
332         this._waitingToPause = false;
333         this._stepping = false;
334
335         this._clearInterface();
336         this._toggleDebuggerSidebarButton.setEnabled(true);
337     },
338
339     _debuggerWasEnabled: function()
340     {
341         this._updateDebuggerButtons();
342     },
343
344     _debuggerWasDisabled: function()
345     {
346         this._debuggerReset();
347     },
348
349     _debuggerReset: function()
350     {
351         this._debuggerResumed();
352         this.sidebarPanes.watchExpressions.reset();
353     },
354
355     _projectWillReset: function(event)
356     {
357         var project = event.data;
358         var uiSourceCodes = project.uiSourceCodes();
359         this._removeUISourceCodes(uiSourceCodes);
360         if (project.type() === WebInspector.projectTypes.Network)
361             this._editorContainer.reset();
362     },
363
364     get visibleView()
365     {
366         return this._editorContainer.visibleView;
367     },
368
369     _updateScriptViewStatusBarItems: function()
370     {
371         this._scriptViewStatusBarItemsContainer.removeChildren();
372
373         var sourceFrame = this.visibleView;
374         if (sourceFrame) {
375             var statusBarItems = sourceFrame.statusBarItems() || [];
376             for (var i = 0; i < statusBarItems.length; ++i)
377                 this._scriptViewStatusBarItemsContainer.appendChild(statusBarItems[i]);
378         }
379     },
380
381     canShowAnchorLocation: function(anchor)
382     {
383         if (WebInspector.debuggerModel.debuggerEnabled() && anchor.uiSourceCode)
384             return true;
385         var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(anchor.href);
386         if (uiSourceCode) {
387             anchor.uiSourceCode = uiSourceCode;
388             return true;
389         }
390         return false;
391     },
392
393     showAnchorLocation: function(anchor)
394     {
395         this._showSourceLine(anchor.uiSourceCode, anchor.lineNumber);
396     },
397
398     /**
399      * @param {WebInspector.UISourceCode} uiSourceCode
400      * @param {number} lineNumber
401      */
402     showUISourceCode: function(uiSourceCode, lineNumber)
403     {
404         this._showSourceLine(uiSourceCode, lineNumber);
405     },
406
407     /**
408      * @param {WebInspector.UISourceCode} uiSourceCode
409      * @param {number=} lineNumber
410      */
411     _showSourceLine: function(uiSourceCode, lineNumber)
412     {
413         var sourceFrame = this._showFile(uiSourceCode);
414         if (typeof lineNumber === "number")
415             sourceFrame.highlightLine(lineNumber);
416         sourceFrame.focus();
417
418         WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
419             action: WebInspector.UserMetrics.UserActionNames.OpenSourceLink,
420             url: uiSourceCode.originURL(),
421             lineNumber: lineNumber
422         });
423     },
424
425     /**
426      * @param {WebInspector.UISourceCode} uiSourceCode
427      * @return {WebInspector.SourceFrame}
428      */
429     _showFile: function(uiSourceCode)
430     {
431         var sourceFrame = this._getOrCreateSourceFrame(uiSourceCode);
432         if (this._currentUISourceCode === uiSourceCode)
433             return sourceFrame;
434         this._currentUISourceCode = uiSourceCode;
435         if (!uiSourceCode.project().isServiceProject())
436             this._navigator.revealUISourceCode(uiSourceCode, true);
437         this._editorContainer.showFile(uiSourceCode);
438         this._updateScriptViewStatusBarItems();
439
440         return sourceFrame;
441     },
442
443     /**
444      * @param {WebInspector.UISourceCode} uiSourceCode
445      * @return {WebInspector.SourceFrame}
446      */
447     _createSourceFrame: function(uiSourceCode)
448     {
449         var sourceFrame;
450         switch (uiSourceCode.contentType()) {
451         case WebInspector.resourceTypes.Script:
452             if (uiSourceCode.project().type() === WebInspector.projectTypes.Snippets)
453                 sourceFrame = new WebInspector.SnippetJavaScriptSourceFrame(this, uiSourceCode);
454             else
455                 sourceFrame = new WebInspector.JavaScriptSourceFrame(this, uiSourceCode);
456             break;
457         case WebInspector.resourceTypes.Document:
458             sourceFrame = new WebInspector.JavaScriptSourceFrame(this, uiSourceCode);
459             break;
460         case WebInspector.resourceTypes.Stylesheet:
461         default:
462             sourceFrame = new WebInspector.UISourceCodeFrame(uiSourceCode);
463         break;
464         }
465         this._sourceFramesByUISourceCode.put(uiSourceCode, sourceFrame);
466         return sourceFrame;
467     },
468
469     /**
470      * @param {WebInspector.UISourceCode} uiSourceCode
471      * @return {WebInspector.SourceFrame}
472      */
473     _getOrCreateSourceFrame: function(uiSourceCode)
474     {
475         return this._sourceFramesByUISourceCode.get(uiSourceCode) || this._createSourceFrame(uiSourceCode);
476     },
477
478     /**
479      * @param {WebInspector.UISourceCode} uiSourceCode
480      * @return {WebInspector.SourceFrame}
481      */
482     viewForFile: function(uiSourceCode)
483     {
484         return this._getOrCreateSourceFrame(uiSourceCode);
485     },
486
487     /**
488      * @param {WebInspector.UISourceCode} uiSourceCode
489      */
490     _removeSourceFrame: function(uiSourceCode)
491     {
492         var sourceFrame = this._sourceFramesByUISourceCode.get(uiSourceCode);
493         if (!sourceFrame)
494             return;
495         this._sourceFramesByUISourceCode.remove(uiSourceCode);
496         sourceFrame.detach();
497     },
498
499     _clearCurrentExecutionLine: function()
500     {
501         if (this._executionSourceFrame)
502             this._executionSourceFrame.clearExecutionLine();
503         delete this._executionSourceFrame;
504     },
505
506     _executionLineChanged: function(event)
507     {
508         var uiLocation = event.data;
509
510         this._clearCurrentExecutionLine();
511         if (!uiLocation)
512             return;
513         var sourceFrame = this._getOrCreateSourceFrame(uiLocation.uiSourceCode);
514         sourceFrame.setExecutionLine(uiLocation.lineNumber);
515         this._executionSourceFrame = sourceFrame;
516     },
517
518     _revealExecutionLine: function(uiLocation)
519     {
520         var uiSourceCode = uiLocation.uiSourceCode;
521         // Some scripts (anonymous and snippets evaluations) are not added to files select by default.
522         if (this._currentUISourceCode && this._currentUISourceCode.scriptFile() && this._currentUISourceCode.scriptFile().isDivergingFromVM())
523             return;
524         if (this._toggleFormatSourceButton.toggled && !uiSourceCode.formatted())
525             uiSourceCode.setFormatted(true);
526         var sourceFrame = this._showFile(uiSourceCode);
527         sourceFrame.revealLine(uiLocation.lineNumber);
528         sourceFrame.focus();
529     },
530
531     _callFrameSelected: function(event)
532     {
533         var callFrame = event.data;
534
535         if (!callFrame)
536             return;
537
538         this.sidebarPanes.scopechain.update(callFrame);
539         this.sidebarPanes.watchExpressions.refreshExpressions();
540         this.sidebarPanes.callstack.setSelectedCallFrame(callFrame);
541         callFrame.createLiveLocation(this._revealExecutionLine.bind(this));
542     },
543
544     _editorClosed: function(event)
545     {
546         this._navigatorController.hideNavigatorOverlay();
547         var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data);
548
549         if (this._currentUISourceCode === uiSourceCode)
550             delete this._currentUISourceCode;
551
552         // ScriptsNavigator does not need to update on EditorClosed.
553         this._updateScriptViewStatusBarItems();
554         WebInspector.searchController.resetSearch();
555     },
556
557     _editorSelected: function(event)
558     {
559         var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data);
560         var sourceFrame = this._showFile(uiSourceCode);
561         this._navigatorController.hideNavigatorOverlay();
562         sourceFrame.focus();
563         WebInspector.searchController.resetSearch();
564     },
565
566     _scriptSelected: function(event)
567     {
568         var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data.uiSourceCode);
569         var sourceFrame = this._showFile(uiSourceCode);
570         this._navigatorController.hideNavigatorOverlay();
571         if (sourceFrame && event.data.focusSource)
572             sourceFrame.focus();
573     },
574
575     _pauseOnExceptionStateChanged: function()
576     {
577         var pauseOnExceptionsState = WebInspector.settings.pauseOnExceptionStateString.get();
578         switch (pauseOnExceptionsState) {
579         case WebInspector.DebuggerModel.PauseOnExceptionsState.DontPauseOnExceptions:
580             this._pauseOnExceptionButton.title = WebInspector.UIString("Don't pause on exceptions.\nClick to Pause on all exceptions.");
581             break;
582         case WebInspector.DebuggerModel.PauseOnExceptionsState.PauseOnAllExceptions:
583             this._pauseOnExceptionButton.title = WebInspector.UIString("Pause on all exceptions.\nClick to Pause on uncaught exceptions.");
584             break;
585         case WebInspector.DebuggerModel.PauseOnExceptionsState.PauseOnUncaughtExceptions:
586             this._pauseOnExceptionButton.title = WebInspector.UIString("Pause on uncaught exceptions.\nClick to Not pause on exceptions.");
587             break;
588         }
589         this._pauseOnExceptionButton.state = pauseOnExceptionsState;
590     },
591
592     _updateDebuggerButtons: function()
593     {
594         if (WebInspector.debuggerModel.debuggerEnabled()) {
595             this.enableToggleButton.title = WebInspector.UIString("Debugging enabled. Click to disable.");
596             this.enableToggleButton.toggled = true;
597             this._pauseOnExceptionButton.visible = true;
598             this.panelEnablerView.detach();
599         } else {
600             this.enableToggleButton.title = WebInspector.UIString("Debugging disabled. Click to enable.");
601             this.enableToggleButton.toggled = false;
602             this._pauseOnExceptionButton.visible = false;
603             this.panelEnablerView.show(this.element);
604         }
605
606         if (this._paused) {
607             this._updateButtonTitle(this.pauseButton, WebInspector.UIString("Resume script execution (%s)."))
608             this.pauseButton.addStyleClass("paused");
609
610             this.pauseButton.disabled = false;
611             this.stepOverButton.disabled = false;
612             this.stepIntoButton.disabled = false;
613             this.stepOutButton.disabled = false;
614
615             this.debuggerStatusElement.textContent = WebInspector.UIString("Paused");
616         } else {
617             this._updateButtonTitle(this.pauseButton, WebInspector.UIString("Pause script execution (%s)."))
618             this.pauseButton.removeStyleClass("paused");
619
620             this.pauseButton.disabled = this._waitingToPause;
621             this.stepOverButton.disabled = true;
622             this.stepIntoButton.disabled = true;
623             this.stepOutButton.disabled = true;
624
625             if (this._waitingToPause)
626                 this.debuggerStatusElement.textContent = WebInspector.UIString("Pausing");
627             else if (this._stepping)
628                 this.debuggerStatusElement.textContent = WebInspector.UIString("Stepping");
629             else
630                 this.debuggerStatusElement.textContent = "";
631         }
632     },
633
634     _clearInterface: function()
635     {
636         this.sidebarPanes.callstack.update(null);
637         this.sidebarPanes.scopechain.update(null);
638         this.sidebarPanes.jsBreakpoints.clearBreakpointHighlight();
639         WebInspector.domBreakpointsSidebarPane.clearBreakpointHighlight();
640         this.sidebarPanes.eventListenerBreakpoints.clearBreakpointHighlight();
641         this.sidebarPanes.xhrBreakpoints.clearBreakpointHighlight();
642
643         this._clearCurrentExecutionLine();
644         this._updateDebuggerButtons();
645     },
646
647     _enableDebugging: function()
648     {
649         this._toggleDebugging(this.panelEnablerView.alwaysEnabled);
650     },
651
652     _toggleDebugging: function(optionalAlways)
653     {
654         this._paused = false;
655         this._waitingToPause = false;
656         this._stepping = false;
657
658         if (WebInspector.debuggerModel.debuggerEnabled()) {
659             WebInspector.settings.debuggerEnabled.set(false);
660             WebInspector.debuggerModel.disableDebugger();
661         } else {
662             WebInspector.settings.debuggerEnabled.set(!!optionalAlways);
663             WebInspector.debuggerModel.enableDebugger();
664         }
665     },
666
667     _togglePauseOnExceptions: function()
668     {
669         var nextStateMap = {};
670         var stateEnum = WebInspector.DebuggerModel.PauseOnExceptionsState;
671         nextStateMap[stateEnum.DontPauseOnExceptions] = stateEnum.PauseOnAllExceptions;
672         nextStateMap[stateEnum.PauseOnAllExceptions] = stateEnum.PauseOnUncaughtExceptions;
673         nextStateMap[stateEnum.PauseOnUncaughtExceptions] = stateEnum.DontPauseOnExceptions;
674         WebInspector.settings.pauseOnExceptionStateString.set(nextStateMap[this._pauseOnExceptionButton.state]);
675     },
676
677     _togglePause: function()
678     {
679         if (this._paused) {
680             this._paused = false;
681             this._waitingToPause = false;
682             DebuggerAgent.resume();
683         } else {
684             this._stepping = false;
685             this._waitingToPause = true;
686             DebuggerAgent.pause();
687         }
688
689         this._clearInterface();
690     },
691
692     _stepOverClicked: function()
693     {
694         if (!this._paused)
695             return;
696
697         this._paused = false;
698         this._stepping = true;
699
700         this._clearInterface();
701
702         DebuggerAgent.stepOver();
703     },
704
705     _stepIntoClicked: function()
706     {
707         if (!this._paused)
708             return;
709
710         this._paused = false;
711         this._stepping = true;
712
713         this._clearInterface();
714
715         DebuggerAgent.stepInto();
716     },
717
718     _stepOutClicked: function()
719     {
720         if (!this._paused)
721             return;
722
723         this._paused = false;
724         this._stepping = true;
725
726         this._clearInterface();
727
728         DebuggerAgent.stepOut();
729     },
730
731     _toggleBreakpointsClicked: function(event)
732     {
733         WebInspector.debuggerModel.setBreakpointsActive(!WebInspector.debuggerModel.breakpointsActive());
734     },
735
736     _breakpointsActiveStateChanged: function(event)
737     {
738         var active = event.data;
739         this._toggleBreakpointsButton.toggled = active;
740         if (active) {
741             this._toggleBreakpointsButton.title = WebInspector.UIString("Deactivate breakpoints.");
742             WebInspector.inspectorView.element.removeStyleClass("breakpoints-deactivated");
743             this.sidebarPanes.jsBreakpoints.listElement.removeStyleClass("breakpoints-list-deactivated");
744         } else {
745             this._toggleBreakpointsButton.title = WebInspector.UIString("Activate breakpoints.");
746             WebInspector.inspectorView.element.addStyleClass("breakpoints-deactivated");
747             this.sidebarPanes.jsBreakpoints.listElement.addStyleClass("breakpoints-list-deactivated");
748         }
749     },
750
751     _evaluateSelectionInConsole: function()
752     {
753         var selection = window.getSelection();
754         if (selection.type !== "Range" || selection.isCollapsed)
755             return false;
756         WebInspector.evaluateInConsole(selection.toString());
757         return true;
758     },
759
760     _createDebugToolbar: function()
761     {
762         var debugToolbar = document.createElement("div");
763         debugToolbar.className = "status-bar";
764         debugToolbar.id = "scripts-debug-toolbar";
765
766         var title, handler;
767         var platformSpecificModifier = WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta;
768
769         // Continue.
770         handler = this._togglePause.bind(this);
771         this.pauseButton = this._createButtonAndRegisterShortcuts("scripts-pause", "", handler, WebInspector.ScriptsPanelDescriptor.ShortcutKeys.PauseContinue);
772         debugToolbar.appendChild(this.pauseButton);
773
774         // Step over.
775         title = WebInspector.UIString("Step over next function call (%s).");
776         handler = this._stepOverClicked.bind(this);
777         this.stepOverButton = this._createButtonAndRegisterShortcuts("scripts-step-over", title, handler, WebInspector.ScriptsPanelDescriptor.ShortcutKeys.StepOver);
778         debugToolbar.appendChild(this.stepOverButton);
779
780         // Step into.
781         title = WebInspector.UIString("Step into next function call (%s).");
782         handler = this._stepIntoClicked.bind(this);
783         this.stepIntoButton = this._createButtonAndRegisterShortcuts("scripts-step-into", title, handler, WebInspector.ScriptsPanelDescriptor.ShortcutKeys.StepInto);
784         debugToolbar.appendChild(this.stepIntoButton);
785
786         // Step out.
787         title = WebInspector.UIString("Step out of current function (%s).");
788         handler = this._stepOutClicked.bind(this);
789         this.stepOutButton = this._createButtonAndRegisterShortcuts("scripts-step-out", title, handler, WebInspector.ScriptsPanelDescriptor.ShortcutKeys.StepOut);
790         debugToolbar.appendChild(this.stepOutButton);
791
792         this._toggleBreakpointsButton = new WebInspector.StatusBarButton(WebInspector.UIString("Deactivate breakpoints."), "toggle-breakpoints");
793         this._toggleBreakpointsButton.toggled = true;
794         this._toggleBreakpointsButton.addEventListener("click", this._toggleBreakpointsClicked, this);
795         debugToolbar.appendChild(this._toggleBreakpointsButton.element);
796
797         this.debuggerStatusElement = document.createElement("div");
798         this.debuggerStatusElement.id = "scripts-debugger-status";
799         debugToolbar.appendChild(this.debuggerStatusElement);
800
801         return debugToolbar;
802     },
803
804     _updateButtonTitle: function(button, buttonTitle)
805     {
806         button.buttonTitle = buttonTitle;
807         var hasShortcuts = button.shortcuts && button.shortcuts.length;
808         if (hasShortcuts)
809             button.title = String.vsprintf(buttonTitle, [button.shortcuts[0].name]);
810         else
811             button.title = buttonTitle;
812     },
813
814     /**
815      * @param {string} buttonId
816      * @param {string} buttonTitle
817      * @param {function(Event)} handler
818      * @param {!Array.<!WebInspector.KeyboardShortcut.Descriptor>} shortcuts
819      */
820     _createButtonAndRegisterShortcuts: function(buttonId, buttonTitle, handler, shortcuts)
821     {
822         var button = document.createElement("button");
823         button.className = "status-bar-item";
824         button.id = buttonId;
825         button.shortcuts = shortcuts;
826         this._updateButtonTitle(button, buttonTitle);
827         button.disabled = true;
828         button.appendChild(document.createElement("img"));
829         button.addEventListener("click", handler, false);
830
831         this.registerShortcuts(shortcuts, handler);
832
833         return button;
834     },
835
836     searchCanceled: function()
837     {
838         if (this._searchView)
839             this._searchView.searchCanceled();
840
841         delete this._searchView;
842         delete this._searchQuery;
843     },
844
845     /**
846      * @param {string} query
847      */
848     performSearch: function(query)
849     {
850         WebInspector.searchController.updateSearchMatchesCount(0, this);
851
852         if (!this.visibleView)
853             return;
854
855         // Call searchCanceled since it will reset everything we need before doing a new search.
856         this.searchCanceled();
857
858         this._searchView = this.visibleView;
859         this._searchQuery = query;
860
861         function finishedCallback(view, searchMatches)
862         {
863             if (!searchMatches)
864                 return;
865
866             WebInspector.searchController.updateSearchMatchesCount(searchMatches, this);
867             view.jumpToNextSearchResult();
868             WebInspector.searchController.updateCurrentMatchIndex(view.currentSearchResultIndex, this);
869         }
870
871         this._searchView.performSearch(query, finishedCallback.bind(this));
872     },
873
874     jumpToNextSearchResult: function()
875     {
876         if (!this._searchView)
877             return;
878
879         if (this._searchView !== this.visibleView) {
880             this.performSearch(this._searchQuery);
881             return;
882         }
883
884         if (this._searchView.showingLastSearchResult())
885             this._searchView.jumpToFirstSearchResult();
886         else
887             this._searchView.jumpToNextSearchResult();
888         WebInspector.searchController.updateCurrentMatchIndex(this._searchView.currentSearchResultIndex, this);
889         return true;
890     },
891
892     jumpToPreviousSearchResult: function()
893     {
894         if (!this._searchView)
895             return;
896
897         if (this._searchView !== this.visibleView) {
898             this.performSearch(this._searchQuery);
899             if (this._searchView)
900                 this._searchView.jumpToLastSearchResult();
901             return;
902         }
903
904         if (this._searchView.showingFirstSearchResult())
905             this._searchView.jumpToLastSearchResult();
906         else
907             this._searchView.jumpToPreviousSearchResult();
908         WebInspector.searchController.updateCurrentMatchIndex(this._searchView.currentSearchResultIndex, this);
909     },
910
911     /**
912      * @return {boolean}
913      */
914     canSearchAndReplace: function()
915     {
916         var view = /** @type {WebInspector.SourceFrame} */ (this.visibleView);
917         return !!view && view.canEditSource();
918     },
919
920     /**
921      * @param {string} text
922      */
923     replaceSelectionWith: function(text)
924     {
925         var view = /** @type {WebInspector.SourceFrame} */ (this.visibleView);
926         view.replaceSearchMatchWith(text);
927     },
928
929     /**
930      * @param {string} query
931      * @param {string} text
932      */
933     replaceAllWith: function(query, text)
934     {
935         var view = /** @type {WebInspector.SourceFrame} */ (this.visibleView);
936         view.replaceAllWith(query, text);
937     },
938
939     _toggleFormatSource: function()
940     {
941         this._toggleFormatSourceButton.toggled = !this._toggleFormatSourceButton.toggled;
942         var uiSourceCodes = this._workspace.uiSourceCodes();
943         for (var i = 0; i < uiSourceCodes.length; ++i)
944             uiSourceCodes[i].setFormatted(this._toggleFormatSourceButton.toggled);
945
946         WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
947             action: WebInspector.UserMetrics.UserActionNames.TogglePrettyPrint,
948             enabled: this._toggleFormatSourceButton.toggled,
949             url: this._editorContainer.currentFile().originURL()
950         });
951     },
952
953     addToWatch: function(expression)
954     {
955         this.sidebarPanes.watchExpressions.addExpression(expression);
956     },
957
958     _toggleBreakpoint: function()
959     {
960         var sourceFrame = this.visibleView;
961         if (!sourceFrame)
962             return false;
963
964         if (sourceFrame instanceof WebInspector.JavaScriptSourceFrame) {
965             var javaScriptSourceFrame = /** @type {WebInspector.JavaScriptSourceFrame} */ (sourceFrame);
966             javaScriptSourceFrame.toggleBreakpointOnCurrentLine();
967             return true;
968         }
969         return false;
970     },
971
972     _showOutlineDialog: function()
973     {
974         var uiSourceCode = this._editorContainer.currentFile();
975         if (!uiSourceCode)
976             return false;
977
978         switch (uiSourceCode.contentType()) {
979         case WebInspector.resourceTypes.Document:
980         case WebInspector.resourceTypes.Script:
981             WebInspector.JavaScriptOutlineDialog.show(this.visibleView, uiSourceCode);
982             return true;
983         case WebInspector.resourceTypes.Stylesheet:
984             WebInspector.StyleSheetOutlineDialog.show(this.visibleView, uiSourceCode);
985             return true;
986         }
987         return false;
988     },
989
990     _installDebuggerSidebarController: function()
991     {
992         this._toggleDebuggerSidebarButton = new WebInspector.StatusBarButton(WebInspector.UIString("Hide debugger"), "scripts-debugger-show-hide-button", 3);
993         this._toggleDebuggerSidebarButton.state = "shown";
994         this._toggleDebuggerSidebarButton.addEventListener("click", clickHandler, this);
995
996         function clickHandler()
997         {
998             if (this._toggleDebuggerSidebarButton.state === "shown")
999                 this._hideDebuggerSidebar();
1000             else
1001                 this._showDebuggerSidebar();
1002         }
1003         this.editorView.element.appendChild(this._toggleDebuggerSidebarButton.element);
1004
1005         if (WebInspector.settings.debuggerSidebarHidden.get())
1006             this._hideDebuggerSidebar();
1007
1008     },
1009
1010     _showDebuggerSidebar: function()
1011     {
1012         if (this._toggleDebuggerSidebarButton.state === "shown")
1013             return;
1014         this._toggleDebuggerSidebarButton.state = "shown";
1015         this._toggleDebuggerSidebarButton.title = WebInspector.UIString("Hide debugger");
1016         this.splitView.showSidebarElement();
1017         this.debugSidebarResizeWidgetElement.removeStyleClass("hidden");
1018         WebInspector.settings.debuggerSidebarHidden.set(false);
1019     },
1020
1021     _hideDebuggerSidebar: function()
1022     {
1023         if (this._toggleDebuggerSidebarButton.state === "hidden")
1024             return;
1025         this._toggleDebuggerSidebarButton.state = "hidden";
1026         this._toggleDebuggerSidebarButton.title = WebInspector.UIString("Show debugger");
1027         this.splitView.hideSidebarElement();
1028         this.debugSidebarResizeWidgetElement.addStyleClass("hidden");
1029         WebInspector.settings.debuggerSidebarHidden.set(true);
1030     },
1031
1032     _fileRenamed: function(event)
1033     {
1034         var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data.uiSourceCode);
1035         var name = /** @type {string} */ (event.data.name);
1036         if (uiSourceCode.project().type() !== WebInspector.projectTypes.Snippets)
1037             return;
1038         WebInspector.scriptSnippetModel.renameScriptSnippet(uiSourceCode, name);
1039         uiSourceCode.rename(name);
1040     },
1041         
1042     /**
1043      * @param {WebInspector.Event} event
1044      */
1045     _snippetCreationRequested: function(event)
1046     {
1047         var uiSourceCode = WebInspector.scriptSnippetModel.createScriptSnippet();
1048         this._showSourceLine(uiSourceCode);
1049         
1050         var shouldHideNavigator = !this._navigatorController.isNavigatorPinned();
1051         if (this._navigatorController.isNavigatorHidden())
1052             this._navigatorController.showNavigatorOverlay();
1053         this._navigator.rename(uiSourceCode, callback.bind(this));
1054     
1055         /**
1056          * @param {boolean} committed
1057          */
1058         function callback(committed)
1059         {
1060             if (shouldHideNavigator)
1061                 this._navigatorController.hideNavigatorOverlay();
1062
1063             if (!committed) {
1064                 WebInspector.scriptSnippetModel.deleteScriptSnippet(uiSourceCode);
1065                 return;
1066             }
1067
1068             this._showSourceLine(uiSourceCode);
1069         }
1070     },
1071
1072     /**
1073      * @param {WebInspector.Event} event
1074      */
1075     _itemRenamingRequested: function(event)
1076     {
1077         var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (event.data);
1078         
1079         var shouldHideNavigator = !this._navigatorController.isNavigatorPinned();
1080         if (this._navigatorController.isNavigatorHidden())
1081             this._navigatorController.showNavigatorOverlay();
1082         this._navigator.rename(uiSourceCode, callback.bind(this));
1083     
1084         /**
1085          * @param {boolean} committed
1086          */
1087         function callback(committed)
1088         {
1089             if (shouldHideNavigator && committed) {
1090                 this._navigatorController.hideNavigatorOverlay();
1091                 this._showSourceLine(uiSourceCode);
1092             }
1093         }
1094     },
1095
1096     /**
1097      * @param {WebInspector.UISourceCode} uiSourceCode
1098      */
1099     _showLocalHistory: function(uiSourceCode)
1100     {
1101         WebInspector.RevisionHistoryView.showHistory(uiSourceCode);
1102     },
1103
1104     /**
1105      * @param {WebInspector.ContextMenu} contextMenu
1106      * @param {Object} target
1107      */
1108     appendApplicableItems: function(event, contextMenu, target)
1109     {
1110         this._appendUISourceCodeItems(contextMenu, target);
1111         this._appendFunctionItems(contextMenu, target);
1112     },
1113
1114     /** 
1115      * @param {WebInspector.UISourceCode} uiSourceCode
1116      */
1117     _mapFileSystemToNetwork: function(uiSourceCode)
1118     {
1119         WebInspector.SelectUISourceCodeForProjectTypeDialog.show(uiSourceCode.name(), WebInspector.projectTypes.Network, mapFileSystemToNetwork.bind(this), this.editorView.mainElement)                
1120
1121         /** 
1122          * @param {WebInspector.UISourceCode} networkUISourceCode
1123          */
1124         function mapFileSystemToNetwork(networkUISourceCode)
1125         {
1126             this._workspace.addMapping(networkUISourceCode, uiSourceCode);
1127         }
1128     },
1129
1130     /** 
1131      * @param {WebInspector.UISourceCode} uiSourceCode
1132      */
1133     _removeNetworkMapping: function(uiSourceCode)
1134     {
1135         if (confirm(WebInspector.UIString("Are you sure you want to remove network mapping?")))
1136             this._workspace.removeMapping(uiSourceCode);
1137     },
1138
1139     /** 
1140      * @param {WebInspector.UISourceCode} networkUISourceCode
1141      */
1142     _mapNetworkToFileSystem: function(networkUISourceCode)
1143     {
1144         WebInspector.SelectUISourceCodeForProjectTypeDialog.show(networkUISourceCode.name(), WebInspector.projectTypes.FileSystem, mapNetworkToFileSystem.bind(this), this.editorView.mainElement)                
1145
1146         /** 
1147          * @param {WebInspector.UISourceCode} uiSourceCode
1148          */
1149         function mapNetworkToFileSystem(uiSourceCode)
1150         {
1151             this._workspace.addMapping(networkUISourceCode, uiSourceCode);
1152         }
1153     },
1154
1155     /** 
1156      * @param {WebInspector.ContextMenu} contextMenu
1157      * @param {WebInspector.UISourceCode} uiSourceCode
1158      */
1159     _appendUISourceCodeMappingItems: function(contextMenu, uiSourceCode)
1160     {
1161         if (uiSourceCode.project().type() === WebInspector.projectTypes.FileSystem) {
1162             var hasMappings = !!uiSourceCode.url;
1163             if (!hasMappings)
1164                 contextMenu.appendItem(WebInspector.UIString("Map to network resource..."), this._mapFileSystemToNetwork.bind(this, uiSourceCode));
1165             else
1166                 contextMenu.appendItem(WebInspector.UIString("Remove network mapping"), this._removeNetworkMapping.bind(this, uiSourceCode));
1167         }
1168
1169         if (uiSourceCode.project().type() === WebInspector.projectTypes.Network) {
1170             /** 
1171              * @param {WebInspector.Project} project
1172              */
1173             function filterProject(project)
1174             {
1175                 return project.type() === WebInspector.projectTypes.FileSystem;
1176             }
1177
1178             if (!this._workspace.projects().filter(filterProject).length)
1179                 return;
1180             if (this._workspace.uiSourceCodeForURL(uiSourceCode.url) === uiSourceCode)
1181                 contextMenu.appendItem(WebInspector.UIString("Map to file system resource..."), this._mapNetworkToFileSystem.bind(this, uiSourceCode));
1182         }
1183     },
1184
1185     /** 
1186      * @param {WebInspector.ContextMenu} contextMenu
1187      * @param {Object} target
1188      */
1189     _appendUISourceCodeItems: function(contextMenu, target)
1190     {
1191         if (!(target instanceof WebInspector.UISourceCode))
1192             return;
1193
1194         var uiSourceCode = /** @type {WebInspector.UISourceCode} */ (target);
1195         contextMenu.appendItem(WebInspector.UIString("Local modifications..."), this._showLocalHistory.bind(this, uiSourceCode));
1196
1197         if (WebInspector.isolatedFileSystemManager.supportsFileSystems() && WebInspector.experimentsSettings.fileSystemProject.isEnabled())
1198             this._appendUISourceCodeMappingItems(contextMenu, uiSourceCode);
1199
1200         var resource = WebInspector.resourceForURL(uiSourceCode.url);
1201         if (resource && resource.request)
1202             contextMenu.appendApplicableItems(resource.request);
1203     },
1204
1205     /** 
1206      * @param {WebInspector.ContextMenu} contextMenu
1207      * @param {Object} target
1208      */
1209     _appendFunctionItems: function(contextMenu, target)
1210     {
1211         if (!(target instanceof WebInspector.RemoteObject))
1212             return;
1213         var remoteObject = /** @type {WebInspector.RemoteObject} */ (target);
1214         if (remoteObject.type !== "function")
1215             return;
1216
1217         function didGetDetails(error, response)
1218         {
1219             if (error) {
1220                 console.error(error);
1221                 return;
1222             }
1223             WebInspector.inspectorView.showPanelForAnchorNavigation(this);
1224             var uiLocation = WebInspector.debuggerModel.rawLocationToUILocation(response.location);
1225             this._showSourceLine(uiLocation.uiSourceCode, uiLocation.lineNumber);
1226         }
1227
1228         function revealFunction()
1229         {
1230             DebuggerAgent.getFunctionDetails(remoteObject.objectId, didGetDetails.bind(this));
1231         }
1232
1233         contextMenu.appendItem(WebInspector.UIString("Show function definition"), revealFunction.bind(this));
1234     },
1235
1236     showGoToSourceDialog: function()
1237     {
1238         WebInspector.OpenResourceDialog.show(this, this.editorView.mainElement);
1239     },
1240
1241     _dockSideChanged: function()
1242     {
1243         var dockSide = WebInspector.dockController.dockSide();
1244         var vertically = dockSide === WebInspector.DockController.State.DockedToRight && WebInspector.settings.splitVerticallyWhenDockedToRight.get();
1245         this._splitVertically(vertically);
1246     },
1247
1248     /**
1249      * @param {boolean} vertically
1250      */
1251     _splitVertically: function(vertically)
1252     {
1253         if (this.sidebarPaneView && vertically === !this.splitView.isVertical())
1254             return;
1255
1256         if (this.sidebarPaneView)
1257             this.sidebarPaneView.detach();
1258
1259         this.splitView.setVertical(!vertically);
1260
1261         if (!vertically) {
1262             this.sidebarPaneView = new WebInspector.SidebarPaneStack();
1263             for (var pane in this.sidebarPanes)
1264                 this.sidebarPaneView.addPane(this.sidebarPanes[pane]);
1265
1266             this.sidebarElement.appendChild(this.debugToolbar);
1267         } else {
1268             this._showDebuggerSidebar();
1269
1270             this.sidebarPaneView = new WebInspector.SplitView(true, this.name + "PanelSplitSidebarRatio", 0.5);
1271
1272             var group1 = new WebInspector.SidebarPaneStack();
1273             group1.show(this.sidebarPaneView.firstElement());
1274             group1.element.id = "scripts-sidebar-stack-pane";
1275             group1.addPane(this.sidebarPanes.watchExpressions);
1276             group1.addPane(this.sidebarPanes.callstack);
1277             group1.addPane(this.sidebarPanes.scopechain);
1278
1279             var group2 = new WebInspector.SidebarTabbedPane();
1280             group2.show(this.sidebarPaneView.secondElement());
1281             group2.addPane(this.sidebarPanes.jsBreakpoints);
1282             group2.addPane(this.sidebarPanes.domBreakpoints);
1283             group2.addPane(this.sidebarPanes.xhrBreakpoints);
1284             group2.addPane(this.sidebarPanes.eventListenerBreakpoints);
1285
1286             this.sidebarPaneView.firstElement().appendChild(this.debugToolbar);
1287         }
1288
1289         this.sidebarPaneView.element.id = "scripts-debug-sidebar-contents";
1290         this.sidebarPaneView.show(this.splitView.sidebarElement);
1291
1292         this.sidebarPanes.scopechain.expand();
1293         this.sidebarPanes.jsBreakpoints.expand();
1294         this.sidebarPanes.callstack.expand();
1295
1296         if (WebInspector.settings.watchExpressions.get().length > 0)
1297             this.sidebarPanes.watchExpressions.expand();
1298     },
1299
1300     __proto__: WebInspector.Panel.prototype
1301 }