Bug 919831 - Fix support of packaged apps with custom origin. r=paul
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 26 Sep 2013 14:07:44 -0400
changeset 148911 5fd6af0ff7f806b5f31d7954243eb8f29e98dee0
parent 148910 f57dd2d6ec4d9a4084ea7f26826cbe79fc5d29f4
child 148912 8a0fd7b642db244dde7830736aec1ca783866653
push id34380
push userryanvm@gmail.com
push dateFri, 27 Sep 2013 01:41:00 +0000
treeherdermozilla-inbound@fdc6054e33e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaul
bugs919831
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 919831 - Fix support of packaged apps with custom origin. r=paul
browser/devtools/app-manager/app-projects.js
browser/devtools/app-manager/content/projects.js
--- a/browser/devtools/app-manager/app-projects.js
+++ b/browser/devtools/app-manager/app-projects.js
@@ -63,16 +63,33 @@ const IDB = {
     };
     request.onsuccess = function() {
       deferred.resolve();
     };
 
     return deferred.promise;
   },
 
+  update: function(project) {
+    let deferred = promise.defer();
+
+    var transaction = IDB._db.transaction(["projects"], "readwrite");
+    var objectStore = transaction.objectStore("projects");
+    var request = objectStore.put(project);
+    request.onerror = function(event) {
+      deferred.reject("Unable to update project to the AppProjects indexedDB: " +
+                      this.error.name + " - " + this.error.message );
+    };
+    request.onsuccess = function() {
+      deferred.resolve();
+    };
+
+    return deferred.promise;
+  },
+
   remove: function(location) {
     let deferred = promise.defer();
 
     let request = IDB._db.transaction(["projects"], "readwrite")
                     .objectStore("projects")
                     .delete(location);
     request.onsuccess = function(event) {
       deferred.resolve();
@@ -105,16 +122,18 @@ const AppProjects = {
     let project = {
       type: "packaged",
       location: folder.path,
       // We need a unique id, that is the app origin,
       // in order to identify the app when being installed on the device.
       // The packaged app local path is a valid id, but only on the client.
       // This origin will be used to generate the true id of an app:
       // its manifest URL.
+      // If the app ends up specifying an explicit origin in its manifest,
+      // we will override this random UUID on app install.
       packagedAppOrigin: generateUUID().toString().slice(1, -1)
     };
     return IDB.add(project).then(function () {
       store.object.projects.push(project);
       // return the added objects (proxified)
       return store.object.projects[store.object.projects.length - 1];
     });
   },
@@ -126,16 +145,24 @@ const AppProjects = {
     };
     return IDB.add(project).then(function () {
       store.object.projects.push(project);
       // return the added objects (proxified)
       return store.object.projects[store.object.projects.length - 1];
     });
   },
 
+  update: function (project) {
+    return IDB.update({
+      type: project.type,
+      location: project.location,
+      packagedAppOrigin: project.packagedAppOrigin
+    }).then(() => project);
+  },
+
   remove: function(location) {
     return IDB.remove(location).then(function () {
       let projects = store.object.projects;
       for (let i = 0; i < projects.length; i++) {
         if (projects[i].location == location) {
           projects.splice(i, 1);
           return;
         }
--- a/browser/devtools/app-manager/content/projects.js
+++ b/browser/devtools/app-manager/content/projects.js
@@ -203,30 +203,35 @@ let UI = {
     if (project.type == "packaged") {
       return "app://" + project.packagedAppOrigin + "/manifest.webapp";
     } else if (project.type == "hosted") {
       return project.location;
     }
   },
 
   install: function(project) {
-    let install;
     if (project.type == "packaged") {
-      install = installPackaged(this.connection.client, this.listTabsResponse.webappsActor, project.location, project.packagedAppOrigin);
+      return installPackaged(this.connection.client, this.listTabsResponse.webappsActor, project.location, project.packagedAppOrigin)
+        .then(({ appId }) => {
+          // If the packaged app specified a custom origin override,
+          // we need to update the local project origin
+          project.packagedAppOrigin = appId;
+          // And ensure the indexed db on disk is also updated
+          AppProjects.update(project);
+        });
     } else {
       let manifestURLObject = Services.io.newURI(project.location, null, null);
       let origin = Services.io.newURI(manifestURLObject.prePath, null, null);
       let appId = origin.host;
       let metadata = {
         origin: origin.spec,
         manifestURL: project.location
       };
-      install = installHosted(this.connection.client, this.listTabsResponse.webappsActor, appId, metadata, project.manifest);
+      return installHosted(this.connection.client, this.listTabsResponse.webappsActor, appId, metadata, project.manifest);
     }
-    return install;
   },
 
   start: function(project) {
     let deferred = promise.defer();
     let request = {
       to: this.listTabsResponse.webappsActor,
       type: "launch",
       manifestURL: this._getProjectManifestURL(project)