Bug 815974 - [System] Remember geolocation permission for an app is broken. r=sicking
authorGregor Wagner <anygregor@gmail.com>
Fri, 30 Nov 2012 09:32:05 -0800
changeset 114604 5ae27ec3d9ec
parent 114603 ce1e1e13511b
child 114605 b88467155adc
push id18869
push usergwagner@mozilla.com
push dateFri, 30 Nov 2012 17:38:22 +0000
treeherdermozilla-inbound@5ae27ec3d9ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs815974
milestone20.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 815974 - [System] Remember geolocation permission for an app is broken. r=sicking
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) {