diff --git a/browser/base/content/tabcandy/core/tabs.js b/browser/base/content/tabcandy/core/tabs.js index f7eba173396..7ed194ab38a 100644 --- a/browser/base/content/tabcandy/core/tabs.js +++ b/browser/base/content/tabcandy/core/tabs.js @@ -328,16 +328,8 @@ window.TabsManager = $.extend(new Subscribable(), { // Sets up the TabsManager and window.Tabs init: function() { var self = this; -/* - var wm = Cc["@mozilla.org/appshell/window-mediator;1"] - .getService(Ci.nsIWindowMediator); - var chromeWindow = wm.getMostRecentWindow("navigator:browser"); -*/ - var chromeWindow = Utils.activeWindow; - if(!chromeWindow.getBrowser || !chromeWindow.getBrowser()) - chromeWindow = null; - - if(!chromeWindow) { + var chromeWindow = Utils.getCurrentWindow(); + if(!chromeWindow || !chromeWindow.getBrowser || !chromeWindow.getBrowser()) { setTimeout(function() { self.init(); }, 100); diff --git a/browser/base/content/tabcandy/core/utils.js b/browser/base/content/tabcandy/core/utils.js index 28b0d024054..7cc5c8c1dfc 100644 --- a/browser/base/content/tabcandy/core/utils.js +++ b/browser/base/content/tabcandy/core/utils.js @@ -358,7 +358,31 @@ var Utils = { return null; }, + + // ---------- + // Function: getCurrentWindow + // Returns the nsIDOMWindowInternal for the currently active window, + // i.e. the window belonging to the active page's DOM "window" object. + getCurrentWindow: function() { + var wm = Cc["@mozilla.org/appshell/window-mediator;1"] + .getService(Ci.nsIWindowMediator); + var browserEnumerator = wm.getEnumerator("navigator:browser"); + while (browserEnumerator.hasMoreElements()) { + var browserWin = browserEnumerator.getNext(); + var tabbrowser = browserWin.gBrowser; + + // Check each tab of this browser instance + var numTabs = tabbrowser.browsers.length; + for (var index = 0; index < numTabs; index++) { + var currentBrowser = tabbrowser.getBrowserAtIndex(index); + if(currentBrowser.contentWindow == window) + return browserWin; + } + } + return null; + }, + // ___ Files getInstallDirectory: function(id, callback) { if (Cc["@mozilla.org/extensions/manager;1"]) { @@ -443,6 +467,7 @@ var Utils = { log: function() { // pass as many arguments as you want, it'll print them all var text = this.expandArgumentsForLog(arguments); +/* $('body').prepend(text + '
'); */ consoleService.logStringMessage(text); },