gecko-dev/dom/apps/ScriptPreloader.jsm
Birunthan Mohanathas b09d89b288 Bug 1058101 - Flatten dom/apps/src/ into parent directory. r=mccr8
--HG--
rename : dom/apps/src/AppDownloadManager.jsm => dom/apps/AppDownloadManager.jsm
rename : dom/apps/src/AppsService.js => dom/apps/AppsService.js
rename : dom/apps/src/AppsService.manifest => dom/apps/AppsService.manifest
rename : dom/apps/src/AppsServiceChild.jsm => dom/apps/AppsServiceChild.jsm
rename : dom/apps/src/AppsUtils.jsm => dom/apps/AppsUtils.jsm
rename : dom/apps/src/FreeSpaceWatcher.jsm => dom/apps/FreeSpaceWatcher.jsm
rename : dom/apps/src/InterAppComm.cpp => dom/apps/InterAppComm.cpp
rename : dom/apps/src/InterAppComm.h => dom/apps/InterAppComm.h
rename : dom/apps/src/InterAppComm.manifest => dom/apps/InterAppComm.manifest
rename : dom/apps/src/InterAppCommService.js => dom/apps/InterAppCommService.js
rename : dom/apps/src/InterAppCommService.jsm => dom/apps/InterAppCommService.jsm
rename : dom/apps/src/InterAppConnection.js => dom/apps/InterAppConnection.js
rename : dom/apps/src/InterAppMessagePort.js => dom/apps/InterAppMessagePort.js
rename : dom/apps/src/OfflineCacheInstaller.jsm => dom/apps/OfflineCacheInstaller.jsm
rename : dom/apps/src/OperatorApps.jsm => dom/apps/OperatorApps.jsm
rename : dom/apps/src/PermissionsInstaller.jsm => dom/apps/PermissionsInstaller.jsm
rename : dom/apps/src/PermissionsTable.jsm => dom/apps/PermissionsTable.jsm
rename : dom/apps/src/ScriptPreloader.jsm => dom/apps/ScriptPreloader.jsm
rename : dom/apps/src/StoreTrustAnchor.jsm => dom/apps/StoreTrustAnchor.jsm
rename : dom/apps/src/Webapps.js => dom/apps/Webapps.js
rename : dom/apps/src/Webapps.jsm => dom/apps/Webapps.jsm
rename : dom/apps/src/Webapps.manifest => dom/apps/Webapps.manifest
2014-08-27 10:12:06 -07:00

77 lines
2.2 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const Cu = Components.utils;
const Ci = Components.interfaces;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Promise.jsm");
this.EXPORTED_SYMBOLS = ["ScriptPreloader"];
function debug(aMsg) {
//dump("--*-- ScriptPreloader: " + aMsg + "\n");
}
this.ScriptPreloader = {
#ifdef MOZ_B2G
_enabled: true,
#else
_enabled: false,
#endif
preload: function(aApp, aManifest) {
debug("Preloading " + aApp.origin);
let deferred = Promise.defer();
if (!this._enabled) {
deferred.resolve();
return deferred.promise;
}
if (aManifest.precompile &&
Array.isArray(aManifest.precompile) &&
aManifest.precompile.length > 0) {
let origin = Services.io.newURI(aApp.origin, null, null);
let toLoad = aManifest.precompile.length;
let principal =
Services.scriptSecurityManager
.getAppCodebasePrincipal(origin, aApp.localId, false);
aManifest.precompile.forEach((aPath) => {
let uri = Services.io.newURI(aPath, null, origin);
debug("Script to compile: " + uri.spec);
try {
Services.scriptloader.precompileScript(uri, principal,
(aSubject, aTopic, aData) => {
let uri = aSubject.QueryInterface(Ci.nsIURI);
debug("Done compiling " + uri.spec);
toLoad--;
if (toLoad == 0) {
deferred.resolve();
}
});
} catch (e) {
// Resolve the promise if precompileScript throws.
deferred.resolve();
}
});
} else {
// The precompile field is not an array, let the developer know.
// We don't want to have to enable debug for that to show up.
if (aManifest.precompile) {
Cu.reportError("ASM.JS compilation failed: the 'precompile' manifest " +
"property should be an array of script uris.\n");
}
deferred.resolve();
}
return deferred.promise;
}
}