Bug 595810 Part 3: support geolocation notifications from files r=IanN
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Sat, 25 Sep 2010 19:49:05 +0100
changeset 6426 b30b6002d7f5b4a3926073ba834bc98c41e6d784
parent 6425 ea410ea7805e6fc3e1a7c57d1cbcdb17c15fc652
child 6427 4f719059999e13424a068f23ce9998ca5ed14c2e
push idunknown
push userunknown
push dateunknown
reviewersIanN
bugs595810
Bug 595810 Part 3: support geolocation notifications from files r=IanN
suite/common/bindings/notification.xml
suite/common/src/nsSuiteGlue.js
suite/locales/en-US/chrome/common/notification.properties
--- a/suite/common/bindings/notification.xml
+++ b/suite/common/bindings/notification.xml
@@ -400,17 +400,18 @@
                                               null, this.PRIORITY_INFO_LOW,
                                               buttons);
             box.persistence = 3; // arbitrary number, just so bar sticks around for a bit
           ]]>
         </body>
       </method>
 
       <method name="showGeolocationPrompt">
-        <parameter name="spec"/>
+        <parameter name="file"/>
+        <parameter name="site"/>
         <parameter name="image"/>
         <parameter name="allowCallback"/>
         <parameter name="cancelCallback"/>
         <body>
           <![CDATA[
             var type = "geolocation";
             if (this.getNotificationWithValue(type))
               return;
@@ -425,39 +426,47 @@
             }, {
               label: this._stringBundle.GetStringFromName(type + ".dontShareLocation"),
               accessKey: this._stringBundle.GetStringFromName(type + ".dontShareLocation.accesskey"),
               popup: null,
               callback: function (aNotificationBox, aButton) {
                 cancelCallback(aNotificationBox.checkbox.checked);
               }
             }];
-            var message = this._stringBundle
-                              .formatStringFromName(type + ".siteWantsToKnow",
-                                                    [spec], 1);
+            var message;
+            if (site)
+              message = this._stringBundle
+                            .formatStringFromName(type + ".siteWantsToKnow",
+                                                  [site], 1);
+            else
+              message = this._stringBundle
+                            .formatStringFromName(type + ".fileWantsToKnow",
+                                                  [file], 1);
             var box = this.appendNotification(message, type, image,
                                               this.PRIORITY_INFO_HIGH, buttons);
             // Create the checkbox on a timeout to allow the XBL to bind first.
             setTimeout(function(stringBundle) {
-              box.checkbox = document.createElement("checkbox");
-              box.checkbox.className = "rememberChoice";
-              box.checkbox.setAttribute("label", stringBundle.GetStringFromName(type + ".remember"));
-              box.appendChild(box.checkbox);
+              if (site) {
+                box.checkbox = document.createElement("checkbox");
+                box.checkbox.className = "rememberChoice";
+                box.checkbox.setAttribute("label", stringBundle.GetStringFromName(type + ".remember"));
+                box.appendChild(box.checkbox);
+              }
               var link = document.createElement("label");
               link.className = "text-link";
               link.setAttribute("value", stringBundle.GetStringFromName(type + ".learnMore"));
 
               var formatter = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"]
                                         .getService(Components.interfaces.nsIURLFormatter);
               link.href = formatter.formatURLPref("browser.geolocation.warning.infoURL");
 
               document.getAnonymousElementByAttribute(box, "anonid", "messageText").appendChild(link);
             }, 0, this._stringBundle);
 
-            // Tests try to access the checkbox before we've created it.
+            // Create a dummy checkbox so file requests don't try to remember.
             box.checkbox = { checked: false };
           ]]>
         </body>
       </method>
 
       <constructor>
         <![CDATA[
           var os = Components.classes["@mozilla.org/observer-service;1"]
--- a/suite/common/src/nsSuiteGlue.js
+++ b/suite/common/src/nsSuiteGlue.js
@@ -941,20 +941,24 @@ ContentPermissionPrompt.prototype = {
 
   QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIContentPermissionPrompt]),
 
   prompt: function(aRequest)
   {
     if (aRequest.type != "geolocation")
       return;
 
+    var path, host;
     var requestingURI = aRequest.uri;
-
+    if (requestingURI instanceof Components.interfaces.nsIFileURL)
+      path = requestingURI.file.path;
+    else if (requestingURI instanceof Components.interfaces.nsIStandardURL)
+      host = requestingURI.host;
     // Ignore requests from non-nsIStandardURLs
-    if (!(requestingURI instanceof Components.interfaces.nsIStandardURL))
+    else
       return;
 
     switch (Services.perms.testExactPermission(requestingURI, "geo")) {
       case Services.perms.ALLOW_ACTION:
         aRequest.allow();
         return;
       case Services.perms.DENY_ACTION:
         aRequest.cancel();
@@ -973,17 +977,17 @@ ContentPermissionPrompt.prototype = {
       aRequest.cancel();
     }
 
     aRequest.window
             .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
             .getInterface(Components.interfaces.nsIWebNavigation)
             .QueryInterface(Components.interfaces.nsIDocShell)
             .chromeEventHandler.parentNode.wrappedJSObject
-            .showGeolocationPrompt(requestingURI.spec,
+            .showGeolocationPrompt(path, host,
                                    "chrome://communicator/skin/icons/geo.png",
                                    allowCallback,
                                    cancelCallback);
   },
 };
 
 //module initialization
 var NSGetFactory = XPCOMUtils.generateNSGetFactory([SuiteGlue, ContentPermissionPrompt]);
--- a/suite/locales/en-US/chrome/common/notification.properties
+++ b/suite/locales/en-US/chrome/common/notification.properties
@@ -25,16 +25,17 @@ xpinstallDisabledButton.accesskey=n
 # Geolocation UI
 # LOCALIZATION NOTE (geolocation.shareLocation geolocation.dontShareLocation): 
 #If you're having trouble with the word Share, please use Allow and Block in your language.
 geolocation.shareLocation=Share Location
 geolocation.shareLocation.accesskey=a
 geolocation.dontShareLocation=Don't Share
 geolocation.dontShareLocation.accesskey=o
 geolocation.siteWantsToKnow=%S wants to know your location.
+geolocation.fileWantsToKnow=The file %S wants to know your location.
 # LOCALIZATION NOTE (geolocation.learnMore): Use the unicode ellipsis char, \u2026,
 # or use "..." unless \u2026 doesn't suit traditions in your locale.
 geolocation.learnMore=Learn Moreā€¦
 geolocation.remember=Remember for this website
 
 # Block autorefresh
 refreshBlocked.goButton=Allow
 refreshBlocked.goButton.accesskey=A