Bug 468294: Make sure BrowserUI can handle background tab loads [r=mark.finkle]

This commit is contained in:
Vivien Nicolas 2009-10-09 08:34:02 -04:00
parent 0ba9982809
commit 42e44c7790
5 changed files with 80 additions and 50 deletions

View File

@ -42,14 +42,22 @@ Cu.import("resource://gre/modules/PluralForm.jsm");
const TOOLBARSTATE_LOADING = 1;
const TOOLBARSTATE_LOADED = 2;
const kDefaultFavIconURL = "chrome://browser/skin/images/favicon-default-30.png";
[
[
"gHistSvc",
"@mozilla.org/browser/nav-history-service;1",
[Ci.nsINavHistoryService, Ci.nsIBrowserHistory]
],
[
"gFaviconService",
"@mozilla.org/browser/favicon-service;1",
[Ci.nsIFaviconService]
],
[
"gIOService",
"@mozilla.org/network/io-service;1",
[Ci.nsIIOService],
],
[
"gURIFixup",
"@mozilla.org/docshell/urifixup;1",
@ -75,7 +83,6 @@ var BrowserUI = {
_edit : null,
_throbber : null,
_favicon : null,
_faviconLink : null,
_dialogs: [],
_domWillOpenModalDialog: function(e) {
@ -133,12 +140,16 @@ var BrowserUI = {
return;
if (/\bicon\b/i(link.rel)) {
this._faviconLink = link.href;
var ownerDoc = link.ownerDocument;
if (!ownerDoc) // no document, no icon
return;
let tab = Browser.getTabForDocument(ownerDoc);
tab.setIcon(link.href);
// If the link changes after pageloading, update it right away.
// otherwise we wait until the pageload finishes
if (this._favicon.src != "")
this._setIcon(this._faviconLink);
if ((tab.browser == Browser.selectedBrowser) && !tab.isLoading())
this._updateIcon(tab.browser.mIconURL);
}
else if (/\bsearch\b/i(link.rel)) {
var type = link.type && link.type.toLowerCase();
@ -163,33 +174,8 @@ var BrowserUI = {
var browser = Browser.selectedBrowser;
this._titleChanged(browser.contentDocument);
this._updateButtons(browser);
this._updateIcon(browser.mIconURL);
this.updateStar();
this._favicon.src = browser.mIconURL || kDefaultFavIconURL;
// for new tabs, _tabSelect & update(TOOLBARSTATE_LOADED) are called when
// about:blank is loaded. set _faviconLink here so it is not overriden in update
this._faviconLink = this._favicon.src;
this.updateIcon();
},
_setIcon : function(aURI) {
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
try {
var faviconURI = ios.newURI(aURI, null, null);
}
catch (e) {
faviconURI = null;
}
var fis = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService);
if (!faviconURI || faviconURI.schemeIs("javascript") || fis.isFailedFavicon(faviconURI))
faviconURI = ios.newURI(kDefaultFavIconURL, null, null);
var browser = getBrowser();
browser.mIconURL = faviconURI.spec;
fis.setAndLoadFaviconForPage(browser.currentURI, faviconURI, true);
this._favicon.src = faviconURI.spec;
},
showToolbar : function showToolbar(aEdit) {
@ -427,35 +413,32 @@ var BrowserUI = {
update : function(aState) {
let icons = document.getElementById("urlbar-icons");
let browser = Browser.selectedBrowser;
// Use documentURIObject in the favicon construction so that we
// do the right thing with about:-style error pages. Bug 515188
let uri = Browser.selectedBrowser.contentDocument.documentURIObject;
let uri = browser.contentDocument.documentURIObject;
switch (aState) {
case TOOLBARSTATE_LOADED:
if (icons.getAttribute("mode") != "edit")
icons.setAttribute("mode", "view");
if (!this._faviconLink)
this._faviconLink = uri.prePath + "/favicon.ico";
this._setIcon(this._faviconLink);
this.updateIcon();
this._faviconLink = null;
this._updateIcon(browser.mIconURL);
break;
case TOOLBARSTATE_LOADING:
if (icons.getAttribute("mode") != "edit")
icons.setAttribute("mode", "loading");
this._favicon.src = "";
this._faviconLink = null;
this.updateIcon();
browser.mIconURL = "";
this._updateIcon();
break;
}
},
updateIcon : function() {
_updateIcon : function(aIconSrc) {
this._favicon.src = aIconSrc || "";
if (Browser.selectedTab.isLoading()) {
this._throbber.hidden = false;
this._throbber.setAttribute("loading", "true");
@ -682,7 +665,7 @@ var BrowserUI = {
break;
// Favicon events
case "error":
this._favicon.src = "chrome://browser/skin/images/default-favicon.png";
this._favicon.src = "";
break;
}
},

View File

@ -445,7 +445,6 @@ var Browser = {
window.controllers.appendController(this);
window.controllers.appendController(BrowserUI);
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var styleSheets = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
// Should we hide the cursors
@ -453,12 +452,12 @@ var Browser = {
if (hideCursor) {
window.QueryInterface(Ci.nsIDOMChromeWindow).setCursor("none");
var styleURI = ios.newURI("chrome://browser/content/cursor.css", null, null);
var styleURI = gIOService.newURI("chrome://browser/content/cursor.css", null, null);
styleSheets.loadAndRegisterSheet(styleURI, styleSheets.AGENT_SHEET);
}
// load styles for scrollbars
var styleURI = ios.newURI("chrome://browser/content/content.css", null, null);
var styleURI = gIOService.newURI("chrome://browser/content/content.css", null, null);
styleSheets.loadAndRegisterSheet(styleURI, styleSheets.AGENT_SHEET);
var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
@ -633,6 +632,15 @@ var Browser = {
return this._selectedTab.browser;
},
getTabForDocument: function(aDocument) {
let tabs = this._tabs;
for (let i = 0; i < tabs.length; i++) {
if (tabs[i].browser.contentDocument === aDocument)
return tabs[i];
}
return null;
},
getTabAtIndex: function(index) {
if (index > this._tabs.length || index < 0)
return null;
@ -1361,8 +1369,7 @@ nsBrowserAccess.prototype = {
if (aURI) {
if (aOpener) {
location = aOpener.location;
referrer = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService)
.newURI(location, null, null);
referrer = gIOService.newURI(location, null, null);
}
newWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
@ -2374,6 +2381,7 @@ Tab.prototype = {
endLoading: function() {
//if (!this._loading)
// dump("!!! Already finished loading this tab, please file a bug\n");
this.setIcon(this._browser.mIconURL);
this._loading = false;
clearTimeout(this._loadingTimeout);
@ -2511,6 +2519,33 @@ Tab.prototype = {
this._chromeTab.updateThumbnail(this._browser, browserView);
},
setIcon: function(aURI) {
let faviconURI = null;
if (aURI) {
try {
faviconURI = gIOService.newURI(aURI, null, null);
}
catch (e) {
faviconURI = null;
}
}
if (!faviconURI || faviconURI.schemeIs("javascript") || gFaviconService.isFailedFavicon(faviconURI)) {
try {
faviconURI = gIOService.newURI(this._browser.currentURI.prePath + "/favicon.ico", null, null);
gFaviconService.setAndLoadFaviconForPage(this._browser.currentURI, faviconURI, true);
}
catch (e) {
faviconURI = null;
}
if (faviconURI && gFaviconService.isFailedFavicon(faviconURI))
faviconURI = null;
}
this._browser.mIconURL = faviconURI ? faviconURI.spec : "";
},
toString: function() {
return "[Tab " + (this._browser ? this._browser.contentDocument.location.toString() : "(no browser)") + "]";
}

View File

@ -173,6 +173,10 @@ toolbarbutton.urlbar-cap-button {
height: 30px;
}
#urlbar-favicon[src=""] {
list-style-image: url("chrome://browser/skin/images/favicon-default-30.png");
}
#urlbar-editarea {
min-height: 64px;
-moz-box-align: center;

View File

@ -119,6 +119,10 @@
height: 30px;
}
#urlbar-favicon[src=""] {
list-style-image: url("chrome://browser/skin/images/favicon-default-30.png");
}
#urlbar-editarea {
min-height: 64px;
-moz-box-align: center;

View File

@ -118,6 +118,10 @@
height: 24px;
}
#urlbar-favicon[src=""] {
list-style-image: url("chrome://browser/skin/images/favicon-default-24.png");
}
#urlbar-editarea {
min-height: 36px;
-moz-box-align: center;