Bug 605706 - Add desktop notifications to clearable list of permissions [r=mbrubeck]
authorMark Finkle <mfinkle@mozilla.com>
Fri, 28 Jan 2011 15:39:48 -0500
changeset 67327 c2f004eac2c8876ffbcc98bdf8e3e070a6afdd19
parent 67326 68b5825397ba173e2bacb622fb313d1beb5e616a
child 67328 f7c484c2cce59b2d175d0d375308523ff771a0cf
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)
reviewersmbrubeck
bugs605706
Bug 605706 - Add desktop notifications to clearable list of permissions [r=mbrubeck]
mobile/chrome/content/common-ui.js
mobile/components/ContentPermissionPrompt.js
mobile/locales/en-US/chrome/browser.properties
--- a/mobile/chrome/content/common-ui.js
+++ b/mobile/chrome/content/common-ui.js
@@ -160,18 +160,18 @@ var PageActions = {
     this._updateAttributes();
   },
 
   get _loginManager() {
     delete this._loginManager;
     return this._loginManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
   },
 
-  // This is easy for an addon to add his own perm type here
-  _permissions: ["popup", "offline-app", "geo"],
+  // Permissions we track in Page Actions
+  _permissions: ["popup", "offline-app", "geolocation", "desktop-notification"],
 
   _forEachPermissions: function _forEachPermissions(aHost, aCallback) {
     let pm = Services.perms;
     for (let i = 0; i < this._permissions.length; i++) {
       let type = this._permissions[i];
       if (!pm.testPermission(aHost, type))
         continue;
 
@@ -225,16 +225,20 @@ var PageActions = {
     aEvent.stopPropagation(); // Don't hide the site menu.
   },
 
   clearPagePermissions: function clearPagePermissions(aEvent) {
     let pm = Services.perms;
     let host = Browser.selectedBrowser.currentURI;
     this._forEachPermissions(host, function(aType) {
       pm.remove(host.asciiHost, aType);
+
+      // reset the 'remember' counter for permissions that support it
+      if (["geolocation", "desktop-notification"].indexOf(aType) != -1)
+        Services.contentPrefs.setPref(host.asciiHost, aType + ".request.remember", 0);
     });
 
     let lm = this._loginManager;
     if (!lm.getLoginSavingEnabled(host.prePath))
       lm.setLoginSavingEnabled(host.prePath, true);
 
     this.hideItem(aEvent.target);
     aEvent.stopPropagation(); // Don't hide the site menu.
--- a/mobile/components/ContentPermissionPrompt.js
+++ b/mobile/components/ContentPermissionPrompt.js
@@ -24,16 +24,18 @@ function setPagePermission(type, uri, al
     
   contentPrefs.setPref(uri, contentPrefName, count);
   if (count == kCountBeforeWeRemember)
     pm.add(uri, type, Ci.nsIPermissionManager.ALLOW_ACTION);
   else if (count == -kCountBeforeWeRemember)
     pm.add(uri, type, Ci.nsIPermissionManager.DENY_ACTION);
 }
 
+const kEntities = { "geolocation": "geolocation", "desktop-notification": "desktopNotification" };
+
 function ContentPermissionPrompt() {}
 
 ContentPermissionPrompt.prototype = {
   classID: Components.ID("{C6E8C44D-9F39-4AF7-BCC0-76E38A8310F5}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPermissionPrompt]),
 
   getChromeWindow: function getChromeWindow(aWindow) {
@@ -80,38 +82,40 @@ ContentPermissionPrompt.prototype = {
     let pm = Services.perms;
     let notificationBox = this.getNotificationBoxForRequest(request);
     let browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
     
     let notification = notificationBox.getNotificationWithValue(request.type);
     if (notification)
       return;
 
+    let entityName = kEntities[request.type];
+
     let buttons = [{
-      label: browserBundle.GetStringFromName(request.type + ".allow"),
+      label: browserBundle.GetStringFromName(entityName + ".allow"),
       accessKey: null,
       callback: function(notification) {
-                setPagePermission(request.type, request.uri, true);
-                request.allow();},
+        setPagePermission(request.type, request.uri, true);
+        request.allow();
+      }
     },
     {
-      label: browserBundle.GetStringFromName(request.type + ".dontAllow"),
+      label: browserBundle.GetStringFromName(entityName + ".dontAllow"),
       accessKey: null,
       callback: function(notification) {
-            setPagePermission(request.type, request.uri, false);
-            request.cancel();},
+        setPagePermission(request.type, request.uri, false);
+        request.cancel();
+      }
     }];
 
-    let message = browserBundle.formatStringFromName(request.type + ".siteWantsTo",
+    let message = browserBundle.formatStringFromName(entityName + ".siteWantsTo",
                                                      [request.uri.host], 1);
     let newBar = notificationBox.appendNotification(message,
                                                     request.type,
                                                     "", // Notifications in Fennec do not display images.
                                                     notificationBox.PRIORITY_WARNING_MEDIUM,
                                                     buttons);
-    return;
-  },
-
+  }
 };
 
 
 //module initialization
 const NSGetFactory = XPCOMUtils.generateNSGetFactory([ContentPermissionPrompt]);
--- a/mobile/locales/en-US/chrome/browser.properties
+++ b/mobile/locales/en-US/chrome/browser.properties
@@ -138,19 +138,19 @@ identity.unknown.tooltip=This web site d
 identity.ownerUnknown2=(unknown)
 
 # Geolocation UI
 geolocation.allow=Share
 geolocation.dontAllow=Don't share
 geolocation.siteWantsTo=%S wants your location.
 
 # Desktop notification UI
-desktop-notification.allow=Allow
-desktop-notification.dontAllow=Don't allow
-desktop-notification.siteWantsTo=%S wants use notifications.
+desktopNotification.allow=Allow
+desktopNotification.dontAllow=Don't allow
+desktopNotification.siteWantsTo=%S wants use notifications.
 
 # New Tab Popup
 # LOCALIZATION NOTE (newtabpopup): Semi-colon list of plural forms.
 # See: http://developer.mozilla.org/en/docs/Localization_and_Plurals
 # #1 number of tabs
 newtabpopup.opened=New tab opened;#1 new tabs opened
 
 # Error Console
@@ -186,20 +186,21 @@ tabs.crashReload=Reload tab
 # Homepage
 # LOCALIZATION NOTE: homepage.custom2 is the text displayed on the selector button if
 # the user selects a webpage to be the startpage. We can't display the entire URL
 # or webpage title on the menulist
 homepage.custom2=Custom Page
 
 # Page Actions
 pageactions.saveas.pdf=Save As PDF
-pageactions.geo=Location
+pageactions.geolocation=Location
 pageactions.popup=Popups
 pageactions.offline-app=Offline Storage
 pageactions.password=Password
+pageactions.desktop-notification=Web Notifications
 
 # Open Search
 opensearch.searchWith=Search With:
 opensearch.searchFor=Search for "%S"
 
 # Open in Another App
 # LOCALIZATION NOTE: openinapp.specific is the text displayed if there is a single external app
 # %S is the name of the app, like "YouTube" or "Picassa"