Skip to content

Commit

Permalink
Fixes #204
Browse files Browse the repository at this point in the history
 * Rework getFirebugConsole() to function with Firebug versions 1.3 and 1.4.
  • Loading branch information
arantius committed Jan 23, 2009
1 parent d279923 commit 2ff97d1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 25 deletions.
69 changes: 46 additions & 23 deletions src/components/greasemonkey.js
Expand Up @@ -387,35 +387,58 @@ var greasemonkeyService = {
},

getFirebugConsole: function(unsafeContentWin, chromeWin) {
if (!chromeWin) return null;
var firebugConsole = null;
var firebugContext = chromeWin.top.TabWatcher &&
chromeWin.top.TabWatcher.getContextByWindow(unsafeContentWin);
// on first load (of multiple tabs) the context might not exist
if (!firebugContext) return null;
if (chromeWin.FirebugConsole) { // < Firebug 1.2
firebugConsole =
new chromeWin.FirebugConsole(firebugContext, unsafeContentWin);
} else if (chromeWin.Firebug.Console) { // >= Firebug 1.2
if (!chromeWin.Firebug.Console.isEnabled(firebugContext)) {
try {
chromeWin = chromeWin.top;
var fbVersion = parseFloat(chromeWin.Firebug.version, 10);
var fbConsole = chromeWin.Firebug.Console;
var fbContext = chromeWin.TabWatcher &&
chromeWin.TabWatcher.getContextByWindow(unsafeContentWin);

function findActiveContext() {
for (var i=0; i<fbContext.activeConsoleHandlers.length; i++) {
if (fbContext.activeConsoleHandlers[i].window == unsafeContentWin) {
return fbContext.activeConsoleHandlers[i];
}
}
return null;
}
var safeWin = new XPCNativeWrapper(unsafeContentWin);
if (firebugContext.consoleHandler) {
for (var i = 0; i < firebugContext.consoleHandler.length; i++) {
if (firebugContext.consoleHandler[i].window == safeWin) {
return firebugContext.consoleHandler[i].handler;

try {
if (!fbConsole.isEnabled(fbContext)) return null;
} catch (e) {
// FB 1.1 can't be enabled/disabled. Function to check doesn't exist.
// Silently ignore.
}

if (fbVersion < 1.2) {
return new chromeWin.FirebugConsole(fbContext, unsafeContentWin);
} else if (1.2 == fbVersion) {
var safeWin = new XPCNativeWrapper(unsafeContentWin);

if (fbContext.consoleHandler) {
for (var i = 0; i < fbContext.consoleHandler.length; i++) {
if (fbContext.consoleHandler[i].window == safeWin) {
return fbContext.consoleHandler[i].handler;
}
}
}

var dummyElm = safeWin.document.createElement("div");
dummyElm.setAttribute("id", "_firebugConsole");
safeWin.document.documentElement.appendChild(dummyElm);
chromeWin.Firebug.Console.injector.addConsoleListener(fbContext, safeWin);
dummyElm.parentNode.removeChild(dummyElm);

return fbContext.consoleHandler.pop().handler;
} else if (1.3 == fbVersion || 1.4 == fbVersion) {
fbConsole.injector.attachIfNeeded(fbContext, unsafeContentWin);
return findActiveContext();
}
var dummyElm = safeWin.document.createElement("div");
dummyElm.setAttribute("id", "_firebugConsole");
safeWin.document.documentElement.appendChild(dummyElm);
chromeWin.Firebug.Console.injector.addConsoleListener(firebugContext, safeWin);
dummyElm.parentNode.removeChild(dummyElm);
firebugConsole = firebugContext.consoleHandler.pop().handler;
} catch (e) {
dump('Greasemonkey getFirebugConsole() error:\n'+uneval(e)+'\n');
}
return firebugConsole;

return null;
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/install.rdf
Expand Up @@ -7,7 +7,7 @@

<em:id>{e4a8a97b-f2ed-450b-b12d-ee082ba24781}</em:id>
<!-- NOTE : build.sh will correct the em:version, if applicable -->
<em:version>0.8.20080609.0</em:version>
<em:version>0.8.20090123.1</em:version>
<em:creator>Aaron Boodman; http://youngpup.net/</em:creator>
<em:homepageURL>http://www.greasespot.net/</em:homepageURL>
<em:optionsURL>chrome://greasemonkey/content/manage.xul</em:optionsURL>
Expand Down Expand Up @@ -42,7 +42,7 @@
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>1.5</em:minVersion>
<em:maxVersion>3.0.*</em:maxVersion>
<em:maxVersion>3.1b2</em:maxVersion>
</Description>
</em:targetApplication>

Expand Down

0 comments on commit 2ff97d1

Please sign in to comment.