Bug 794102 - checkInstalled should return an app object. r=felipc
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 02 Oct 2012 16:38:51 -0400
changeset 109047 dfe50b46ef8cb713413a4464e68216ddeb27fac2
parent 109046 0b1ff56c95ae8e3e33133a2923006d481194a756
child 109048 64c541e0b0544043c66743f43b76c09dcbb1179b
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersfelipc
bugs794102
milestone18.0a1
Bug 794102 - checkInstalled should return an app object. r=felipc
dom/apps/src/Webapps.js
dom/apps/src/Webapps.jsm
dom/interfaces/apps/nsIDOMApplicationRegistry.idl
dom/tests/mochitest/webapps/file_bug_779982.html
dom/tests/mochitest/webapps/file_bug_779982.js
dom/tests/mochitest/webapps/test_bug_779982.html
dom/tests/mochitest/webapps/test_list_api.xul
--- a/dom/apps/src/Webapps.js
+++ b/dom/apps/src/Webapps.js
@@ -60,18 +60,18 @@ WebappsRegistry.prototype = {
       case "Webapps:GetSelf:Return:OK":
         if (msg.apps.length) {
           app = msg.apps[0];
           Services.DOMRequest.fireSuccess(req, createApplicationObject(this._window, app));
         } else {
           Services.DOMRequest.fireSuccess(req, null);
         }
         break;
-      case "Webapps:IsInstalled:Return:OK":
-        Services.DOMRequest.fireSuccess(req, msg.installed);
+      case "Webapps:CheckInstalled:Return:OK":
+        Services.DOMRequest.fireSuccess(req, msg.app);
         break;
       case "Webapps:GetInstalled:Return:OK":
         Services.DOMRequest.fireSuccess(req, convertAppsArray(msg.apps, this._window));
         break;
     }
     this.removeRequest(msg.requestID);
   },
 
@@ -154,25 +154,25 @@ WebappsRegistry.prototype = {
     let request = this.createRequest();
     cpmm.sendAsyncMessage("Webapps:GetSelf", { origin: this._getOrigin(this._window.location.href),
                                                appId: this._window.document.nodePrincipal.appId,
                                                oid: this._id,
                                                requestID: this.getRequestId(request) });
     return request;
   },
 
-  isInstalled: function(aManifestURL) {
+  checkInstalled: function(aManifestURL) {
     let manifestURL = Services.io.newURI(aManifestURL, null, this._window.document.baseURIObject);
     this._window.document.nodePrincipal.checkMayLoad(manifestURL, true, false);
 
     let request = this.createRequest();
-    cpmm.sendAsyncMessage("Webapps:IsInstalled", { origin: this._getOrigin(this._window.location.href),
-                                                   manifestURL: manifestURL.spec,
-                                                   oid: this._id,
-                                                   requestID: this.getRequestId(request) });
+    cpmm.sendAsyncMessage("Webapps:CheckInstalled", { origin: this._getOrigin(this._window.location.href),
+                                                      manifestURL: manifestURL.spec,
+                                                      oid: this._id,
+                                                      requestID: this.getRequestId(request) });
     return request;
   },
 
   getInstalled: function() {
     let request = this.createRequest();
     cpmm.sendAsyncMessage("Webapps:GetInstalled", { origin: this._getOrigin(this._window.location.href),
                                                     oid: this._id,
                                                     requestID: this.getRequestId(request) });
@@ -254,17 +254,17 @@ WebappsRegistry.prototype = {
     return request;
   },
 
   // nsIDOMGlobalPropertyInitializer implementation
   init: function(aWindow) {
     this.initHelper(aWindow, ["Webapps:Install:Return:OK", "Webapps:Install:Return:KO",
                               "Webapps:GetInstalled:Return:OK",
                               "Webapps:GetSelf:Return:OK",
-                              "Webapps:IsInstalled:Return:OK" ]);
+                              "Webapps:CheckInstalled:Return:OK" ]);
 
     let util = this._window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
     this._id = util.outerWindowID;
     cpmm.sendAsyncMessage("Webapps:RegisterForMessages",
                           ["Webapps:Install:Return:OK"]);
   },
 
   classID: Components.ID("{fff440b3-fae2-45c1-bf03-3b5a2e432270}"),
