Bug 1348257 - Hide the "always remember" checkbox for webrtc prompts in PBM. r=Nihanth, a=lizzard
authorJohann Hofmann <jhofmann@mozilla.com>
Tue, 28 Mar 2017 21:35:55 -0400
changeset 395498 93a70cd28ef91670a90a21c9553541c8d98d7027
parent 395497 59706edc8cc029bb443e8aa73195b2cea8b5c4f8
child 395499 a98117ea6bca00cf987acf75dc00461f3a57155f
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNihanth, lizzard
bugs1348257
milestone54.0a2
Bug 1348257 - Hide the "always remember" checkbox for webrtc prompts in PBM. r=Nihanth, a=lizzard It's important to not remember any user choices made in private mode (except the ones we specifically mention in the private browsing landing page). The original idea was to change the checkbox behavior to store the permission for session duration if in PBM, but this would actually be inconsistent with the other permission prompts which hide it completely. MozReview-Commit-ID: 8ioVmE4XefE
browser/modules/webrtcUI.jsm
--- a/browser/modules/webrtcUI.jsm
+++ b/browser/modules/webrtcUI.jsm
@@ -13,16 +13,18 @@ const Ci = Components.interfaces;
 Cu.import("resource:///modules/syncedtabs/EventEmitter.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
                                   "resource://gre/modules/AppConstants.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
                                   "resource://gre/modules/PluralForm.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
+                                  "resource://gre/modules/PrivateBrowsingUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Task",
                                   "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "SitePermissions",
                                   "resource:///modules/SitePermissions.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "gBrandBundle", function() {
   return Services.strings.createBundle("chrome://branding/locale/brand.properties");
 });
@@ -446,39 +448,19 @@ function prompt(aBrowser, aRequest) {
           SitePermissions.set(uri, sharingScreen ? "screen" : "camera",
                               SitePermissions.BLOCK, scope, notification.browser);
       }
     }
   ];
 
   let productName = gBrandBundle.GetStringFromName("brandShortName");
 
-  // Disable the permanent 'Allow' action if the connection isn't secure, or for
-  // screen/audio sharing (because we can't guess which window the user wants to
-  // share without prompting).
-  let reasonForNoPermanentAllow = "";
-  if (sharingScreen) {
-    reasonForNoPermanentAllow = "getUserMedia.reasonForNoPermanentAllow.screen2";
-  } else if (sharingAudio) {
-    reasonForNoPermanentAllow = "getUserMedia.reasonForNoPermanentAllow.audio";
-  } else if (!aRequest.secure) {
-    reasonForNoPermanentAllow = "getUserMedia.reasonForNoPermanentAllow.insecure";
-  }
-
   let options = {
     persistent: true,
     hideClose: !Services.prefs.getBoolPref("privacy.permissionPrompts.showCloseButton"),
-    checkbox: {
-      label: stringBundle.getString("getUserMedia.remember"),
-      checkedState: reasonForNoPermanentAllow ? {
-        disableMainAction: true,
-        warningLabel: stringBundle.getFormattedString(reasonForNoPermanentAllow,
-                                                      [productName])
-      } : undefined,
-    },
     eventCallback(aTopic, aNewBrowser) {
       if (aTopic == "swapping")
         return true;
 
       let doc = this.browser.ownerDocument;
 
       // Clean-up video streams of screensharing previews.
       if ((aTopic == "dismissed" || aTopic == "removed") &&
@@ -808,16 +790,41 @@ function prompt(aBrowser, aRequest) {
         mm.sendAsyncMessage("webrtc:Allow", {callID: aRequest.callID,
                                              windowID: aRequest.windowID,
                                              devices: allowedDevices});
       };
       return false;
     }
   };
 
+  // Don't offer "always remember" action in PB mode.
+  if (!PrivateBrowsingUtils.isBrowserPrivate(aBrowser)) {
+
+    // Disable the permanent 'Allow' action if the connection isn't secure, or for
+    // screen/audio sharing (because we can't guess which window the user wants to
+    // share without prompting).
+    let reasonForNoPermanentAllow = "";
+    if (sharingScreen) {
+      reasonForNoPermanentAllow = "getUserMedia.reasonForNoPermanentAllow.screen2";
+    } else if (sharingAudio) {
+      reasonForNoPermanentAllow = "getUserMedia.reasonForNoPermanentAllow.audio";
+    } else if (!aRequest.secure) {
+      reasonForNoPermanentAllow = "getUserMedia.reasonForNoPermanentAllow.insecure";
+    }
+
+    options.checkbox = {
+      label: stringBundle.getString("getUserMedia.remember"),
+      checkedState: reasonForNoPermanentAllow ? {
+        disableMainAction: true,
+        warningLabel: stringBundle.getFormattedString(reasonForNoPermanentAllow,
+                                                      [productName])
+      } : undefined,
+    };
+  }
+
   let iconType = "Devices";
   if (requestTypes.length == 1 && (requestTypes[0] == "Microphone" ||
                                    requestTypes[0] == "AudioCapture"))
     iconType = "Microphone";
   if (requestTypes.includes("Screen"))
     iconType = "Screen";
   let anchorId = "webRTC-share" + iconType + "-notification-icon";