Bug 1417238 - Hide container context menu when there are no items to display. r?Gijs draft
authorJonathan Kingston <jkt@mozilla.com>
Tue, 26 Dec 2017 18:31:05 +0000
changeset 714602 9207d382cbc00f8859f73516645f348f69b81b64
parent 714124 0843e4e6cb1d6e32a35ce4d7014bd250c24f74fa
child 744625 6ebac30b8a73574d5bf92bb7ea609d40d343b606
push id93962
push userbmo:jkt@mozilla.com
push dateTue, 26 Dec 2017 18:31:33 +0000
reviewersGijs
bugs1417238
milestone59.0a1
Bug 1417238 - Hide container context menu when there are no items to display. r?Gijs MozReview-Commit-ID: YxwMTzd0AH
browser/base/content/nsContextMenu.js
browser/base/content/test/general/browser_contextmenu.js
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -349,17 +349,18 @@ nsContextMenu.prototype = {
         ContextualIdentityService.getUserContextLabel(gContextMenuContentData.userContextId);
       item.setAttribute("label",
          gBrowserBundle.formatStringFromName("userContextOpenLink.label",
                                              [label], 1));
     }
 
     var shouldShow = this.onSaveableLink || isMailtoInternal || this.onPlainTextLink;
     var isWindowPrivate = PrivateBrowsingUtils.isWindowPrivate(window);
-    var showContainers = Services.prefs.getBoolPref("privacy.userContext.enabled");
+    var showContainers = Services.prefs.getBoolPref("privacy.userContext.enabled")
+                         && ContextualIdentityService.getPublicIdentities().length;
     this.showItem("context-openlink", shouldShow && !isWindowPrivate);
     this.showItem("context-openlinkprivate", shouldShow);
     this.showItem("context-openlinkintab", shouldShow && !inContainer);
     this.showItem("context-openlinkincontainertab", shouldShow && inContainer);
     this.showItem("context-openlinkinusercontext-menu", shouldShow && !isWindowPrivate && showContainers);
     this.showItem("context-openlinkincurrent", this.onPlainTextLink);
     this.showItem("context-sep-open", shouldShow);
   },
--- a/browser/base/content/test/general/browser_contextmenu.js
+++ b/browser/base/content/test/general/browser_contextmenu.js
@@ -6,17 +6,18 @@ let LOGIN_FILL_ITEMS = [
   "fill-login", null,
     [
       "fill-login-no-logins", false,
       "---", null,
       "fill-login-saved-passwords", true
     ], null,
 ];
 let hasPocket = Services.prefs.getBoolPref("extensions.pocket.enabled");
-let hasContainers = Services.prefs.getBoolPref("privacy.userContext.enabled");
+let hasContainers = Services.prefs.getBoolPref("privacy.userContext.enabled")
+                    && ContextualIdentityService.getPublicIdentities().length;
 
 const example_base = "http://example.com/browser/browser/base/content/test/general/";
 const chrome_base = "chrome://mochitests/content/browser/browser/base/content/test/general/";
 
 /* import-globals-from contextmenu_common.js */
 Services.scriptloader.loadSubScript(chrome_base + "contextmenu_common.js", this);
 
 // Below are test cases for XUL element