--- a/dom/apps/src/Webapps.jsm
+++ b/dom/apps/src/Webapps.jsm
@@ -149,17 +149,17 @@ let DOMApplicationRegistry = {
   appsFile: null,
   webapps: { },
   children: [ ],
   allAppsLaunchable: false,
   downloads: { },
 
   init: function() {
     this.messages = ["Webapps:Install", "Webapps:Uninstall",
-                     "Webapps:GetSelf", "Webapps:IsInstalled",
+                     "Webapps:GetSelf", "Webapps:CheckInstalled",
                      "Webapps:GetInstalled", "Webapps:GetNotInstalled",
                      "Webapps:Launch", "Webapps:GetAll",
                      "Webapps:InstallPackage", "Webapps:GetBasePath",
                      "Webapps:GetList", "Webapps:RegisterForMessages",
                      "Webapps:CancelDownload", "Webapps:CheckForUpdate",
                      "Webapps::Download", "Webapps::ApplyDownload",
                      "child-process-shutdown"];
 
@@ -556,18 +556,18 @@ let DOMApplicationRegistry = {
         break;
       case "Webapps:Uninstall":
         this.uninstall(msg, mm);
         debug("Webapps:Uninstall");
         break;
       case "Webapps:Launch":
         this.launchApp(msg, mm);
         break;
-      case "Webapps:IsInstalled":
-        this.isInstalled(msg, mm);
+      case "Webapps:CheckInstalled":
+        this.checkInstalled(msg, mm);
         break;
       case "Webapps:GetInstalled":
         this.getInstalled(msg, mm);
         break;
       case "Webapps:GetNotInstalled":
         this.getNotInstalled(msg, mm);
         break;
       case "Webapps:GetAll":
@@ -1449,27 +1449,35 @@ let DOMApplicationRegistry = {
 
     this._readManifests(tmp, (function(aResult) {
       for (let i = 0; i < aResult.length; i++)
         aData.apps[i].manifest = aResult[i].manifest;
       aMm.sendAsyncMessage("Webapps:GetSelf:Return:OK", aData);
     }).bind(this));
   },
 
-  isInstalled: function(aData, aMm) {
-    aData.installed = false;
+  checkInstalled: function(aData, aMm) {
+    aData.app = null;
+    let tmp = [];
 
     for (let appId in this.webapps) {
       if (this.webapps[appId].manifestURL == aData.manifestURL) {
-        aData.installed = true;
+        aData.app = AppsUtils.cloneAppObject(this.webapps[appId]);
+        tmp.push({ id: appId });
         break;
       }
     }
 
-    aMm.sendAsyncMessage("Webapps:IsInstalled:Return:OK", aData);
+    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));
   },
 
   getInstalled: function(aData, aMm) {
     aData.apps = [];
     let tmp = [];
 
     for (let id in this.webapps) {
       if (this.webapps[id].installOrigin == aData.origin &&
--- a/dom/interfaces/apps/nsIDOMApplicationRegistry.idl
+++ b/dom/interfaces/apps/nsIDOMApplicationRegistry.idl
@@ -117,17 +117,17 @@ interface mozIDOMApplicationMgmt : nsISu
   /**
    * Applies a downloaded update.
    * This function is a no-op if it's passed an app object which doesn't have
    * |readyToApplyDownload| set to true.
    */
   void applyDownload(in mozIDOMApplication app);
 };
 
-[scriptable, uuid(7ca34d3e-d855-4d0a-a3b3-58c0acad9ec3)]
+[scriptable, uuid(abfc6c15-8b92-4b9a-b892-52e6ae76f379)]
 interface mozIDOMApplicationRegistry : nsISupports
 {
   /**
    * Install a web app.
    *
    * @param manifestUrl : the URL of the webapps manifest.
    * @param parameters  : A structure with optional information.
    *                      {
@@ -139,19 +139,19 @@ interface mozIDOMApplicationRegistry : n
   nsIDOMDOMRequest install(in DOMString manifestUrl, [optional] in jsval parameters);
 
   /**
    * the request will return the application currently installed, or null.
    */
   nsIDOMDOMRequest getSelf();
 
   /**
-   * the request will return true if the app from that origin is installed
+   * the request will return the application if the app from that origin is installed
    */
-  nsIDOMDOMRequest isInstalled(in DOMString manifestUrl);
+  nsIDOMDOMRequest checkInstalled(in DOMString manifestUrl);
 
   /**
    * the request will return the applications installed from this origin, or null.
    */
   nsIDOMDOMRequest getInstalled();
 
   readonly attribute mozIDOMApplicationMgmt mgmt;
 };
--- a/dom/tests/mochitest/webapps/file_bug_779982.html
+++ b/dom/tests/mochitest/webapps/file_bug_779982.html
@@ -18,29 +18,29 @@
           if (data[1] == 'true') {
             finish(this.result == null);
           } else {
             finish(this.result != null);
           }
         }
         break;
 
-      case "isInstalled":
-        navigator.mozApps.isInstalled('http://example.org/manifest.webapp').onsuccess = function onIsInstalled() {
+      case "checkInstalled":
+        navigator.mozApps.checkInstalled('http://example.org/manifest.webapp').onsuccess = function onCheckInstalled() {
           if (data[1] == 'true') {
-            finish(this.result == false);
+            finish(!this.result);
           } else {
-            finish(this.result == true);
+            finish(!!this.result);
           }
         }
         break;
 
-      case "isInstalledWrong":
+      case "checkInstalledWrong":
         try {
-          navigator.mozApps.isInstalled('http://something.org/manifest.webapp');
+          navigator.mozApps.checkInstalled('http://something.org/manifest.webapp');
           finish(false);
         } catch (e) {
           finish(true);
         }
         break;
 
       default:
         finish(false);
--- a/dom/tests/mochitest/webapps/file_bug_779982.js
+++ b/dom/tests/mochitest/webapps/file_bug_779982.js
@@ -41,49 +41,49 @@ var gData = [
     app: 'http://example.org/manifest.webapp',
     action: 'getSelf',
     isnull: false,
     src: fileTestOnCurrentOrigin,
     message: 'getSelf() for app should return something'
   },
   {
     app: 'http://example.org/manifest.webapp',
-    action: 'isInstalled',
+    action: 'checkInstalled',
     isnull: false,
     src: fileTestOnCurrentOrigin,
-    message: 'isInstalled() for app should return true'
+    message: 'checkInstalled() for app should return true'
   },
   {
     app: 'http://example.org/manifest.webapp',
-    action: 'isInstalledWrong',
+    action: 'checkInstalledWrong',
     isnull: true,
     src: fileTestOnCurrentOrigin,
-    message: 'isInstalled() for browser should return true'
+    message: 'checkInstalled() for browser should return true'
   },
   // Browser
   {
     browser: true,
     action: 'getSelf',
     isnull: true,
     src: fileTestOnCurrentOrigin,
     message: 'getSelf() for browser should return null'
   },
   {
     browser: true,
-    action: 'isInstalled',
+    action: 'checkInstalled',
     isnull: false,
     src: fileTestOnCurrentOrigin,
-    message: 'isInstalled() for browser should return true'
+    message: 'checkInstalled() for browser should return true'
   },
   {
     browser: true,
-    action: 'isInstalledWrong',
+    action: 'checkInstalledWrong',
     isnull: true,
     src: fileTestOnCurrentOrigin,
-    message: 'isInstalled() for browser should return true'
+    message: 'checkInstalled() for browser should return true'
   },
 ];
 
 function runTest() {
   for (var i in gData) {
     var iframe = document.createElement('iframe');
     var data = gData[i];
 
--- a/dom/tests/mochitest/webapps/test_bug_779982.html
+++ b/dom/tests/mochitest/webapps/test_bug_779982.html
@@ -1,15 +1,15 @@
 <!DOCTYPE HTML>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=779982
 -->
 <head>
-  <title>Test for getSelf()/isInstalled() in browser and in apps</title>
+  <title>Test for getSelf()/checkInstalled() in browser and in apps</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=779982">Mozilla Bug 779982</a>
 <div id="content" style="display: none">
 
 </div>
--- a/dom/tests/mochitest/webapps/test_list_api.xul
+++ b/dom/tests/mochitest/webapps/test_list_api.xul
@@ -15,17 +15,17 @@
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741549"
      target="_blank">Mozilla Bug 741549</a>
   </body>
 
 <script>
 
 var props = {
   QueryInterface: "function",
-  isInstalled: "function",
+  checkInstalled: "function",
   getInstalled: "function",
   getSelf: "function",
   install: "function",
   mgmt: "object",
 };
 
 isDeeply([p for (p in navigator.mozApps)].sort(), Object.keys(props).sort(),
          "navigator.mozApps has only the expected properties");