Bug 679194 - Add a permission prompt for mozApps.mgmt.list and mozApps.mgmt.uninstall [r=mfinkle]
authorFabrice Desré <fabrice@mozilla.com>
Mon, 15 Aug 2011 18:56:42 -0700
changeset 78852 d8a22be1e9c7e3552d674c66709a0dd9e2585db7
parent 78851 282cc7688390e0a56d36db81df1f3a154bdf662c
child 78853 3c6a26f33adfcd58adc9a6e3bb39f44f3f1be195
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs679194
milestone9.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 679194 - Add a permission prompt for mozApps.mgmt.list and mozApps.mgmt.uninstall [r=mfinkle]
mobile/chrome/content/PageActions.js
mobile/chrome/content/WebappsUI.js
mobile/components/ContentPermissionPrompt.js
mobile/locales/en-US/chrome/browser.properties
toolkit/mozapps/webapps/OpenWebapps.js
--- a/mobile/chrome/content/PageActions.js
+++ b/mobile/chrome/content/PageActions.js
@@ -84,17 +84,17 @@ var PageActions = {
   },
 
   get _loginManager() {
     delete this._loginManager;
     return this._loginManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
   },
 
   // Permissions we track in Page Actions
-  _permissions: ["popup", "offline-app", "geolocation", "desktop-notification"],
+  _permissions: ["popup", "offline-app", "geolocation", "desktop-notification", "openWebappsManage"],
 
   _forEachPermissions: function _forEachPermissions(aHost, aCallback) {
     let pm = Services.perms;
     for (let i = 0; i < this._permissions.length; i++) {
       let type = this._permissions[i];
       if (!pm.testPermission(aHost, type))
         continue;
 
--- a/mobile/chrome/content/WebappsUI.js
+++ b/mobile/chrome/content/WebappsUI.js
@@ -91,16 +91,47 @@ var WebappsUI = {
       app.iconURI = icon;
 
     let root = baseURI.resolve("/").toString();
     app.appURI = root.substring(0, root.length - 1);
 
     return app;
   },
 
+  askPermission: function(aMessage, aType, aCallbacks) {
+    let uri = Services.io.newURI(aMessage.json.from, null, null);
+    let perm = Services.perms.testExactPermission(uri, aType);
+    switch(perm) {
+      case Ci.nsIPermissionManager.ALLOW_ACTION:
+        aCallbacks.allow();
+        return;
+      case Ci.nsIPermissionManager.DENY_ACTION:
+        aCallbacks.cancel();
+        return;
+    }
+
+    let prompt = Cc["@mozilla.org/content-permission/prompt;1"].createInstance(Ci.nsIContentPermissionPrompt);
+
+    prompt.prompt({
+      type: aType,
+      uri: uri,
+      window: null,
+      element: getBrowser(),
+
+      cancel: function() {
+        aCallbacks.cancel();
+      },
+
+      allow: function() {
+        Services.perms.add(uri, aType, Ci.nsIPermissionManager.ALLOW_ACTION);
+        aCallbacks.allow();
+      }
+    });
+  },
+
   receiveMessage: function(aMessage) {
     this._browser = aMessage.target.QueryInterface(Ci.nsIFrameMessageManager);
     switch(aMessage.name) {
       case "OpenWebapps:Install":
         WebappsUI.show(WebappsUI.convertManifest(aMessage.json));
         break;
       case "OpenWebapps:GetInstalledBy":
         let apps = OpenWebapps.getInstalledBy(aMessage.json.storeURI);
@@ -108,30 +139,48 @@ var WebappsUI = {
             { apps: apps, callbackID: aMessage.json.callbackID });
         break;
       case "OpenWebapps:AmInstalled":
         let app = OpenWebapps.amInstalled(aMessage.json.appURI);
         this._browser.sendAsyncMessage("OpenWebapps:AmInstalled:Return",
             { installed: app != null, app: app, callbackID: aMessage.json.callbackID });
         break;
       case "OpenWebapps:MgmtList":
-        let list = OpenWebapps.mgmtList();
-        this._browser.sendAsyncMessage("OpenWebapps:MgmtList:Return",
-            { ok: true, apps: list, callbackID: aMessage.json.callbackID });
+        this.askPermission(aMessage, "openWebappsManage", {
+          cancel: function() {
+            WebappsUI.messageManager.sendAsyncMessage("OpenWebapps:MgmtList:Return",
+              { ok: false, callbackID: aMessage.json.callbackID });
+          },
+
+          allow: function() {
+            let list = OpenWebapps.mgmtList();
+            WebappsUI.messageManager.sendAsyncMessage("OpenWebapps:MgmtList:Return",
+              { ok: true, apps: list, callbackID: aMessage.json.callbackID });
+          }
+        });
         break;
       case "OpenWebapps:MgmtLaunch":
         let res = OpenWebapps.mgmtLaunch(aMessage.json.origin);
         this._browser.sendAsyncMessage("OpenWebapps:MgmtLaunch:Return",
             { ok: res, callbackID: aMessage.json.callbackID });
         break;
       case "OpenWebapps:MgmtUninstall":
-        app = OpenWebapps.amInstalled(aMessage.json.origin);
-        let uninstalled = OpenWebapps.mgmtUninstall(aMessage.json.origin);
-        this.messageManager.sendAsyncMessage("OpenWebapps:MgmtUninstall:Return",
-            { ok: uninstalled, app: app, callbackID: aMessage.json.callbackID });
+        this.askPermission(aMessage, "openWebappsManage", {
+          cancel: function() {
+            WebappsUI.messageManager.sendAsyncMessage("OpenWebapps:MgmtUninstall:Return",
+              { ok: false, callbackID: aMessage.json.callbackID });
+          },
+
+          allow: function() {
+            let app = OpenWebapps.amInstalled(aMessage.json.origin);
+            let uninstalled = OpenWebapps.mgmtUninstall(aMessage.json.origin);
+            WebappsUI.messageManager.sendAsyncMessage("OpenWebapps:MgmtUninstall:Return",
+              { ok: uninstalled, app: app, callbackID: aMessage.json.callbackID });
+          }
+        });
         break;
     }
   },
 
   checkBox: function(aEvent) {
     let elem = aEvent.originalTarget;
     let perm = elem.getAttribute("perm");
     if (this._application.capabilities && this._application.capabilities.indexOf(perm) != -1) {
--- a/mobile/components/ContentPermissionPrompt.js
+++ b/mobile/components/ContentPermissionPrompt.js
@@ -25,17 +25,18 @@ function setPagePermission(type, uri, al
   contentPrefs.setPref(uri, contentPrefName, count);
   if (count == kCountBeforeWeRemember)
     pm.add(uri, type, Ci.nsIPermissionManager.ALLOW_ACTION);
   else if (count == -kCountBeforeWeRemember)
     pm.add(uri, type, Ci.nsIPermissionManager.DENY_ACTION);
 }
 
 const kEntities = { "geolocation": "geolocation", "desktop-notification": "desktopNotification",
-                    "indexedDB": "offlineApps", "indexedDBQuota": "indexedDBQuota" };
+                    "indexedDB": "offlineApps", "indexedDBQuota": "indexedDBQuota",
+                    "openWebappsManage": "openWebappsManage" };
 
 function ContentPermissionPrompt() {}
 
 ContentPermissionPrompt.prototype = {
   classID: Components.ID("{C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt]),
 
--- a/mobile/locales/en-US/chrome/browser.properties
+++ b/mobile/locales/en-US/chrome/browser.properties
@@ -168,16 +168,21 @@ offlineApps.notNow=Not Now
 offlineApps.dontAllow=Don't Allow
 offlineApps.wantsTo=%S wants to store data on your device for offline use.
 
 # IndexedDB Quota increases
 indexedDBQuota.allow=Allow
 indexedDBQuota.dontAllow=Don't Allow
 indexedDBQuota.wantsTo=%S wants to store a lot of data on your device for offline use.
 
+# Open Web Apps management API
+openWebappsManage.allow=Allow
+openWebappsManage.dontAllow=Don't Allow
+openWebappsManage.wantsTo=%S wants to manage applications on your device.
+
 # Bookmark List
 bookmarkList.desktop=Desktop Bookmarks
 
 # Closing Tabs
 tabs.closeWarningTitle=Confirm close
 
 # LOCALIZATION NOTE (tabs.closeWarning): Semi-colon list of plural forms.
 # See: http://developer.mozilla.org/en/docs/Localization_and_Plurals
@@ -201,16 +206,17 @@ homepage.custom2=Custom Page
 
 # Page Actions
 pageactions.saveas.pdf=Save As PDF
 pageactions.geolocation=Location
 pageactions.popup=Popups
 pageactions.offline-app=Offline Storage
 pageactions.password=Password
 pageactions.desktop-notification=Web Notifications
+pageactions.openWebappsManage=Manage Web Apps
 
 # Open Search
 opensearch.searchWith=Search With:
 opensearch.searchFor=Search for "%S"
 
 # Open in Another App
 # LOCALIZATION NOTE: openinapp.specific is the text displayed if there is a single external app
 # %S is the name of the app, like "YouTube" or "Picassa"
--- a/toolkit/mozapps/webapps/OpenWebapps.js
+++ b/toolkit/mozapps/webapps/OpenWebapps.js
@@ -204,21 +204,21 @@ OpenWebapps.prototype = {
   },
   
   // nsIOpenWebappsMgmt implementation
   launch: function(aOrigin, aSuccess, aError) {
     this.mm.sendAsyncMessage("OpenWebapps:MgmtLaunch", { origin: aOrigin, callbackID:  this.getCallbackId({ success: aSuccess, error: aError }) });
   },
   
   list: function(aSuccess, aError) {
-    this.mm.sendAsyncMessage("OpenWebapps:MgmtList", { callbackID:  this.getCallbackId({ success: aSuccess, error: aError }) });
+    this.mm.sendAsyncMessage("OpenWebapps:MgmtList", { from: this._window.location.href, callbackID:  this.getCallbackId({ success: aSuccess, error: aError }) });
   },
   
   uninstall: function(aOrigin, aSuccess, aError) {
-    this.mm.sendAsyncMessage("OpenWebapps:MgmtUninstall", { origin: aOrigin, callbackID:  this.getCallbackId({ success: aSuccess, error: aError }) });
+    this.mm.sendAsyncMessage("OpenWebapps:MgmtUninstall", { from: this._window.location.href, origin: aOrigin, callbackID:  this.getCallbackId({ success: aSuccess, error: aError }) });
   },
 
   _onRepoChange: function(aWhat, aApps) {
     for (let prop in this._callbacks) {
       if (this._callbacks[prop].isWatch) {
         let apps = this._convertAppsArray(aApps);
         this._callbacks[prop].callback.update(aWhat, apps, apps.length);
       }