Bug 1297475 - Have FlyWeb publish server permission prompt use ContentPermissionIntegration. r?justindarc draft
authorMike Conley <mconley@mozilla.com>
Wed, 31 Aug 2016 23:59:18 -0400
changeset 416140 af2a8fb265a74732ffabc30c1fa98fcf4061fc35
parent 416139 ccc00fceefb0472a4f4d14266fc59324a21f4a55
child 531761 35eba0fa002ddc079fc741acc1c9b58eea145b03
push id30036
push usermconley@mozilla.com
push dateWed, 21 Sep 2016 14:50:38 +0000
reviewersjustindarc
bugs1297475
milestone51.0a1
Bug 1297475 - Have FlyWeb publish server permission prompt use ContentPermissionIntegration. r?justindarc MozReview-Commit-ID: Sh0IBn78fB
browser/extensions/flyweb/bootstrap.js
browser/locales/en-US/chrome/browser/browser.properties
--- a/browser/extensions/flyweb/bootstrap.js
+++ b/browser/extensions/flyweb/bootstrap.js
@@ -8,16 +8,20 @@ const {classes: Cc, interfaces: Ci, util
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI",
                                   "resource:///modules/CustomizableUI.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Console",
                                   "resource://gre/modules/Console.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
                                   "resource://gre/modules/Services.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Integration",
+                                  "resource://gre/modules/Integration.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PermissionUI",
+                                  "resource:///modules/PermissionUI.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "gFlyWebBundle", function() {
   const tns = {
     "flyweb-button.label": "FlyWeb",
     "flyweb-button.tooltiptext": "Discover nearby FlyWeb services",
     "flyweb-items-empty": "There are no FlyWeb services currently nearby"
   };
   return {
@@ -109,16 +113,85 @@ class DiscoveryManager {
     if (!this._id || !this._callback) {
       return;
     }
 
     this._callback(services);
   }
 }
 
+const FlyWebPermissionPromptIntegration = (base) => ({
+  __proto__: base,
+  createPermissionPrompt(type, request) {
+    if (type != "flyweb-publish-server") {
+      return super.createPermissionPrompt(...arguments);
+    }
+
+    return {
+      __proto__: PermissionUI.PermissionPromptForRequestPrototype,
+      get request() {
+        return request;
+      },
+      get permissionKey() {
+        return "flyweb-publish-server";
+      },
+      get popupOptions() {
+        return {
+          learnMoreURL: "https://flyweb.github.io",
+          popupIconURL: "chrome://flyweb/skin/icon-64.png",
+        };
+      },
+      get notificationID() {
+        return "flyweb-publish-server";
+      },
+      get anchorID() {
+        const kAnchorID = "flyweb-publish-server-notification-icon";
+        let chromeDoc = this.browser.ownerDocument;
+        let anchor = chromeDoc.getElementById(kAnchorID);
+        if (!anchor) {
+          let notificationPopupBox =
+            chromeDoc.getElementById("notification-popup-box");
+          let notificationIcon = chromeDoc.createElement("image");
+          notificationIcon.id = kAnchorID;
+          notificationIcon.setAttribute("src",
+                                        "chrome://flyweb/skin/icon-64.png");
+          notificationIcon.classList.add("notification-anchor-icon");
+          notificationIcon.setAttribute("role", "button");
+          notificationIcon.setAttribute("aria-label",
+                                        "View the publish-server request");
+          notificationIcon.style.filter =
+            "url('chrome://browser/skin/filters.svg#fill')";
+          notificationIcon.style.fill = "currentcolor";
+          notificationIcon.style.opacity = "0.4";
+          notificationPopupBox.appendChild(notificationIcon);
+        }
+
+        return kAnchorID;
+      },
+      get message() {
+        return "Would you like to let this site start a server accessible " +
+               "to nearby devices and people?";
+      },
+      get promptActions() {
+        return [{
+          label: "Allow Server",
+          accessKey: "A",
+          action: Ci.nsIPermissionManager.ALLOW_ACTION,
+          expireType:  Ci.nsIPermissionManager.EXPIRE_SESSION,
+        }, {
+          label: "Block Server",
+          accessKey: "B",
+          action: Ci.nsIPermissionManager.DENY_ACTION,
+          expireType: Ci.nsIPermissionManager.EXPIRE_SESSION,
+        }];
+      },
+    };
+  },
+});
+
 let FlyWebView = {
   init() {
     // Create widget and add it to the menu panel.
     CustomizableUI.createWidget({
       id: "flyweb-button",
       type: "view",
       viewId: "flyweb-panel",
       label: gFlyWebBundle.GetStringFromName("flyweb-button.label"),
@@ -201,19 +274,25 @@ let FlyWebView = {
         if (aEvent.type === "command") {
           let serviceId = aEvent.target.getAttribute("data-service-id");
           gDiscoveryManagerInstance.pairWith(serviceId, (service) => {
             aEvent.view.openUILinkIn(service.uiUrl, "tab");
           });
         }
       }
     });
+
+    Integration.contentPermission
+               .register(FlyWebPermissionPromptIntegration);
   },
 
   uninit() {
     CustomizableUI.destroyWidget("flyweb-button");
 
     if (gDiscoveryManagerInstance) {
       gDiscoveryManagerInstance.destroy();
       gDiscoveryManagerInstance = null;
     }
+
+    Integration.contentPermission
+               .unregister(FlyWebPermissionPromptIntegration);
   }
 };
--- a/browser/locales/en-US/chrome/browser/browser.properties
+++ b/browser/locales/en-US/chrome/browser/browser.properties
@@ -373,26 +373,16 @@ geolocation.shareLocation=Share Location
 geolocation.shareLocation.accesskey=a
 geolocation.alwaysShareLocation=Always Share Location
 geolocation.alwaysShareLocation.accesskey=A
 geolocation.neverShareLocation=Never Share Location
 geolocation.neverShareLocation.accesskey=N
 geolocation.shareWithSite2=Would you like to share your location with this site?
 geolocation.shareWithFile2=Would you like to share your location with this file?
 
-# FlyWeb UI
-# LOCALIZATION NOTE (flyWebPublishServer.allowPublishServer): This is an experimental feature only shipping in Nightly, and doesn't need translation.
-flyWebPublishServer.allowPublishServer=Allow Server
-# LOCALIZATION NOTE (flyWebPublishServer.allowPublishServer.accessKey): This is an experimental feature only shipping in Nightly, and doesn't need translation.
-flyWebPublishServer.allowPublishServer.accesskey=A
-# LOCALIZATION NOTE (flyWebPublishServer.denyPublishServer): This is an experimental feature only shipping in Nightly, and doesn't need translation.
-flyWebPublishServer.denyPublishServer=Block Server
-# LOCALIZATION NOTE (flyWebPublishServer.denyPublishServer.accessKey): This is an experimental feature only shipping in Nightly, and doesn't need translation.
-flyWebPublishServer.denyPublishServer.accesskey=B
-
 webNotifications.receiveForSession=Receive for this session
 webNotifications.receiveForSession.accesskey=s
 webNotifications.alwaysReceive=Always Receive Notifications
 webNotifications.alwaysReceive.accesskey=A
 webNotifications.neverShow=Always Block Notifications
 webNotifications.neverShow.accesskey=N
 webNotifications.receiveFromSite=Would you like to receive notifications from this site?
 # LOCALIZATION NOTE (webNotifications.upgradeTitle): When using native notifications on OS X, the title may be truncated around 32 characters.