From 3f2b8bfc516854a0f745b4b9d5a5ce652aea5ac2 Mon Sep 17 00:00:00 2001 From: Nochum Sossonko Date: Wed, 29 Jul 2009 07:55:03 +0200 Subject: [PATCH] Bug 506116 - speed up makeURI(str) and use it in browser.js. r=gavin, sr=vlad --- browser/base/content/browser.js | 43 ++++++++--------------------- toolkit/content/contentAreaUtils.js | 23 ++++++++------- 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 8316f133f2b..2cae4f4b2d5 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -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) @@ -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,11 +5611,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 +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); diff --git a/toolkit/content/contentAreaUtils.js b/toolkit/content/contentAreaUtils.js index c3ac0f345c3..83cbad59841 100644 --- a/toolkit/content/contentAreaUtils.js +++ b/toolkit/content/contentAreaUtils.js @@ -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);