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

Side by Side Diff: chrome_frame/tools/test/reference_build/chrome/resources/inspector/ScriptsPanel.js

Issue 218019: Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 2 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 WebInspector.ScriptsPanel = function()
27 {
28 WebInspector.Panel.call(this);
29
30 this.element.addStyleClass("scripts");
31
32 this.topStatusBar = document.createElement("div");
33 this.topStatusBar.className = "status-bar";
34 this.topStatusBar.id = "scripts-status-bar";
35 this.element.appendChild(this.topStatusBar);
36
37 this.backButton = document.createElement("button");
38 this.backButton.className = "status-bar-item";
39 this.backButton.id = "scripts-back";
40 this.backButton.title = WebInspector.UIString("Show the previous script reso urce.");
41 this.backButton.disabled = true;
42 this.backButton.appendChild(document.createElement("img"));
43 this.backButton.addEventListener("click", this._goBack.bind(this), false);
44 this.topStatusBar.appendChild(this.backButton);
45
46 this.forwardButton = document.createElement("button");
47 this.forwardButton.className = "status-bar-item";
48 this.forwardButton.id = "scripts-forward";
49 this.forwardButton.title = WebInspector.UIString("Show the next script resou rce.");
50 this.forwardButton.disabled = true;
51 this.forwardButton.appendChild(document.createElement("img"));
52 this.forwardButton.addEventListener("click", this._goForward.bind(this), fal se);
53 this.topStatusBar.appendChild(this.forwardButton);
54
55 this.filesSelectElement = document.createElement("select");
56 this.filesSelectElement.className = "status-bar-item";
57 this.filesSelectElement.id = "scripts-files";
58 this.filesSelectElement.addEventListener("change", this._changeVisibleFile.b ind(this), false);
59 this.filesSelectElement.handleKeyEvent = this.handleKeyEvent.bind(this);
60 this.topStatusBar.appendChild(this.filesSelectElement);
61
62 this.functionsSelectElement = document.createElement("select");
63 this.functionsSelectElement.className = "status-bar-item";
64 this.functionsSelectElement.id = "scripts-functions";
65
66 // FIXME: append the functions select element to the top status bar when it is implemented.
67 // this.topStatusBar.appendChild(this.functionsSelectElement);
68
69 this.sidebarButtonsElement = document.createElement("div");
70 this.sidebarButtonsElement.id = "scripts-sidebar-buttons";
71 this.topStatusBar.appendChild(this.sidebarButtonsElement);
72
73 this.pauseButton = document.createElement("button");
74 this.pauseButton.className = "status-bar-item";
75 this.pauseButton.id = "scripts-pause";
76 this.pauseButton.title = WebInspector.UIString("Pause script execution.");
77 this.pauseButton.disabled = true;
78 this.pauseButton.appendChild(document.createElement("img"));
79 this.pauseButton.addEventListener("click", this._togglePause.bind(this), fal se);
80 this.sidebarButtonsElement.appendChild(this.pauseButton);
81
82 this.stepOverButton = document.createElement("button");
83 this.stepOverButton.className = "status-bar-item";
84 this.stepOverButton.id = "scripts-step-over";
85 this.stepOverButton.title = WebInspector.UIString("Step over next function c all.");
86 this.stepOverButton.disabled = true;
87 this.stepOverButton.addEventListener("click", this._stepOverClicked.bind(thi s), false);
88 this.stepOverButton.appendChild(document.createElement("img"));
89 this.sidebarButtonsElement.appendChild(this.stepOverButton);
90
91 this.stepIntoButton = document.createElement("button");
92 this.stepIntoButton.className = "status-bar-item";
93 this.stepIntoButton.id = "scripts-step-into";
94 this.stepIntoButton.title = WebInspector.UIString("Step into next function c all.");
95 this.stepIntoButton.disabled = true;
96 this.stepIntoButton.addEventListener("click", this._stepIntoClicked.bind(thi s), false);
97 this.stepIntoButton.appendChild(document.createElement("img"));
98 this.sidebarButtonsElement.appendChild(this.stepIntoButton);
99
100 this.stepOutButton = document.createElement("button");
101 this.stepOutButton.className = "status-bar-item";
102 this.stepOutButton.id = "scripts-step-out";
103 this.stepOutButton.title = WebInspector.UIString("Step out of current functi on.");
104 this.stepOutButton.disabled = true;
105 this.stepOutButton.addEventListener("click", this._stepOutClicked.bind(this) , false);
106 this.stepOutButton.appendChild(document.createElement("img"));
107 this.sidebarButtonsElement.appendChild(this.stepOutButton);
108
109 this.debuggerStatusElement = document.createElement("div");
110 this.debuggerStatusElement.id = "scripts-debugger-status";
111 this.sidebarButtonsElement.appendChild(this.debuggerStatusElement);
112
113 this.viewsContainerElement = document.createElement("div");
114 this.viewsContainerElement.id = "script-resource-views";
115
116 this.sidebarElement = document.createElement("div");
117 this.sidebarElement.id = "scripts-sidebar";
118
119 this.sidebarResizeElement = document.createElement("div");
120 this.sidebarResizeElement.className = "sidebar-resizer-vertical";
121 this.sidebarResizeElement.addEventListener("mousedown", this._startSidebarRe sizeDrag.bind(this), false);
122
123 this.sidebarResizeWidgetElement = document.createElement("div");
124 this.sidebarResizeWidgetElement.id = "scripts-sidebar-resizer-widget";
125 this.sidebarResizeWidgetElement.addEventListener("mousedown", this._startSid ebarResizeDrag.bind(this), false);
126 this.topStatusBar.appendChild(this.sidebarResizeWidgetElement);
127
128 this.sidebarPanes = {};
129 this.sidebarPanes.watchExpressions = new WebInspector.WatchExpressionsSideba rPane();
130 this.sidebarPanes.callstack = new WebInspector.CallStackSidebarPane();
131 this.sidebarPanes.scopechain = new WebInspector.ScopeChainSidebarPane();
132 this.sidebarPanes.breakpoints = new WebInspector.BreakpointsSidebarPane();
133
134 for (var pane in this.sidebarPanes)
135 this.sidebarElement.appendChild(this.sidebarPanes[pane].element);
136
137 this.sidebarPanes.callstack.expanded = true;
138 this.sidebarPanes.callstack.addEventListener("call frame selected", this._ca llFrameSelected, this);
139
140 this.sidebarPanes.scopechain.expanded = true;
141 this.sidebarPanes.breakpoints.expanded = true;
142
143 var panelEnablerHeading = WebInspector.UIString("You need to enable debuggin g before you can use the Scripts panel.");
144 var panelEnablerDisclaimer = WebInspector.UIString("Enabling debugging will make scripts run slower.");
145 var panelEnablerButton = WebInspector.UIString("Enable Debugging");
146
147 this.panelEnablerView = new WebInspector.PanelEnablerView("scripts", panelEn ablerHeading, panelEnablerDisclaimer, panelEnablerButton);
148 this.panelEnablerView.addEventListener("enable clicked", this._enableDebuggi ng, this);
149
150 this.element.appendChild(this.panelEnablerView.element);
151 this.element.appendChild(this.viewsContainerElement);
152 this.element.appendChild(this.sidebarElement);
153 this.element.appendChild(this.sidebarResizeElement);
154
155 this.enableToggleButton = new WebInspector.StatusBarButton("", "enable-toggl e-status-bar-item");
156 this.enableToggleButton.addEventListener("click", this._toggleDebugging.bind (this), false);
157
158 this.pauseOnExceptionButton = new WebInspector.StatusBarButton("", "scripts- pause-on-exceptions-status-bar-item");
159 this.pauseOnExceptionButton.addEventListener("click", this._togglePauseOnExc eptions.bind(this), false);
160
161 this._breakpointsURLMap = {};
162
163 this._shortcuts = {};
164
165 var isMac = InspectorController.platform().indexOf("mac-") === 0;
166 var platformSpecificModifier = isMac ? WebInspector.KeyboardShortcut.Modifie rs.Meta : WebInspector.KeyboardShortcut.Modifiers.Ctrl;
167
168 // Continue.
169 var handler = this.pauseButton.click.bind(this.pauseButton);
170 var shortcut = WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardSh ortcut.KeyCodes.F8);
171 this._shortcuts[shortcut] = handler;
172 var shortcut = WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardSh ortcut.KeyCodes.Slash, platformSpecificModifier);
173 this._shortcuts[shortcut] = handler;
174
175 // Step over.
176 var handler = this.stepOverButton.click.bind(this.stepOverButton);
177 var shortcut = WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardSh ortcut.KeyCodes.F10);
178 this._shortcuts[shortcut] = handler;
179 var shortcut = WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardSh ortcut.KeyCodes.SingleQuote, platformSpecificModifier);
180 this._shortcuts[shortcut] = handler;
181
182 // Step into.
183 var handler = this.stepIntoButton.click.bind(this.stepIntoButton);
184 var shortcut = WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardSh ortcut.KeyCodes.F11);
185 this._shortcuts[shortcut] = handler;
186 var shortcut = WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardSh ortcut.KeyCodes.Semicolon, platformSpecificModifier);
187 this._shortcuts[shortcut] = handler;
188
189 // Step out.
190 var handler = this.stepOutButton.click.bind(this.stepOutButton);
191 var shortcut = WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardSh ortcut.KeyCodes.F11, WebInspector.KeyboardShortcut.Modifiers.Shift);
192 this._shortcuts[shortcut] = handler;
193 var shortcut = WebInspector.KeyboardShortcut.makeKey(WebInspector.KeyboardSh ortcut.KeyCodes.Semicolon, WebInspector.KeyboardShortcut.Modifiers.Shift, platfo rmSpecificModifier);
194 this._shortcuts[shortcut] = handler;
195
196 this.reset();
197 }
198
199 WebInspector.ScriptsPanel.prototype = {
200 toolbarItemClass: "scripts",
201
202 get toolbarItemLabel()
203 {
204 return WebInspector.UIString("Scripts");
205 },
206
207 get statusBarItems()
208 {
209 return [this.enableToggleButton.element, this.pauseOnExceptionButton.ele ment];
210 },
211
212 get paused()
213 {
214 return this._paused;
215 },
216
217 show: function()
218 {
219 WebInspector.Panel.prototype.show.call(this);
220 this.sidebarResizeElement.style.right = (this.sidebarElement.offsetWidth - 3) + "px";
221
222 if (this.visibleView) {
223 if (this.visibleView instanceof WebInspector.ResourceView)
224 this.visibleView.headersVisible = false;
225 this.visibleView.show(this.viewsContainerElement);
226 }
227
228 // Hide any views that are visible that are not this panel's current vis ible view.
229 // This can happen when a ResourceView is visible in the Resources panel then switched
230 // to the this panel.
231 for (var sourceID in this._sourceIDMap) {
232 var scriptOrResource = this._sourceIDMap[sourceID];
233 var view = this._sourceViewForScriptOrResource(scriptOrResource);
234 if (!view || view === this.visibleView)
235 continue;
236 view.visible = false;
237 }
238 if (this._attachDebuggerWhenShown) {
239 InspectorController.enableDebugger(false);
240 delete this._attachDebuggerWhenShown;
241 }
242 },
243
244 get searchableViews()
245 {
246 var views = [];
247
248 const visibleView = this.visibleView;
249 if (visibleView && visibleView.performSearch) {
250 visibleView.alreadySearching = true;
251 views.push(visibleView);
252 }
253
254 for (var sourceID in this._sourceIDMap) {
255 var scriptOrResource = this._sourceIDMap[sourceID];
256 var view = this._sourceViewForScriptOrResource(scriptOrResource);
257 if (!view || !view.performSearch || view.alreadySearching)
258 continue;
259
260 view.alreadySearching = true;
261 views.push(view);
262 }
263
264 for (var i = 0; i < views.length; ++i)
265 delete views[i].alreadySearching;
266
267 return views;
268 },
269
270 addScript: function(sourceID, sourceURL, source, startingLine, errorLine, er rorMessage)
271 {
272 var script = new WebInspector.Script(sourceID, sourceURL, source, starti ngLine, errorLine, errorMessage);
273
274 if (sourceURL in WebInspector.resourceURLMap) {
275 var resource = WebInspector.resourceURLMap[sourceURL];
276 resource.addScript(script);
277 }
278
279 if (sourceURL in this._breakpointsURLMap && sourceID) {
280 var breakpoints = this._breakpointsURLMap[sourceURL];
281 var breakpointsLength = breakpoints.length;
282 for (var i = 0; i < breakpointsLength; ++i) {
283 var breakpoint = breakpoints[i];
284 if (startingLine <= breakpoint.line) {
285 breakpoint.sourceID = sourceID;
286 if (breakpoint.enabled)
287 InspectorController.addBreakpoint(breakpoint.sourceID, b reakpoint.line, breakpoint.condition);
288 }
289 }
290 }
291
292 if (sourceID)
293 this._sourceIDMap[sourceID] = (resource || script);
294
295 this._addScriptToFilesMenu(script);
296 },
297
298 scriptOrResourceForID: function(id)
299 {
300 return this._sourceIDMap[id];
301 },
302
303 addBreakpoint: function(breakpoint)
304 {
305 this.sidebarPanes.breakpoints.addBreakpoint(breakpoint);
306
307 var sourceFrame;
308 if (breakpoint.url) {
309 if (!(breakpoint.url in this._breakpointsURLMap))
310 this._breakpointsURLMap[breakpoint.url] = [];
311 this._breakpointsURLMap[breakpoint.url].unshift(breakpoint);
312
313 if (breakpoint.url in WebInspector.resourceURLMap) {
314 var resource = WebInspector.resourceURLMap[breakpoint.url];
315 sourceFrame = this._sourceFrameForScriptOrResource(resource);
316 }
317 }
318
319 if (breakpoint.sourceID && !sourceFrame) {
320 var object = this._sourceIDMap[breakpoint.sourceID]
321 sourceFrame = this._sourceFrameForScriptOrResource(object);
322 }
323
324 if (sourceFrame)
325 sourceFrame.addBreakpoint(breakpoint);
326 },
327
328 removeBreakpoint: function(breakpoint)
329 {
330 this.sidebarPanes.breakpoints.removeBreakpoint(breakpoint);
331
332 var sourceFrame;
333 if (breakpoint.url && breakpoint.url in this._breakpointsURLMap) {
334 var breakpoints = this._breakpointsURLMap[breakpoint.url];
335 breakpoints.remove(breakpoint);
336 if (!breakpoints.length)
337 delete this._breakpointsURLMap[breakpoint.url];
338
339 if (breakpoint.url in WebInspector.resourceURLMap) {
340 var resource = WebInspector.resourceURLMap[breakpoint.url];
341 sourceFrame = this._sourceFrameForScriptOrResource(resource);
342 }
343 }
344
345 if (breakpoint.sourceID && !sourceFrame) {
346 var object = this._sourceIDMap[breakpoint.sourceID]
347 sourceFrame = this._sourceFrameForScriptOrResource(object);
348 }
349
350 if (sourceFrame)
351 sourceFrame.removeBreakpoint(breakpoint);
352 },
353
354 evaluateInSelectedCallFrame: function(code, updateInterface, callback)
355 {
356 var selectedCallFrame = this.sidebarPanes.callstack.selectedCallFrame;
357 if (!this._paused || !selectedCallFrame)
358 return;
359
360 if (typeof updateInterface === "undefined")
361 updateInterface = true;
362
363 var self = this;
364 function updatingCallbackWrapper(result, exception)
365 {
366 callback(result, exception);
367 if (updateInterface)
368 self.sidebarPanes.scopechain.update(selectedCallFrame);
369 }
370 this.doEvalInCallFrame(selectedCallFrame, code, updatingCallbackWrapper) ;
371 },
372
373 doEvalInCallFrame: function(callFrame, code, callback)
374 {
375 function evalCallback(result)
376 {
377 if (result)
378 callback(result.value, result.isException);
379 }
380 InjectedScriptAccess.evaluateInCallFrame(callFrame.id, code, evalCallbac k);
381 },
382
383 variablesInSelectedCallFrame: function()
384 {
385 var selectedCallFrame = this.sidebarPanes.callstack.selectedCallFrame;
386 if (!this._paused || !selectedCallFrame)
387 return {};
388
389 var result = {};
390 var scopeChain = selectedCallFrame.scopeChain;
391 for (var i = 0; i < scopeChain.length; ++i) {
392 var scopeObjectProperties = scopeChain[i].properties;
393 for (var j = 0; j < scopeObjectProperties.length; ++j)
394 result[scopeObjectProperties[j]] = true;
395 }
396 return result;
397 },
398
399 debuggerPaused: function(callFrames)
400 {
401 this._paused = true;
402 this._waitingToPause = false;
403 this._stepping = false;
404
405 this._updateDebuggerButtons();
406
407 this.sidebarPanes.callstack.update(callFrames, this._sourceIDMap);
408 this.sidebarPanes.callstack.selectedCallFrame = callFrames[0];
409
410 WebInspector.currentPanel = this;
411 window.focus();
412 },
413
414 debuggerResumed: function()
415 {
416 this._paused = false;
417 this._waitingToPause = false;
418 this._stepping = false;
419
420 this._clearInterface();
421 },
422
423 attachDebuggerWhenShown: function()
424 {
425 if (this.element.parentElement) {
426 InspectorController.enableDebugger(false);
427 } else {
428 this._attachDebuggerWhenShown = true;
429 }
430 },
431
432 debuggerWasEnabled: function()
433 {
434 this.reset();
435 },
436
437 debuggerWasDisabled: function()
438 {
439 this.reset();
440 },
441
442 reset: function()
443 {
444 this.visibleView = null;
445
446 delete this.currentQuery;
447 this.searchCanceled();
448
449 if (!InspectorController.debuggerEnabled()) {
450 this._paused = false;
451 this._waitingToPause = false;
452 this._stepping = false;
453 }
454
455 this._clearInterface();
456
457 this._backForwardList = [];
458 this._currentBackForwardIndex = -1;
459 this._updateBackAndForwardButtons();
460
461 this._scriptsForURLsInFilesSelect = {};
462 this.filesSelectElement.removeChildren();
463 this.functionsSelectElement.removeChildren();
464 this.viewsContainerElement.removeChildren();
465
466 if (this._sourceIDMap) {
467 for (var sourceID in this._sourceIDMap) {
468 var object = this._sourceIDMap[sourceID];
469 if (object instanceof WebInspector.Resource)
470 object.removeAllScripts();
471 }
472 }
473
474 this._sourceIDMap = {};
475
476 this.sidebarPanes.watchExpressions.refreshExpressions();
477 },
478
479 get visibleView()
480 {
481 return this._visibleView;
482 },
483
484 set visibleView(x)
485 {
486 if (this._visibleView === x)
487 return;
488
489 if (this._visibleView)
490 this._visibleView.hide();
491
492 this._visibleView = x;
493
494 if (x)
495 x.show(this.viewsContainerElement);
496 },
497
498 canShowResource: function(resource)
499 {
500 return resource && resource.scripts.length && InspectorController.debugg erEnabled();
501 },
502
503 showScript: function(script, line)
504 {
505 this._showScriptOrResource(script, line, true);
506 },
507
508 showResource: function(resource, line)
509 {
510 this._showScriptOrResource(resource, line, true);
511 },
512
513 showView: function(view)
514 {
515 if (!view)
516 return;
517 this._showScriptOrResource((view.resource || view.script));
518 },
519
520 handleKeyEvent: function(event)
521 {
522 var shortcut = WebInspector.KeyboardShortcut.makeKeyFromEvent(event);
523 var handler = this._shortcuts[shortcut];
524 if (handler) {
525 handler(event);
526 event.preventDefault();
527 event.handled = true;
528 } else {
529 this.sidebarPanes.callstack.handleKeyEvent(event);
530 }
531 },
532
533 scriptViewForScript: function(script)
534 {
535 if (!script)
536 return null;
537 if (!script._scriptView)
538 script._scriptView = new WebInspector.ScriptView(script);
539 return script._scriptView;
540 },
541
542 sourceFrameForScript: function(script)
543 {
544 var view = this.scriptViewForScript(script);
545 if (!view)
546 return null;
547
548 // Setting up the source frame requires that we be attached.
549 if (!this.element.parentNode)
550 this.attach();
551
552 view.setupSourceFrameIfNeeded();
553 return view.sourceFrame;
554 },
555
556 _sourceViewForScriptOrResource: function(scriptOrResource)
557 {
558 if (scriptOrResource instanceof WebInspector.Resource) {
559 if (!WebInspector.panels.resources)
560 return null;
561 return WebInspector.panels.resources.resourceViewForResource(scriptO rResource);
562 }
563 if (scriptOrResource instanceof WebInspector.Script)
564 return this.scriptViewForScript(scriptOrResource);
565 },
566
567 _sourceFrameForScriptOrResource: function(scriptOrResource)
568 {
569 if (scriptOrResource instanceof WebInspector.Resource) {
570 if (!WebInspector.panels.resources)
571 return null;
572 return WebInspector.panels.resources.sourceFrameForResource(scriptOr Resource);
573 }
574 if (scriptOrResource instanceof WebInspector.Script)
575 return this.sourceFrameForScript(scriptOrResource);
576 },
577
578 _showScriptOrResource: function(scriptOrResource, line, shouldHighlightLine, fromBackForwardAction)
579 {
580 if (!scriptOrResource)
581 return;
582
583 var view;
584 if (scriptOrResource instanceof WebInspector.Resource) {
585 if (!WebInspector.panels.resources)
586 return null;
587 view = WebInspector.panels.resources.resourceViewForResource(scriptO rResource);
588 view.headersVisible = false;
589
590 if (scriptOrResource.url in this._breakpointsURLMap) {
591 var sourceFrame = this._sourceFrameForScriptOrResource(scriptOrR esource);
592 if (sourceFrame && !sourceFrame.breakpoints.length) {
593 var breakpoints = this._breakpointsURLMap[scriptOrResource.u rl];
594 var breakpointsLength = breakpoints.length;
595 for (var i = 0; i < breakpointsLength; ++i)
596 sourceFrame.addBreakpoint(breakpoints[i]);
597 }
598 }
599 } else if (scriptOrResource instanceof WebInspector.Script)
600 view = this.scriptViewForScript(scriptOrResource);
601
602 if (!view)
603 return;
604
605 if (!fromBackForwardAction) {
606 var oldIndex = this._currentBackForwardIndex;
607 if (oldIndex >= 0)
608 this._backForwardList.splice(oldIndex + 1, this._backForwardList .length - oldIndex);
609
610 // Check for a previous entry of the same object in _backForwardList .
611 // If one is found, remove it and update _currentBackForwardIndex to match.
612 var previousEntryIndex = this._backForwardList.indexOf(scriptOrResou rce);
613 if (previousEntryIndex !== -1) {
614 this._backForwardList.splice(previousEntryIndex, 1);
615 --this._currentBackForwardIndex;
616 }
617
618 this._backForwardList.push(scriptOrResource);
619 ++this._currentBackForwardIndex;
620
621 this._updateBackAndForwardButtons();
622 }
623
624 this.visibleView = view;
625
626 if (line) {
627 if (view.revealLine)
628 view.revealLine(line);
629 if (view.highlightLine && shouldHighlightLine)
630 view.highlightLine(line);
631 }
632
633 var option;
634 if (scriptOrResource instanceof WebInspector.Script) {
635 option = scriptOrResource.filesSelectOption;
636 console.assert(option);
637 } else {
638 var url = scriptOrResource.url;
639 var script = this._scriptsForURLsInFilesSelect[url];
640 if (script)
641 option = script.filesSelectOption;
642 }
643
644 if (option)
645 this.filesSelectElement.selectedIndex = option.index;
646 },
647
648 _addScriptToFilesMenu: function(script)
649 {
650 if (script.resource && this._scriptsForURLsInFilesSelect[script.sourceUR L])
651 return;
652
653 this._scriptsForURLsInFilesSelect[script.sourceURL] = script;
654
655 var select = this.filesSelectElement;
656
657 var option = document.createElement("option");
658 option.representedObject = (script.resource || script);
659 option.text = (script.sourceURL ? WebInspector.displayNameForURL(script. sourceURL) : WebInspector.UIString("(program)"));
660
661 function optionCompare(a, b)
662 {
663 var aTitle = a.text.toLowerCase();
664 var bTitle = b.text.toLowerCase();
665 if (aTitle < bTitle)
666 return -1;
667 else if (aTitle > bTitle)
668 return 1;
669
670 var aSourceID = a.representedObject.sourceID;
671 var bSourceID = b.representedObject.sourceID;
672 if (aSourceID < bSourceID)
673 return -1;
674 else if (aSourceID > bSourceID)
675 return 1;
676 return 0;
677 }
678
679 var insertionIndex = insertionIndexForObjectInListSortedByFunction(optio n, select.childNodes, optionCompare);
680 if (insertionIndex < 0)
681 select.appendChild(option);
682 else
683 select.insertBefore(option, select.childNodes.item(insertionIndex));
684
685 script.filesSelectOption = option;
686
687 // Call _showScriptOrResource if the option we just appended ended up be ing selected.
688 // This will happen for the first item added to the menu.
689 if (select.options[select.selectedIndex] === option)
690 this._showScriptOrResource(option.representedObject);
691 },
692
693 _clearCurrentExecutionLine: function()
694 {
695 if (this._executionSourceFrame)
696 this._executionSourceFrame.executionLine = 0;
697 delete this._executionSourceFrame;
698 },
699
700 _callFrameSelected: function()
701 {
702 this._clearCurrentExecutionLine();
703
704 var callStackPane = this.sidebarPanes.callstack;
705 var currentFrame = callStackPane.selectedCallFrame;
706 if (!currentFrame)
707 return;
708
709 this.sidebarPanes.scopechain.update(currentFrame);
710 this.sidebarPanes.watchExpressions.refreshExpressions();
711
712 var scriptOrResource = this._sourceIDMap[currentFrame.sourceID];
713 this._showScriptOrResource(scriptOrResource, currentFrame.line);
714
715 this._executionSourceFrame = this._sourceFrameForScriptOrResource(script OrResource);
716 if (this._executionSourceFrame)
717 this._executionSourceFrame.executionLine = currentFrame.line;
718 },
719
720 _changeVisibleFile: function(event)
721 {
722 var select = this.filesSelectElement;
723 this._showScriptOrResource(select.options[select.selectedIndex].represen tedObject);
724 },
725
726 _startSidebarResizeDrag: function(event)
727 {
728 WebInspector.elementDragStart(this.sidebarElement, this._sidebarResizeDr ag.bind(this), this._endSidebarResizeDrag.bind(this), event, "col-resize");
729
730 if (event.target === this.sidebarResizeWidgetElement)
731 this._dragOffset = (event.target.offsetWidth - (event.pageX - event. target.totalOffsetLeft));
732 else
733 this._dragOffset = 0;
734 },
735
736 _endSidebarResizeDrag: function(event)
737 {
738 WebInspector.elementDragEnd(event);
739
740 delete this._dragOffset;
741 },
742
743 _sidebarResizeDrag: function(event)
744 {
745 var x = event.pageX + this._dragOffset;
746 var newWidth = Number.constrain(window.innerWidth - x, Preferences.minSc riptsSidebarWidth, window.innerWidth * 0.66);
747
748 this.sidebarElement.style.width = newWidth + "px";
749 this.sidebarButtonsElement.style.width = newWidth + "px";
750 this.viewsContainerElement.style.right = newWidth + "px";
751 this.sidebarResizeWidgetElement.style.right = newWidth + "px";
752 this.sidebarResizeElement.style.right = (newWidth - 3) + "px";
753
754 event.preventDefault();
755 },
756
757 _updatePauseOnExceptionsButton: function()
758 {
759 if (InspectorController.pauseOnExceptions()) {
760 this.pauseOnExceptionButton.title = WebInspector.UIString("Don't pau se on exceptions.");
761 this.pauseOnExceptionButton.toggled = true;
762 } else {
763 this.pauseOnExceptionButton.title = WebInspector.UIString("Pause on exceptions.");
764 this.pauseOnExceptionButton.toggled = false;
765 }
766 },
767
768 _updateDebuggerButtons: function()
769 {
770 if (InspectorController.debuggerEnabled()) {
771 this.enableToggleButton.title = WebInspector.UIString("Debugging ena bled. Click to disable.");
772 this.enableToggleButton.toggled = true;
773 this.pauseOnExceptionButton.visible = true;
774 this.panelEnablerView.visible = false;
775 } else {
776 this.enableToggleButton.title = WebInspector.UIString("Debugging dis abled. Click to enable.");
777 this.enableToggleButton.toggled = false;
778 this.pauseOnExceptionButton.visible = false;
779 this.panelEnablerView.visible = true;
780 }
781
782 this._updatePauseOnExceptionsButton();
783
784 if (this._paused) {
785 this.pauseButton.addStyleClass("paused");
786
787 this.pauseButton.disabled = false;
788 this.stepOverButton.disabled = false;
789 this.stepIntoButton.disabled = false;
790 this.stepOutButton.disabled = false;
791
792 this.debuggerStatusElement.textContent = WebInspector.UIString("Paus ed");
793 } else {
794 this.pauseButton.removeStyleClass("paused");
795
796 this.pauseButton.disabled = this._waitingToPause;
797 this.stepOverButton.disabled = true;
798 this.stepIntoButton.disabled = true;
799 this.stepOutButton.disabled = true;
800
801 if (this._waitingToPause)
802 this.debuggerStatusElement.textContent = WebInspector.UIString(" Pausing");
803 else if (this._stepping)
804 this.debuggerStatusElement.textContent = WebInspector.UIString(" Stepping");
805 else
806 this.debuggerStatusElement.textContent = "";
807 }
808 },
809
810 _updateBackAndForwardButtons: function()
811 {
812 this.backButton.disabled = this._currentBackForwardIndex <= 0;
813 this.forwardButton.disabled = this._currentBackForwardIndex >= (this._ba ckForwardList.length - 1);
814 },
815
816 _clearInterface: function()
817 {
818 this.sidebarPanes.callstack.update(null);
819 this.sidebarPanes.scopechain.update(null);
820
821 this._clearCurrentExecutionLine();
822 this._updateDebuggerButtons();
823 },
824
825 _goBack: function()
826 {
827 if (this._currentBackForwardIndex <= 0) {
828 console.error("Can't go back from index " + this._currentBackForward Index);
829 return;
830 }
831
832 this._showScriptOrResource(this._backForwardList[--this._currentBackForw ardIndex], null, false, true);
833 this._updateBackAndForwardButtons();
834 },
835
836 _goForward: function()
837 {
838 if (this._currentBackForwardIndex >= this._backForwardList.length - 1) {
839 console.error("Can't go forward from index " + this._currentBackForw ardIndex);
840 return;
841 }
842
843 this._showScriptOrResource(this._backForwardList[++this._currentBackForw ardIndex], null, false, true);
844 this._updateBackAndForwardButtons();
845 },
846
847 _enableDebugging: function()
848 {
849 if (InspectorController.debuggerEnabled())
850 return;
851 this._toggleDebugging(this.panelEnablerView.alwaysEnabled);
852 },
853
854 _toggleDebugging: function(optionalAlways)
855 {
856 this._paused = false;
857 this._waitingToPause = false;
858 this._stepping = false;
859
860 if (InspectorController.debuggerEnabled())
861 InspectorController.disableDebugger(true);
862 else
863 InspectorController.enableDebugger(!!optionalAlways);
864 },
865
866 _togglePauseOnExceptions: function()
867 {
868 InspectorController.setPauseOnExceptions(!InspectorController.pauseOnExc eptions());
869 this._updatePauseOnExceptionsButton();
870 },
871
872 _togglePause: function()
873 {
874 if (this._paused) {
875 this._paused = false;
876 this._waitingToPause = false;
877 InspectorController.resumeDebugger();
878 } else {
879 this._stepping = false;
880 this._waitingToPause = true;
881 InspectorController.pauseInDebugger();
882 }
883
884 this._clearInterface();
885 },
886
887 _stepOverClicked: function()
888 {
889 this._paused = false;
890 this._stepping = true;
891
892 this._clearInterface();
893
894 InspectorController.stepOverStatementInDebugger();
895 },
896
897 _stepIntoClicked: function()
898 {
899 this._paused = false;
900 this._stepping = true;
901
902 this._clearInterface();
903
904 InspectorController.stepIntoStatementInDebugger();
905 },
906
907 _stepOutClicked: function()
908 {
909 this._paused = false;
910 this._stepping = true;
911
912 this._clearInterface();
913
914 InspectorController.stepOutOfFunctionInDebugger();
915 }
916 }
917
918 WebInspector.ScriptsPanel.prototype.__proto__ = WebInspector.Panel.prototype;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698