Fix bug 462393 - Sunbird tinderboxen busted [Error: mozilla/dist/bin/js: Not a directory]. r=philipp
authorDaniel Boelzle [:dbo] <daniel.boelzle@sun.com>
Mon, 03 Nov 2008 10:12:34 +0100
changeset 800 9415304586253a2e99ff4d78da0797f053b23803
parent 799 46da6c5e9740f3789d3753718d69f30162af79fc
child 801 d59e13b2f37ecf019c6253545370f66f4011af29
push idunknown
push userunknown
push dateunknown
reviewersphilipp
bugs462393
Fix bug 462393 - Sunbird tinderboxen busted [Error: mozilla/dist/bin/js: Not a directory]. r=philipp
calendar/base/src/Makefile.in
calendar/base/src/calItemModule.js
calendar/base/src/calUtils.jsm
calendar/import-export/Makefile.in
calendar/import-export/calImportExportModule.js
calendar/installer/removed-files.in
calendar/installer/windows/packages-static
calendar/itip/calItipEmailTransport.js
calendar/lightning/components/lightningTextCalendarConverter.js
calendar/providers/base/Makefile.in
calendar/providers/caldav/Makefile.in
calendar/providers/caldav/calDavCalendarModule.js
calendar/providers/composite/calCompositeCalendar.js
calendar/providers/gdata/components/calGoogleCalendarModule.js
calendar/providers/ics/Makefile.in
calendar/providers/ics/calICSCalendarModule.js
calendar/providers/memory/Makefile.in
calendar/providers/memory/calMemoryCalendarModule.js
calendar/providers/storage/Makefile.in
calendar/providers/storage/calStorageCalendarModule.js
calendar/providers/wcap/Makefile.in
calendar/providers/wcap/calWcapCalendarModule.js
calendar/test/unit/head_consts.js
--- a/calendar/base/src/Makefile.in
+++ b/calendar/base/src/Makefile.in
@@ -110,16 +110,16 @@ EXTRA_SCRIPTS = \
     $(NULL)
 
 EXTRA_JS_MODULES = \
     calUtils.jsm \
     $(NULL)
 
 # Use NSINSTALL to make the directory, as there's no mtime to preserve.
 libs:: $(EXTRA_SCRIPTS)
-	if test ! -d $(FINAL_TARGET)/js; then $(NSINSTALL) -D $(FINAL_TARGET)/js; fi
-	$(INSTALL) $^ $(FINAL_TARGET)/js
+	if test ! -d $(FINAL_TARGET)/calendar-js; then $(NSINSTALL) -D $(FINAL_TARGET)/calendar-js; fi
+	$(INSTALL) $^ $(FINAL_TARGET)/calendar-js
 
 # The install target must use SYSINSTALL, which is NSINSTALL in copy mode.
 install:: $(EXTRA_SCRIPTS)
-	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/js
+	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/calendar-js
 
 include $(topsrcdir)/config/rules.mk
