Skip to content

Instantly share code, notes, and snippets.

@grssam
Created Sep 14, 2012
Embed
What would you like to do?
test patch
# HG changeset patch
# User Girish Sharma <scrapmachines@gmail.com>
# Date 1347637171 -19800
# Node ID da31829c11c69e85a392a4161f6167c6e2297f94
# Parent a97775b456cf873ca6f809e03ff62e02028e7fe0
[mq]: scratchpad
diff --git a/browser/devtools/webconsole/HUDService.jsm b/browser/devtools/webconsole/HUDService.jsm
--- a/browser/devtools/webconsole/HUDService.jsm
+++ b/browser/devtools/webconsole/HUDService.jsm
@@ -1049,6 +1049,111 @@ WebConsole.prototype = {
},
/**
+ * Open a link in Firefox's view source.
+ *
+ * @param string aSourceURL
+ * The URL of the file.
+ * @param integer aSourceLine
+ * The line number which should be highlighted.
+ */
+ viewSource: function WC_viewSource(aSourceURL, aSourceLine)
+ {
+ this.gViewSourceUtils.viewSource(aSourceURL, null,
+ this.iframeWindow.document, aSourceLine);
+ },
+
+ /**
+ * Tries to open a Stylesheet file related to the web page for the web console
+ * instance in the Style Editor. If the file is not found, it is opened in
+ * source view instead.
+ *
+ * @param string aSourceURL
+ * The URL of the file.
+ * @param integer aSourceLine
+ * The line number which you want to place the caret.
+ */
+ viewSourceInStyleEditor:
+ function WC_viewSourceInStyleEditor(aSourceURL, aSourceLine)
+ {
+ let styleSheets = this.chromeWindow.content.window.document.styleSheets;
+ for each (let style in styleSheets) {
+ if (style.href == aSourceURL) {
+ this.chromeWindow.StyleEditor.openChrome(style, aSourceLine);
+ return;
+ }
+ }
+ // Open view source if style editor fails.
+ this.viewSource(aSourceURL, aSourceLine);
+ },
+
+ /**
+ * Tries to open a JavaScript file related to the web page for the web console
+ * instance in the Script Debugger. If the file is not found, it is opened in
+ * source view instead.
+ *
+ * @param string aSourceURL
+ * The URL of the file.
+ * @param integer aSourceLine
+ * The line number which you want to place the caret.
+ */
+ viewSourceInDebugger:
+ function WC_viewSourceInDebugger(aSourceURL, aSourceLine)
+ {
+ function openScript(scriptsView, stackFrames) {
+ let scriptLocations = scriptsView.scriptLocations;
+
+ if (scriptLocations.indexOf(aSourceURL) === -1) {
+ if (debuggerOpenedByThis) {
+ this.chromeWindow.DebuggerUI.toggleDebugger();
+ }
+ // Open view source if style editor fails.
+ this.viewSource(aSourceURL, aSourceLine);
+ return;
+ }
+
+ if (scriptsView.isSelected(aSourceURL)) {
+ stackFrames.updateEditorToLocation(aSourceURL, aSourceLine, 0, 0, 1);
+ Cu.reportError("Script was selected");
+ }
+ else {
+ dbg.addEventListener("Debugger:ScriptShown", function scriptAdded() {
+ //if (scriptsView.isSelected(aSourceURL)) {
+ dbg.removeEventListener("Debugger:ScriptShown", scriptAdded);
+ //}
+ Cu.reportError("Script not selected");
+ stackFrames.updateEditorToLocation(aSourceURL, aSourceLine, 0, 0, 1);
+ Cu.reportError("selected the script");
+ });
+ stackFrames.updateEditorToLocation(aSourceURL, aSourceLine, 0, 0, 1);
+ }
+ }
+
+ let dbg = null, debuggerOpenedByThis = false;
+ if (this.chromeWindow.DebuggerUI.getDebugger() == null) {
+ this.chromeWindow.DebuggerUI.toggleDebugger();
+ debuggerOpenedByThis = true;
+ dbg = this.chromeWindow.DebuggerUI.getDebugger().contentWindow;
+
+ dbg.addEventListener("Debugger:Connecting", function onConnecting() {
+ dbg.removeEventListener("Debugger:Connecting", onConnecting);
+
+ let scripts = dbg.DebuggerView.Scripts;
+ let frames = dbg.DebuggerController.StackFrames;
+
+ dbg.addEventListener("Debugger:AfterScriptsAdded", function scriptsAdded() {
+ dbg.removeEventListener("Debugger:AfterScriptsAdded", scriptsAdded);
+ openScript.call(this, scripts, frames);
+ }.bind(this));
+ }.bind(this));
+ }
+ else {
+ dbg = this.chromeWindow.DebuggerUI.getDebugger().contentWindow;
+ let client = dbg.DebuggerController.client;
+ openScript.call(this, dbg.DebuggerView.Scripts, dbg.DebuggerController.StackFrames);
+ }
+ },
+
+ /**
* Destroy the object. Call this method to avoid memory leaks when the Web
* Console is closed.
*/
diff --git a/browser/devtools/webconsole/webconsole.js b/browser/devtools/webconsole/webconsole.js
--- a/browser/devtools/webconsole/webconsole.js
+++ b/browser/devtools/webconsole/webconsole.js
@@ -2169,10 +2169,16 @@ WebConsoleFrame.prototype = {
if (win) {
win.focus();
}
- return;
}
- let viewSourceUtils = this.owner.gViewSourceUtils;
- viewSourceUtils.viewSource(aSourceURL, null, this.document, aSourceLine);
+ else if (locationNode.parentNode.category == CATEGORY_JS) {
+ this.owner.viewSourceInDebugger(aSourceURL, aSourceLine);
+ }
+ else if (locationNode.parentNode.category == CATEGORY_CSS) {
+ this.owner.viewSourceInStyleEditor(aSourceURL, aSourceLine);
+ }
+ else {
+ this.owner.viewSource(aSourceURL, aSourceLine);
+ }
}.bind(this), true);
return locationNode;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment