Bug 595442: Port front end of Bug 594261 |Factor out geolocation prompt into something that can be reused|. r=Neil
authorPhilip Chee <philip.chee@gmail.com>
Sun, 12 Sep 2010 12:42:33 +0800
changeset 6358 130bca1d699e041381d4c3e3fee9a5ca3ef7a2bb
parent 6357 a56e315af01d5f2383539a3f796dccee54ee1911
child 6359 8d1b298446ac7a8f86606d1a9be3bbd1b2bc7756
push idunknown
push userunknown
push dateunknown
reviewersNeil
bugs595442, 594261
Bug 595442: Port front end of Bug 594261 |Factor out geolocation prompt into something that can be reused|. r=Neil
suite/common/src/SuiteCommon.manifest
suite/common/src/nsSuiteGlue.js
--- a/suite/common/src/SuiteCommon.manifest
+++ b/suite/common/src/SuiteCommon.manifest
@@ -9,13 +9,13 @@ contract @mozilla.org/network/protocol/a
 component {4e6c1112-57b6-44ba-adf9-99fb573b0a30} nsSessionStartup.js
 contract @mozilla.org/suite/sessionstartup;1 {4e6c1112-57b6-44ba-adf9-99fb573b0a30}
 category app-startup SessionStartup service,@mozilla.org/suite/sessionstartup;1
 component {d37ccdf1-496f-4135-9575-037180af010d} nsSessionStore.js
 contract @mozilla.org/suite/sessionstore;1 {d37ccdf1-496f-4135-9575-037180af010d}
 component {bbbbe845-5a1b-40ee-813c-f84b8faaa07c} nsSuiteGlue.js
 contract @mozilla.org/suite/suiteglue;1 {bbbbe845-5a1b-40ee-813c-f84b8faaa07c}
 category app-startup nsSuiteGlue service,@mozilla.org/suite/suiteglue;1
-component {450a13bd-0d07-4e5d-a9f0-448c201728b1} nsSuiteGlue.js
-contract @mozilla.org/geolocation/prompt;1 {450a13bd-0d07-4e5d-a9f0-448c201728b1}
+component {9d4c845d-3f09-402a-b66d-50f291d7d50f} nsSuiteGlue.js
+contract @mozilla.org/content-permission/prompt;1 {9d4c845d-3f09-402a-b66d-50f291d7d50f}
 component {22117140-9c6e-11d3-aaf1-00805f8a4905} nsSidebar.js
 contract @mozilla.org/sidebar;1 {22117140-9c6e-11d3-aaf1-00805f8a4905}
 category JavaScript-global-property sidebar @mozilla.org/sidebar;1
--- a/suite/common/src/nsSuiteGlue.js
+++ b/suite/common/src/nsSuiteGlue.js
@@ -956,36 +956,45 @@ SuiteGlue.prototype = {
   classID: Components.ID("{bbbbe845-5a1b-40ee-813c-f84b8faaa07c}"),
 
   QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIObserver,
                                          Components.interfaces.nsISupportsWeakReference,
                                          Components.interfaces.nsISuiteGlue])
 
 }
 
-function GeolocationPrompt() {}
+function ContentPermissionPrompt() {}
 
-GeolocationPrompt.prototype = {
-  classID: Components.ID("{450a13bd-0d07-4e5d-a9f0-448c201728b1}"),
+ContentPermissionPrompt.prototype = {
+  classID: Components.ID("{9d4c845d-3f09-402a-b66d-50f291d7d50f}"),
 
-  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIGeolocationPrompt]),
+  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIContentPermissionPrompt]),
 
   prompt: function(aRequest)
   {
-    switch (Services.perms.testExactPermission(aRequest.requestingURI, "geo")) {
+    if (aRequest.type != "geolocation")
+      return;
+
+    var requestingURI = aRequest.uri;
+
+    // Ignore requests from non-nsIStandardURLs
+    if (!(requestingURI instanceof Components.interfaces.nsIStandardURL))
+      return;
+
+    switch (Services.perms.testExactPermission(requestingURI, "geo")) {
       case Services.perms.ALLOW_ACTION:
         aRequest.allow();
         return;
       case Services.perms.DENY_ACTION:
         aRequest.cancel();
         return;
     }
 
     var notificationBox =
-        aRequest.requestingWindow
+        aRequest.window
                 .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                 .getInterface(Components.interfaces.nsIWebNavigation)
                 .QueryInterface(Components.interfaces.nsIDocShell)
                 .chromeEventHandler.parentNode.wrappedJSObject;
 
     var notification = notificationBox.getNotificationWithValue("geolocation");
     if (!notification) {
       var notificationBundle =
@@ -994,36 +1003,36 @@ GeolocationPrompt.prototype = {
       var buttons =
           [{
             label: notificationBundle.GetStringFromName("geolocation.shareLocation"),
             accessKey: notificationBundle.GetStringFromName("geolocation.shareLocation.accesskey"),
             callback: function(notification) {
               // in tests, click can be fast enough that our hack hasn't set up the checkbox yet
               if (notification.getElementsByClassName("rememberChoice")[0] &&
                   notification.getElementsByClassName("rememberChoice")[0].checked)
-                Services.perms.add(aRequest.requestingURI, "geo",
+                Services.perms.add(requestingURI, "geo",
                                    Services.perms.ALLOW_ACTION);
               aRequest.allow();
             },
           }, {
             label: notificationBundle.GetStringFromName("geolocation.dontShareLocation"),
             accessKey: notificationBundle.GetStringFromName("geolocation.dontShareLocation.accesskey"),
             callback: function(notification) {
               // in tests, click can be fast enough that our hack hasn't set up the checkbox yet
               if (notification.getElementsByClassName("rememberChoice")[0] &&
                   notification.getElementsByClassName("rememberChoice")[0].checked)
-                Services.perms.add(aRequest.requestingURI, "geo",
+                Services.perms.add(requestingURI, "geo",
                                    Services.perms.DENY_ACTION);
               aRequest.cancel();
             },
           }];
 
       var message =
           notificationBundle.formatStringFromName("geolocation.siteWantsToKnow",
-                                                  [aRequest.requestingURI.spec], 1);
+                                                  [requestingURI.spec], 1);
       var newBar = notificationBox.appendNotification(message,
                                                       "geolocation",
                                                       "chrome://communicator/skin/icons/geo.png",
                                                       notificationBox.PRIORITY_INFO_HIGH,
                                                       buttons);
 
       // For whatever reason, if we do this immediately
       // (eg, without the setTimeout), the "link"
@@ -1048,9 +1057,9 @@ GeolocationPrompt.prototype = {
       };
 
       notificationBox.ownerDocument.defaultView.setTimeout(geolocation_hacks_to_notification, 0);
     }
   },
 };
 
 //module initialization
-var NSGetFactory = XPCOMUtils.generateNSGetFactory([SuiteGlue, GeolocationPrompt]);
+var NSGetFactory = XPCOMUtils.generateNSGetFactory([SuiteGlue, ContentPermissionPrompt]);