Bug 506116 - speed up makeURI(str) and use it in browser.js. r=gavin, sr=vlad

This commit is contained in:
Nochum Sossonko 2009-07-28 08:01:31 +02:00
parent 66e5b468d3
commit 8b1e3cbd38
2 changed files with 23 additions and 46 deletions

View File

@ -2660,10 +2660,9 @@ var browserDragAndDrop = {
var file = dt.mozGetDataAt("application/x-moz-file", 0);
if (file) {
var name = file instanceof Ci.nsIFile ? file.leafName : "";
var ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var fileHandler = ioService.getProtocolHandler("file")
.QueryInterface(Ci.nsIFileProtocolHandler);
var fileHandler = ContentAreaUtils.ioService
.getProtocolHandler("file")
.QueryInterface(Ci.nsIFileProtocolHandler);
return [fileHandler.getURLSpecFromFile(file), name];
}
@ -2889,9 +2888,7 @@ const DOMLinkHandler = {
break;
var targetDoc = link.ownerDocument;
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var uri = ios.newURI(link.href, targetDoc.characterSet, null);
var uri = makeURI(link.href, targetDoc.characterSet);
if (gBrowser.isFailedIcon(uri))
break;
@ -4422,10 +4419,7 @@ nsBrowserAccess.prototype =
if (aURI) {
if (aOpener) {
location = aOpener.location;
referrer =
Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newURI(location, null, null);
referrer = makeURI(location);
}
newWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
@ -4442,10 +4436,7 @@ nsBrowserAccess.prototype =
newWindow = aOpener.top;
if (aURI) {
location = aOpener.location;
referrer =
Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newURI(location, null, null);
referrer = makeURI(location);
newWindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(nsIWebNavigation)
@ -5415,17 +5406,7 @@ var OfflineApps = {
_getManifestURI: function(aWindow) {
if (!aWindow.document.documentElement) return null;
var attr = aWindow.document.documentElement.getAttribute("manifest");
if (!attr) return null;
try {
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var contentURI = ios.newURI(aWindow.location.href, null, null);
return ios.newURI(attr, aWindow.document.characterSet, contentURI);
} catch (e) {
return null;
}
return attr ? aWindow.document.documentURIObject : null;
},
// A cache update isn't tied to a specific window. Try to find
@ -5623,11 +5604,8 @@ var OfflineApps = {
if (!manifest)
return;
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var manifestURI = ios.newURI(manifest, aDocument.characterSet,
aDocument.documentURIObject);
var manifestURI = makeURI(manifest, aDocument.characterSet,
aDocument.documentURIObject);
var updateService = Cc["@mozilla.org/offlinecacheupdate-service;1"].
getService(Ci.nsIOfflineCacheUpdateService);
@ -5640,9 +5618,7 @@ var OfflineApps = {
{
if (aTopic == "dom-storage-warn-quota-exceeded") {
if (aSubject) {
var uri = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService).
newURI(aSubject.location.href, null, null);
var uri = aSubject.document.documentURIObject;
if (OfflineApps._checkUsage(uri)) {
var browserWindow =
@ -5703,9 +5679,7 @@ var MailIntegration = {
mailtoUrl += "&subject=" + encodeURIComponent(aSubject);
}
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ioService.newURI(mailtoUrl, null, null);
var uri = makeURI(mailtoUrl);
// now pass this uri to the operating system
this._launchExternalUrl(uri);

View File

@ -41,6 +41,15 @@
#
# ***** END LICENSE BLOCK *****
var ContentAreaUtils = {
get ioService() {
delete this.ioService;
return this.ioService =
Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
}
}
/**
* urlSecurityCheck: JavaScript wrapper for checkLoadURIWithPrincipal
* and checkLoadURIStrWithPrincipal.
@ -772,16 +781,12 @@ function makeWebBrowserPersist()
*/
function makeURI(aURL, aOriginCharset, aBaseURI)
{
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
return ioService.newURI(aURL, aOriginCharset, aBaseURI);
return ContentAreaUtils.ioService.newURI(aURL, aOriginCharset, aBaseURI);
}
function makeFileURI(aFile)
{
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
return ioService.newFileURI(aFile);
return ContentAreaUtils.ioService.newFileURI(aFile);
}
function makeFilePicker()
@ -1025,9 +1030,7 @@ function getCharsetforSave(aDocument)
*/
function openURL(aURL)
{
var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = ios.newURI(aURL, null, null);
var uri = makeURI(aURL, null, null);
var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
.getService(Components.interfaces.nsIExternalProtocolService);