Bug 919496 - [app manager] Once an app has been installed, it doesn't show up in the 'installed app' tab. r=ochameau

This commit is contained in:
Paul Rouget 2013-10-05 10:43:06 -04:00
parent a3272dcdc0
commit e22ceb0302
4 changed files with 109 additions and 5 deletions

View File

@ -8,9 +8,6 @@ const {Connection} = require("devtools/client/connection-manager");
const {Cu} = require("chrome");
const dbgClient = Cu.import("resource://gre/modules/devtools/dbg-client.jsm");
dbgClient.UnsolicitedNotifications.appOpen = "appOpen";
dbgClient.UnsolicitedNotifications.appClose = "appClose"
const _knownWebappsStores = new WeakMap();
let WebappsStore;
@ -103,6 +100,14 @@ WebappsStore.prototype = {
this._onAppClose(manifestURL);
});
client.addListener("appInstall", (type, { manifestURL }) => {
this._onAppInstall(manifestURL);
});
client.addListener("appUninstall", (type, { manifestURL }) => {
this._onAppUninstall(manifestURL);
});
return deferred.resolve();
})
return deferred.promise;
@ -177,6 +182,10 @@ WebappsStore.prototype = {
let a = allApps[idx++];
request.manifestURL = a.manifestURL;
return client.request(request, (res) => {
if (res.error) {
Cu.reportError(res.message || res.error);
}
if (res.url) {
a.iconURL = res.url;
}
@ -204,4 +213,57 @@ WebappsStore.prototype = {
return m != manifest;
});
},
_onAppInstall: function(manifest) {
let client = this._connection.client;
let request = {
to: this._webAppsActor,
type: "getApp",
manifestURL: manifest
};
client.request(request, (res) => {
if (res.error) {
if (res.error == "forbidden") {
// We got a notification for an app we don't have access to.
// Ignore.
return;
}
Cu.reportError(res.message || res.error);
return;
}
let app = res.app;
app.running = false;
let notFound = true;
let proxifiedApp;
for (let i = 0; i < this.object.all.length; i++) {
let storedApp = this.object.all[i];
if (storedApp.manifestURL == app.manifestURL) {
this.object.all[i] = app;
proxifiedApp = this.object.all[i];
notFound = false;
break;
}
}
if (notFound) {
this.object.all.push(app);
proxifiedApp = this.object.all[this.object.all.length - 1];
}
request.type = "getIconAsDataURL";
client.request(request, (res) => {
if (res.url) {
proxifiedApp.iconURL = res.url;
}
});
});
},
_onAppUninstall: function(manifest) {
this.object.all = this.object.all.filter((app) => {
return (app.manifestURL != manifest);
});
},
}

View File

@ -98,7 +98,6 @@ function do_get_webappsdir() {
coreAppsDir.append("test_coreapps");
if (!coreAppsDir.exists())
coreAppsDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("755", 8));
var tmpDir = Services.dirsvc.get("TmpD", Ci.nsILocalFile);
// Register our own provider for the profile directory.
// It will return our special docshell profile directory.
@ -111,7 +110,6 @@ function do_get_webappsdir() {
else if (prop == "coreAppsDir") {
return coreAppsDir.clone();
}
return tmpDir.clone();
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: function(iid) {

View File

@ -57,6 +57,23 @@ add_test(function testGetAll() {
});
});
add_test(function testGetApp() {
let manifestURL = APP_ORIGIN + "/manifest.webapp";
let request = {type: "getApp", manifestURL: manifestURL};
webappActorRequest(request, function (aResponse) {
do_check_true("app" in aResponse);
let app = aResponse.app;
do_check_eq(app.id, gAppId);
do_check_eq(app.name, "Test app");
do_check_eq(app.manifest.description, "Testing webapps actor");
do_check_eq(app.manifest.launch_path, "/index.html");
do_check_eq(app.origin, APP_ORIGIN);
do_check_eq(app.installOrigin, app.origin);
do_check_eq(app.manifestURL, app.origin + "/manifest.webapp");
run_next_test();
});
});
add_test(function testLaunchApp() {
let manifestURL = APP_ORIGIN + "/manifest.webapp";
let startPoint = "/index.html";

View File

@ -544,6 +544,32 @@ WebappsActor.prototype = {
return deferred.promise;
},
getApp: function wa_actorGetApp(aRequest) {
debug("getApp");
let manifestURL = aRequest.manifestURL;
if (!manifestURL) {
return { error: "missingParameter",
message: "missing parameter manifestURL" };
}
let reg = DOMApplicationRegistry;
let app = reg.getAppByManifestURL(manifestURL);
if (!app) {
return { error: "appNotFound" };
}
if (this._isAppAllowedForManifest(app.manifestURL)) {
let deferred = promise.defer();
reg.getManifestFor(manifestURL, function (manifest) {
app.manifest = manifest;
deferred.resolve({app: app});
});
return deferred.promise;
}
return { error: "forbidden" };
},
_areCertifiedAppsAllowed: function wa__areCertifiedAppsAllowed() {
let pref = "devtools.debugger.forbid-certified-apps";
return !Services.prefs.getBoolPref(pref);
@ -955,6 +981,7 @@ if (Services.prefs.getBoolPref("devtools.debugger.enable-content-actors")) {
let requestTypes = WebappsActor.prototype.requestTypes;
requestTypes.uploadPackage = WebappsActor.prototype.uploadPackage;
requestTypes.getAll = WebappsActor.prototype.getAll;
requestTypes.getApp = WebappsActor.prototype.getApp;
requestTypes.launch = WebappsActor.prototype.launch;
requestTypes.close = WebappsActor.prototype.close;
requestTypes.uninstall = WebappsActor.prototype.uninstall;