Bug 1417238 - Hide container context menu when there are no items to display. r?Gijs
MozReview-Commit-ID: YxwMTzd0AH
--- 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