comparison ambnews/content/ambnews.js @ 13:fe30d1d71ee5

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.
author Atul Varma <varmaa@toolness.com>
date Sat, 23 Aug 2008 09:15:27 -0700
parents f259d52d361e
children 2f58ecd38d7a
comparison
equal deleted inserted replaced
12:f7c72b3d2bfb 13:fe30d1d71ee5
129 var feed = AmbNews.url(aEvent.target.href); 129 var feed = AmbNews.url(aEvent.target.href);
130 annSvc.setPageAnnotation(page, "ambnews/feed", 130 annSvc.setPageAnnotation(page, "ambnews/feed",
131 feed.spec, 0, annSvc.EXPIRE_WEEKS); 131 feed.spec, 0, annSvc.EXPIRE_WEEKS);
132 } 132 }
133 }, 133 },
134 onLoad: function AmbNews_onLoad(aEvent) { 134 initBrowser: function AmbNews_initBrowser() {
135 if (aEvent.target.baseURI == "about:blank") { 135 // Listen for the addition of new <link> elements on pages.
136 var doc = aEvent.target; 136 window.addEventListener("DOMLinkAdded", AmbNews.onLinkAdded, false);
137 doc.defaultView.location = "about:news"; 137
138 // TODO: The delay here only works most of the time; 138 // Whenever the user opens a new tab, have it point to
139 // its effectiveness is a race condition and we should 139 // about:news by default, and select the URL.
140 // figure out what even to listen for to actually select 140
141 // the URL bar text consistently 141 // The following code was taken from the "New Tab Homepage 0.4"
142 window.setTimeout(function() { gURLBar.select(); }, 50); 142 // extension's 'chrome/content/tabhomepage.js' file. Thanks,
143 // Ben Basson, for figuring this out for me.
144 gBrowser.removeEventListener("NewTab", BrowserOpenTab, false);
145 function onOpenTab(aEvent) {
146 var newTab = gBrowser.addTab("about:news");
147 gBrowser.selectedTab = newTab;
148 if (gURLBar)
149 setTimeout(function() { gURLBar.select(); }, 0);
150 if (aEvent)
151 aEvent.stopPropagation();
152
153 return newTab;
143 } 154 }
155 window.BrowserOpenTab = onOpenTab;
156 gBrowser.addEventListener("NewTab", onOpenTab, false);
144 } 157 }
145 }; 158 };