2012-03-06 19:50:58 +00:00
|
|
|
/* 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/. */
|
2011-11-28 20:13:26 +00:00
|
|
|
|
2012-07-03 00:16:55 +00:00
|
|
|
"use strict";
|
|
|
|
|
2012-04-28 07:10:08 +00:00
|
|
|
const Cu = Components.utils;
|
2011-11-28 20:13:26 +00:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
2012-07-11 15:38:33 +00:00
|
|
|
const Cr = Components.results;
|
2011-11-28 20:13:26 +00:00
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.EXPORTED_SYMBOLS = ["DOMApplicationRegistry"];
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2011-12-06 04:22:01 +00:00
|
|
|
Cu.import("resource://gre/modules/FileUtils.jsm");
|
2012-07-20 15:41:30 +00:00
|
|
|
Cu.import('resource://gre/modules/ActivitiesService.jsm');
|
2012-08-28 02:43:57 +00:00
|
|
|
Cu.import("resource://gre/modules/AppsUtils.jsm");
|
2012-10-03 05:38:06 +00:00
|
|
|
Cu.import("resource://gre/modules/PermissionsInstaller.jsm");
|
2012-10-23 20:52:57 +00:00
|
|
|
Cu.import("resource://gre/modules/OfflineCacheInstaller.jsm");
|
2011-11-28 20:13:26 +00:00
|
|
|
|
2012-09-27 01:01:20 +00:00
|
|
|
function debug(aMsg) {
|
|
|
|
//dump("-*-*- Webapps.jsm : " + aMsg + "\n");
|
|
|
|
}
|
|
|
|
|
2012-04-17 14:11:53 +00:00
|
|
|
const WEBAPP_RUNTIME = Services.appinfo.ID == "webapprt@mozilla.org";
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "NetUtil", function() {
|
|
|
|
Cu.import("resource://gre/modules/NetUtil.jsm");
|
|
|
|
return NetUtil;
|
|
|
|
});
|
|
|
|
|
2012-08-27 14:13:02 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
|
|
|
|
"@mozilla.org/parentprocessmessagemanager;1",
|
|
|
|
"nsIMessageBroadcaster");
|
2012-03-06 19:50:58 +00:00
|
|
|
|
2012-07-20 15:41:30 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
|
|
|
|
"@mozilla.org/childprocessmessagemanager;1",
|
2012-08-27 14:13:02 +00:00
|
|
|
"nsIMessageSender");
|
2012-07-20 15:41:30 +00:00
|
|
|
|
2012-07-03 00:16:55 +00:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "msgmgr", function() {
|
2012-07-11 15:38:33 +00:00
|
|
|
return Cc["@mozilla.org/system-message-internal;1"]
|
|
|
|
.getService(Ci.nsISystemMessagesInternal);
|
2012-07-03 00:16:55 +00:00
|
|
|
});
|
|
|
|
|
2012-03-23 23:39:15 +00:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
const DIRECTORY_NAME = "webappsDir";
|
2012-08-15 21:02:15 +00:00
|
|
|
#elifdef ANDROID
|
|
|
|
const DIRECTORY_NAME = "webappsDir";
|
2012-03-23 23:39:15 +00:00
|
|
|
#else
|
2012-04-17 14:11:53 +00:00
|
|
|
// If we're executing in the context of the webapp runtime, the data files
|
|
|
|
// are in a different directory (currently the Firefox profile that installed
|
|
|
|
// the webapp); otherwise, they're in the current profile.
|
|
|
|
const DIRECTORY_NAME = WEBAPP_RUNTIME ? "WebappRegD" : "ProfD";
|
2012-03-23 23:39:15 +00:00
|
|
|
#endif
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.DOMApplicationRegistry = {
|
2011-11-28 20:13:26 +00:00
|
|
|
appsFile: null,
|
|
|
|
webapps: { },
|
2012-08-28 02:43:57 +00:00
|
|
|
children: [ ],
|
2012-06-29 20:46:21 +00:00
|
|
|
allAppsLaunchable: false,
|
2012-09-27 19:34:41 +00:00
|
|
|
downloads: { },
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
init: function() {
|
2012-03-13 00:33:10 +00:00
|
|
|
this.messages = ["Webapps:Install", "Webapps:Uninstall",
|
2012-10-02 20:38:51 +00:00
|
|
|
"Webapps:GetSelf", "Webapps:CheckInstalled",
|
2012-08-28 02:43:57 +00:00
|
|
|
"Webapps:GetInstalled", "Webapps:GetNotInstalled",
|
|
|
|
"Webapps:Launch", "Webapps:GetAll",
|
|
|
|
"Webapps:InstallPackage", "Webapps:GetBasePath",
|
2012-09-18 17:34:55 +00:00
|
|
|
"Webapps:GetList", "Webapps:RegisterForMessages",
|
2012-10-19 18:17:05 +00:00
|
|
|
"Webapps:UnregisterForMessages",
|
2012-09-29 17:57:18 +00:00
|
|
|
"Webapps:CancelDownload", "Webapps:CheckForUpdate",
|
2012-10-30 00:17:47 +00:00
|
|
|
"Webapps:Download", "Webapps:ApplyDownload",
|
2012-10-01 20:29:59 +00:00
|
|
|
"child-process-shutdown"];
|
2011-11-28 20:13:26 +00:00
|
|
|
|
2012-09-26 22:03:25 +00:00
|
|
|
this.frameMessages = ["Webapps:ClearBrowserData"];
|
|
|
|
|
2012-03-13 00:33:10 +00:00
|
|
|
this.messages.forEach((function(msgName) {
|
2012-03-06 19:50:58 +00:00
|
|
|
ppmm.addMessageListener(msgName, this);
|
2011-11-28 20:13:26 +00:00
|
|
|
}).bind(this));
|
|
|
|
|
2012-09-19 16:28:55 +00:00
|
|
|
cpmm.addMessageListener("Activities:Register:OK", this);
|
|
|
|
|
2012-03-13 00:33:10 +00:00
|
|
|
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
|
|
|
|
2012-07-11 15:38:33 +00:00
|
|
|
this.appsFile = FileUtils.getFile(DIRECTORY_NAME,
|
|
|
|
["webapps", "webapps.json"], true);
|
2011-12-06 04:22:01 +00:00
|
|
|
|
2012-09-19 16:28:55 +00:00
|
|
|
this.loadAndUpdateApps();
|
|
|
|
},
|
2012-08-29 22:58:31 +00:00
|
|
|
|
2012-09-19 16:28:55 +00:00
|
|
|
// loads the current registry, that could be empty on first run.
|
|
|
|
// aNext() is called after we load the current webapps list.
|
|
|
|
loadCurrentRegistry: function loadCurrentRegistry(aNext) {
|
|
|
|
let file = FileUtils.getFile(DIRECTORY_NAME, ["webapps", "webapps.json"], false);
|
2012-10-23 20:52:57 +00:00
|
|
|
if (file && file.exists()) {
|
2012-09-19 16:28:55 +00:00
|
|
|
this._loadJSONAsync(file, (function loadRegistry(aData) {
|
|
|
|
if (aData) {
|
|
|
|
this.webapps = aData;
|
|
|
|
let appDir = FileUtils.getDir(DIRECTORY_NAME, ["webapps"], false);
|
|
|
|
for (let id in this.webapps) {
|
|
|
|
// Make sure we have a localId
|
|
|
|
if (this.webapps[id].localId === undefined) {
|
|
|
|
this.webapps[id].localId = this._nextLocalId();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.webapps[id].basePath === undefined) {
|
|
|
|
this.webapps[id].basePath = appDir.path;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default to removable apps.
|
|
|
|
if (this.webapps[id].removable === undefined) {
|
|
|
|
this.webapps[id].removable = true;
|
2012-08-29 21:20:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default to a non privileged status.
|
|
|
|
if (this.webapps[id].appStatus === undefined) {
|
|
|
|
this.webapps[id].appStatus = Ci.nsIPrincipal.APP_STATUS_INSTALLED;
|
|
|
|
}
|
|
|
|
};
|
2012-09-19 16:28:55 +00:00
|
|
|
}
|
|
|
|
aNext();
|
|
|
|
}).bind(this));
|
|
|
|
} else {
|
|
|
|
aNext();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-17 04:30:43 +00:00
|
|
|
// Notify we are starting with registering apps.
|
|
|
|
notifyAppsRegistryStart: function notifyAppsRegistryStart() {
|
|
|
|
Services.obs.notifyObservers(this, "webapps-registry-start", null);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Notify we are done with registering apps and save a copy of the registry.
|
|
|
|
notifyAppsRegistryReady: function notifyAppsRegistryReady() {
|
2012-09-19 16:28:55 +00:00
|
|
|
Services.obs.notifyObservers(this, "webapps-registry-ready", null);
|
|
|
|
this._saveApps();
|
|
|
|
},
|
|
|
|
|
2012-10-17 04:30:43 +00:00
|
|
|
// Registers all the activities and system messages.
|
2012-11-03 03:28:32 +00:00
|
|
|
registerAppsHandlers: function registerAppsHandlers(aRunUpdate) {
|
2012-10-17 04:30:43 +00:00
|
|
|
this.notifyAppsRegistryStart();
|
2012-09-19 16:28:55 +00:00
|
|
|
let ids = [];
|
|
|
|
for (let id in this.webapps) {
|
|
|
|
ids.push({ id: id });
|
|
|
|
}
|
2012-10-19 10:43:17 +00:00
|
|
|
#ifdef MOZ_SYS_MSG
|
2012-11-03 03:28:32 +00:00
|
|
|
this._processManifestForIds(ids, aRunUpdate);
|
2012-09-19 16:28:55 +00:00
|
|
|
#else
|
2012-10-19 10:43:17 +00:00
|
|
|
// Read the CSPs. If MOZ_SYS_MSG is defined this is done on
|
|
|
|
// _processManifestForIds so as to not reading the manifests
|
|
|
|
// twice
|
|
|
|
this._readManifests(ids, (function readCSPs(aResults) {
|
|
|
|
aResults.forEach(function registerManifest(aResult) {
|
|
|
|
this.webapps[aResult.id].csp = manifest.csp || "";
|
|
|
|
}, this);
|
|
|
|
}).bind(this));
|
|
|
|
|
2012-09-19 16:28:55 +00:00
|
|
|
// Nothing else to do but notifying we're ready.
|
2012-10-17 04:30:43 +00:00
|
|
|
this.notifyAppsRegistryReady();
|
2012-09-12 01:17:01 +00:00
|
|
|
#endif
|
2012-09-19 16:28:55 +00:00
|
|
|
},
|
|
|
|
|
2012-10-10 16:16:49 +00:00
|
|
|
updatePermissionsForApp: function updatePermissionsForApp(aId) {
|
|
|
|
// Install the permissions for this app, as if we were updating
|
|
|
|
// to cleanup the old ones if needed.
|
|
|
|
this._readManifests([{ id: aId }], (function(aResult) {
|
|
|
|
let data = aResult[0];
|
|
|
|
PermissionsInstaller.installPermissions({
|
|
|
|
manifest: data.manifest,
|
|
|
|
manifestURL: this.webapps[aId].manifestURL,
|
|
|
|
origin: this.webapps[aId].origin
|
|
|
|
}, true, function() {
|
|
|
|
debug("Error installing permissions for " + aId);
|
|
|
|
});
|
|
|
|
}).bind(this));
|
|
|
|
},
|
|
|
|
|
2012-10-23 20:52:57 +00:00
|
|
|
updateOfflineCacheForApp: function updateOfflineCacheForApp(aId) {
|
|
|
|
let app = this.webapps[aId];
|
|
|
|
OfflineCacheInstaller.installCache({
|
|
|
|
basePath: app.basePath,
|
|
|
|
appId: aId,
|
|
|
|
origin: app.origin,
|
|
|
|
localId: app.localId
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-09-19 16:28:55 +00:00
|
|
|
// Implements the core of bug 787439
|
2012-10-23 20:52:57 +00:00
|
|
|
// if at first run, go through these steps:
|
2012-09-19 16:28:55 +00:00
|
|
|
// a. load the core apps registry.
|
|
|
|
// b. uninstall any core app from the current registry but not in the
|
|
|
|
// new core apps registry.
|
|
|
|
// c. for all apps in the new core registry, install them if they are not
|
|
|
|
// yet in the current registry, and run installPermissions()
|
2012-10-23 20:52:57 +00:00
|
|
|
installSystemApps: function installSystemApps(aNext) {
|
|
|
|
let file;
|
|
|
|
try {
|
|
|
|
file = FileUtils.getFile("coreAppsDir", ["webapps", "webapps.json"], false);
|
|
|
|
} catch(e) { }
|
2012-09-19 16:28:55 +00:00
|
|
|
|
2012-10-23 20:52:57 +00:00
|
|
|
if (file && file.exists()) {
|
|
|
|
// a
|
|
|
|
this._loadJSONAsync(file, (function loadCoreRegistry(aData) {
|
|
|
|
if (!aData) {
|
|
|
|
aNext();
|
|
|
|
return;
|
|
|
|
}
|
2012-09-19 16:28:55 +00:00
|
|
|
|
2012-10-23 20:52:57 +00:00
|
|
|
// b : core apps are not removable.
|
|
|
|
for (let id in this.webapps) {
|
|
|
|
if (id in aData || this.webapps[id].removable)
|
|
|
|
continue;
|
|
|
|
delete this.webapps[id];
|
|
|
|
// Remove the permissions, cookies and private data for this app.
|
|
|
|
let localId = this.webapps[id].localId;
|
|
|
|
let permMgr = Cc["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Ci.nsIPermissionManager);
|
|
|
|
permMgr.RemovePermissionsForApp(localId);
|
|
|
|
Services.cookies.removeCookiesForApp(localId, false);
|
|
|
|
this._clearPrivateData(localId, false);
|
|
|
|
}
|
2012-09-19 16:28:55 +00:00
|
|
|
|
2012-10-23 20:52:57 +00:00
|
|
|
let appDir = FileUtils.getDir("coreAppsDir", ["webapps"], false);
|
|
|
|
// c
|
|
|
|
for (let id in aData) {
|
|
|
|
// Core apps have ids matching their domain name (eg: dialer.gaiamobile.org)
|
|
|
|
// Use that property to check if they are new or not.
|
|
|
|
if (!(id in this.webapps)) {
|
|
|
|
this.webapps[id] = aData[id];
|
|
|
|
this.webapps[id].basePath = appDir.path;
|
2012-09-19 16:28:55 +00:00
|
|
|
|
2012-10-23 20:52:57 +00:00
|
|
|
// Create a new localId.
|
|
|
|
this.webapps[id].localId = this._nextLocalId();
|
2012-09-19 16:28:55 +00:00
|
|
|
|
2012-10-23 20:52:57 +00:00
|
|
|
// Core apps are not removable.
|
|
|
|
if (this.webapps[id].removable === undefined) {
|
|
|
|
this.webapps[id].removable = false;
|
2012-09-19 16:28:55 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-23 20:52:57 +00:00
|
|
|
}
|
|
|
|
aNext();
|
|
|
|
}).bind(this));
|
|
|
|
} else {
|
|
|
|
aNext();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-30 07:11:17 +00:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
fixIndexedDb: function fixIndexedDb() {
|
|
|
|
debug("Fixing indexedDb folder names");
|
|
|
|
let idbDir = FileUtils.getDir("indexedDBPDir", ["indexedDB"]);
|
|
|
|
|
|
|
|
if (!idbDir.isDirectory()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let re = /^(\d+)\+(.*)\+(f|t)$/;
|
|
|
|
|
|
|
|
let entries = idbDir.directoryEntries;
|
|
|
|
while (entries.hasMoreElements()) {
|
|
|
|
let entry = entries.getNext().QueryInterface(Ci.nsIFile);
|
|
|
|
if (!entry.isDirectory()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let newName = entry.leafName.replace(re, "$1+$3+$2");
|
|
|
|
if (newName != entry.leafName) {
|
|
|
|
try {
|
|
|
|
entry.moveTo(idbDir, newName);
|
|
|
|
} catch(e) { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
|
2012-10-23 20:52:57 +00:00
|
|
|
loadAndUpdateApps: function loadAndUpdateApps() {
|
|
|
|
let runUpdate = AppsUtils.isFirstRun(Services.prefs);
|
|
|
|
|
2012-10-30 07:11:17 +00:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
if (runUpdate) {
|
|
|
|
this.fixIndexedDb();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-23 20:52:57 +00:00
|
|
|
let onAppsLoaded = (function onAppsLoaded() {
|
|
|
|
if (runUpdate) {
|
|
|
|
// At first run, set up the permissions
|
2012-10-10 16:16:49 +00:00
|
|
|
for (let id in this.webapps) {
|
|
|
|
this.updatePermissionsForApp(id);
|
2012-10-23 20:52:57 +00:00
|
|
|
this.updateOfflineCacheForApp(id);
|
2012-10-10 16:16:49 +00:00
|
|
|
}
|
2012-08-29 21:20:03 +00:00
|
|
|
}
|
2012-11-03 03:28:32 +00:00
|
|
|
this.registerAppsHandlers(runUpdate);
|
2012-10-23 20:52:57 +00:00
|
|
|
}).bind(this);
|
|
|
|
|
|
|
|
this.loadCurrentRegistry((function() {
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
// if first run, merge the system apps.
|
|
|
|
if (runUpdate)
|
|
|
|
this.installSystemApps(onAppsLoaded);
|
|
|
|
else
|
|
|
|
onAppsLoaded();
|
2012-09-19 16:28:55 +00:00
|
|
|
#else
|
2012-10-23 20:52:57 +00:00
|
|
|
onAppsLoaded();
|
2012-09-19 16:28:55 +00:00
|
|
|
#endif
|
2012-08-29 21:20:03 +00:00
|
|
|
}).bind(this));
|
2011-12-05 23:26:18 +00:00
|
|
|
},
|
|
|
|
|
2012-07-03 00:16:55 +00:00
|
|
|
#ifdef MOZ_SYS_MSG
|
2012-10-18 07:32:15 +00:00
|
|
|
// |aEntryPoint| is either the entry_point name or the null in which case we
|
2012-09-13 18:47:34 +00:00
|
|
|
// use the root of the manifest.
|
|
|
|
_registerSystemMessagesForEntryPoint: function(aManifest, aApp, aEntryPoint) {
|
|
|
|
let root = aManifest;
|
|
|
|
if (aEntryPoint && aManifest.entry_points[aEntryPoint]) {
|
|
|
|
root = aManifest.entry_points[aEntryPoint];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!root.messages || !Array.isArray(root.messages) ||
|
|
|
|
root.messages.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-03 05:38:03 +00:00
|
|
|
let manifest = new ManifestHelper(aManifest, aApp.origin);
|
2012-09-13 18:47:34 +00:00
|
|
|
let launchPath = Services.io.newURI(manifest.fullLaunchPath(aEntryPoint), null, null);
|
|
|
|
let manifestURL = Services.io.newURI(aApp.manifestURL, null, null);
|
|
|
|
root.messages.forEach(function registerPages(aMessage) {
|
|
|
|
let href = launchPath;
|
|
|
|
let messageName;
|
|
|
|
if (typeof(aMessage) === "object" && Object.keys(aMessage).length === 1) {
|
|
|
|
messageName = Object.keys(aMessage)[0];
|
|
|
|
href = Services.io.newURI(manifest.resolveFromOrigin(aMessage[messageName]), null, null);
|
|
|
|
} else {
|
|
|
|
messageName = aMessage;
|
|
|
|
}
|
|
|
|
msgmgr.registerPage(messageName, href, manifestURL);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2012-07-03 00:16:55 +00:00
|
|
|
_registerSystemMessages: function(aManifest, aApp) {
|
2012-09-13 18:47:34 +00:00
|
|
|
this._registerSystemMessagesForEntryPoint(aManifest, aApp, null);
|
|
|
|
|
|
|
|
if (!aManifest.entry_points) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let entryPoint in aManifest.entry_points) {
|
|
|
|
this._registerSystemMessagesForEntryPoint(aManifest, aApp, entryPoint);
|
2012-07-03 00:16:55 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-10-18 07:32:15 +00:00
|
|
|
// |aEntryPoint| is either the entry_point name or the null in which case we
|
2012-09-13 18:47:34 +00:00
|
|
|
// use the root of the manifest.
|
2012-11-03 03:28:32 +00:00
|
|
|
_createActivitiesToRegister: function(aManifest, aApp, aEntryPoint, aRunUpdate) {
|
2012-10-18 07:32:15 +00:00
|
|
|
let activitiesToRegister = [];
|
2012-09-13 18:47:34 +00:00
|
|
|
let root = aManifest;
|
|
|
|
if (aEntryPoint && aManifest.entry_points[aEntryPoint]) {
|
|
|
|
root = aManifest.entry_points[aEntryPoint];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!root.activities) {
|
2012-10-18 07:32:15 +00:00
|
|
|
return activitiesToRegister;
|
2012-07-20 15:41:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 05:38:03 +00:00
|
|
|
let manifest = new ManifestHelper(aManifest, aApp.origin);
|
2012-09-13 18:47:34 +00:00
|
|
|
for (let activity in root.activities) {
|
|
|
|
let description = root.activities[activity];
|
2012-08-15 02:40:12 +00:00
|
|
|
if (!description.href) {
|
|
|
|
description.href = manifest.launch_path;
|
|
|
|
}
|
|
|
|
description.href = manifest.resolveFromOrigin(description.href);
|
2012-11-03 03:28:32 +00:00
|
|
|
|
|
|
|
if (aRunUpdate) {
|
|
|
|
activitiesToRegister.push({ "manifest": aApp.manifestURL,
|
|
|
|
"name": activity,
|
|
|
|
"title": manifest.name,
|
|
|
|
"icon": manifest.iconURLForSize(128),
|
|
|
|
"description": description });
|
|
|
|
}
|
|
|
|
|
|
|
|
let launchPath = Services.io.newURI(description.href, null, null);
|
2012-07-20 15:41:30 +00:00
|
|
|
let manifestURL = Services.io.newURI(aApp.manifestURL, null, null);
|
|
|
|
msgmgr.registerPage("activity", launchPath, manifestURL);
|
|
|
|
}
|
2012-10-18 07:32:15 +00:00
|
|
|
return activitiesToRegister;
|
2012-07-20 15:41:30 +00:00
|
|
|
},
|
|
|
|
|
2012-10-18 07:32:15 +00:00
|
|
|
// |aAppsToRegister| contains an array of apps to be registered, where
|
|
|
|
// each element is an object in the format of {manifest: foo, app: bar}.
|
2012-11-03 03:28:32 +00:00
|
|
|
_registerActivitiesForApps: function(aAppsToRegister, aRunUpdate) {
|
2012-10-18 07:32:15 +00:00
|
|
|
// Collect the activities to be registered for root and entry_points.
|
|
|
|
let activitiesToRegister = [];
|
|
|
|
aAppsToRegister.forEach(function (aApp) {
|
|
|
|
let manifest = aApp.manifest;
|
|
|
|
let app = aApp.app;
|
|
|
|
activitiesToRegister.push.apply(activitiesToRegister,
|
2012-11-03 03:28:32 +00:00
|
|
|
this._createActivitiesToRegister(manifest, app, null, aRunUpdate));
|
2012-10-18 07:32:15 +00:00
|
|
|
|
|
|
|
if (!manifest.entry_points) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-13 18:47:34 +00:00
|
|
|
|
2012-10-18 07:32:15 +00:00
|
|
|
for (let entryPoint in manifest.entry_points) {
|
|
|
|
activitiesToRegister.push.apply(activitiesToRegister,
|
2012-11-03 03:28:32 +00:00
|
|
|
this._createActivitiesToRegister(manifest, app, entryPoint, aRunUpdate));
|
2012-10-18 07:32:15 +00:00
|
|
|
}
|
|
|
|
}, this);
|
2012-09-13 18:47:34 +00:00
|
|
|
|
2012-11-03 03:28:32 +00:00
|
|
|
if (!aRunUpdate || activitiesToRegister.length == 0) {
|
|
|
|
this.notifyAppsRegistryReady();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-18 07:32:15 +00:00
|
|
|
// Send the array carrying all the activities to be registered.
|
|
|
|
cpmm.sendAsyncMessage("Activities:Register", activitiesToRegister);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Better to directly use |_registerActivitiesForApps()| if we have
|
|
|
|
// multiple apps to be registered for activities.
|
2012-11-03 03:28:32 +00:00
|
|
|
_registerActivities: function(aManifest, aApp, aRunUpdate) {
|
|
|
|
this._registerActivitiesForApps([{ manifest: aManifest, app: aApp }], aRunUpdate);
|
2012-09-13 18:47:34 +00:00
|
|
|
},
|
|
|
|
|
2012-10-18 07:32:15 +00:00
|
|
|
// |aEntryPoint| is either the entry_point name or the null in which case we
|
|
|
|
// use the root of the manifest.
|
|
|
|
_createActivitiesToUnregister: function(aManifest, aApp, aEntryPoint) {
|
|
|
|
let activitiesToUnregister = [];
|
2012-09-13 18:47:34 +00:00
|
|
|
let root = aManifest;
|
|
|
|
if (aEntryPoint && aManifest.entry_points[aEntryPoint]) {
|
|
|
|
root = aManifest.entry_points[aEntryPoint];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!root.activities) {
|
2012-10-18 07:32:15 +00:00
|
|
|
return activitiesToUnregister;
|
2012-07-20 15:41:30 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 18:47:34 +00:00
|
|
|
for (let activity in root.activities) {
|
|
|
|
let description = root.activities[activity];
|
2012-10-18 07:32:15 +00:00
|
|
|
activitiesToUnregister.push({ "manifest": aApp.manifestURL,
|
|
|
|
"name": activity });
|
2012-07-20 15:41:30 +00:00
|
|
|
}
|
2012-10-18 07:32:15 +00:00
|
|
|
return activitiesToUnregister;
|
2012-07-20 15:41:30 +00:00
|
|
|
},
|
|
|
|
|
2012-10-18 07:32:15 +00:00
|
|
|
// |aAppsToUnregister| contains an array of apps to be unregistered, where
|
|
|
|
// each element is an object in the format of {manifest: foo, app: bar}.
|
|
|
|
_unregisterActivitiesForApps: function(aAppsToUnregister) {
|
|
|
|
// Collect the activities to be unregistered for root and entry_points.
|
|
|
|
let activitiesToUnregister = [];
|
|
|
|
aAppsToUnregister.forEach(function (aApp) {
|
|
|
|
let manifest = aApp.manifest;
|
|
|
|
let app = aApp.app;
|
|
|
|
activitiesToUnregister.push.apply(activitiesToUnregister,
|
|
|
|
this._createActivitiesToUnregister(manifest, app, null));
|
|
|
|
|
|
|
|
if (!manifest.entry_points) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-13 18:47:34 +00:00
|
|
|
|
2012-10-18 07:32:15 +00:00
|
|
|
for (let entryPoint in manifest.entry_points) {
|
|
|
|
activitiesToUnregister.push.apply(activitiesToUnregister,
|
|
|
|
this._createActivitiesToUnregister(manifest, app, entryPoint));
|
|
|
|
}
|
|
|
|
}, this);
|
2012-09-13 18:47:34 +00:00
|
|
|
|
2012-10-18 07:32:15 +00:00
|
|
|
// Send the array carrying all the activities to be unregistered.
|
|
|
|
cpmm.sendAsyncMessage("Activities:Unregister", activitiesToUnregister);
|
2012-09-13 18:47:34 +00:00
|
|
|
},
|
|
|
|
|
2012-10-18 07:32:15 +00:00
|
|
|
// Better to directly use |_unregisterActivitiesForApps()| if we have
|
|
|
|
// multiple apps to be unregistered for activities.
|
|
|
|
_unregisterActivities: function(aManifest, aApp) {
|
|
|
|
this._unregisterActivitiesForApps([{ manifest: aManifest, app: aApp }]);
|
2012-10-17 04:30:43 +00:00
|
|
|
},
|
|
|
|
|
2012-11-03 03:28:32 +00:00
|
|
|
_processManifestForIds: function(aIds, aRunUpdate) {
|
2012-09-12 01:17:01 +00:00
|
|
|
this._readManifests(aIds, (function registerManifests(aResults) {
|
2012-10-18 07:32:15 +00:00
|
|
|
let appsToRegister = [];
|
2012-09-12 01:17:01 +00:00
|
|
|
aResults.forEach(function registerManifest(aResult) {
|
|
|
|
let app = this.webapps[aResult.id];
|
|
|
|
let manifest = aResult.manifest;
|
|
|
|
app.name = manifest.name;
|
2012-10-19 10:43:17 +00:00
|
|
|
app.csp = manifest.csp || "";
|
2012-09-12 01:17:01 +00:00
|
|
|
this._registerSystemMessages(manifest, app);
|
2012-10-18 07:32:15 +00:00
|
|
|
appsToRegister.push({ manifest: manifest, app: app });
|
2012-09-12 01:17:01 +00:00
|
|
|
}, this);
|
2012-11-03 03:28:32 +00:00
|
|
|
this._registerActivitiesForApps(appsToRegister, aRunUpdate);
|
2012-07-03 00:16:55 +00:00
|
|
|
}).bind(this));
|
|
|
|
},
|
|
|
|
#endif
|
|
|
|
|
2012-03-13 00:33:10 +00:00
|
|
|
observe: function(aSubject, aTopic, aData) {
|
|
|
|
if (aTopic == "xpcom-shutdown") {
|
|
|
|
this.messages.forEach((function(msgName) {
|
|
|
|
ppmm.removeMessageListener(msgName, this);
|
|
|
|
}).bind(this));
|
|
|
|
Services.obs.removeObserver(this, "xpcom-shutdown");
|
|
|
|
ppmm = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
_loadJSONAsync: function(aFile, aCallback) {
|
2011-11-28 20:13:26 +00:00
|
|
|
try {
|
2011-12-05 23:26:18 +00:00
|
|
|
let channel = NetUtil.newChannel(aFile);
|
2011-11-28 20:13:26 +00:00
|
|
|
channel.contentType = "application/json";
|
|
|
|
NetUtil.asyncFetch(channel, function(aStream, aResult) {
|
|
|
|
if (!Components.isSuccessCode(aResult)) {
|
2012-07-11 15:38:33 +00:00
|
|
|
Cu.reportError("DOMApplicationRegistry: Could not read from json file "
|
|
|
|
+ aFile.path);
|
2011-12-05 23:26:18 +00:00
|
|
|
if (aCallback)
|
|
|
|
aCallback(null);
|
2011-11-28 20:13:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read json file into a string
|
|
|
|
let data = null;
|
|
|
|
try {
|
2012-07-31 10:06:56 +00:00
|
|
|
// Obtain a converter to read from a UTF-8 encoded input stream.
|
|
|
|
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
|
|
|
|
.createInstance(Ci.nsIScriptableUnicodeConverter);
|
|
|
|
converter.charset = "UTF-8";
|
|
|
|
|
|
|
|
data = JSON.parse(converter.ConvertToUnicode(NetUtil.readInputStreamToString(aStream,
|
|
|
|
aStream.available()) || ""));
|
2011-11-28 20:13:26 +00:00
|
|
|
aStream.close();
|
2011-12-05 23:26:18 +00:00
|
|
|
if (aCallback)
|
|
|
|
aCallback(data);
|
2011-11-28 20:13:26 +00:00
|
|
|
} catch (ex) {
|
2012-09-22 03:40:03 +00:00
|
|
|
Cu.reportError("DOMApplicationRegistry: Could not parse JSON: " +
|
2012-10-23 20:52:57 +00:00
|
|
|
aFile.path + " " + ex + "\n" + ex.stack);
|
2011-12-05 23:26:18 +00:00
|
|
|
if (aCallback)
|
|
|
|
aCallback(null);
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (ex) {
|
2012-07-11 15:38:33 +00:00
|
|
|
Cu.reportError("DOMApplicationRegistry: Could not read from " +
|
2012-10-23 20:52:57 +00:00
|
|
|
aFile.path + " : " + ex + "\n" + ex.stack);
|
2011-12-05 23:26:18 +00:00
|
|
|
if (aCallback)
|
|
|
|
aCallback(null);
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-09-18 17:34:55 +00:00
|
|
|
addMessageListener: function(aMsgNames, aMm) {
|
|
|
|
aMsgNames.forEach(function (aMsgName) {
|
|
|
|
if (!(aMsgName in this.children)) {
|
|
|
|
this.children[aMsgName] = [];
|
|
|
|
}
|
2012-10-19 18:17:05 +00:00
|
|
|
|
|
|
|
let mmFound = this.children[aMsgName].some(function(mmRef) {
|
|
|
|
if (mmRef.mm === aMm) {
|
|
|
|
mmRef.refCount++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!mmFound) {
|
|
|
|
this.children[aMsgName].push({
|
|
|
|
mm: aMm,
|
|
|
|
refCount: 1
|
|
|
|
});
|
|
|
|
}
|
2012-09-18 17:34:55 +00:00
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
2012-10-19 18:17:05 +00:00
|
|
|
removeMessageListener: function(aMsgNames, aMm) {
|
|
|
|
if (aMsgNames.length === 1 &&
|
|
|
|
aMsgNames[0] === "Webapps:Internal:AllMessages") {
|
2012-11-09 00:53:31 +00:00
|
|
|
for (let msgName in this.children) {
|
|
|
|
let msg = this.children[msgName];
|
2012-10-19 18:17:05 +00:00
|
|
|
|
|
|
|
for (let mmI = msg.length - 1; mmI >= 0; mmI -= 1) {
|
|
|
|
let mmRef = msg[mmI];
|
|
|
|
if (mmRef.mm === aMm) {
|
|
|
|
msg.splice(mmI, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg.length === 0) {
|
2012-11-09 00:53:31 +00:00
|
|
|
delete this.children[msgName];
|
2012-10-19 18:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aMsgNames.forEach(function(aMsgName) {
|
|
|
|
if (!(aMsgName in this.children)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-01 20:29:59 +00:00
|
|
|
|
2012-10-19 18:17:05 +00:00
|
|
|
let removeIndex;
|
|
|
|
this.children[aMsgName].some(function(mmRef, index) {
|
|
|
|
if (mmRef.mm === aMm) {
|
|
|
|
mmRef.refCount--;
|
|
|
|
if (mmRef.refCount === 0) {
|
|
|
|
removeIndex = index;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2012-09-18 17:34:55 +00:00
|
|
|
|
2012-10-19 18:17:05 +00:00
|
|
|
if (removeIndex) {
|
|
|
|
this.children[aMsgName].splice(removeIndex, 1);
|
2012-09-18 17:34:55 +00:00
|
|
|
}
|
2012-10-19 18:17:05 +00:00
|
|
|
}, this);
|
2012-09-18 17:34:55 +00:00
|
|
|
},
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
receiveMessage: function(aMessage) {
|
2012-06-26 20:12:33 +00:00
|
|
|
// nsIPrefBranch throws if pref does not exist, faster to simply write
|
|
|
|
// the pref instead of first checking if it is false.
|
|
|
|
Services.prefs.setBoolPref("dom.mozApps.used", true);
|
|
|
|
|
2012-09-30 03:08:01 +00:00
|
|
|
// We need to check permissions for calls coming from mozApps.mgmt.
|
|
|
|
// These are: getAll(), getNotInstalled() and applyDownload()
|
|
|
|
if (["Webapps:GetAll",
|
|
|
|
"Webapps:GetNotInstalled",
|
2012-10-30 00:17:47 +00:00
|
|
|
"Webapps:ApplyDownload"].indexOf(aMessage.name) != -1) {
|
2012-09-30 03:08:01 +00:00
|
|
|
if (!aMessage.target.assertPermission("webapps-manage")) {
|
|
|
|
debug("mozApps message " + aMessage.name +
|
|
|
|
" from a content process with no 'webapps-manage' privileges.");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-01 20:29:59 +00:00
|
|
|
let msg = aMessage.data || {};
|
2012-09-18 17:34:55 +00:00
|
|
|
let mm = aMessage.target;
|
|
|
|
msg.mm = mm;
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Webapps:Install":
|
|
|
|
// always ask for UI to install
|
2012-09-18 17:34:55 +00:00
|
|
|
Services.obs.notifyObservers(mm, "webapps-ask-install", JSON.stringify(msg));
|
2011-11-28 20:13:26 +00:00
|
|
|
break;
|
2012-03-06 19:50:58 +00:00
|
|
|
case "Webapps:GetSelf":
|
2012-09-18 17:34:55 +00:00
|
|
|
this.getSelf(msg, mm);
|
2012-03-06 19:50:58 +00:00
|
|
|
break;
|
2011-11-28 20:13:26 +00:00
|
|
|
case "Webapps:Uninstall":
|
2012-09-28 16:24:45 +00:00
|
|
|
this.uninstall(msg, mm);
|
2011-11-28 20:13:26 +00:00
|
|
|
break;
|
|
|
|
case "Webapps:Launch":
|
2012-09-27 01:01:20 +00:00
|
|
|
this.launchApp(msg, mm);
|
2011-11-28 20:13:26 +00:00
|
|
|
break;
|
2012-10-02 20:38:51 +00:00
|
|
|
case "Webapps:CheckInstalled":
|
|
|
|
this.checkInstalled(msg, mm);
|
2012-09-25 15:04:24 +00:00
|
|
|
break;
|
2012-03-06 19:50:58 +00:00
|
|
|
case "Webapps:GetInstalled":
|
2012-09-18 17:34:55 +00:00
|
|
|
this.getInstalled(msg, mm);
|
2011-12-15 17:20:57 +00:00
|
|
|
break;
|
2012-06-29 20:46:21 +00:00
|
|
|
case "Webapps:GetNotInstalled":
|
2012-09-18 17:34:55 +00:00
|
|
|
this.getNotInstalled(msg, mm);
|
2012-06-29 20:46:21 +00:00
|
|
|
break;
|
2012-03-06 19:50:58 +00:00
|
|
|
case "Webapps:GetAll":
|
|
|
|
if (msg.hasPrivileges)
|
2012-09-18 17:34:55 +00:00
|
|
|
this.getAll(msg, mm);
|
2012-03-06 19:50:58 +00:00
|
|
|
else
|
2012-09-18 17:34:55 +00:00
|
|
|
mm.sendAsyncMessage("Webapps:GetAll:Return:KO", msg);
|
2011-11-28 20:13:26 +00:00
|
|
|
break;
|
2012-07-11 15:38:33 +00:00
|
|
|
case "Webapps:InstallPackage":
|
2012-10-01 23:45:32 +00:00
|
|
|
// always ask for UI to install
|
|
|
|
Services.obs.notifyObservers(mm, "webapps-ask-install", JSON.stringify(msg));
|
2012-07-11 15:38:33 +00:00
|
|
|
break;
|
2012-07-11 15:38:36 +00:00
|
|
|
case "Webapps:GetBasePath":
|
2012-08-29 21:20:03 +00:00
|
|
|
return this.webapps[msg.id].basePath;
|
2012-07-11 15:38:36 +00:00
|
|
|
break;
|
2012-09-18 17:34:55 +00:00
|
|
|
case "Webapps:RegisterForMessages":
|
|
|
|
this.addMessageListener(msg, mm);
|
|
|
|
break;
|
2012-10-19 18:17:05 +00:00
|
|
|
case "Webapps:UnregisterForMessages":
|
|
|
|
this.removeMessageListener(msg, mm);
|
|
|
|
break;
|
|
|
|
case "child-process-shutdown":
|
|
|
|
this.removeMessageListener(["Webapps:Internal:AllMessages"], mm);
|
|
|
|
break;
|
2012-08-28 02:43:57 +00:00
|
|
|
case "Webapps:GetList":
|
2012-09-18 17:34:55 +00:00
|
|
|
this.addMessageListener(["Webapps:AddApp", "Webapps:RemoveApp"], mm);
|
2012-08-28 02:43:57 +00:00
|
|
|
return this.webapps;
|
2012-09-29 17:57:18 +00:00
|
|
|
case "Webapps:Download":
|
|
|
|
this.startDownload(msg.manifestURL);
|
|
|
|
break;
|
2012-09-27 01:01:20 +00:00
|
|
|
case "Webapps:CancelDownload":
|
2012-09-29 17:57:18 +00:00
|
|
|
this.cancelDownload(msg.manifestURL);
|
2012-09-27 01:01:20 +00:00
|
|
|
break;
|
|
|
|
case "Webapps:CheckForUpdate":
|
|
|
|
this.checkForUpdate(msg, mm);
|
|
|
|
break;
|
2012-10-30 00:17:47 +00:00
|
|
|
case "Webapps:ApplyDownload":
|
|
|
|
this.applyDownload(msg.manifestURL);
|
2012-09-29 17:57:18 +00:00
|
|
|
break;
|
2012-09-19 16:28:55 +00:00
|
|
|
case "Activities:Register:OK":
|
2012-10-18 07:32:15 +00:00
|
|
|
this.notifyAppsRegistryReady();
|
2012-09-19 16:28:55 +00:00
|
|
|
break;
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-09-18 17:34:55 +00:00
|
|
|
// Some messages can be listened by several content processes:
|
|
|
|
// Webapps:AddApp
|
|
|
|
// Webapps:RemoveApp
|
|
|
|
// Webapps:Install:Return:OK
|
|
|
|
// Webapps:Uninstall:Return:OK
|
|
|
|
// Webapps:OfflineCache
|
|
|
|
broadcastMessage: function broadcastMessage(aMsgName, aContent) {
|
|
|
|
if (!(aMsgName in this.children)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-10-19 18:17:05 +00:00
|
|
|
this.children[aMsgName].forEach(function(mmRef) {
|
|
|
|
mmRef.mm.sendAsyncMessage(aMsgName, aContent);
|
|
|
|
});
|
2012-09-18 17:34:55 +00:00
|
|
|
},
|
|
|
|
|
2012-08-29 21:20:03 +00:00
|
|
|
_getAppDir: function(aId) {
|
|
|
|
return FileUtils.getDir(DIRECTORY_NAME, ["webapps", aId], true, true);
|
|
|
|
},
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
_writeFile: function ss_writeFile(aFile, aData, aCallbak) {
|
|
|
|
// Initialize the file output stream.
|
2011-12-06 04:22:01 +00:00
|
|
|
let ostream = FileUtils.openSafeFileOutputStream(aFile);
|
2011-11-28 20:13:26 +00:00
|
|
|
|
|
|
|
// Obtain a converter to convert our data to a UTF-8 encoded input stream.
|
2012-07-11 15:38:33 +00:00
|
|
|
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
|
|
|
|
.createInstance(Ci.nsIScriptableUnicodeConverter);
|
2011-11-28 20:13:26 +00:00
|
|
|
converter.charset = "UTF-8";
|
|
|
|
|
|
|
|
// Asynchronously copy the data to the file.
|
|
|
|
let istream = converter.convertToInputStream(aData);
|
|
|
|
NetUtil.asyncCopy(istream, ostream, function(rc) {
|
|
|
|
if (aCallbak)
|
|
|
|
aCallbak();
|
|
|
|
});
|
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
2012-09-27 01:01:20 +00:00
|
|
|
launchApp: function launchApp(aData, aMm) {
|
|
|
|
let app = this.getAppByManifestURL(aData.manifestURL);
|
|
|
|
if (!app) {
|
|
|
|
aMm.sendAsyncMessage("Webapps:Launch:Return:KO", aData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fire an error when trying to launch an app that is not
|
|
|
|
// yet fully installed.
|
|
|
|
if (app.installState == "pending") {
|
|
|
|
aMm.sendAsyncMessage("Webapps:Launch:Return:KO", aData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Services.obs.notifyObservers(aMm, "webapps-launch", JSON.stringify(aData));
|
|
|
|
},
|
|
|
|
|
2012-09-29 17:57:18 +00:00
|
|
|
cancelDownload: function cancelDownload(aManifestURL) {
|
|
|
|
// We can't cancel appcache downloads for now.
|
2012-09-27 19:34:41 +00:00
|
|
|
if (!this.downloads[aManifestURL]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// This is a HTTP channel.
|
|
|
|
let download = this.downloads[aManifestURL]
|
|
|
|
download.channel.cancel(Cr.NS_BINDING_ABORTED);
|
2012-09-29 17:57:18 +00:00
|
|
|
let app = this.webapps[download.appId];
|
2012-09-27 19:34:41 +00:00
|
|
|
|
|
|
|
app.progress = 0;
|
|
|
|
app.installState = app.previousState;
|
2012-09-29 17:57:18 +00:00
|
|
|
app.downloading = false;
|
2012-10-30 00:17:47 +00:00
|
|
|
app.downloadAvailable = false;
|
2012-09-27 19:34:41 +00:00
|
|
|
app.downloadSize = 0;
|
|
|
|
this._saveApps((function() {
|
|
|
|
this.broadcastMessage("Webapps:PackageEvent",
|
|
|
|
{ type: "canceled",
|
|
|
|
manifestURL: aApp.manifestURL,
|
|
|
|
app: app,
|
|
|
|
error: "DOWNLOAD_CANCELED" });
|
|
|
|
}).bind(this));
|
2012-09-27 01:01:20 +00:00
|
|
|
},
|
|
|
|
|
2012-10-30 00:17:47 +00:00
|
|
|
startDownload: function startDownload(aManifestURL) {
|
|
|
|
debug("startDownload for " + aManifestURL);
|
|
|
|
let id = this._appIdForManifestURL(aManifestURL);
|
|
|
|
let app = this.webapps[id];
|
2012-09-29 17:57:18 +00:00
|
|
|
if (!app) {
|
2012-10-30 00:17:47 +00:00
|
|
|
debug("startDownload: No app found for " + aManifestURL);
|
2012-09-29 17:57:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to get the update manifest here, not the webapp manifest.
|
|
|
|
let file = FileUtils.getFile(DIRECTORY_NAME,
|
|
|
|
["webapps", id, "update.webapp"], true);
|
|
|
|
|
|
|
|
this._loadJSONAsync(file, (function(aJSON) {
|
|
|
|
if (!aJSON) {
|
2012-10-30 00:17:47 +00:00
|
|
|
debug("startDownload: No update manifest found at " + file.path + " " + aManifestURL);
|
2012-09-29 17:57:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-30 00:17:47 +00:00
|
|
|
let manifest = new ManifestHelper(aJSON, app.installOrigin);
|
2012-09-29 17:57:18 +00:00
|
|
|
this.downloadPackage(manifest, { manifestURL: aManifestURL,
|
|
|
|
origin: app.origin }, true,
|
|
|
|
function(aId, aManifest) {
|
|
|
|
// Success! Keep the zip in of TmpD, we'll move it out when
|
|
|
|
// applyDownload() will be called.
|
|
|
|
let tmpDir = FileUtils.getDir("TmpD", ["webapps", aId], true, true);
|
|
|
|
|
|
|
|
// Save the manifest in TmpD also
|
|
|
|
let manFile = tmpDir.clone();
|
|
|
|
manFile.append("manifest.webapp");
|
|
|
|
DOMApplicationRegistry._writeFile(manFile,
|
|
|
|
JSON.stringify(aManifest),
|
|
|
|
function() { });
|
|
|
|
// Set state and fire events.
|
|
|
|
app.downloading = false;
|
2012-10-30 00:17:47 +00:00
|
|
|
app.downloadAvailable = false;
|
2012-09-29 17:57:18 +00:00
|
|
|
app.readyToApplyDownload = true;
|
2012-11-17 03:37:41 +00:00
|
|
|
app.updateTime = Date.now();
|
2012-09-29 17:57:18 +00:00
|
|
|
DOMApplicationRegistry._saveApps(function() {
|
|
|
|
debug("About to fire Webapps:PackageEvent");
|
|
|
|
DOMApplicationRegistry.broadcastMessage("Webapps:PackageEvent",
|
|
|
|
{ type: "downloaded",
|
2012-10-30 00:17:47 +00:00
|
|
|
manifestURL: aManifestURL,
|
2012-09-29 17:57:18 +00:00
|
|
|
app: app,
|
|
|
|
manifest: aManifest });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
applyDownload: function applyDownload(aManifestURL) {
|
2012-10-30 00:17:47 +00:00
|
|
|
debug("applyDownload for " + aManifestURL);
|
|
|
|
let app = this.getAppByManifestURL(aManifestURL);
|
2012-09-29 17:57:18 +00:00
|
|
|
if (!app || (app && !app.readyToApplyDownload)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-30 00:17:47 +00:00
|
|
|
let id = this._appIdForManifestURL(app.manifestURL);
|
2012-09-29 17:57:18 +00:00
|
|
|
|
2012-11-03 03:28:32 +00:00
|
|
|
// Clean up the deprecated manifest cache if needed.
|
|
|
|
if (id in this._manifestCache) {
|
|
|
|
delete this._manifestCache[id];
|
|
|
|
}
|
|
|
|
|
2012-09-29 17:57:18 +00:00
|
|
|
// Move the application.zip and manifest.webapp files out of TmpD
|
2012-10-30 00:17:47 +00:00
|
|
|
let tmpDir = FileUtils.getDir("TmpD", ["webapps", id], true, true);
|
2012-09-29 17:57:18 +00:00
|
|
|
let manFile = tmpDir.clone();
|
|
|
|
manFile.append("manifest.webapp");
|
|
|
|
let appFile = tmpDir.clone();
|
|
|
|
appFile.append("application.zip");
|
|
|
|
|
|
|
|
let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
|
|
|
|
appFile.moveTo(dir, "application.zip");
|
|
|
|
manFile.moveTo(dir, "manifest.webapp");
|
|
|
|
|
|
|
|
try {
|
|
|
|
tmpDir.remove(true);
|
|
|
|
} catch(e) { }
|
|
|
|
|
|
|
|
// Get the manifest, and set properties.
|
2012-10-10 21:29:07 +00:00
|
|
|
this.getManifestFor(app.origin, (function(aData) {
|
2012-09-29 17:57:18 +00:00
|
|
|
app.readyToApplyDownload = false;
|
|
|
|
this.broadcastMessage("Webapps:PackageEvent",
|
|
|
|
{ type: "applied",
|
2012-10-30 00:17:47 +00:00
|
|
|
manifestURL: app.manifestURL,
|
2012-09-29 17:57:18 +00:00
|
|
|
app: app,
|
|
|
|
manifest: aData });
|
2012-10-10 21:29:07 +00:00
|
|
|
// Update the permissions for this app.
|
|
|
|
PermissionsInstaller.installPermissions({ manifest: aData,
|
|
|
|
origin: app.origin,
|
2012-10-30 00:17:47 +00:00
|
|
|
manifestURL: app.manifestURL },
|
2012-10-10 21:29:07 +00:00
|
|
|
true);
|
|
|
|
}).bind(this));
|
2012-09-29 17:57:18 +00:00
|
|
|
},
|
|
|
|
|
2012-10-04 18:18:39 +00:00
|
|
|
startOfflineCacheDownload: function startOfflineCacheDownload(aManifest, aApp,
|
|
|
|
aProfileDir,
|
|
|
|
aOfflineCacheObserver) {
|
2012-09-27 01:01:20 +00:00
|
|
|
// if the manifest has an appcache_path property, use it to populate the appcache
|
|
|
|
if (aManifest.appcache_path) {
|
|
|
|
let appcacheURI = Services.io.newURI(aManifest.fullAppcachePath(), null, null);
|
|
|
|
let updateService = Cc["@mozilla.org/offlinecacheupdate-service;1"]
|
|
|
|
.getService(Ci.nsIOfflineCacheUpdateService);
|
|
|
|
let docURI = Services.io.newURI(aManifest.fullLaunchPath(), null, null);
|
|
|
|
let cacheUpdate = aProfileDir ? updateService.scheduleCustomProfileUpdate(appcacheURI, docURI, aProfileDir)
|
2012-11-08 01:48:56 +00:00
|
|
|
: updateService.scheduleAppUpdate(appcacheURI, docURI, aApp.localId, false);
|
2012-09-27 01:01:20 +00:00
|
|
|
cacheUpdate.addObserver(new AppcacheObserver(aApp), false);
|
|
|
|
if (aOfflineCacheObserver) {
|
|
|
|
cacheUpdate.addObserver(aOfflineCacheObserver, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
checkForUpdate: function(aData, aMm) {
|
2012-10-30 00:17:47 +00:00
|
|
|
debug("checkForUpdate for " + aData.manifestURL);
|
|
|
|
let id = this._appIdForManifestURL(aData.manifestURL);
|
|
|
|
let app = this.webapps[id];
|
2012-10-18 10:32:03 +00:00
|
|
|
|
2012-09-27 01:01:20 +00:00
|
|
|
if (!app) {
|
|
|
|
aData.error = "NO_SUCH_APP";
|
|
|
|
aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:KO", aData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendError(aError) {
|
|
|
|
aData.error = aError;
|
|
|
|
aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:KO", aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatePackagedApp(aManifest) {
|
|
|
|
debug("updatePackagedApp");
|
2012-10-30 00:17:47 +00:00
|
|
|
|
|
|
|
// if the app manifestURL has a app:// scheme, we can't have an
|
|
|
|
// update.
|
|
|
|
if (app.manifestURL.startsWith("app://")) {
|
|
|
|
aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:KO", aData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-03 05:38:03 +00:00
|
|
|
let manifest = new ManifestHelper(aManifest, app.manifestURL);
|
2012-09-29 17:57:18 +00:00
|
|
|
// A package is available: set downloadAvailable to fire the matching
|
|
|
|
// event.
|
|
|
|
app.downloadAvailable = true;
|
|
|
|
app.downloadSize = manifest.size;
|
|
|
|
aData.event = "downloadavailable";
|
|
|
|
aData.app = {
|
|
|
|
downloadAvailable: true,
|
|
|
|
downloadSize: manifest.size
|
|
|
|
}
|
|
|
|
DOMApplicationRegistry._saveApps(function() {
|
|
|
|
aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:OK", aData);
|
|
|
|
});
|
2012-09-27 01:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateHostedApp(aManifest) {
|
|
|
|
debug("updateHostedApp");
|
|
|
|
let id = this._appId(app.origin);
|
|
|
|
|
2012-11-03 03:28:32 +00:00
|
|
|
if (id in this._manifestCache) {
|
|
|
|
delete this._manifestCache[id];
|
|
|
|
}
|
|
|
|
|
2012-10-17 04:30:43 +00:00
|
|
|
// Update the web apps' registration.
|
|
|
|
this.notifyAppsRegistryStart();
|
2012-09-27 01:01:20 +00:00
|
|
|
#ifdef MOZ_SYS_MSG
|
|
|
|
this._readManifests([{ id: id }], (function unregisterManifest(aResult) {
|
|
|
|
this._unregisterActivities(aResult[0].manifest, app);
|
|
|
|
this._registerSystemMessages(aManifest, app);
|
2012-11-03 03:28:32 +00:00
|
|
|
this._registerActivities(aManifest, app, true);
|
2012-09-27 01:01:20 +00:00
|
|
|
}).bind(this));
|
2012-10-17 04:30:43 +00:00
|
|
|
#else
|
|
|
|
// Nothing else to do but notifying we're ready.
|
|
|
|
this.notifyAppsRegistryReady();
|
2012-09-27 01:01:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Store the new manifest.
|
|
|
|
let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
|
|
|
|
let manFile = dir.clone();
|
|
|
|
manFile.append("manifest.webapp");
|
|
|
|
this._writeFile(manFile, JSON.stringify(aManifest), function() { });
|
|
|
|
|
2012-10-03 05:38:03 +00:00
|
|
|
let manifest = new ManifestHelper(aManifest, app.origin);
|
2012-09-27 01:01:20 +00:00
|
|
|
|
|
|
|
if (manifest.appcache_path) {
|
|
|
|
app.installState = "updating";
|
|
|
|
app.downloadAvailable = true;
|
|
|
|
app.downloading = true;
|
|
|
|
app.downloadsize = 0;
|
|
|
|
app.readyToApplyDownload = false;
|
|
|
|
} else {
|
|
|
|
app.installState = "installed";
|
|
|
|
app.downloadAvailable = false;
|
|
|
|
app.downloading = false;
|
|
|
|
app.readyToApplyDownload = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
app.name = aManifest.name;
|
2012-10-19 10:43:17 +00:00
|
|
|
app.csp = aManifest.csp || "";
|
2012-11-17 03:37:41 +00:00
|
|
|
app.updateTime = Date.now();
|
2012-09-27 01:01:20 +00:00
|
|
|
|
|
|
|
// Update the registry.
|
|
|
|
this.webapps[id] = app;
|
|
|
|
|
2012-10-30 00:17:47 +00:00
|
|
|
this._saveApps(function() {
|
|
|
|
aData.event = "downloadapplied";
|
|
|
|
aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:OK", aData);
|
|
|
|
});
|
2012-09-27 01:01:20 +00:00
|
|
|
|
|
|
|
// Preload the appcache if needed.
|
|
|
|
this.startOfflineCacheDownload(manifest, app);
|
2012-10-10 21:29:07 +00:00
|
|
|
|
|
|
|
// Update the permissions for this app.
|
|
|
|
PermissionsInstaller.installPermissions({ manifest: aManifest,
|
|
|
|
origin: app.origin,
|
|
|
|
manifestURL: aData.manifestURL },
|
2012-10-30 00:17:47 +00:00
|
|
|
true);
|
2012-09-27 01:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// First, we download the manifest.
|
|
|
|
let xhr = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
|
|
|
.createInstance(Ci.nsIXMLHttpRequest);
|
|
|
|
xhr.open("GET", aData.manifestURL, true);
|
2012-10-30 00:17:47 +00:00
|
|
|
if (app.etag) {
|
|
|
|
xhr.setRequestHeader("If-None-Match", app.etag);
|
2012-09-27 01:01:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xhr.addEventListener("load", (function() {
|
|
|
|
if (xhr.status == 200) {
|
|
|
|
let manifest;
|
|
|
|
try {
|
2012-10-18 10:32:03 +00:00
|
|
|
manifest = JSON.parse(xhr.responseText);
|
2012-09-27 01:01:20 +00:00
|
|
|
} catch(e) {
|
|
|
|
sendError("MANIFEST_PARSE_ERROR");
|
|
|
|
return;
|
|
|
|
}
|
2012-10-30 00:17:47 +00:00
|
|
|
if (!AppsUtils.checkManifest(manifest, app.installOrigin)) {
|
2012-09-27 01:01:20 +00:00
|
|
|
sendError("INVALID_MANIFEST");
|
|
|
|
} else {
|
|
|
|
app.etag = xhr.getResponseHeader("Etag");
|
|
|
|
app.lastCheckedUpdate = Date.now();
|
2012-10-30 00:17:47 +00:00
|
|
|
if (app.origin.startsWith("app://")) {
|
2012-09-27 01:01:20 +00:00
|
|
|
updatePackagedApp(manifest);
|
|
|
|
} else {
|
2012-10-30 00:17:47 +00:00
|
|
|
updateHostedApp.call(this, manifest);
|
2012-09-27 01:01:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this._saveApps();
|
|
|
|
} else if (xhr.status == 304) {
|
|
|
|
// The manifest has not changed. We just update lastCheckedUpdate.
|
|
|
|
app.lastCheckedUpdate = Date.now();
|
|
|
|
aData.event = "downloadapplied";
|
|
|
|
aData.app = {
|
|
|
|
lastCheckedUpdate: app.lastCheckedUpdate
|
|
|
|
}
|
|
|
|
aMm.sendAsyncMessage("Webapps:CheckForUpdate:Return:OK", aData);
|
|
|
|
this._saveApps();
|
|
|
|
} else {
|
|
|
|
sendError("MANIFEST_URL_ERROR");
|
|
|
|
}
|
|
|
|
}).bind(this), false);
|
|
|
|
|
|
|
|
xhr.addEventListener("error", (function() {
|
2012-10-30 00:17:47 +00:00
|
|
|
sendError("NETWORK_ERROR");
|
2012-09-27 01:01:20 +00:00
|
|
|
}).bind(this), false);
|
|
|
|
|
|
|
|
xhr.send(null);
|
|
|
|
},
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
denyInstall: function(aData) {
|
2012-07-11 15:38:33 +00:00
|
|
|
let packageId = aData.app.packageId;
|
|
|
|
if (packageId) {
|
|
|
|
let dir = FileUtils.getDir("TmpD", ["webapps", packageId],
|
|
|
|
true, true);
|
|
|
|
try {
|
|
|
|
dir.remove(true);
|
|
|
|
} catch(e) {
|
|
|
|
}
|
|
|
|
}
|
2012-09-18 17:34:55 +00:00
|
|
|
aData.mm.sendAsyncMessage("Webapps:Install:Return:KO", aData);
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
2012-06-11 18:41:46 +00:00
|
|
|
confirmInstall: function(aData, aFromSync, aProfileDir, aOfflineCacheObserver) {
|
2012-09-28 22:16:29 +00:00
|
|
|
let isReinstall = false;
|
2011-11-28 20:13:26 +00:00
|
|
|
let app = aData.app;
|
2012-08-29 21:20:03 +00:00
|
|
|
app.removable = true;
|
2012-09-27 19:34:41 +00:00
|
|
|
|
|
|
|
let origin = Services.io.newURI(app.origin, null, null);
|
|
|
|
let manifestURL = origin.resolve(app.manifestURL);
|
|
|
|
|
2012-09-27 21:37:39 +00:00
|
|
|
let id = app.syncId || this._appId(app.origin);
|
2012-09-27 19:34:41 +00:00
|
|
|
let localId = this.getAppLocalIdByManifestURL(manifestURL);
|
2011-11-28 20:13:26 +00:00
|
|
|
|
2012-07-11 15:38:33 +00:00
|
|
|
// Installing an application again is considered as an update.
|
2011-11-28 20:13:26 +00:00
|
|
|
if (id) {
|
2012-09-28 22:16:29 +00:00
|
|
|
isReinstall = true;
|
2012-08-29 21:20:03 +00:00
|
|
|
let dir = this._getAppDir(id);
|
2011-11-28 20:13:26 +00:00
|
|
|
try {
|
|
|
|
dir.remove(true);
|
|
|
|
} catch(e) {
|
|
|
|
}
|
2012-04-28 07:10:08 +00:00
|
|
|
} else {
|
|
|
|
id = this.makeAppId();
|
2012-09-28 22:16:29 +00:00
|
|
|
app.id = id;
|
2012-07-09 10:25:41 +00:00
|
|
|
localId = this._nextLocalId();
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-09-27 19:34:41 +00:00
|
|
|
let manifestName = "manifest.webapp";
|
|
|
|
if (aData.isPackage) {
|
2012-07-11 15:38:33 +00:00
|
|
|
// Override the origin with the correct id.
|
|
|
|
app.origin = "app://" + id;
|
2012-09-27 19:34:41 +00:00
|
|
|
|
|
|
|
// For packaged apps, keep the update manifest distinct from the app
|
|
|
|
// manifest.
|
|
|
|
manifestName = "update.webapp";
|
2012-07-11 15:38:33 +00:00
|
|
|
}
|
|
|
|
|
2012-08-28 02:43:57 +00:00
|
|
|
let appObject = AppsUtils.cloneAppObject(app);
|
2012-08-28 02:43:57 +00:00
|
|
|
appObject.appStatus = app.appStatus || Ci.nsIPrincipal.APP_STATUS_INSTALLED;
|
2012-10-31 21:02:37 +00:00
|
|
|
// For hosted apps, allow application status override in dev mode.
|
|
|
|
if (!aData.isPackage &&
|
|
|
|
Services.prefs.getBoolPref("dom.mozApps.dev_mode")) {
|
|
|
|
appObject.appStatus = AppsUtils.getAppManifestStatus(app.manifest);
|
|
|
|
}
|
|
|
|
|
2012-06-18 19:49:35 +00:00
|
|
|
appObject.installTime = app.installTime = Date.now();
|
2012-09-27 01:01:20 +00:00
|
|
|
appObject.lastUpdateCheck = app.lastUpdateCheck = Date.now();
|
2012-04-28 07:10:08 +00:00
|
|
|
let appNote = JSON.stringify(appObject);
|
|
|
|
appNote.id = id;
|
2011-12-06 04:22:01 +00:00
|
|
|
|
2012-07-09 10:25:41 +00:00
|
|
|
appObject.localId = localId;
|
2012-09-06 00:37:41 +00:00
|
|
|
appObject.basePath = FileUtils.getDir(DIRECTORY_NAME, ["webapps"], true, true).path;
|
2012-04-28 07:10:08 +00:00
|
|
|
let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", id], true, true);
|
2011-11-28 20:13:26 +00:00
|
|
|
let manFile = dir.clone();
|
2012-09-27 19:34:41 +00:00
|
|
|
manFile.append(manifestName);
|
|
|
|
let jsonManifest = aData.isPackage ? app.updateManifest : app.manifest;
|
|
|
|
this._writeFile(manFile, JSON.stringify(jsonManifest), function() { });
|
2011-11-28 20:13:26 +00:00
|
|
|
|
2012-10-03 05:38:03 +00:00
|
|
|
let manifest = new ManifestHelper(jsonManifest, app.origin);
|
2012-09-27 01:01:20 +00:00
|
|
|
|
|
|
|
if (manifest.appcache_path) {
|
|
|
|
appObject.installState = "pending";
|
|
|
|
appObject.downloadAvailable = true;
|
|
|
|
appObject.downloading = true;
|
2012-09-27 19:34:41 +00:00
|
|
|
appObject.downloadSize = 0;
|
|
|
|
appObject.readyToApplyDownload = false;
|
|
|
|
} else if (manifest.package_path) {
|
|
|
|
appObject.installState = "pending";
|
|
|
|
appObject.downloadAvailable = true;
|
|
|
|
appObject.downloading = true;
|
|
|
|
appObject.downloadSize = manifest.size;
|
2012-09-27 01:01:20 +00:00
|
|
|
appObject.readyToApplyDownload = false;
|
|
|
|
} else {
|
|
|
|
appObject.installState = "installed";
|
|
|
|
appObject.downloadAvailable = false;
|
|
|
|
appObject.downloading = false;
|
|
|
|
appObject.readyToApplyDownload = false;
|
|
|
|
}
|
|
|
|
|
2012-09-27 19:34:41 +00:00
|
|
|
appObject.name = manifest.name;
|
2012-10-19 10:43:17 +00:00
|
|
|
appObject.csp = manifest.csp || "";
|
2012-09-26 23:49:43 +00:00
|
|
|
|
2012-09-27 01:01:20 +00:00
|
|
|
this.webapps[id] = appObject;
|
2012-10-03 05:38:06 +00:00
|
|
|
|
2012-10-10 21:29:07 +00:00
|
|
|
// For package apps, the permissions are not in the mini-manifest, so
|
|
|
|
// don't update the permissions yet.
|
|
|
|
if (!aData.isPackage) {
|
2012-10-31 21:02:37 +00:00
|
|
|
PermissionsInstaller.installPermissions({ origin: appObject.origin,
|
|
|
|
manifestURL: appObject.manifestURL,
|
|
|
|
manifest: jsonManifest },
|
|
|
|
isReinstall, (function() {
|
2012-10-10 21:29:07 +00:00
|
|
|
this.uninstall(aData, aData.mm);
|
|
|
|
}).bind(this));
|
|
|
|
}
|
2012-10-03 05:38:06 +00:00
|
|
|
|
2012-09-27 19:34:41 +00:00
|
|
|
["installState", "downloadAvailable",
|
|
|
|
"downloading", "downloadSize", "readyToApplyDownload"].forEach(function(aProp) {
|
|
|
|
aData.app[aProp] = appObject[aProp];
|
|
|
|
});
|
2012-06-11 18:41:46 +00:00
|
|
|
|
2011-12-08 13:32:54 +00:00
|
|
|
if (!aFromSync)
|
|
|
|
this._saveApps((function() {
|
2012-09-18 17:34:55 +00:00
|
|
|
this.broadcastMessage("Webapps:Install:Return:OK", aData);
|
2012-04-28 07:10:08 +00:00
|
|
|
Services.obs.notifyObservers(this, "webapps-sync-install", appNote);
|
2012-09-18 17:34:55 +00:00
|
|
|
this.broadcastMessage("Webapps:AddApp", { id: id, app: appObject });
|
2011-12-08 13:32:54 +00:00
|
|
|
}).bind(this));
|
2012-06-11 18:41:46 +00:00
|
|
|
|
2012-09-27 19:34:41 +00:00
|
|
|
if (!aData.isPackage) {
|
2012-10-17 04:30:43 +00:00
|
|
|
this.notifyAppsRegistryStart();
|
|
|
|
#ifdef MOZ_SYS_MSG
|
2012-09-27 19:34:41 +00:00
|
|
|
this._registerSystemMessages(app.manifest, app);
|
2012-11-03 03:28:32 +00:00
|
|
|
this._registerActivities(app.manifest, app, true);
|
2012-10-17 04:30:43 +00:00
|
|
|
#else
|
|
|
|
// Nothing else to do but notifying we're ready.
|
|
|
|
this.notifyAppsRegistryReady();
|
2012-07-03 00:16:55 +00:00
|
|
|
#endif
|
2012-10-17 04:30:43 +00:00
|
|
|
}
|
2012-07-03 00:16:55 +00:00
|
|
|
|
2012-10-04 18:18:39 +00:00
|
|
|
this.startOfflineCacheDownload(manifest, appObject, aProfileDir, aOfflineCacheObserver);
|
2012-09-27 19:34:41 +00:00
|
|
|
if (manifest.package_path) {
|
2012-09-29 17:57:18 +00:00
|
|
|
// origin for install apps is meaningless here, since it's app:// and this
|
|
|
|
// can't be used to resolve package paths.
|
2012-10-03 05:38:03 +00:00
|
|
|
manifest = new ManifestHelper(jsonManifest, app.manifestURL);
|
2012-09-29 17:57:18 +00:00
|
|
|
this.downloadPackage(manifest, appObject, false, function(aId, aManifest) {
|
|
|
|
// Success! Move the zip out of TmpD.
|
|
|
|
let app = DOMApplicationRegistry.webapps[id];
|
|
|
|
let zipFile = FileUtils.getFile("TmpD", ["webapps", aId, "application.zip"], true);
|
|
|
|
let dir = FileUtils.getDir(DIRECTORY_NAME, ["webapps", aId], true, true);
|
|
|
|
zipFile.moveTo(dir, "application.zip");
|
|
|
|
let tmpDir = FileUtils.getDir("TmpD", ["webapps", aId], true, true);
|
|
|
|
try {
|
|
|
|
tmpDir.remove(true);
|
|
|
|
} catch(e) { }
|
|
|
|
|
|
|
|
// Save the manifest
|
|
|
|
let manFile = dir.clone();
|
|
|
|
manFile.append("manifest.webapp");
|
|
|
|
DOMApplicationRegistry._writeFile(manFile,
|
|
|
|
JSON.stringify(aManifest),
|
|
|
|
function() { });
|
|
|
|
// Set state and fire events.
|
|
|
|
app.installState = "installed";
|
|
|
|
app.downloading = false;
|
2012-10-30 00:17:47 +00:00
|
|
|
app.downloadAvailable = false;
|
2012-09-29 17:57:18 +00:00
|
|
|
DOMApplicationRegistry._saveApps(function() {
|
2012-10-10 21:29:07 +00:00
|
|
|
// Update the permissions for this app.
|
|
|
|
PermissionsInstaller.installPermissions({ manifest: aManifest,
|
|
|
|
origin: appObject.origin,
|
|
|
|
manifestURL: appObject.manifestURL },
|
|
|
|
true);
|
2012-10-30 00:17:47 +00:00
|
|
|
debug("About to fire Webapps:PackageEvent 'installed'");
|
2012-09-29 17:57:18 +00:00
|
|
|
DOMApplicationRegistry.broadcastMessage("Webapps:PackageEvent",
|
|
|
|
{ type: "installed",
|
|
|
|
manifestURL: appObject.manifestURL,
|
|
|
|
app: app,
|
|
|
|
manifest: aManifest });
|
|
|
|
});
|
|
|
|
});
|
2012-09-27 19:34:41 +00:00
|
|
|
}
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
2012-07-09 10:25:41 +00:00
|
|
|
_nextLocalId: function() {
|
2012-09-06 01:07:21 +00:00
|
|
|
let id = Services.prefs.getIntPref("dom.mozApps.maxLocalId") + 1;
|
|
|
|
Services.prefs.setIntPref("dom.mozApps.maxLocalId", id);
|
|
|
|
return id;
|
2012-07-09 10:25:41 +00:00
|
|
|
},
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
_appId: function(aURI) {
|
|
|
|
for (let id in this.webapps) {
|
|
|
|
if (this.webapps[id].origin == aURI)
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2012-09-27 19:34:41 +00:00
|
|
|
_appIdForManifestURL: function(aURI) {
|
|
|
|
for (let id in this.webapps) {
|
|
|
|
if (this.webapps[id].manifestURL == aURI)
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2012-04-28 07:10:08 +00:00
|
|
|
makeAppId: function() {
|
|
|
|
let uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
|
|
|
|
return uuidGenerator.generateUUID().toString();
|
|
|
|
},
|
|
|
|
|
2011-12-08 13:32:54 +00:00
|
|
|
_saveApps: function(aCallback) {
|
2012-09-27 01:01:20 +00:00
|
|
|
this._writeFile(this.appsFile, JSON.stringify(this.webapps, null, 2), function() {
|
2011-12-08 13:32:54 +00:00
|
|
|
if (aCallback)
|
|
|
|
aCallback();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
/**
|
|
|
|
* Asynchronously reads a list of manifests
|
|
|
|
*/
|
2012-11-03 03:28:32 +00:00
|
|
|
|
|
|
|
_manifestCache: {},
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
_readManifests: function(aData, aFinalCallback, aIndex) {
|
2011-12-15 17:20:57 +00:00
|
|
|
if (!aData.length) {
|
|
|
|
aFinalCallback(aData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
let index = aIndex || 0;
|
|
|
|
let id = aData[index].id;
|
2012-05-22 21:38:34 +00:00
|
|
|
|
2012-11-03 03:28:32 +00:00
|
|
|
// Use the cached manifest instead of reading the file again from disk.
|
|
|
|
if (id in this._manifestCache) {
|
|
|
|
aData[index].manifest = this._manifestCache[id];
|
|
|
|
if (index == aData.length - 1)
|
|
|
|
aFinalCallback(aData);
|
|
|
|
else
|
|
|
|
this._readManifests(aData, aFinalCallback, index + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-22 21:38:34 +00:00
|
|
|
// the manifest file used to be named manifest.json, so fallback on this.
|
2012-08-29 21:20:03 +00:00
|
|
|
let baseDir = (this.webapps[id].removable ? DIRECTORY_NAME : "coreAppsDir");
|
|
|
|
let file = FileUtils.getFile(baseDir, ["webapps", id, "manifest.webapp"], true);
|
2012-09-27 19:34:41 +00:00
|
|
|
if (!file.exists()) {
|
|
|
|
file = FileUtils.getFile(baseDir, ["webapps", id, "update.webapp"], true);
|
|
|
|
}
|
2012-05-22 21:38:34 +00:00
|
|
|
if (!file.exists()) {
|
2012-08-29 21:20:03 +00:00
|
|
|
file = FileUtils.getFile(baseDir, ["webapps", id, "manifest.json"], true);
|
2012-05-22 21:38:34 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
this._loadJSONAsync(file, (function(aJSON) {
|
2012-11-03 03:28:32 +00:00
|
|
|
aData[index].manifest = this._manifestCache[id] = aJSON;
|
2011-12-05 23:26:18 +00:00
|
|
|
if (index == aData.length - 1)
|
|
|
|
aFinalCallback(aData);
|
|
|
|
else
|
|
|
|
this._readManifests(aData, aFinalCallback, index + 1);
|
2012-04-28 07:10:08 +00:00
|
|
|
}).bind(this));
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
2012-09-29 17:57:18 +00:00
|
|
|
downloadPackage: function(aManifest, aApp, aIsUpdate, aOnSuccess) {
|
2012-07-11 15:38:33 +00:00
|
|
|
// Here are the steps when installing a package:
|
|
|
|
// - create a temp directory where to store the app.
|
|
|
|
// - download the zip in this directory.
|
|
|
|
// - extract the manifest from the zip and check it.
|
|
|
|
// - ask confirmation to the user.
|
|
|
|
// - add the new app to the registry.
|
|
|
|
// If we fail at any step, we backout the previous ones and return an error.
|
|
|
|
|
2012-09-27 19:34:41 +00:00
|
|
|
debug(JSON.stringify(aApp));
|
2012-07-11 15:38:33 +00:00
|
|
|
|
2012-09-27 19:34:41 +00:00
|
|
|
let id = this._appIdForManifestURL(aApp.manifestURL);
|
|
|
|
let app = this.webapps[id];
|
2012-07-11 15:38:33 +00:00
|
|
|
|
2012-11-15 09:35:37 +00:00
|
|
|
let self = this;
|
2012-07-11 15:38:33 +00:00
|
|
|
// Removes the directory we created, and sends an error to the DOM side.
|
|
|
|
function cleanup(aError) {
|
2012-09-27 19:34:41 +00:00
|
|
|
debug("Cleanup: " + aError);
|
|
|
|
let dir = FileUtils.getDir("TmpD", ["webapps", id], true, true);
|
2012-07-11 15:38:33 +00:00
|
|
|
try {
|
|
|
|
dir.remove(true);
|
|
|
|
} catch (e) { }
|
2012-11-15 09:35:37 +00:00
|
|
|
self.broadcastMessage("Webapps:PackageEvent",
|
2012-09-27 19:34:41 +00:00
|
|
|
{ type: "error",
|
|
|
|
manifestURL: aApp.manifestURL,
|
2012-11-15 09:35:37 +00:00
|
|
|
error: aError });
|
2012-07-11 15:38:33 +00:00
|
|
|
}
|
|
|
|
|
2012-08-28 02:43:57 +00:00
|
|
|
function getInferedStatus() {
|
|
|
|
// XXX Update once we have digital signatures (bug 772365)
|
|
|
|
return Ci.nsIPrincipal.APP_STATUS_INSTALLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAppStatus(aManifest) {
|
2012-10-03 05:38:06 +00:00
|
|
|
let manifestStatus = AppsUtils.getAppManifestStatus(aManifest);
|
2012-08-28 02:43:57 +00:00
|
|
|
let inferedStatus = getInferedStatus();
|
|
|
|
|
|
|
|
return (Services.prefs.getBoolPref("dom.mozApps.dev_mode") ? manifestStatus
|
|
|
|
: inferedStatus);
|
|
|
|
}
|
|
|
|
// Returns true if the privilege level from the manifest
|
|
|
|
// is lower or equal to the one we infered for the app.
|
|
|
|
function checkAppStatus(aManifest) {
|
|
|
|
if (Services.prefs.getBoolPref("dom.mozApps.dev_mode")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-03 05:38:06 +00:00
|
|
|
return (AppsUtils.getAppManifestStatus(aManifest) <= getInferedStatus());
|
2012-08-28 02:43:57 +00:00
|
|
|
}
|
|
|
|
|
2012-11-15 09:35:37 +00:00
|
|
|
function download() {
|
|
|
|
debug("About to download " + aManifest.fullPackagePath());
|
|
|
|
|
|
|
|
let requestChannel = NetUtil.newChannel(aManifest.fullPackagePath())
|
|
|
|
.QueryInterface(Ci.nsIHttpChannel);
|
|
|
|
self.downloads[aApp.manifestURL] =
|
|
|
|
{ channel:requestChannel,
|
|
|
|
appId: id,
|
|
|
|
previousState: aIsUpdate ? "installed" : "pending"
|
|
|
|
};
|
|
|
|
requestChannel.notificationCallbacks = {
|
|
|
|
QueryInterface: function notifQI(aIID) {
|
|
|
|
if (aIID.equals(Ci.nsISupports) ||
|
|
|
|
aIID.equals(Ci.nsIProgressEventSink))
|
|
|
|
return this;
|
|
|
|
|
|
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
getInterface: function notifGI(aIID) {
|
|
|
|
return this.QueryInterface(aIID);
|
|
|
|
},
|
|
|
|
onProgress: function notifProgress(aRequest, aContext,
|
|
|
|
aProgress, aProgressMax) {
|
|
|
|
debug("onProgress: " + aProgress + "/" + aProgressMax);
|
|
|
|
app.progress = aProgress;
|
|
|
|
self.broadcastMessage("Webapps:PackageEvent",
|
|
|
|
{ type: "progress",
|
|
|
|
manifestURL: aApp.manifestURL,
|
|
|
|
progress: aProgress });
|
|
|
|
},
|
|
|
|
onStatus: function notifStatus(aRequest, aContext, aStatus, aStatusArg) { }
|
2012-07-11 15:38:33 +00:00
|
|
|
}
|
2012-11-15 09:35:37 +00:00
|
|
|
NetUtil.asyncFetch(requestChannel,
|
|
|
|
function(aInput, aResult, aRequest) {
|
2012-07-11 15:38:33 +00:00
|
|
|
if (!Components.isSuccessCode(aResult)) {
|
2012-11-15 09:35:37 +00:00
|
|
|
// We failed to fetch the zip.
|
|
|
|
cleanup("NETWORK_ERROR");
|
2012-07-11 15:38:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-15 09:35:37 +00:00
|
|
|
// Copy the zip on disk.
|
|
|
|
let zipFile = FileUtils.getFile("TmpD",
|
|
|
|
["webapps", id, "application.zip"], true);
|
|
|
|
let ostream = FileUtils.openSafeFileOutputStream(zipFile);
|
|
|
|
NetUtil.asyncCopy(aInput, ostream, function (aResult) {
|
|
|
|
if (!Components.isSuccessCode(aResult)) {
|
|
|
|
// We failed to save the zip.
|
|
|
|
cleanup("DOWNLOAD_ERROR");
|
|
|
|
return;
|
2012-07-11 15:38:33 +00:00
|
|
|
}
|
|
|
|
|
2012-11-15 09:35:37 +00:00
|
|
|
let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
|
|
|
|
.createInstance(Ci.nsIZipReader);
|
|
|
|
try {
|
|
|
|
zipReader.open(zipFile);
|
|
|
|
if (!zipReader.hasEntry("manifest.webapp")) {
|
2012-11-16 17:36:27 +00:00
|
|
|
throw "MISSING_MANIFEST";
|
2012-11-15 09:35:37 +00:00
|
|
|
}
|
2012-09-27 19:34:41 +00:00
|
|
|
|
2012-11-15 09:35:37 +00:00
|
|
|
let istream = zipReader.getInputStream("manifest.webapp");
|
2012-09-27 19:34:41 +00:00
|
|
|
|
2012-11-15 09:35:37 +00:00
|
|
|
// Obtain a converter to read from a UTF-8 encoded input stream.
|
|
|
|
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
|
|
|
|
.createInstance(Ci.nsIScriptableUnicodeConverter);
|
|
|
|
converter.charset = "UTF-8";
|
2012-09-27 19:34:41 +00:00
|
|
|
|
2012-11-15 09:35:37 +00:00
|
|
|
let manifest = JSON.parse(converter.ConvertToUnicode(NetUtil.readInputStreamToString(istream,
|
|
|
|
istream.available()) || ""));
|
2012-08-28 02:43:57 +00:00
|
|
|
|
2012-11-15 09:35:37 +00:00
|
|
|
if (!AppsUtils.checkManifest(manifest, aApp.installOrigin)) {
|
|
|
|
throw "INVALID_MANIFEST";
|
|
|
|
}
|
2012-07-11 15:38:33 +00:00
|
|
|
|
2012-11-15 09:35:37 +00:00
|
|
|
if (!checkAppStatus(manifest)) {
|
|
|
|
throw "INVALID_SECURITY_LEVEL";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aOnSuccess) {
|
|
|
|
aOnSuccess(id, manifest);
|
|
|
|
}
|
|
|
|
delete self.downloads[aApp.manifestURL];
|
|
|
|
} catch (e) {
|
2012-11-16 17:36:27 +00:00
|
|
|
// Something bad happened when reading the package.
|
|
|
|
if (typeof e == 'object') {
|
|
|
|
cleanup("INVALID_PACKAGE");
|
|
|
|
} else {
|
|
|
|
cleanup(e);
|
|
|
|
}
|
2012-11-15 09:35:37 +00:00
|
|
|
} finally {
|
|
|
|
zipReader.close();
|
2012-09-29 17:57:18 +00:00
|
|
|
}
|
2012-11-15 09:35:37 +00:00
|
|
|
});
|
2012-07-11 15:38:33 +00:00
|
|
|
});
|
2012-11-15 09:35:37 +00:00
|
|
|
};
|
|
|
|
|
2012-11-16 20:16:46 +00:00
|
|
|
let deviceStorage = Services.wm.getMostRecentWindow("navigator:browser")
|
|
|
|
.navigator.getDeviceStorage("apps");
|
2012-11-15 09:35:37 +00:00
|
|
|
let req = deviceStorage.stat();
|
|
|
|
req.onsuccess = req.onerror = function statResult(e) {
|
|
|
|
// Even if we could not retrieve the device storage free space, we try
|
|
|
|
// to download the package.
|
|
|
|
if (!e.target.result) {
|
|
|
|
download();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let freeBytes = e.target.result.freeBytes;
|
|
|
|
if (freeBytes) {
|
|
|
|
debug("Free storage: " + freeBytes + ". Download size: " +
|
|
|
|
aApp.downloadSize);
|
|
|
|
if (freeBytes <= aApp.downloadSize) {
|
|
|
|
cleanup("INSUFFICIENT_STORAGE");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
download();
|
|
|
|
}
|
2012-07-11 15:38:33 +00:00
|
|
|
},
|
|
|
|
|
2012-09-28 16:24:45 +00:00
|
|
|
uninstall: function(aData, aMm) {
|
2011-11-28 20:13:26 +00:00
|
|
|
for (let id in this.webapps) {
|
|
|
|
let app = this.webapps[id];
|
2012-07-20 15:41:30 +00:00
|
|
|
if (app.origin != aData.origin) {
|
|
|
|
continue;
|
|
|
|
}
|
2012-04-28 07:10:08 +00:00
|
|
|
|
2012-08-29 21:20:03 +00:00
|
|
|
if (!this.webapps[id].removable)
|
|
|
|
return;
|
|
|
|
|
2012-11-03 03:28:32 +00:00
|
|
|
// Clean up the deprecated manifest cache if needed.
|
|
|
|
if (id in this._manifestCache) {
|
|
|
|
delete this._manifestCache[id];
|
|
|
|
}
|
|
|
|
|
2012-09-28 16:24:45 +00:00
|
|
|
// Clear private data first.
|
|
|
|
this._clearPrivateData(app.localId, false);
|
|
|
|
|
|
|
|
// Then notify observers.
|
|
|
|
Services.obs.notifyObservers(aMm, "webapps-uninstall", JSON.stringify(aData));
|
|
|
|
|
2012-08-28 02:43:57 +00:00
|
|
|
let appNote = JSON.stringify(AppsUtils.cloneAppObject(app));
|
2012-07-20 15:41:30 +00:00
|
|
|
appNote.id = id;
|
2012-04-28 07:10:08 +00:00
|
|
|
|
2012-07-20 15:41:30 +00:00
|
|
|
#ifdef MOZ_SYS_MSG
|
2012-09-27 01:01:20 +00:00
|
|
|
this._readManifests([{ id: id }], (function unregisterManifest(aResult) {
|
2012-07-20 15:41:30 +00:00
|
|
|
this._unregisterActivities(aResult[0].manifest, app);
|
|
|
|
}).bind(this));
|
2012-09-27 01:01:20 +00:00
|
|
|
#endif
|
2012-07-20 15:41:30 +00:00
|
|
|
|
2012-08-29 21:20:03 +00:00
|
|
|
let dir = this._getAppDir(id);
|
2012-07-20 15:41:30 +00:00
|
|
|
try {
|
|
|
|
dir.remove(true);
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
delete this.webapps[id];
|
|
|
|
|
|
|
|
this._saveApps((function() {
|
2012-09-18 17:34:55 +00:00
|
|
|
this.broadcastMessage("Webapps:Uninstall:Return:OK", aData);
|
2012-07-20 15:41:30 +00:00
|
|
|
Services.obs.notifyObservers(this, "webapps-sync-uninstall", appNote);
|
2012-09-18 17:34:55 +00:00
|
|
|
this.broadcastMessage("Webapps:RemoveApp", { id: id });
|
2012-07-20 15:41:30 +00:00
|
|
|
}).bind(this));
|
|
|
|
|
2012-09-28 16:24:45 +00:00
|
|
|
return;
|
2012-07-20 15:41:30 +00:00
|
|
|
}
|
2012-09-28 16:24:45 +00:00
|
|
|
|
|
|
|
aMm.sendAsyncMessage("Webapps:Uninstall:Return:KO", aData);
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
2012-09-18 17:34:55 +00:00
|
|
|
getSelf: function(aData, aMm) {
|
2011-11-28 20:13:26 +00:00
|
|
|
aData.apps = [];
|
2012-09-25 15:04:24 +00:00
|
|
|
|
|
|
|
if (aData.appId == Ci.nsIScriptSecurityManager.NO_APP_ID ||
|
|
|
|
aData.appId == Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID) {
|
|
|
|
aMm.sendAsyncMessage("Webapps:GetSelf:Return:OK", aData);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
let tmp = [];
|
2012-03-06 19:50:58 +00:00
|
|
|
|
2012-09-25 15:04:24 +00:00
|
|
|
for (let id in this.webapps) {
|
|
|
|
if (this.webapps[id].origin == aData.origin &&
|
|
|
|
this.webapps[id].localId == aData.appId &&
|
|
|
|
this._isLaunchable(this.webapps[id].origin)) {
|
|
|
|
let app = AppsUtils.cloneAppObject(this.webapps[id]);
|
|
|
|
aData.apps.push(app);
|
|
|
|
tmp.push({ id: id });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aData.apps.length) {
|
|
|
|
aMm.sendAsyncMessage("Webapps:GetSelf:Return:OK", aData);
|
|
|
|
return;
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2012-03-06 19:50:58 +00:00
|
|
|
this._readManifests(tmp, (function(aResult) {
|
|
|
|
for (let i = 0; i < aResult.length; i++)
|
|
|
|
aData.apps[i].manifest = aResult[i].manifest;
|
2012-09-18 17:34:55 +00:00
|
|
|
aMm.sendAsyncMessage("Webapps:GetSelf:Return:OK", aData);
|
2012-03-06 19:50:58 +00:00
|
|
|
}).bind(this));
|
|
|
|
},
|
2011-11-28 20:13:26 +00:00
|
|
|
|
2012-10-02 20:38:51 +00:00
|
|
|
checkInstalled: function(aData, aMm) {
|
|
|
|
aData.app = null;
|
|
|
|
let tmp = [];
|
2012-09-25 15:04:24 +00:00
|
|
|
|
|
|
|
for (let appId in this.webapps) {
|
|
|
|
if (this.webapps[appId].manifestURL == aData.manifestURL) {
|
2012-10-02 20:38:51 +00:00
|
|
|
aData.app = AppsUtils.cloneAppObject(this.webapps[appId]);
|
|
|
|
tmp.push({ id: appId });
|
2012-09-25 15:04:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-02 20:38:51 +00:00
|
|
|
this._readManifests(tmp, (function(aResult) {
|
|
|
|
for (let i = 0; i < aResult.length; i++) {
|
|
|
|
aData.app.manifest = aResult[i].manifest;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aMm.sendAsyncMessage("Webapps:CheckInstalled:Return:OK", aData);
|
|
|
|
}).bind(this));
|
2012-09-25 15:04:24 +00:00
|
|
|
},
|
|
|
|
|
2012-09-18 17:34:55 +00:00
|
|
|
getInstalled: function(aData, aMm) {
|
2012-03-06 19:50:58 +00:00
|
|
|
aData.apps = [];
|
|
|
|
let tmp = [];
|
|
|
|
|
2012-06-29 20:46:21 +00:00
|
|
|
for (let id in this.webapps) {
|
|
|
|
if (this.webapps[id].installOrigin == aData.origin &&
|
2012-07-03 03:45:00 +00:00
|
|
|
this._isLaunchable(this.webapps[id].origin)) {
|
2012-08-28 02:43:57 +00:00
|
|
|
aData.apps.push(AppsUtils.cloneAppObject(this.webapps[id]));
|
2012-03-06 19:50:58 +00:00
|
|
|
tmp.push({ id: id });
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
this._readManifests(tmp, (function(aResult) {
|
|
|
|
for (let i = 0; i < aResult.length; i++)
|
|
|
|
aData.apps[i].manifest = aResult[i].manifest;
|
2012-09-18 17:34:55 +00:00
|
|
|
aMm.sendAsyncMessage("Webapps:GetInstalled:Return:OK", aData);
|
2011-12-05 23:26:18 +00:00
|
|
|
}).bind(this));
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
2012-09-18 17:34:55 +00:00
|
|
|
getNotInstalled: function(aData, aMm) {
|
2012-06-29 20:46:21 +00:00
|
|
|
aData.apps = [];
|
|
|
|
let tmp = [];
|
|
|
|
|
|
|
|
for (let id in this.webapps) {
|
2012-08-20 17:19:56 +00:00
|
|
|
if (!this._isLaunchable(this.webapps[id].origin)) {
|
2012-08-28 02:43:57 +00:00
|
|
|
aData.apps.push(AppsUtils.cloneAppObject(this.webapps[id]));
|
2012-06-29 20:46:21 +00:00
|
|
|
tmp.push({ id: id });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._readManifests(tmp, (function(aResult) {
|
|
|
|
for (let i = 0; i < aResult.length; i++)
|
|
|
|
aData.apps[i].manifest = aResult[i].manifest;
|
2012-09-18 17:34:55 +00:00
|
|
|
aMm.sendAsyncMessage("Webapps:GetNotInstalled:Return:OK", aData);
|
2012-06-29 20:46:21 +00:00
|
|
|
}).bind(this));
|
|
|
|
},
|
|
|
|
|
2012-09-18 17:34:55 +00:00
|
|
|
getAll: function(aData, aMm) {
|
2011-11-28 20:13:26 +00:00
|
|
|
aData.apps = [];
|
2011-12-05 23:26:18 +00:00
|
|
|
let tmp = [];
|
2011-11-28 20:13:26 +00:00
|
|
|
|
2012-04-28 07:10:08 +00:00
|
|
|
for (let id in this.webapps) {
|
2012-08-28 02:43:57 +00:00
|
|
|
let app = AppsUtils.cloneAppObject(this.webapps[id]);
|
2012-07-03 03:45:00 +00:00
|
|
|
if (!this._isLaunchable(app.origin))
|
2012-06-29 20:46:21 +00:00
|
|
|
continue;
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
aData.apps.push(app);
|
2011-12-05 23:26:18 +00:00
|
|
|
tmp.push({ id: id });
|
2011-11-28 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
this._readManifests(tmp, (function(aResult) {
|
|
|
|
for (let i = 0; i < aResult.length; i++)
|
|
|
|
aData.apps[i].manifest = aResult[i].manifest;
|
2012-09-18 17:34:55 +00:00
|
|
|
aMm.sendAsyncMessage("Webapps:GetAll:Return:OK", aData);
|
2011-12-05 23:26:18 +00:00
|
|
|
}).bind(this));
|
2011-11-28 20:13:26 +00:00
|
|
|
},
|
|
|
|
|
2011-12-05 23:26:18 +00:00
|
|
|
getManifestFor: function(aOrigin, aCallback) {
|
|
|
|
if (!aCallback)
|
|
|
|
return;
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
let id = this._appId(aOrigin);
|
2012-09-27 19:34:41 +00:00
|
|
|
if (!id || this.webapps[id].installState == "pending") {
|
2011-12-05 23:26:18 +00:00
|
|
|
aCallback(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._readManifests([{ id: id }], function(aResult) {
|
|
|
|
aCallback(aResult[0].manifest);
|
|
|
|
});
|
2011-12-08 13:32:54 +00:00
|
|
|
},
|
|
|
|
|
2012-04-28 07:10:08 +00:00
|
|
|
/** Added to support AITC and classic sync */
|
|
|
|
itemExists: function(aId) {
|
|
|
|
return !!this.webapps[aId];
|
|
|
|
},
|
2011-12-08 13:32:54 +00:00
|
|
|
|
|
|
|
getAppById: function(aId) {
|
|
|
|
if (!this.webapps[aId])
|
|
|
|
return null;
|
2012-07-14 02:52:30 +00:00
|
|
|
|
2012-08-28 02:43:57 +00:00
|
|
|
let app = AppsUtils.cloneAppObject(this.webapps[aId]);
|
2011-12-08 13:32:54 +00:00
|
|
|
return app;
|
|
|
|
},
|
2012-05-16 10:40:47 +00:00
|
|
|
|
|
|
|
getAppByManifestURL: function(aManifestURL) {
|
2012-08-28 02:43:57 +00:00
|
|
|
return AppsUtils.getAppByManifestURL(this.webapps, aManifestURL);
|
2012-05-16 10:40:47 +00:00
|
|
|
},
|
2012-07-09 10:25:41 +00:00
|
|
|
|
2012-10-19 10:43:17 +00:00
|
|
|
getCSPByLocalId: function(aLocalId) {
|
|
|
|
debug("getCSPByLocalId:" + aLocalId);
|
|
|
|
return AppsUtils.getCSPByLocalId(this.webapps, aLocalId);
|
|
|
|
},
|
|
|
|
|
2012-08-08 16:41:47 +00:00
|
|
|
getAppByLocalId: function(aLocalId) {
|
2012-08-28 02:43:57 +00:00
|
|
|
return AppsUtils.getAppByLocalId(this.webapps, aLocalId);
|
2012-08-08 16:41:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getManifestURLByLocalId: function(aLocalId) {
|
2012-08-28 02:43:57 +00:00
|
|
|
return AppsUtils.getManifestURLByLocalId(this.webapps, aLocalId);
|
2012-08-08 16:41:47 +00:00
|
|
|
},
|
|
|
|
|
2012-07-09 10:25:41 +00:00
|
|
|
getAppLocalIdByManifestURL: function(aManifestURL) {
|
2012-08-28 02:43:57 +00:00
|
|
|
return AppsUtils.getAppLocalIdByManifestURL(this.webapps, aManifestURL);
|
2012-07-09 10:25:41 +00:00
|
|
|
},
|
|
|
|
|
2012-08-31 14:34:28 +00:00
|
|
|
getAppFromObserverMessage: function(aMessage) {
|
|
|
|
return AppsUtils.getAppFromObserverMessage(this.webapps, aMessage);
|
|
|
|
},
|
|
|
|
|
2012-04-28 07:10:08 +00:00
|
|
|
getAllWithoutManifests: function(aCallback) {
|
|
|
|
let result = {};
|
|
|
|
for (let id in this.webapps) {
|
2012-08-28 02:43:57 +00:00
|
|
|
let app = AppsUtils.cloneAppObject(this.webapps[id]);
|
2012-04-28 07:10:08 +00:00
|
|
|
result[id] = app;
|
|
|
|
}
|
|
|
|
aCallback(result);
|
2011-12-08 13:32:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updateApps: function(aRecords, aCallback) {
|
|
|
|
for (let i = 0; i < aRecords.length; i++) {
|
|
|
|
let record = aRecords[i];
|
2012-06-23 17:22:53 +00:00
|
|
|
if (record.hidden) {
|
2012-08-29 21:20:03 +00:00
|
|
|
if (!this.webapps[record.id] || !this.webapps[record.id].removable)
|
2011-12-08 13:32:54 +00:00
|
|
|
continue;
|
2012-09-28 22:16:29 +00:00
|
|
|
|
2012-11-03 03:28:32 +00:00
|
|
|
// Clean up the deprecated manifest cache if needed.
|
|
|
|
if (record.id in this._manifestCache) {
|
|
|
|
delete this._manifestCache[record.id];
|
|
|
|
}
|
|
|
|
|
2011-12-08 13:32:54 +00:00
|
|
|
let origin = this.webapps[record.id].origin;
|
|
|
|
delete this.webapps[record.id];
|
2012-08-29 21:20:03 +00:00
|
|
|
let dir = this._getAppDir(record.id);
|
2011-12-08 13:32:54 +00:00
|
|
|
try {
|
|
|
|
dir.remove(true);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
2012-09-18 17:34:55 +00:00
|
|
|
this.broadcastMessage("Webapps:Uninstall:Return:OK", { origin: origin });
|
2011-12-08 13:32:54 +00:00
|
|
|
} else {
|
2012-04-28 07:10:08 +00:00
|
|
|
if (this.webapps[record.id]) {
|
2011-12-08 13:32:54 +00:00
|
|
|
this.webapps[record.id] = record.value;
|
|
|
|
delete this.webapps[record.id].manifest;
|
2012-04-28 07:10:08 +00:00
|
|
|
} else {
|
2011-12-08 13:32:54 +00:00
|
|
|
let data = { app: record.value };
|
|
|
|
this.confirmInstall(data, true);
|
2012-09-18 17:34:55 +00:00
|
|
|
this.broadcastMessage("Webapps:Install:Return:OK", data);
|
2011-12-08 13:32:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._saveApps(aCallback);
|
|
|
|
},
|
|
|
|
|
|
|
|
getAllIDs: function() {
|
|
|
|
let apps = {};
|
|
|
|
for (let id in this.webapps) {
|
|
|
|
// only sync http and https apps
|
|
|
|
if (this.webapps[id].origin.indexOf("http") == 0)
|
|
|
|
apps[id] = true;
|
|
|
|
}
|
|
|
|
return apps;
|
|
|
|
},
|
|
|
|
|
|
|
|
wipe: function(aCallback) {
|
|
|
|
let ids = this.getAllIDs();
|
|
|
|
for (let id in ids) {
|
2012-08-29 21:20:03 +00:00
|
|
|
if (!this.webapps[id].removable) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-12-08 13:32:54 +00:00
|
|
|
delete this.webapps[id];
|
2012-08-29 21:20:03 +00:00
|
|
|
let dir = this._getAppDir(id);
|
2011-12-08 13:32:54 +00:00
|
|
|
try {
|
|
|
|
dir.remove(true);
|
|
|
|
} catch (e) {
|
|
|
|
}
|
|
|
|
}
|
2012-11-03 03:28:32 +00:00
|
|
|
|
|
|
|
// Clear the manifest cache.
|
|
|
|
this._manifestCache = { };
|
|
|
|
|
2011-12-08 13:32:54 +00:00
|
|
|
this._saveApps(aCallback);
|
2012-06-29 20:46:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_isLaunchable: function(aOrigin) {
|
|
|
|
if (this.allAppsLaunchable)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
let uninstallKey = Cc["@mozilla.org/windows-registry-key;1"]
|
|
|
|
.createInstance(Ci.nsIWindowsRegKey);
|
|
|
|
try {
|
|
|
|
uninstallKey.open(uninstallKey.ROOT_KEY_CURRENT_USER,
|
|
|
|
"SOFTWARE\\Microsoft\\Windows\\" +
|
|
|
|
"CurrentVersion\\Uninstall\\" +
|
|
|
|
aOrigin,
|
|
|
|
uninstallKey.ACCESS_READ);
|
|
|
|
uninstallKey.close();
|
|
|
|
return true;
|
|
|
|
} catch (ex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#elifdef XP_MACOSX
|
|
|
|
let mwaUtils = Cc["@mozilla.org/widget/mac-web-app-utils;1"]
|
|
|
|
.createInstance(Ci.nsIMacWebAppUtils);
|
|
|
|
|
|
|
|
return !!mwaUtils.pathForAppWithIdentifier(aOrigin);
|
|
|
|
#elifdef XP_UNIX
|
|
|
|
let env = Cc["@mozilla.org/process/environment;1"]
|
|
|
|
.getService(Ci.nsIEnvironment);
|
|
|
|
let xdg_data_home_env = env.get("XDG_DATA_HOME");
|
|
|
|
|
|
|
|
let desktopINI;
|
|
|
|
if (xdg_data_home_env != "") {
|
|
|
|
desktopINI = Cc["@mozilla.org/file/local;1"]
|
|
|
|
.createInstance(Ci.nsIFile);
|
|
|
|
desktopINI.initWithPath(xdg_data_home_env);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
desktopINI = Services.dirsvc.get("Home", Ci.nsIFile);
|
|
|
|
desktopINI.append(".local");
|
|
|
|
desktopINI.append("share");
|
|
|
|
}
|
|
|
|
desktopINI.append("applications");
|
|
|
|
|
|
|
|
let origin = Services.io.newURI(aOrigin, null, null);
|
|
|
|
let uniqueName = origin.scheme + ";" +
|
|
|
|
origin.host +
|
|
|
|
(origin.port != -1 ? ";" + origin.port : "");
|
|
|
|
|
|
|
|
desktopINI.append("owa-" + uniqueName + ".desktop");
|
|
|
|
|
|
|
|
return desktopINI.exists();
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
2012-09-26 22:03:25 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_notifyCategoryAndObservers: function(subject, topic, data) {
|
|
|
|
const serviceMarker = "service,";
|
|
|
|
|
|
|
|
// First create observers from the category manager.
|
|
|
|
let cm =
|
|
|
|
Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
|
|
|
|
let enumerator = cm.enumerateCategory(topic);
|
|
|
|
|
|
|
|
let observers = [];
|
|
|
|
|
|
|
|
while (enumerator.hasMoreElements()) {
|
|
|
|
let entry =
|
|
|
|
enumerator.getNext().QueryInterface(Ci.nsISupportsCString).data;
|
|
|
|
let contractID = cm.getCategoryEntry(topic, entry);
|
|
|
|
|
|
|
|
let factoryFunction;
|
|
|
|
if (contractID.substring(0, serviceMarker.length) == serviceMarker) {
|
|
|
|
contractID = contractID.substring(serviceMarker.length);
|
|
|
|
factoryFunction = "getService";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
factoryFunction = "createInstance";
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
let handler = Cc[contractID][factoryFunction]();
|
|
|
|
if (handler) {
|
|
|
|
let observer = handler.QueryInterface(Ci.nsIObserver);
|
|
|
|
observers.push(observer);
|
|
|
|
}
|
|
|
|
} catch(e) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next enumerate the registered observers.
|
|
|
|
enumerator = Services.obs.enumerateObservers(topic);
|
|
|
|
while (enumerator.hasMoreElements()) {
|
2012-09-28 16:24:45 +00:00
|
|
|
try {
|
|
|
|
let observer = enumerator.getNext().QueryInterface(Ci.nsIObserver);
|
|
|
|
if (observers.indexOf(observer) == -1) {
|
|
|
|
observers.push(observer);
|
|
|
|
}
|
|
|
|
} catch (e) { }
|
2012-09-26 22:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
observers.forEach(function (observer) {
|
|
|
|
try {
|
|
|
|
observer.observe(subject, topic, data);
|
|
|
|
} catch(e) { }
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
registerBrowserElementParentForApp: function(bep, appId) {
|
|
|
|
let mm = bep._mm;
|
|
|
|
|
|
|
|
// Make a listener function that holds on to this appId.
|
|
|
|
let listener = this.receiveAppMessage.bind(this, appId);
|
|
|
|
|
|
|
|
this.frameMessages.forEach(function(msgName) {
|
|
|
|
mm.addMessageListener(msgName, listener);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
receiveAppMessage: function(appId, message) {
|
|
|
|
switch (message.name) {
|
|
|
|
case "Webapps:ClearBrowserData":
|
2012-09-28 16:24:45 +00:00
|
|
|
this._clearPrivateData(appId, true);
|
2012-09-26 22:03:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-09-28 16:24:45 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_clearPrivateData: function(appId, browserOnly) {
|
|
|
|
let subject = {
|
|
|
|
appId: appId,
|
|
|
|
browserOnly: browserOnly,
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.mozIApplicationClearPrivateDataParams])
|
|
|
|
};
|
|
|
|
this._notifyCategoryAndObservers(subject, "webapps-clear-data", null);
|
2012-04-28 07:10:08 +00:00
|
|
|
}
|
2011-11-28 20:13:26 +00:00
|
|
|
};
|
|
|
|
|
2012-06-11 18:41:46 +00:00
|
|
|
/**
|
|
|
|
* Appcache download observer
|
|
|
|
*/
|
2012-07-03 00:16:55 +00:00
|
|
|
let AppcacheObserver = function(aApp) {
|
2012-06-11 18:41:46 +00:00
|
|
|
this.app = aApp;
|
2012-09-27 01:01:20 +00:00
|
|
|
this.startStatus = aApp.installState;
|
2012-06-11 18:41:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AppcacheObserver.prototype = {
|
|
|
|
// nsIOfflineCacheUpdateObserver implementation
|
|
|
|
updateStateChanged: function appObs_Update(aUpdate, aState) {
|
|
|
|
let mustSave = false;
|
|
|
|
let app = this.app;
|
|
|
|
|
|
|
|
let setStatus = function appObs_setStatus(aStatus) {
|
2012-09-27 01:01:20 +00:00
|
|
|
mustSave = (app.installState != aStatus);
|
|
|
|
app.installState = aStatus;
|
2012-10-04 18:18:39 +00:00
|
|
|
app.downloading = false;
|
2012-09-27 01:01:20 +00:00
|
|
|
DOMApplicationRegistry.broadcastMessage("Webapps:OfflineCache",
|
|
|
|
{ manifest: app.manifestURL,
|
|
|
|
installState: app.installState });
|
|
|
|
}
|
|
|
|
|
|
|
|
let setError = function appObs_setError(aError) {
|
2012-09-18 17:34:55 +00:00
|
|
|
DOMApplicationRegistry.broadcastMessage("Webapps:OfflineCache",
|
|
|
|
{ manifest: app.manifestURL,
|
2012-09-27 01:01:20 +00:00
|
|
|
error: aError });
|
2012-10-04 18:18:39 +00:00
|
|
|
app.downloading = false;
|
|
|
|
mustSave = true;
|
2012-06-11 18:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (aState) {
|
|
|
|
case Ci.nsIOfflineCacheUpdateObserver.STATE_ERROR:
|
|
|
|
aUpdate.removeObserver(this);
|
2012-09-27 01:01:20 +00:00
|
|
|
setError("APP_CACHE_DOWNLOAD_ERROR");
|
2012-06-11 18:41:46 +00:00
|
|
|
break;
|
|
|
|
case Ci.nsIOfflineCacheUpdateObserver.STATE_NOUPDATE:
|
|
|
|
case Ci.nsIOfflineCacheUpdateObserver.STATE_FINISHED:
|
|
|
|
aUpdate.removeObserver(this);
|
2012-09-27 01:01:20 +00:00
|
|
|
setStatus("installed");
|
2012-06-11 18:41:46 +00:00
|
|
|
break;
|
|
|
|
case Ci.nsIOfflineCacheUpdateObserver.STATE_DOWNLOADING:
|
|
|
|
case Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMSTARTED:
|
|
|
|
case Ci.nsIOfflineCacheUpdateObserver.STATE_ITEMPROGRESS:
|
2012-09-27 01:01:20 +00:00
|
|
|
setStatus(this.startStatus);
|
2012-06-11 18:41:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Status changed, update the stored version.
|
|
|
|
if (mustSave) {
|
|
|
|
DOMApplicationRegistry._saveApps();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
applicationCacheAvailable: function appObs_CacheAvail(aApplicationCache) {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-11-28 20:13:26 +00:00
|
|
|
DOMApplicationRegistry.init();
|