diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index a172251baa8b..e84fb05ed117 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -69,7 +69,6 @@ const MAX_HISTORY_MENU_ITEMS = 15; // We use this once, for Clear Private Data const GLUE_CID = "@mozilla.org/browser/browserglue;1"; -var gURIFixup = null; var gCharsetMenu = null; var gLastBrowserCharset = null; var gPrevCharset = null; @@ -1966,37 +1965,25 @@ function checkForDirectoryListing() } } -function URLBarSetURI(aURI) { +function URLBarSetURI(aURI, aValid) { var value = gBrowser.userTypedValue; - var state = "invalid"; + var valid = false; if (!value) { - if (aURI) { - // If the url has "wyciwyg://" as the protocol, strip it off. - // Nobody wants to see it on the urlbar for dynamically generated - // pages. - if (!gURIFixup) - gURIFixup = Cc["@mozilla.org/docshell/urifixup;1"] - .getService(Ci.nsIURIFixup); - try { - aURI = gURIFixup.createExposableURI(aURI); - } catch (ex) {} - } else { - aURI = getWebNavigation().currentURI; - } + let uri = aURI || getWebNavigation().currentURI; - if (aURI.spec == "about:blank") { - // Replace "about:blank" with an empty string - // only if there's no opener (bug 370555). - value = content.opener ? aURI.spec : ""; - } else { - value = losslessDecodeURI(aURI); - state = "valid"; - } + // Replace "about:blank" with an empty string + // only if there's no opener (bug 370555). + if (uri.spec == "about:blank") + value = content.opener ? "about:blank" : ""; + else + value = losslessDecodeURI(uri); + + valid = value && (!aURI || aValid); } gURLBar.value = value; - SetPageProxyState(state); + SetPageProxyState(valid ? "valid" : "invalid"); } function losslessDecodeURI(aURI) { @@ -3756,6 +3743,11 @@ var XULBrowserWindow = { delete this.isImage; return this.isImage = document.getElementById("isImage"); }, + get _uriFixup () { + delete this._uriFixup; + return this._uriFixup = Cc["@mozilla.org/docshell/urifixup;1"] + .getService(Ci.nsIURIFixup); + }, init: function () { this.throbberElement = document.getElementById("navigator-throbber"); @@ -4013,8 +4005,15 @@ var XULBrowserWindow = { gBrowser.setIcon(gBrowser.mCurrentTab, null); if (gURLBar) { - URLBarSetURI(aLocationURI); - PlacesStarButton.updateState(); // Update starring UI + // Strip off "wyciwyg://" and passwords for the location bar + let uri = aLocationURI; + try { + uri = this._uriFixup.createExposableURI(uri); + } catch (e) {} + URLBarSetURI(uri, true); + + // Update starring UI + PlacesStarButton.updateState(); } FullZoom.onLocationChange(aLocationURI); @@ -4221,22 +4220,26 @@ var XULBrowserWindow = { // clear out search-engine data gBrowser.mCurrentBrowser.engines = null; - const nsIChannel = Components.interfaces.nsIChannel; - var urlStr = aRequest.QueryInterface(nsIChannel).URI.spec; - var observerService = Components.classes["@mozilla.org/observer-service;1"] - .getService(Components.interfaces.nsIObserverService); + var uri = aRequest.QueryInterface(Ci.nsIChannel).URI; + var observerService = Cc["@mozilla.org/observer-service;1"] + .getService(Ci.nsIObserverService); + + if (gURLBar && + gURLBar.value == "" && + getWebNavigation().currentURI.spec == "about:blank") + URLBarSetURI(uri); + try { - observerService.notifyObservers(content, "StartDocumentLoad", urlStr); + observerService.notifyObservers(content, "StartDocumentLoad", uri.spec); } catch (e) { } }, endDocumentLoad: function (aRequest, aStatus) { - const nsIChannel = Components.interfaces.nsIChannel; - var urlStr = aRequest.QueryInterface(nsIChannel).originalURI.spec; + var urlStr = aRequest.QueryInterface(Ci.nsIChannel).originalURI.spec; - var observerService = Components.classes["@mozilla.org/observer-service;1"] - .getService(Components.interfaces.nsIObserverService); + var observerService = Cc["@mozilla.org/observer-service;1"] + .getService(Ci.nsIObserverService); var notification = Components.isSuccessCode(aStatus) ? "EndDocumentLoad" : "FailDocumentLoad"; try {