Bug 849988 - Implement support for a removable property for preinstalled apps to define if the app can be uninstalled or not. r=ferjm

This commit is contained in:
Fabrice Desré 2013-03-15 07:18:58 -07:00
Родитель 39d7e6b890
Коммит 0d2eaabdc2
4 изменённых файлов: 37 добавлений и 17 удалений

Просмотреть файл

@ -103,6 +103,7 @@ this.DOMApplicationRegistry = {
debug("getAppFromObserverMessage " + aMessage);
return AppsUtils.getAppFromObserverMessage(this.webapps. aMessage);
},
getCoreAppsBasePath: function getCoreAppsBasePath() {
debug("getCoreAppsBasePath() not yet supported on child!");
return null;
@ -114,13 +115,8 @@ this.DOMApplicationRegistry = {
},
getAppInfo: function getAppInfo(aAppId) {
if (!this.webapps[aAppId]) {
debug("No webapp for " + aAppId);
return null;
}
return { "basePath": this.webapps[aAppId].basePath + "/",
"isCoreApp": !this.webapps[aAppId].removable };
},
return AppsUtils.getAppInfo(this.webapps, aAppId);
}
}
DOMApplicationRegistry.init();

Просмотреть файл

@ -11,6 +11,7 @@ const Cr = Components.results;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
XPCOMUtils.defineLazyGetter(this, "NetUtil", function() {
return Cc["@mozilla.org/network/util;1"]
@ -176,6 +177,34 @@ this.AppsUtils = {
return null;
},
getCoreAppsBasePath: function getCoreAppsBasePath() {
debug("getCoreAppsBasePath()");
try {
return FileUtils.getDir("coreAppsDir", ["webapps"], false).path;
} catch(e) {
return null;
}
},
getAppInfo: function getAppInfo(aApps, aAppId) {
if (!aApps[aAppId]) {
debug("No webapp for " + aAppId);
return null;
}
// We can have 3rd party apps that are non-removable,
// so we can't use the 'removable' property for isCoreApp
// Instead, we check if the app is installed under /system/b2g
let isCoreApp = false;
let app = aApps[aAppId];
#ifdef MOZ_WIDGET_GONK
isCoreApp = app.basePath == this.getCoreAppsBasePath();
#endif
debug(app.name + " isCoreApp: " + isCoreApp);
return { "basePath": app.basePath + "/",
"isCoreApp": isCoreApp };
},
/**
* From https://developer.mozilla.org/en/OpenWebApps/The_Manifest
* Only the name property is mandatory.

Просмотреть файл

@ -21,11 +21,11 @@ EXTRA_PP_COMPONENTS = \
EXTRA_PP_JS_MODULES += \
Webapps.jsm \
AppsUtils.jsm \
$(NULL)
EXTRA_JS_MODULES += \
AppsServiceChild.jsm \
AppsUtils.jsm \
OfflineCacheInstaller.jsm \
PermissionsInstaller.jsm \
PermissionsTable.jsm \

Просмотреть файл

@ -283,7 +283,6 @@ this.DOMApplicationRegistry = {
}
app.origin = "app://" + aId;
app.removable = true;
// Extract the manifest.webapp file from application.zip.
let zipFile = baseDir.clone();
@ -861,12 +860,7 @@ this.DOMApplicationRegistry = {
},
getAppInfo: function getAppInfo(aAppId) {
if (!this.webapps[aAppId]) {
debug("No webapp for " + aAppId);
return null;
}
return { "basePath": this.webapps[aAppId].basePath + "/",
"isCoreApp": !this.webapps[aAppId].removable };
return AppsUtils.getAppInfo(this.webapps, aAppId);
},
// Some messages can be listened by several content processes:
@ -2027,7 +2021,8 @@ this.DOMApplicationRegistry = {
}
// the manifest file used to be named manifest.json, so fallback on this.
let baseDir = (this.webapps[id].removable ? DIRECTORY_NAME : "coreAppsDir");
let baseDir = this.webapps[id].basePath == this.getCoreAppsBasePath()
? "coreAppsDir" : DIRECTORY_NAME;
let file = FileUtils.getFile(baseDir, ["webapps", id, "manifest.webapp"], true);
if (!file.exists()) {
file = FileUtils.getFile(baseDir, ["webapps", id, "update.webapp"], true);
@ -2661,7 +2656,7 @@ this.DOMApplicationRegistry = {
},
getCoreAppsBasePath: function() {
return FileUtils.getDir("coreAppsDir", ["webapps"], false).path;
return AppsUtils.getCoreAppsBasePath();
},
getWebAppsBasePath: function getWebAppsBasePath() {