Bug 815974 - [System] Remember geolocation permission for an app is broken. r=sicking, a=blocking-basecamp
authorGregor Wagner <anygregor@gmail.com>
Fri, 30 Nov 2012 09:32:05 -0800
changeset 118531 d7dc900021c28bb3e54b5c47e63fec7e8721956d
parent 118530 5803a827afcbc95c547e860898c0670a070aa4d8
child 118532 89d29a551f80f3e5fa5389384b469205fb72274c
push id2832
push userryanvm@gmail.com
push dateSun, 02 Dec 2012 04:00:55 +0000
treeherdermozilla-aurora@2b40d4ebe90f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking, blocking-basecamp
bugs815974
milestone19.0a2
Bug 815974 - [System] Remember geolocation permission for an app is broken. r=sicking, a=blocking-basecamp
b2g/components/ContentPermissionPrompt.js
--- a/b2g/components/ContentPermissionPrompt.js
+++ b/b2g/components/ContentPermissionPrompt.js
@@ -1,26 +1,30 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+"use strict"
+
 let DEBUG = 0;
 let debug;
 if (DEBUG) {
   debug = function (s) { dump("-*- ContentPermissionPrompt: " + s + "\n"); };
 }
 else {
   debug = function (s) {};
 }
 
 const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 const Cc = Components.classes;
 
+const PROMPT_FOR_UNKNOWN = ['geolocation'];
+
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Webapps.jsm");
 Cu.import("resource://gre/modules/AppsUtils.jsm");
 Cu.import("resource://gre/modules/PermissionsInstaller.jsm");
 
 var permissionManager = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager);
 var secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].getService(Ci.nsIScriptSecurityManager);
@@ -31,50 +35,50 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                    "nsIDOMPermissionSettings");
 
 function rememberPermission(aPermission, aPrincipal)
 {
   function convertPermToAllow(aPerm, aPrincipal)
   {
     let type =
       permissionManager.testExactPermissionFromPrincipal(aPrincipal, aPerm);
-    if (type == Ci.nsIPermissionManager.PROMPT_ACTION) {
+    if (type == Ci.nsIPermissionManager.PROMPT_ACTION ||
+        (type == Ci.nsIPermissionManager.UNKNOWN_ACTION &&
+        PROMPT_FOR_UNKNOWN.indexOf(aPermission) >= 0)) {
       permissionManager.addFromPrincipal(aPrincipal,
                                          aPerm,
                                          Ci.nsIPermissionManager.ALLOW_ACTION);
     }
   }
 
   // Expand the permission to see if we have multiple access properties to convert
   let access = PermissionsTable[aPermission].access;
   if (access) {
     for (let idx in access) {
       convertPermToAllow(aPermission + "-" + access[idx], aPrincipal);
     }
-  }
-  else {
+  } else {
     convertPermToAllow(aPermission, aPrincipal);
   }
 }
 
 function ContentPermissionPrompt() {}
 
 ContentPermissionPrompt.prototype = {
 
   handleExistingPermission: function handleExistingPermission(request) {
-    let promptForUnknown = ['geolocation'];
     let access = (request.access && request.access !== "unused") ? request.type + "-" + request.access :
                                                                    request.type;
     let result = Services.perms.testExactPermissionFromPrincipal(request.principal, access);
     if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
       request.allow();
       return true;
     }
     if (result == Ci.nsIPermissionManager.DENY_ACTION ||
-        result == Ci.nsIPermissionManager.UNKNOWN_ACTION && promptForUnknown.indexOf(access) < 0) {
+        result == Ci.nsIPermissionManager.UNKNOWN_ACTION && PROMPT_FOR_UNKNOWN.indexOf(access) < 0) {
       request.cancel();
       return true;
     }
     return false;
   },
 
   _id: 0,
   prompt: function(request) {