--- a/calendar/base/src/calItemModule.js
+++ b/calendar/base/src/calItemModule.js
@@ -222,63 +222,26 @@ const componentData =
     ];
 
 var calItemModule = {
     mScriptsLoaded: false,
     loadScripts: function () {
         if (this.mScriptsLoaded)
             return;
 
-        const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
-        const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
-
-        const dirsvcContractID = "@mozilla.org/file/directory_service;1";
-        const propsIID = Components.interfaces.nsIProperties;
-
-        const iosvcContractID = "@mozilla.org/network/io-service;1";
-        const iosvcIID = Components.interfaces.nsIIOService;
-
-        var loader = Components.classes[jssslContractID].getService(jssslIID);
-        var dirsvc = Components.classes[dirsvcContractID].getService(propsIID);
-        var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
-
-        // Note that unintuitively, __LOCATION__.parent == .
-        // We expect to find the subscripts in ./../js
-        let appdir = __LOCATION__.parent.parent.clone();
+        // Register our alias here: this code always needs to run first (triggered by app-startup)
+        let ioService = Components.classes["@mozilla.org/network/io-service;1"]
+                                  .getService(Components.interfaces.nsIIOService2);
+        ioService.getProtocolHandler("resource")
+                 .QueryInterface(Components.interfaces.nsIResProtocolHandler)
+                 .setSubstitution("calendar", ioService.newFileURI(__LOCATION__.parent.parent));
 
-        // Register our alias here: this code always needs to run first (triggered by app-startup)
-        let modulesDir = appdir.clone();
-        modulesDir.append("modules");
-        modulesDir = iosvc.newFileURI(modulesDir);
-        // bug 459196:
-        // we need to cut/hack around the trailing slash, otherwise our modules won't be found
-        // when loaded like "resource://calendar/modules/calUtils.jsm"
-        modulesDir.spec = modulesDir.spec.replace(/\/$/, "");
-        iosvc.getProtocolHandler("resource")
-             .QueryInterface(Components.interfaces.nsIResProtocolHandler)
-             .setSubstitution("calendar", modulesDir);
-
-        appdir.append("js");
-
-        for (var i = 0; i < componentData.length; i++) {
-            var scriptName = componentData[i].script;
-            if (!scriptName)
-                continue;
-
-            var f = appdir.clone();
-            f.append(scriptName);
-
-            try {
-                var fileurl = iosvc.newFileURI(f);
-                loader.loadSubScript(fileurl.spec, null);
-            } catch (e) {
-                dump("Error while loading " + fileurl.spec + "\n");
-                throw e;
-            }
-        }
+        Components.utils.import("resource://calendar/modules/calUtils.jsm");
+        cal.loadScripts(componentData.map(function(entry) { return entry.script; }),
+                        this.__parent__);
 
         this.mScriptsLoaded = true;
     },
 
     registerSelf: function (compMgr, fileSpec, location, type) {
         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
 
         var catman = Components.classes["@mozilla.org/categorymanager;1"]
--- a/calendar/base/src/calUtils.jsm
+++ b/calendar/base/src/calUtils.jsm
@@ -42,16 +42,45 @@ let cal = {
     // new code should land here,
     // and more code should be moved from calUtils.js into this object to avoid
     // clashes with other extensions
 
     getIOService: generateServiceAccessor("@mozilla.org/network/io-service;1",
                                           Components.interfaces.nsIIOService2),
 
     /**
+     * Loads an array of calendar scripts into the passed scope.
+     *
+     * @param scriptNames an array of calendar script names
+     * @param scope       scope to load into
+     * @param baseDir     base dir; defaults to calendar-js/
+     */
+    loadScripts: function cal_loadScripts(scriptNames, scope, baseDir) {
+        let scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
+                                     .createInstance(Components.interfaces.mozIJSSubScriptLoader);
+        let ioService = cal.getIOService();
+
+        if (!baseDir) {
+            baseDir = __LOCATION__.parent.parent;
+        }
+        baseDir = baseDir.clone();
+        baseDir.append("calendar-js");
+
+        for each (let script in scriptNames) {
+            let scriptFile = baseDir.clone();
+            scriptFile.append(script);
+            try {
+                scriptLoader.loadSubScript(ioService.newFileURI(scriptFile).spec, scope);
+            } catch (exc) {
+                Components.utils.reportError(exc);
+            }
+        }
+    },
+
+    /**
      * Checks whether a timezone lacks a definition.
      */
     isPhantomTimezone: function cal_isPhantomTimezone(tz) {
         return (!tz.icalComponent && !tz.isUTC && !tz.isFloating);
     },
 
     // The below functions will move to some different place once the
     // unifinder tress are consolidated.
@@ -228,15 +257,9 @@ function generateServiceAccessor(id, ifa
         }
         return this_.mService;
     };
 }
 
 // Interim import of all symbols into cal:
 // This should serve as a clean start for new code, e.g. new code could use
 // cal.createDatetime instead of plain createDatetime NOW.
-let calUtils = __LOCATION__.parent.parent.clone();
-calUtils.append("js");
-calUtils.append("calUtils.js");
-Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
-          .getService(Components.interfaces.mozIJSSubScriptLoader)
-          .loadSubScript(cal.getIOService().newFileURI(calUtils).spec, cal);
-
+cal.loadScripts(["calUtils.js"], cal);
--- a/calendar/import-export/Makefile.in
+++ b/calendar/import-export/Makefile.in
@@ -52,16 +52,16 @@ EXTRA_SCRIPTS = \
     calListFormatter.js \
     calMonthGridPrinter.js \
     calOutlookCSVImportExport.js \
     calWeekPrinter.js \
     $(NULL)
 
 # Use NSINSTALL to make the directory, as there's no mtime to preserve.
 libs:: $(EXTRA_SCRIPTS)
-	if test ! -d $(FINAL_TARGET)/js; then $(NSINSTALL) -D $(FINAL_TARGET)/js; fi
-	$(INSTALL) $^ $(FINAL_TARGET)/js
+	if test ! -d $(FINAL_TARGET)/calendar-js; then $(NSINSTALL) -D $(FINAL_TARGET)/calendar-js; fi
+	$(INSTALL) $^ $(FINAL_TARGET)/calendar-js
 
 # The install target must use SYSINSTALL, which is NSINSTALL in copy mode.
 install:: $(EXTRA_SCRIPTS)
-	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/js
+	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/calendar-js
 
 include $(topsrcdir)/config/rules.mk
--- a/calendar/import-export/calImportExportModule.js
+++ b/calendar/import-export/calImportExportModule.js
@@ -108,50 +108,19 @@ const componentData =
     ];
 
 var calImportExportModule = {
     mScriptsLoaded: false,
     loadScripts: function () {
         if (this.mScriptsLoaded)
             return;
 
-        const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
-        const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
-
-        const dirsvcContractID = "@mozilla.org/file/directory_service;1";
-        const propsIID = Components.interfaces.nsIProperties;
-
-        const iosvcContractID = "@mozilla.org/network/io-service;1";
-        const iosvcIID = Components.interfaces.nsIIOService;
-
-        var loader = Components.classes[jssslContractID].getService(jssslIID);
-        var dirsvc = Components.classes[dirsvcContractID].getService(propsIID);
-        var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
-
-        // Note that unintuitively, __LOCATION__.parent == .
-        // We expect to find the subscripts in ./../js
-        var appdir = __LOCATION__.parent.parent;
-        appdir.append("js");
-
-        for (var i = 0; i < componentData.length; i++) {
-            var scriptName = componentData[i].script;
-            if (!scriptName)
-                continue;
-
-            var f = appdir.clone();
-            f.append(scriptName);
-
-            try {
-                var fileurl = iosvc.newFileURI(f);
-                loader.loadSubScript(fileurl.spec, null);
-            } catch (e) {
-                dump("Error while loading " + fileurl.spec + "\n");
-                throw e;
-            }
-        }
+        Components.utils.import("resource://calendar/modules/calUtils.jsm");
+        cal.loadScripts(componentData.map(function(entry) { return entry.script; }),
+                        this.__parent__);
 
         this.mScriptsLoaded = true;
     },
 
     registerSelf: function (compMgr, fileSpec, location, type) {
         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
 
         var catman = Components.classes["@mozilla.org/categorymanager;1"]
--- a/calendar/installer/removed-files.in
+++ b/calendar/installer/removed-files.in
@@ -366,8 +366,54 @@ res/html/gopher-binary.gif
 res/html/gopher-find.gif
 res/html/gopher-image.gif
 res/html/gopher-menu.gif
 res/html/gopher-movie.gif
 res/html/gopher-sound.gif
 res/html/gopher-telnet.gif
 res/html/gopher-text.gif
 res/html/gopher-unknown.gif
+
+# Bug 462393 - Sunbird tinderboxen busted [Error: mozilla/dist/bin/js: Not a directory]
+js/calAlarm.js
+js/calAlarmMonitor.js
+js/calAlarmService.js
+js/calAttachment.js
+js/calAttendee.js
+js/calAuthUtils.js
+js/calCachedCalendar.js
+js/calCalendarManager.js
+js/calCalendarSearchService.js
+js/calDateTimeFormatter.js
+js/calDavCalendar.js
+js/calEvent.js
+js/calFilter.js
+js/calFreeBusyService.js
+js/calHtmlExport.js
+js/calICSCalendar.js
+js/calIcsImportExport.js
+js/calIcsParser.js
+js/calIcsSerializer.js
+js/calItemBase.js
+js/calItipItem.js
+js/calItipProcessor.js
+js/calListFormatter.js
+js/calMemoryCalendar.js
+js/calMonthGridPrinter.js
+js/calOutlookCSVImportExport.js
+js/calProtocolHandler.js
+js/calProviderBase.js
+js/calProviderUtils.js
+js/calRecurrenceInfo.js
+js/calRelation.js
+js/calStorageCalendar.js
+js/calTimezoneService.js
+js/calTodo.js
+js/calTransactionManager.js
+js/calUtils.js
+js/calWcapCalendar.js
+js/calWcapCalendarItems.js
+js/calWcapErrors.js
+js/calWcapRequest.js
+js/calWcapSession.js
+js/calWcapUtils.js
+js/calWeekInfoService.js
+js/calWeekPrinter.js
--- a/calendar/installer/windows/packages-static
+++ b/calendar/installer/windows/packages-static
@@ -210,60 +210,60 @@ bin\components\nsProxyAutoConfig.js
 bin\components\nsTryToClose.js
 bin\components\nsUpdateService.js
 bin\components\nsURLFormatter.js
 bin\components\nsWebHandlerApp.js
 bin\components\pluginGlue.js
 bin\components\storage-Legacy.js
 bin\components\storage-mozStorage.js
 bin\components\txEXSLTRegExFunctions.js
-bin\js\calAlarm.js
-bin\js\calAlarmMonitor.js
-bin\js\calAlarmService.js
-bin\js\calAttachment.js
-bin\js\calAttendee.js
-bin\js\calAuthUtils.js
-bin\js\calCachedCalendar.js
-bin\js\calCalendarManager.js
-bin\js\calCalendarSearchService.js
-bin\js\calDateTimeFormatter.js
-bin\js\calDavCalendar.js
-bin\js\calEvent.js
-bin\js\calFilter.js
-bin\js\calFreeBusyService.js
-bin\js\calHtmlExport.js
-bin\js\calICSCalendar.js
-bin\js\calIcsImportExport.js
-bin\js\calIcsParser.js
-bin\js\calIcsSerializer.js
-bin\js\calItemBase.js
-bin\js\calItipItem.js
-bin\js\calItipProcessor.js
-bin\js\calListFormatter.js
-bin\js\calMemoryCalendar.js
-bin\js\calMonthGridPrinter.js
-bin\js\calOutlookCSVImportExport.js
-bin\js\calProtocolHandler.js
-bin\js\calProviderBase.js
-bin\js\calProviderUtils.js
-bin\js\calRecurrenceInfo.js
-bin\js\calRelation.js
-bin\js\calStorageCalendar.js
-bin\js\calTimezoneService.js
-bin\js\calTodo.js
-bin\js\calTransactionManager.js
-bin\js\calUtils.js
-bin\js\calWcapCalendar.js
-bin\js\calWcapCalendarItems.js
-bin\js\calWcapErrors.js
-bin\js\calWcapRequest.js
-bin\js\calWcapSession.js
-bin\js\calWcapUtils.js
-bin\js\calWeekInfoService.js
-bin\js\calWeekPrinter.js
+bin\calendar-js\calAlarm.js
+bin\calendar-js\calAlarmMonitor.js
+bin\calendar-js\calAlarmService.js
+bin\calendar-js\calAttachment.js
+bin\calendar-js\calAttendee.js
+bin\calendar-js\calAuthUtils.js
+bin\calendar-js\calCachedCalendar.js
+bin\calendar-js\calCalendarManager.js
+bin\calendar-js\calCalendarSearchService.js
+bin\calendar-js\calDateTimeFormatter.js
+bin\calendar-js\calDavCalendar.js
+bin\calendar-js\calEvent.js
+bin\calendar-js\calFilter.js
+bin\calendar-js\calFreeBusyService.js
+bin\calendar-js\calHtmlExport.js
+bin\calendar-js\calICSCalendar.js
+bin\calendar-js\calIcsImportExport.js
+bin\calendar-js\calIcsParser.js
+bin\calendar-js\calIcsSerializer.js
+bin\calendar-js\calItemBase.js
+bin\calendar-js\calItipItem.js
+bin\calendar-js\calItipProcessor.js
+bin\calendar-js\calListFormatter.js
+bin\calendar-js\calMemoryCalendar.js
+bin\calendar-js\calMonthGridPrinter.js
+bin\calendar-js\calOutlookCSVImportExport.js
+bin\calendar-js\calProtocolHandler.js
+bin\calendar-js\calProviderBase.js
+bin\calendar-js\calProviderUtils.js
+bin\calendar-js\calRecurrenceInfo.js
+bin\calendar-js\calRelation.js
+bin\calendar-js\calStorageCalendar.js
+bin\calendar-js\calTimezoneService.js
+bin\calendar-js\calTodo.js
+bin\calendar-js\calTransactionManager.js
+bin\calendar-js\calUtils.js
+bin\calendar-js\calWcapCalendar.js
+bin\calendar-js\calWcapCalendarItems.js
+bin\calendar-js\calWcapErrors.js
+bin\calendar-js\calWcapRequest.js
+bin\calendar-js\calWcapSession.js
+bin\calendar-js\calWcapUtils.js
+bin\calendar-js\calWeekInfoService.js
+bin\calendar-js\calWeekPrinter.js
 
 ; [Modules]
 bin\modules\*
 
 ; [Calendar Chrome Files]
 bin\chrome\calendar.jar
 bin\chrome\calendar.manifest
 bin\chrome\sunbird.jar
--- a/calendar/itip/calItipEmailTransport.js
+++ b/calendar/itip/calItipEmailTransport.js
@@ -431,41 +431,18 @@ var calItipEmailTransportModule = {
     mCID: Components.ID("{d4d7b59e-c9e0-4a7a-b5e8-5958f85515f0}"),
     mContractID: "@mozilla.org/calendar/itip-transport;1?type=email",
 
     mUtilsLoaded: false,
     loadUtils: function itipEmailLoadUtils() {
         if (this.mUtilsLoaded)
             return;
 
-        const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
-        const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
-
-        const iosvcContractID = "@mozilla.org/network/io-service;1";
-        const iosvcIID = Components.interfaces.nsIIOService;
-
-        var loader = Components.classes[jssslContractID].getService(jssslIID);
-        var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
-
-        // Note that unintuitively, __LOCATION__.parent == .
-        // We expect to find utils in ./../js
-        var appdir = __LOCATION__.parent.parent;
-        appdir.append("js");
-        var scriptName = "calUtils.js";
-
-        var f = appdir.clone();
-        f.append(scriptName);
-
-        try {
-            var fileurl = iosvc.newFileURI(f);
-            loader.loadSubScript(fileurl.spec, this.__parent__.__parent__);
-        } catch (e) {
-            dump("Error while loading " + fileurl.spec + "\n");
-            throw e;
-        }
+        Components.utils.import("resource://calendar/modules/calUtils.jsm");
+        cal.loadScripts(["calUtils.js"], this.__parent__);
 
         this.mUtilsLoaded = true;
     },
     
     registerSelf: function (compMgr, fileSpec, location, type) {
         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
         compMgr.registerFactoryLocation(this.mCID,
                                         "Calendar iTIP Email Transport",
--- a/calendar/lightning/components/lightningTextCalendarConverter.js
+++ b/calendar/lightning/components/lightningTextCalendarConverter.js
@@ -256,29 +256,20 @@ var myModule = {
 
         catman.addCategoryEntry("simple-mime-converters", "text/calendar",
                                 this.myContractID, true, true);
     },
 
     mScriptsLoaded: false,
     getClassObject: function GCO(aCompMgr, aCid, aIid) {
         if (!this.mScriptsLoaded) {
-            // loading extra scripts from ../js:
-            const scripts = [ "calUtils.js" ];
-            var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
-                                         .createInstance(Components.interfaces.mozIJSSubScriptLoader);
-            var ioService = Components.classes["@mozilla.org/network/io-service;1"]
-                                      .getService(Components.interfaces.nsIIOService);
-            var baseDir = __LOCATION__.parent.parent;
-            baseDir.append("js");
-            for each (var script in scripts) {
-                var scriptFile = baseDir.clone();
-                scriptFile.append(script);
-                scriptLoader.loadSubScript(ioService.newFileURI(scriptFile).spec, null);
-            }
+
+            Components.utils.import("resource://calendar/modules/calUtils.jsm");
+            cal.loadScripts(["calUtils.js"], this.__parent__);
+
             this.mScriptsLoaded = true;
         }
 
         if (!aCid.equals(this.myCID)) {
             throw Components.results.NS_ERROR_NO_INTERFACE;
         }
         if (!aIid.equals(Components.interfaces.nsIFactory)) {
             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
--- a/calendar/providers/base/Makefile.in
+++ b/calendar/providers/base/Makefile.in
@@ -39,16 +39,16 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 EXTRA_SCRIPTS = calProviderBase.js
 
 libs:: $(EXTRA_SCRIPTS)
-	if test ! -d $(FINAL_TARGET)/js; then $(NSINSTALL) -D $(FINAL_TARGET)/js; fi
-	$(INSTALL) $^ $(FINAL_TARGET)/js
+	if test ! -d $(FINAL_TARGET)/calendar-js; then $(NSINSTALL) -D $(FINAL_TARGET)/calendar-js; fi
+	$(INSTALL) $^ $(FINAL_TARGET)/calendar-js
 
 # The install target must use SYSINSTALL, which is NSINSTALL in copy mode.
 install:: $(EXTRA_SCRIPTS)
-	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/js
+	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/calendar-js
 
 include $(topsrcdir)/config/rules.mk
--- a/calendar/providers/caldav/Makefile.in
+++ b/calendar/providers/caldav/Makefile.in
@@ -46,16 +46,16 @@ include $(DEPTH)/config/autoconf.mk
 MODULE = caldav
 
 DIRS = public
 
 EXTRA_COMPONENTS = calDavCalendarModule.js
 EXTRA_SCRIPTS = calDavCalendar.js
 
 libs:: $(EXTRA_SCRIPTS)
-	if test ! -d $(FINAL_TARGET)/js; then $(NSINSTALL) -D $(FINAL_TARGET)/js; fi
-	$(INSTALL) $^ $(FINAL_TARGET)/js
+	if test ! -d $(FINAL_TARGET)/calendar-js; then $(NSINSTALL) -D $(FINAL_TARGET)/calendar-js; fi
+	$(INSTALL) $^ $(FINAL_TARGET)/calendar-js
 
 # The install target must use SYSINSTALL, which is NSINSTALL in copy mode.
 install:: $(EXTRA_SCRIPTS)
-	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/js
+	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/calendar-js
 
 include $(topsrcdir)/config/rules.mk
--- a/calendar/providers/caldav/calDavCalendarModule.js
+++ b/calendar/providers/caldav/calDavCalendarModule.js
@@ -68,44 +68,20 @@ var calDavCalendarModule = {
     mContractID: "@mozilla.org/calendar/calendar;1?type=caldav",
 
     mUtilsLoaded: false,
     loadUtils: function cDCM_loadUtils() {
         if (this.mUtilsLoaded) {
             return;
         }
 
-        const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
-        const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
-
-        const iosvcContractID = "@mozilla.org/network/io-service;1";
-        const iosvcIID = Components.interfaces.nsIIOService;
-
-        var loader = Components.classes[jssslContractID].getService(jssslIID);
-        var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
-
-        // Note that unintuitively, __LOCATION__.parent == .
-        // We expect to find utils in ./../js
-        var appdir = __LOCATION__.parent.parent;
-        appdir.append("js");
-        const scripts = ["calUtils.js", "calAuthUtils.js", "calProviderBase.js",
-                         "calProviderUtils.js", "calDavCalendar.js" ];
-
-        for each (var scriptName in scripts) {
-            var f = appdir.clone();
-            f.append(scriptName);
-
-            try {
-                var fileurl = iosvc.newFileURI(f);
-                loader.loadSubScript(fileurl.spec, null);
-            } catch (e) {
-                Components.utils.reportError("Error while loading " + fileurl.spec);
-                throw e;
-            }
-        }
+        Components.utils.import("resource://calendar/modules/calUtils.jsm");
+        cal.loadScripts(["calUtils.js", "calAuthUtils.js", "calProviderBase.js",
+                         "calProviderUtils.js", "calDavCalendar.js" ],
+                        this.__parent__);
 
         this.mUtilsLoaded = true;
     },
 
     registerSelf: function (compMgr, fileSpec, location, type) {
         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
         compMgr.registerFactoryLocation(this.mCID,
                                         "Calendar CalDAV back-end",
--- a/calendar/providers/composite/calCompositeCalendar.js
+++ b/calendar/providers/composite/calCompositeCalendar.js
@@ -604,41 +604,18 @@ var calCompositeCalendarModule = {
     mCID: Components.ID("{aeff788d-63b0-4996-91fb-40a7654c6224}"),
     mContractID: "@mozilla.org/calendar/calendar;1?type=composite",
 
     mUtilsLoaded: false,
     loadUtils: function compositeLoadUtils() {
         if (this.mUtilsLoaded)
             return;
 
-        const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
-        const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
-
-        const iosvcContractID = "@mozilla.org/network/io-service;1";
-        const iosvcIID = Components.interfaces.nsIIOService;
-
-        var loader = Components.classes[jssslContractID].getService(jssslIID);
-        var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
-
-        // Note that unintuitively, __LOCATION__.parent == .
-        // We expect to find utils in ./../js
-        var appdir = __LOCATION__.parent.parent;
-        appdir.append("js");
-        var scriptName = "calUtils.js";
-
-        var f = appdir.clone();
-        f.append(scriptName);
-
-        try {
-            var fileurl = iosvc.newFileURI(f);
-            loader.loadSubScript(fileurl.spec, this.__parent__.__parent__);
-        } catch (e) {
-            dump("Error while loading " + fileurl.spec + "\n");
-            throw e;
-        }
+        Components.utils.import("resource://calendar/modules/calUtils.jsm");
+        cal.loadScripts(["calUtils.js"], this.__parent__);
 
         this.mUtilsLoaded = true;
     },
 
     registerSelf: function (compMgr, fileSpec, location, type) {
         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
         compMgr.registerFactoryLocation(this.mCID,
                                         "Calendar composite provider",
--- a/calendar/providers/gdata/components/calGoogleCalendarModule.js
+++ b/calendar/providers/gdata/components/calGoogleCalendarModule.js
@@ -133,93 +133,37 @@ var g_classInfo = {
         contractID: "@mozilla.org/calendar/providers/gdata/request;1",
         classID:  Components.ID("{53a3438a-21bc-4a0f-b813-77a8b4f19282}"),
         implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT,
         constructor: "calGoogleRequest",
         flags: 0
     }
 };
 
-function ComponentsUtilsImport(aFile) {
-    var iosvc = Components.classes["@mozilla.org/network/io-service;1"]
-                          .getService(Components.interfaces.nsIIOService);
-
-    var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
-                           .getService(Components.interfaces.mozIJSSubScriptLoader);
-
-    try {
-        var scriptUri = iosvc.newFileURI(aFile);
-        loader.loadSubScript(scriptUri.spec, null);
-    } catch (e) {
-        Components.utils.reportError("Error while loading " + aFile.path);
-        throw e;
-    }
-}
-
 var calGoogleCalendarModule = {
 
     mUtilsLoaded: false,
 
     loadUtils: function cGCM_loadUtils() {
         if (this.mUtilsLoaded)
             return;
 
-        const kSUNBIRD_UID = "{718e30fb-e89b-41dd-9da7-e25a45638b28}";
-        const kLIGHTNING_UID = "{e2fda1a4-762b-4020-b5ad-a41df1933103}";
-        const scripts = ["calGoogleCalendar.js", "calGoogleSession.js",
-                         "calGoogleRequest.js", "calGoogleUtils.js"];
-        const baseScripts = ["calUtils.js", "calAuthUtils.js",
-                             "calProviderBase.js", "calProviderUtils.js"];
-
-        // First, load script from the application dir
-        var appInfo = Components.classes["@mozilla.org/xre/app-info;1"].
-                      getService(Components.interfaces.nsIXULAppInfo);
-        if (appInfo.ID == kSUNBIRD_UID) {
-            // On sunbird, the application dir is the GRE Application Directory
-            var dirsvc = Components.classes["@mozilla.org/file/directory_service;1"]
-                                   .getService(Components.interfaces.nsIProperties);
-            try {
-                var appdir = dirsvc.get("GreD", Components.interfaces.nsIFile);
-                appdir.append("js");
-            } catch (e) {
-                Components.utils.reportError("Error getting GRE Application Directory");
-                throw(e);
-            }
-        } else {
-            // Otherwise, the application directory is the lightning extension directory
-            var extman = Components.classes["@mozilla.org/extensions/manager;1"]
-                                   .getService(Components.interfaces.nsIExtensionManager);
-            try {
-                var appdir = extman.getInstallLocation(kLIGHTNING_UID)
-                                   .getItemLocation(kLIGHTNING_UID);
-                appdir.append("js");
-            } catch (e) {
-                Components.utils.reportError("Error getting Lightning Extension Directory");
-                throw(e);
-            }
-        }
-
-        for each (var script in baseScripts) {
-            var scriptFile = appdir.clone();
-            scriptFile.append(script);
-
-            ComponentsUtilsImport(scriptFile);
-        }
+        Components.utils.import("resource://calendar/modules/calUtils.jsm");
+        cal.loadScripts(["calUtils.js", "calAuthUtils.js",
+                         "calProviderBase.js", "calProviderUtils.js"],
+                        this.__parent__);
 
         // Now load gdata extension scripts. Note that unintuitively,
         // __LOCATION__.parent == . We expect to find the subscripts in ./../js
-        appdir = __LOCATION__.parent.parent;
-        appdir.append("js");
-
-        for each (var script in scripts) {
-            var scriptFile = appdir.clone();
-            scriptFile.append(script);
-
-            ComponentsUtilsImport(scriptFile);
-        }
+        let thisDir = __LOCATION__.parent.parent.clone();
+        thisDir.append("js");
+        cal.loadScripts(["calGoogleCalendar.js", "calGoogleSession.js",
+                         "calGoogleRequest.js", "calGoogleUtils.js"],
+                        this.__parent__,
+                        thisDir);
 
         this.mUtilsLoaded = true;
     },
 
     unregisterSelf: function cGCM_unregisterSelf(aComponentManager) {
         aComponentManager = aComponentManager
                             .QueryInterface(Components.interfaces.nsIComponentRegistrar);
         for each (var component in g_classInfo) {
--- a/calendar/providers/ics/Makefile.in
+++ b/calendar/providers/ics/Makefile.in
@@ -45,16 +45,16 @@ VPATH		= @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = calICSalendar
 
 EXTRA_COMPONENTS = calICSCalendarModule.js
 EXTRA_SCRIPTS = calICSCalendar.js
 
 libs:: $(EXTRA_SCRIPTS)
-	if test ! -d $(FINAL_TARGET)/js; then $(NSINSTALL) -D $(FINAL_TARGET)/js; fi
-	$(INSTALL) $^ $(FINAL_TARGET)/js
+	if test ! -d $(FINAL_TARGET)/calendar-js; then $(NSINSTALL) -D $(FINAL_TARGET)/calendar-js; fi
+	$(INSTALL) $^ $(FINAL_TARGET)/calendar-js
 
 # The install target must use SYSINSTALL, which is NSINSTALL in copy mode.
 install:: $(EXTRA_SCRIPTS)
-	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/js
+	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/calendar-js
 
 include $(topsrcdir)/config/rules.mk
--- a/calendar/providers/ics/calICSCalendarModule.js
+++ b/calendar/providers/ics/calICSCalendarModule.js
@@ -65,44 +65,20 @@ var calICSCalendarModule = {
     mContractID: "@mozilla.org/calendar/calendar;1?type=ics",
 
     mUtilsLoaded: false,
     loadUtils: function cICM_loadUtils() {
         if (this.mUtilsLoaded) {
             return;
         }
 
-        const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
-        const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
-
-        const iosvcContractID = "@mozilla.org/network/io-service;1";
-        const iosvcIID = Components.interfaces.nsIIOService;
-
-        var loader = Components.classes[jssslContractID].getService(jssslIID);
-        var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
-
-        // Note that unintuitively, __LOCATION__.parent == .
-        // We expect to find utils in ./../js
-        var appdir = __LOCATION__.parent.parent;
-        appdir.append("js");
-        const scripts = ["calUtils.js", "calAuthUtils.js", "calProviderBase.js",
-                         "calProviderUtils.js", "calICSCalendar.js" ];
-
-        for each (var scriptName in scripts) {
-            var f = appdir.clone();
-            f.append(scriptName);
-
-            try {
-                var fileurl = iosvc.newFileURI(f);
-                loader.loadSubScript(fileurl.spec, null);
-            } catch (e) {
-                Components.utils.reportError("Error while loading " + fileurl.spec);
-                throw e;
-            }
-        }
+        Components.utils.import("resource://calendar/modules/calUtils.jsm");
+        cal.loadScripts(["calUtils.js", "calAuthUtils.js", "calProviderBase.js",
+                         "calProviderUtils.js", "calICSCalendar.js"],
+                        this.__parent__);
 
         this.mUtilsLoaded = true;
     },
 
     registerSelf: function (compMgr, fileSpec, location, type) {
         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
         compMgr.registerFactoryLocation(this.mCID,
                                         "Calendar ICS provider",
--- a/calendar/providers/memory/Makefile.in
+++ b/calendar/providers/memory/Makefile.in
@@ -44,16 +44,16 @@ VPATH		= @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = calMemoryCalendar
 
 EXTRA_COMPONENTS = calMemoryCalendarModule.js
 EXTRA_SCRIPTS = calMemoryCalendar.js
 
 libs:: $(EXTRA_SCRIPTS)
-	if test ! -d $(FINAL_TARGET)/js; then $(NSINSTALL) -D $(FINAL_TARGET)/js; fi
-	$(INSTALL) $^ $(FINAL_TARGET)/js
+	if test ! -d $(FINAL_TARGET)/calendar-js; then $(NSINSTALL) -D $(FINAL_TARGET)/calendar-js; fi
+	$(INSTALL) $^ $(FINAL_TARGET)/calendar-js
 
 # The install target must use SYSINSTALL, which is NSINSTALL in copy mode.
 install:: $(EXTRA_SCRIPTS)
-	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/js
+	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/calendar-js
 
 include $(topsrcdir)/config/rules.mk
--- a/calendar/providers/memory/calMemoryCalendarModule.js
+++ b/calendar/providers/memory/calMemoryCalendarModule.js
@@ -62,44 +62,20 @@ var calMemoryCalendarModule = {
     mContractID: "@mozilla.org/calendar/calendar;1?type=memory",
 
     mUtilsLoaded: false,
     loadUtils: function cMCM_loadUtils() {
         if (this.mUtilsLoaded) {
             return;
         }
 
-        const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
-        const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
-
-        const iosvcContractID = "@mozilla.org/network/io-service;1";
-        const iosvcIID = Components.interfaces.nsIIOService;
-
-        var loader = Components.classes[jssslContractID].getService(jssslIID);
-        var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
-
-        // Note that unintuitively, __LOCATION__.parent == .
-        // We expect to find utils in ./../js
-        var appdir = __LOCATION__.parent.parent;
-        appdir.append("js");
-        const scripts = ["calUtils.js", "calProviderBase.js", "calProviderUtils.js",
-                         "calMemoryCalendar.js" ];
-
-        for each (var scriptName in scripts) {
-            var f = appdir.clone();
-            f.append(scriptName);
-
-            try {
-                var fileurl = iosvc.newFileURI(f);
-                loader.loadSubScript(fileurl.spec, null);
-            } catch (e) {
-                Components.utils.reportError("Error while loading " + fileurl.spec);
-                throw e;
-            }
-        }
+        Components.utils.import("resource://calendar/modules/calUtils.jsm");
+        cal.loadScripts(["calUtils.js", "calProviderBase.js", "calProviderUtils.js",
+                         "calMemoryCalendar.js"],
+                        this.__parent__);
 
         this.mUtilsLoaded = true;
     },
 
     registerSelf: function (compMgr, fileSpec, location, type) {
         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
         compMgr.registerFactoryLocation(this.mCID,
                                         "Calendar in-memory back-end",
--- a/calendar/providers/storage/Makefile.in
+++ b/calendar/providers/storage/Makefile.in
@@ -44,16 +44,16 @@ VPATH		= @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = calStorageCalendar
 
 EXTRA_COMPONENTS = calStorageCalendarModule.js
 EXTRA_SCRIPTS = calStorageCalendar.js
 
 libs:: $(EXTRA_SCRIPTS)
-	if test ! -d $(FINAL_TARGET)/js; then $(NSINSTALL) -D $(FINAL_TARGET)/js; fi
-	$(INSTALL) $^ $(FINAL_TARGET)/js
+	if test ! -d $(FINAL_TARGET)/calendar-js; then $(NSINSTALL) -D $(FINAL_TARGET)/calendar-js; fi
+	$(INSTALL) $^ $(FINAL_TARGET)/calendar-js
 
 # The install target must use SYSINSTALL, which is NSINSTALL in copy mode.
 install:: $(EXTRA_SCRIPTS)
-	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/js
+	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/calendar-js
 
 include $(topsrcdir)/config/rules.mk
--- a/calendar/providers/storage/calStorageCalendarModule.js
+++ b/calendar/providers/storage/calStorageCalendarModule.js
@@ -65,44 +65,20 @@ var calStorageCalendarModule = {
     mCID: Components.ID("{b3eaa1c4-5dfe-4c0a-b62a-b3a514218461}"),
     mContractID: "@mozilla.org/calendar/calendar;1?type=storage",
 
     mUtilsLoaded: false,
     loadUtils: function storageLoadUtils() {
         if (this.mUtilsLoaded)
             return;
 
-        const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
-        const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
-
-        const iosvcContractID = "@mozilla.org/network/io-service;1";
-        const iosvcIID = Components.interfaces.nsIIOService;
-
-        var loader = Components.classes[jssslContractID].getService(jssslIID);
-        var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
-
-        // Note that unintuitively, __LOCATION__.parent == .
-        // We expect to find utils in ./../js
-        var appdir = __LOCATION__.parent.parent;
-        appdir.append("js");
-        const scripts = ["calUtils.js", "calProviderBase.js", "calProviderUtils.js",
-                         "calStorageCalendar.js" ];
-
-        for each (var scriptName in scripts) {
-            var f = appdir.clone();
-            f.append(scriptName);
-
-            try {
-                var fileurl = iosvc.newFileURI(f);
-                loader.loadSubScript(fileurl.spec, null);
-            } catch (e) {
-                Components.utils.reportError("Error while loading " + fileurl.spec);
-                throw e;
-            }
-        }
+        Components.utils.import("resource://calendar/modules/calUtils.jsm");
+        cal.loadScripts(["calUtils.js", "calProviderBase.js", "calProviderUtils.js",
+                         "calStorageCalendar.js"],
+                        this.__parent__);
 
         initCalStorageCalendarComponent();
         this.mUtilsLoaded = true;
     },
 
     registerSelf: function (compMgr, fileSpec, location, type) {
         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
         compMgr.registerFactoryLocation(this.mCID,
--- a/calendar/providers/wcap/Makefile.in
+++ b/calendar/providers/wcap/Makefile.in
@@ -57,17 +57,17 @@ EXTRA_SCRIPTS = \
 EXTRA_COMPONENTS = \
                 calWcapCalendarModule.js \
                 $(NULL)
 
 # installing EXTRA_SCRIPTS into js/
 
 # using NSINSTALL to make directory: no mtime to preserve:
 libs:: $(EXTRA_SCRIPTS)
-	if test ! -d $(FINAL_TARGET)/js; then $(NSINSTALL) -D $(FINAL_TARGET)/js; fi
-	$(INSTALL) $^ $(FINAL_TARGET)/js
+	if test ! -d $(FINAL_TARGET)/calendar-js; then $(NSINSTALL) -D $(FINAL_TARGET)/calendar-js; fi
+	$(INSTALL) $^ $(FINAL_TARGET)/calendar-js
 
 # using SYSINSTALL (i.e. NSINSTALL in copy mode):
 install:: $(EXTRA_SCRIPTS)
-	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/js
+	$(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/calendar-js
 
 include $(topsrcdir)/config/rules.mk
 
--- a/calendar/providers/wcap/calWcapCalendarModule.js
+++ b/calendar/providers/wcap/calWcapCalendarModule.js
@@ -202,33 +202,23 @@ var calWcapCalendarModule = { // nsIModu
     unregisterSelf: function calWcapCalendarModule_unregisterSelf(compMgr, fileSpec, location) {
         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
         compMgr.unregisterFactoryLocation(g_classInfo.wcapCalendar.classID, fileSpec);
     },
 
     m_scriptsLoaded: false,
     getClassObject: function calWcapCalendarModule_getClassObject(compMgr, cid, iid) {
         if (!this.m_scriptsLoaded) {
-            // loading extra scripts from ../js:
-            const scripts = ["calUtils.js", "calAuthUtils.js",
+            Components.utils.import("resource://calendar/modules/calUtils.jsm");
+            cal.loadScripts(["calUtils.js", "calAuthUtils.js",
                              "calProviderUtils.js", "calProviderBase.js", "calProviderUtils.js",
                              "calWcapUtils.js", "calWcapErrors.js",
                              "calWcapRequest.js", "calWcapSession.js",
-                             "calWcapCalendar.js", "calWcapCalendarItems.js"];
-            var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
-                                         .createInstance(Components.interfaces.mozIJSSubScriptLoader);
-            var ioService = Components.classes["@mozilla.org/network/io-service;1"]
-                                      .getService(Components.interfaces.nsIIOService);
-            var baseDir = __LOCATION__.parent.parent;
-            baseDir.append("js");
-            for each (var script in scripts) {
-                var scriptFile = baseDir.clone();
-                scriptFile.append(script);
-                scriptLoader.loadSubScript(ioService.newFileURI(scriptFile).spec, null);
-            }
+                             "calWcapCalendar.js", "calWcapCalendarItems.js"],
+                            this.__parent__);
             initWcapProvider();
             this.m_scriptsLoaded = true;
         }
 
         if (!iid.equals(Components.interfaces.nsIFactory)) {
             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
         }
         if (!cid.equals(g_classInfo.wcapCalendar.classID)) {
--- a/calendar/test/unit/head_consts.js
+++ b/calendar/test/unit/head_consts.js
@@ -36,23 +36,27 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
-function loadChromeScript(aPath) {
-    var loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
-                 .getService(Ci.mozIJSSubScriptLoader);
-    loader.loadSubScript("chrome://" + aPath);
-}
+let protHandler = Components.classes["@mozilla.org/network/io-service;1"]
+                            .getService(Components.interfaces.nsIIOService2)
+                            .getProtocolHandler("resource")
+                            .QueryInterface(Components.interfaces.nsIResProtocolHandler);
+protHandler.setSubstitution("calendar", protHandler.getSubstitution("gre"));
 
-loadChromeScript("calendar/content/calUtils.js");
+Components.utils.import("resource://calendar/modules/calUtils.jsm");
+
+// we might want to use calUtils.jsm only in the future throughout all tests,
+// but for now source in good old calUtils.js:
+cal.loadScripts(["calUtils.js"], protHandler.__parent__);
 
 function createDate(aYear, aMonth, aDay, aHasTime, aHour, aMinute, aSecond, aTimezone) {
     var cd = Cc["@mozilla.org/calendar/datetime;1"]
              .createInstance(Ci.calIDateTime);
     cd.resetTo(aYear,
                aMonth,
                aDay,
                aHour || 0,