Bug 580576 - Clicking 'Share your location' in Fennec fails with an error in GeolocationPrompt.js [r=mfinkle]
authorVivien Nicolas <21@vingtetun.org>
Thu, 22 Jul 2010 01:41:25 +0200
changeset 66380 61024744dcae3077b471de995ad9d21e63b62ede
parent 66379 235a53d21a91b3449939e539a87142cd67b2aaea
child 66381 46cd5b0d688cd657ca3c8283dcea1e82e72c7f72
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs580576
Bug 580576 - Clicking 'Share your location' in Fennec fails with an error in GeolocationPrompt.js [r=mfinkle]
mobile/components/GeolocationPrompt.js
--- a/mobile/components/GeolocationPrompt.js
+++ b/mobile/components/GeolocationPrompt.js
@@ -5,100 +5,105 @@ const Cu = Components.utils;
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 const kCountBeforeWeRemember = 5;
 
 function GeolocationPrompt() {}
 
 GeolocationPrompt.prototype = {
-  classID:          Components.ID("{C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}"),
+  classID: Components.ID("{C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIGeolocationPrompt]),
- 
-  prompt: function(request) {
-    var result = Services.perms.testExactPermission(request.requestingURI, "geo");
-    
+
+  prompt: function(aRequest) {
+    let pm = Services.perms;
+    let result = pm.testExactPermission(aRequest.requestingURI, "geo");
+
     if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
-      request.allow();
+      aRequest.allow();
       return;
-    }
-    if (result == Ci.nsIPermissionManager.DENY_ACTION) {
-      request.cancel();
+    } else if (result == Ci.nsIPermissionManager.DENY_ACTION) {
+      aRequest.cancel();
       return;
     }
 
-    function setPagePermission(uri, allow) {
-      var prefService = Services.prefs;
-        
-      if (! prefService.hasPref(request.requestingURI, "geo.request.remember"))
-        prefService.setPref(request.requestingURI, "geo.request.remember", 0);
-      
-      var count = prefService.getPref(request.requestingURI, "geo.request.remember");
-      
-      if (allow == false)
+    function setPagePermission(aUri, aAllow) {
+      let contentPrefs = Services.contentPrefs;
+
+      if (!contentPrefs.hasPref(aRequest.requestingURI, "geo.request.remember"))
+        contentPrefs.setPref(aRequest.requestingURI, "geo.request.remember", 0);
+
+      let count = contentPrefs.getPref(aRequest.requestingURI, "geo.request.remember");
+
+      if (aAllow == false)
         count--;
       else
         count++;
 
-      prefService.setPref(request.requestingURI, "geo.request.remember", count);
-        
+      contentPrefs.setPref(aRequest.requestingURI, "geo.request.remember", count);
+
       if (count == kCountBeforeWeRemember)
-        pm.add(uri, "geo", Ci.nsIPermissionManager.ALLOW_ACTION);
+        pm.add(aUri, "geo", Ci.nsIPermissionManager.ALLOW_ACTION);
       else if (count == -kCountBeforeWeRemember)
-        pm.add(uri, "geo", Ci.nsIPermissionManager.DENY_ACTION);
+        pm.add(aUri, "geo", Ci.nsIPermissionManager.DENY_ACTION);
     }
 
     function getChromeWindow(aWindow) {
-      var chromeWin = aWindow 
+      let chromeWin = aWindow
         .QueryInterface(Ci.nsIInterfaceRequestor)
         .getInterface(Ci.nsIWebNavigation)
         .QueryInterface(Ci.nsIDocShellTreeItem)
         .rootTreeItem
         .QueryInterface(Ci.nsIInterfaceRequestor)
         .getInterface(Ci.nsIDOMWindow)
         .QueryInterface(Ci.nsIDOMChromeWindow);
       return chromeWin;
     }
 
-    var requestingWindow = request.requestingWindow.top;
-    var chromeWin = getChromeWindow(requestingWindow).wrappedJSObject;
-
-    var notificationBox = chromeWin.getNotificationBox(requestingWindow);
+    let notificationBox = null;
+    if (aRequest.requestingWindow) {
+      let requestingWindow = aRequest.requestingWindow.top;
+      let chromeWin = getChromeWindow(requestingWindow).wrappedJSObject;
+      notificationBox = chromeWin.getNotificationBox(requestingWindow);
+    } else {
+      let chromeWin = aRequest.requestingElement.ownerDocument.defaultView;
+      notificationBox = chromeWin.Browser.getNotificationBox();
+    }
 
-    var notification = notificationBox.getNotificationWithValue("geolocation");
+    let notification = notificationBox.getNotificationWithValue("geolocation");
     if (!notification) {
-      var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
+      let browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
 
-      var buttons = [{
+      let buttons = [{
         label: browserBundle.GetStringFromName("geolocation.share"),
         accessKey: null,
         callback: function(notification) {
-          setPagePermission(request.requestingURI, true);
-          request.allow(); 
+          setPagePermission(aRequest.requestingURI, true);
+          aRequest.allow();
         },
       },
       {
         label: browserBundle.GetStringFromName("geolocation.dontShare"),
         accessKey: null,
         callback: function(notification) {
-          setPagePermission(request.requestingURI, false);
-          request.cancel();
+          setPagePermission(aRequest.requestingURI, false);
+          aRequest.cancel();
         },
       }];
-      
-      var message = browserBundle.formatStringFromName("geolocation.siteWantsToKnow",
-                                                       [request.requestingURI.host], 1);      
-      
-      var newBar = notificationBox.appendNotification(message,
+
+      let message = browserBundle.formatStringFromName("geolocation.siteWantsToKnow",
+                                                       [aRequest.requestingURI.host], 1);
+
+      let newBar = notificationBox.appendNotification(message,
                                                       "geolocation",
                                                       "chrome://browser/skin/images/geo-16.png",
                                                       notificationBox.PRIORITY_WARNING_MEDIUM,
                                                       buttons);
       // Make this a geolocation notification.
-      newBar.setAttribute("type", "geo"); 
+      newBar.setAttribute("type", "geo");
     }
   }
 };
 
 
 //module initialization
 const NSGetFactory = XPCOMUtils.generateNSGetFactory([GeolocationPrompt]);