# HG changeset patch # User Atul Varma # Date 1219508127 25200 # Node ID fe30d1d71ee5874edeb948c60b912923f448c66c # Parent f7c72b3d2bfbefc3c1cf1a711d53c3234e864278 Fixed the race-condition bug for selecting the about:news URL text, and also probably prevented about:news from loading in places that it wasn't supposed to. diff -r f7c72b3d2bfb -r fe30d1d71ee5 ambnews/content/ambnews.js --- a/ambnews/content/ambnews.js Fri Aug 22 11:10:27 2008 -0700 +++ b/ambnews/content/ambnews.js Sat Aug 23 09:15:27 2008 -0700 @@ -131,15 +131,28 @@ feed.spec, 0, annSvc.EXPIRE_WEEKS); } }, - onLoad: function AmbNews_onLoad(aEvent) { - if (aEvent.target.baseURI == "about:blank") { - var doc = aEvent.target; - doc.defaultView.location = "about:news"; - // TODO: The delay here only works most of the time; - // its effectiveness is a race condition and we should - // figure out what even to listen for to actually select - // the URL bar text consistently - window.setTimeout(function() { gURLBar.select(); }, 50); + initBrowser: function AmbNews_initBrowser() { + // Listen for the addition of new elements on pages. + window.addEventListener("DOMLinkAdded", AmbNews.onLinkAdded, false); + + // Whenever the user opens a new tab, have it point to + // about:news by default, and select the URL. + + // The following code was taken from the "New Tab Homepage 0.4" + // extension's 'chrome/content/tabhomepage.js' file. Thanks, + // Ben Basson, for figuring this out for me. + gBrowser.removeEventListener("NewTab", BrowserOpenTab, false); + function onOpenTab(aEvent) { + var newTab = gBrowser.addTab("about:news"); + gBrowser.selectedTab = newTab; + if (gURLBar) + setTimeout(function() { gURLBar.select(); }, 0); + if (aEvent) + aEvent.stopPropagation(); + + return newTab; } + window.BrowserOpenTab = onOpenTab; + gBrowser.addEventListener("NewTab", onOpenTab, false); } }; diff -r f7c72b3d2bfb -r fe30d1d71ee5 ambnews/content/browser.xul --- a/ambnews/content/browser.xul Fri Aug 22 11:10:27 2008 -0700 +++ b/ambnews/content/browser.xul Sat Aug 23 09:15:27 2008 -0700 @@ -4,11 +4,6 @@