From 40660c86b93a30d05defae4b499fac5c0c6c57e9 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 22 Apr 2014 20:19:12 -0700 Subject: [PATCH] Bug 996448 - Lazify the loading of PluralForm.jsm everywhere. r=mak. --HG-- extra : rebase_source : 371f4ed436bbdb864edcb593f55bad325d98cfca --- browser/base/content/browser.js | 10 ++-------- browser/components/preferences/aboutPermissions.js | 5 ++++- browser/devtools/styleeditor/StyleEditorUI.jsm | 5 ++++- browser/devtools/styleinspector/computed-view.js | 4 +++- browser/modules/webrtcUI.jsm | 4 +++- mobile/android/modules/WebappManager.jsm | 2 +- toolkit/content/aboutSupport.js | 11 +++++++---- toolkit/mozapps/downloads/DownloadUtils.jsm | 9 ++++----- toolkit/mozapps/downloads/content/downloads.js | 4 +++- toolkit/mozapps/extensions/content/extensions.js | 6 ++++-- 10 files changed, 35 insertions(+), 25 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 6ac10a86b3fe..e47cc5123815 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -79,14 +79,8 @@ this.__defineSetter__("AddonManager", function (val) { return this.AddonManager = val; }); -this.__defineGetter__("PluralForm", function() { - Cu.import("resource://gre/modules/PluralForm.jsm"); - return this.PluralForm; -}); -this.__defineSetter__("PluralForm", function (val) { - delete this.PluralForm; - return this.PluralForm = val; -}); +XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", + "resource://gre/modules/PluralForm.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch", "resource://gre/modules/TelemetryStopwatch.jsm"); diff --git a/browser/components/preferences/aboutPermissions.js b/browser/components/preferences/aboutPermissions.js index f506597df3f2..386ea435f7e0 100644 --- a/browser/components/preferences/aboutPermissions.js +++ b/browser/components/preferences/aboutPermissions.js @@ -6,12 +6,15 @@ let Ci = Components.interfaces; let Cc = Components.classes; let Cu = Components.utils; +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/PluralForm.jsm"); Cu.import("resource://gre/modules/DownloadUtils.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm"); Cu.import("resource://gre/modules/ForgetAboutSite.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", + "resource://gre/modules/PluralForm.jsm"); + let gFaviconService = Cc["@mozilla.org/browser/favicon-service;1"]. getService(Ci.nsIFaviconService); diff --git a/browser/devtools/styleeditor/StyleEditorUI.jsm b/browser/devtools/styleeditor/StyleEditorUI.jsm index 94a0b917a84a..73d88fa18931 100644 --- a/browser/devtools/styleeditor/StyleEditorUI.jsm +++ b/browser/devtools/styleeditor/StyleEditorUI.jsm @@ -11,8 +11,8 @@ const Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/PluralForm.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm"); Cu.import("resource://gre/modules/osfile.jsm"); Cu.import("resource://gre/modules/Task.jsm"); @@ -23,6 +23,9 @@ Cu.import("resource:///modules/devtools/SplitView.jsm"); Cu.import("resource:///modules/devtools/StyleSheetEditor.jsm"); const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {}); +XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", + "resource://gre/modules/PluralForm.jsm"); + const require = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools.require; const { PrefObserver, PREF_ORIG_SOURCES } = require("devtools/styleeditor/utils"); diff --git a/browser/devtools/styleinspector/computed-view.js b/browser/devtools/styleinspector/computed-view.js index 6d957cf91b05..bcc96a5caf4b 100644 --- a/browser/devtools/styleinspector/computed-view.js +++ b/browser/devtools/styleinspector/computed-view.js @@ -17,10 +17,12 @@ const {PrefObserver, PREF_ORIG_SOURCES} = require("devtools/styleeditor/utils"); const {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {}); Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/PluralForm.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/devtools/Templater.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", + "resource://gre/modules/PluralForm.jsm"); + const FILTER_CHANGED_TIMEOUT = 300; const HTML_NS = "http://www.w3.org/1999/xhtml"; const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; diff --git a/browser/modules/webrtcUI.jsm b/browser/modules/webrtcUI.jsm index 96ef492d22c9..c4a00378b5da 100644 --- a/browser/modules/webrtcUI.jsm +++ b/browser/modules/webrtcUI.jsm @@ -11,9 +11,11 @@ const Cc = Components.classes; const Ci = Components.interfaces; Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/PluralForm.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", + "resource://gre/modules/PluralForm.jsm"); + XPCOMUtils.defineLazyServiceGetter(this, "MediaManagerService", "@mozilla.org/mediaManagerService;1", "nsIMediaManagerService"); diff --git a/mobile/android/modules/WebappManager.jsm b/mobile/android/modules/WebappManager.jsm index f8084b72c894..c638c5cd1637 100644 --- a/mobile/android/modules/WebappManager.jsm +++ b/mobile/android/modules/WebappManager.jsm @@ -20,10 +20,10 @@ Cu.import("resource://gre/modules/Webapps.jsm"); Cu.import("resource://gre/modules/osfile.jsm"); Cu.import("resource://gre/modules/Promise.jsm"); Cu.import("resource://gre/modules/Task.jsm"); -Cu.import("resource://gre/modules/PluralForm.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Notifications", "resource://gre/modules/Notifications.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "sendMessageToJava", "resource://gre/modules/Messaging.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", "resource://gre/modules/PluralForm.jsm"); XPCOMUtils.defineLazyGetter(this, "Strings", function() { return Services.strings.createBundle("chrome://browser/locale/webapp.properties"); diff --git a/toolkit/content/aboutSupport.js b/toolkit/content/aboutSupport.js index 8e8e33dd276e..4df562ed316a 100644 --- a/toolkit/content/aboutSupport.js +++ b/toolkit/content/aboutSupport.js @@ -4,10 +4,13 @@ const { classes: Cc, interfaces: Ci, utils: Cu } = Components; -Components.utils.import("resource://gre/modules/Services.jsm"); -Components.utils.import("resource://gre/modules/Troubleshoot.jsm"); -Components.utils.import("resource://gre/modules/PluralForm.jsm"); -Components.utils.import("resource://gre/modules/ResetProfile.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/Troubleshoot.jsm"); +Cu.import("resource://gre/modules/ResetProfile.jsm"); + +XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", + "resource://gre/modules/PluralForm.jsm"); window.addEventListener("load", function onload(event) { window.removeEventListener("load", onload, false); diff --git a/toolkit/mozapps/downloads/DownloadUtils.jsm b/toolkit/mozapps/downloads/DownloadUtils.jsm index 8f470c3e474c..29db429d446f 100644 --- a/toolkit/mozapps/downloads/DownloadUtils.jsm +++ b/toolkit/mozapps/downloads/DownloadUtils.jsm @@ -39,11 +39,10 @@ const Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; -this.__defineGetter__("PluralForm", function() { - delete this.PluralForm; - Cu.import("resource://gre/modules/PluralForm.jsm"); - return PluralForm; -}); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", + "resource://gre/modules/PluralForm.jsm"); this.__defineGetter__("gDecimalSymbol", function() { delete this.gDecimalSymbol; diff --git a/toolkit/mozapps/downloads/content/downloads.js b/toolkit/mozapps/downloads/content/downloads.js index a50ae3a9abb7..b4a97cedfbe0 100644 --- a/toolkit/mozapps/downloads/content/downloads.js +++ b/toolkit/mozapps/downloads/content/downloads.js @@ -18,9 +18,11 @@ var Ci = Components.interfaces; let Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/DownloadUtils.jsm"); -Cu.import("resource://gre/modules/PluralForm.jsm"); Cu.import("resource://gre/modules/Services.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", + "resource://gre/modules/PluralForm.jsm"); + const nsIDM = Ci.nsIDownloadManager; let gDownloadManager = Cc["@mozilla.org/download-manager;1"].getService(nsIDM); diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index 65f1dcba4dfb..d444c23665f2 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -9,13 +9,15 @@ const Ci = Components.interfaces; const Cu = Components.utils; const Cr = Components.results; - Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/PluralForm.jsm"); Cu.import("resource://gre/modules/DownloadUtils.jsm"); Cu.import("resource://gre/modules/AddonManager.jsm"); Cu.import("resource://gre/modules/addons/AddonRepository.jsm"); + +XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", + "resource://gre/modules/PluralForm.jsm"); + XPCOMUtils.defineLazyGetter(this, "BrowserToolboxProcess", function () { return Cu.import("resource:///modules/devtools/ToolboxProcess.jsm", {}). BrowserToolboxProcess;