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-29 07:55:03 +02:00
parent bf4c343a15
commit 3f2b8bfc51
2 changed files with 25 additions and 41 deletions

View File

@ -2660,9 +2660,8 @@ 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")
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)
@ -5418,11 +5409,8 @@ var OfflineApps = {
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);
var contentURI = makeURI(aWindow.location.href, null, null);
return makeURI(attr, aWindow.document.characterSet, contentURI);
} catch (e) {
return null;
}
@ -5623,10 +5611,7 @@ var OfflineApps = {
if (!manifest)
return;
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
var manifestURI = ios.newURI(manifest, aDocument.characterSet,
var manifestURI = makeURI(manifest, aDocument.characterSet,
aDocument.documentURIObject);
var updateService = Cc["@mozilla.org/offlinecacheupdate-service;1"].
@ -5640,9 +5625,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 = makeURI(aSubject.location.href);
if (OfflineApps._checkUsage(uri)) {
var browserWindow =
@ -5703,9 +5686,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);
var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
.getService(Components.interfaces.nsIExternalProtocolService);
@ -1075,7 +1078,7 @@ function openURL(aURL)
}
}
var channel = ios.newChannelFromURI(uri);
var channel = ContentAreaUtils.ioService.newChannelFromURI(uri);
var uriLoader = Components.classes["@mozilla.org/uriloader;1"]
.getService(Components.interfaces.nsIURILoader);
uriLoader.openURI(channel, true, uriListener);