Bug 1233886 - "fix up new tab button call to createCodebasePrincipal to use default user context" []
MozReview-Commit-ID: FP5WzSMOVeY
--- a/browser/base/content/browser-context.inc
+++ b/browser/base/content/browser-context.inc
@@ -59,30 +59,18 @@
accesskey="&openLinkCmdInTab.accesskey;"
usercontextid="0"
oncommand="gContextMenu.openLinkInTab(event);"/>
<menu id="context-openlinkinusercontext-menu"
label="&openLinkCmdInContainerTab.label;"
accesskey="&openLinkCmdInContainerTab.accesskey;"
hidden="true">
- <menupopup oncommand="gContextMenu.openLinkInTab(event);">
- <menuitem label="&userContextPersonal.label;"
- usercontextid="1"
- accesskey="&userContextPersonal.accesskey;"/>
- <menuitem label="&userContextWork.label;"
- usercontextid="2"
- accesskey="&userContextWork.accesskey;"/>
- <menuitem label="&userContextBanking.label;"
- usercontextid="3"
- accesskey="&userContextBanking.accesskey;"/>
- <menuitem label="&userContextShopping.label;"
- usercontextid="4"
- accesskey="&userContextShopping.accesskey;"/>
- </menupopup>
+ <menupopup oncommand="gContextMenu.openLinkInTab(event);"
+ onpopupshowing="return createUserContextMenu(event, false);" />
</menu>
<menuitem id="context-openlink"
label="&openLinkCmd.label;"
accesskey="&openLinkCmd.accesskey;"
oncommand="gContextMenu.openLink();"/>
<menuitem id="context-openlinkprivate"
label="&openLinkInPrivateWindowCmd.label;"
--- a/browser/base/content/browser-menubar.inc
+++ b/browser/base/content/browser-menubar.inc
@@ -17,42 +17,17 @@
label="&tabCmd.label;"
command="cmd_newNavigatorTab"
key="key_newNavigatorTab"
accesskey="&tabCmd.accesskey;"/>
<menu id="menu_newUserContext"
label="&newUserContext.label;"
accesskey="&newUserContext.accesskey;"
hidden="true">
- <menupopup>
- <menuitem id="menu_newUserContextTabPersonal"
- usercontextid="1"
- class="menuitem-iconic"
- label="&userContextPersonal.label;"
- command="Browser:NewUserContextTab"
- accesskey="&userContextPersonal.accesskey;"/>
- <menuitem id="menu_newUserContextTabWork"
- usercontextid="2"
- class="menuitem-iconic"
- label="&userContextWork.label;"
- command="Browser:NewUserContextTab"
- accesskey="&userContextWork.accesskey;"/>
- <menuitem id="menu_newUserContextTabBanking"
- usercontextid="3"
- class="menuitem-iconic"
- label="&userContextBanking.label;"
- command="Browser:NewUserContextTab"
- accesskey="&userContextBanking.accesskey;"/>
- <menuitem id="menu_newUserContextTabShopping"
- usercontextid="4"
- class="menuitem-iconic"
- label="&userContextShopping.label;"
- command="Browser:NewUserContextTab"
- accesskey="&userContextShopping.accesskey;"/>
- </menupopup>
+ <menupopup onpopupshowing="return createUserContextMenu(event);" />
</menu>
<menuitem id="menu_newNavigator"
label="&newNavigatorCmd.label;"
accesskey="&newNavigatorCmd.accesskey;"
key="key_newNavigator"
command="cmd_newNavigator"/>
<menuitem id="menu_newPrivateWindow"
label="&newPrivateWindow.label;"
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -609,17 +609,25 @@
command="cmd_newNavigatorTab"
onclick="checkForMiddleClick(this, event);"
tooltip="dynamic-shortcut-tooltip"
ondrop="newTabButtonObserver.onDrop(event)"
ondragover="newTabButtonObserver.onDragOver(event)"
ondragenter="newTabButtonObserver.onDragOver(event)"
ondragexit="newTabButtonObserver.onDragExit(event)"
cui-areatype="toolbar"
- removable="true"/>
+ removable="true">
+<!--
+ We don't set type="menu-button" by default because we are not shipping
+ "containers" yet (bug 1191418), so more likely the following menu will not be
+ shown.
+-->
+ <menupopup anonid="tabs-newtab-menupopup"
+ onpopupshowing="return createUserContextMenu(event);" />
+ </toolbarbutton>
<toolbarbutton id="alltabs-button"
class="toolbarbutton-1 chromeclass-toolbar-additional tabs-alltabs-button"
type="menu"
label="&listAllTabs.label;"
tooltiptext="&listAllTabs.label;"
removable="false">
<menupopup id="alltabs-popup"
--- a/browser/base/content/tabbrowser.xml
+++ b/browser/base/content/tabbrowser.xml
@@ -4861,23 +4861,31 @@
-->
<children/>
<xul:toolbarbutton class="tabs-newtab-button"
anonid="tabs-newtab-button"
command="cmd_newNavigatorTab"
onclick="checkForMiddleClick(this, event);"
onmouseover="document.getBindingParent(this)._enterNewTab();"
onmouseout="document.getBindingParent(this)._leaveNewTab();"
- tooltip="dynamic-shortcut-tooltip"/>
+ tooltip="dynamic-shortcut-tooltip">
+<!--
+ We don't set type="menu-button" by default because we are not shipping
+ "containers" yet (bug 1191418), so more likely the following menu will not be
+ shown.
+-->
+ <xul:menupopup anonid="tabs-newtab-menupopup"
+ onpopupshowing="return createUserContextMenu(event);" />
+ </xul:toolbarbutton>
<xul:spacer class="closing-tabs-spacer" anonid="closing-tabs-spacer"
style="width: 0;"/>
</xul:arrowscrollbox>
</content>
- <implementation implements="nsIDOMEventListener">
+ <implementation implements="nsIDOMEventListener, nsIObserver">
<constructor>
<![CDATA[
this.mTabClipWidth = Services.prefs.getIntPref("browser.tabs.tabClipWidth");
var tab = this.firstChild;
tab.label = this.tabbrowser.mStringBundle.getString("tabs.emptyTabTitle");
tab.setAttribute("crop", "end");
tab.setAttribute("onerror", "this.removeAttribute('image');");
@@ -4886,19 +4894,28 @@
window.addEventListener("load", this, false);
try {
this._tabAnimationLoggingEnabled = Services.prefs.getBoolPref("browser.tabs.animationLogging.enabled");
} catch (ex) {
this._tabAnimationLoggingEnabled = false;
}
this._browserNewtabpageEnabled = Services.prefs.getBoolPref("browser.newtabpage.enabled");
+
+ Services.prefs.addObserver("privacy.userContext.enabled", this, false);
+ this._updateNewTabButton();
]]>
</constructor>
+ <destructor>
+ <![CDATA[
+ Services.prefs.removeObserver("privacy.userContext.enabled", this);
+ ]]>
+ </destructor>
+
<field name="tabbrowser" readonly="true">
document.getElementById(this.getAttribute("tabbrowser"));
</field>
<field name="tabbox" readonly="true">
this.tabbrowser.mTabBox;
</field>
@@ -5616,16 +5633,48 @@
let preview = this._browserNewtabpageEnabled ? "_PREVIEW" : "";
Services.telemetry.getHistogramById("FX_TAB_ANIM_OPEN" + preview + "_FRAME_INTERVAL_MS").add(averageInterval);
}
}
]]>
</body>
</method>
+ <method name="_updateNewTabButton">
+ <body>
+ <![CDATA[
+ let underflowButton = document.getAnonymousElementByAttribute(this, "anonid", "tabs-newtab-button");
+ let customizableButton = document.getElementById("new-tab-button");
+
+ let visible = Services.prefs.getBoolPref("privacy.userContext.enabled");
+ if (visible) {
+ underflowButton.setAttribute('type', 'menu-button');
+ customizableButton.setAttribute('type', 'menu-button');
+ } else {
+ underflowButton.removeAttribute('type');
+ customizableButton.removeAttribute('type');
+ }
+ ]]>
+ </body>
+ </method>
+
+ <method name="observe">
+ <parameter name="aSubject"/>
+ <parameter name="aTopic"/>
+ <parameter name="aData"/>
+ <body><![CDATA[
+ switch(aTopic) {
+ case "nsPref:changed":
+ // privacy.userContext.enabled is the only pref observed.
+ this._updateNewTabButton();
+ break;
+ }
+ ]]></body>
+ </method>
+
<!-- Deprecated stuff, implemented for backwards compatibility. -->
<property name="mAllTabsPopup" readonly="true"
onget="return document.getElementById('alltabs-popup');"/>
</implementation>
<handlers>
<handler event="TabSelect" action="this._handleTabSelect();"/>
--- a/browser/base/content/utilityOverlay.js
+++ b/browser/base/content/utilityOverlay.js
@@ -398,16 +398,68 @@ function checkForMiddleClick(node, event
fn.call(target, event);
// If the middle-click was on part of a menu, close the menu.
// (Menus close automatically with left-click but not with middle-click.)
closeMenus(event.target);
}
}
+// Populate a menu with user-context menu items. This method should be called
+// by onpopupshowing passing the event as first argument. addCommandAttribute
+// param is used to set the 'command' attribute in the new menuitem elements.
+function createUserContextMenu(event, addCommandAttribute = true) {
+ if (event.target.hasChildNodes()) {
+ return true;
+ }
+
+ let userContextItems = [
+ { id: "menu_newUserContextTabPersonal",
+ userContextId: 1,
+ label: "userContextPersonal.label",
+ accessKey: "userContextPersonal.accesskey" },
+ { id: "menu_newUserContextTabWork",
+ userContextId: 2,
+ label: "userContextWork.label",
+ accessKey: "userContextWork.accesskey" },
+ { id: "menu_newUserContextTabBanking",
+ userContextId: 3,
+ label: "userContextBanking.label",
+ accessKey: "userContextBanking.accesskey" },
+ { id: "menu_newUserContextTabShopping",
+ userContextId: 4,
+ label: "userContextShopping.label",
+ accessKey: "userContextShopping.accesskey" },
+ ];
+
+ let bundle = document.getElementById("bundle_browser");
+ if (!bundle) {
+ return false;
+ }
+
+ let docfrag = document.createDocumentFragment();
+
+ for (let item of userContextItems) {
+ let menuitem = document.createElement("menuitem");
+ menuitem.setAttribute("id", item.id);
+ menuitem.setAttribute("usercontextid", item.userContextId);
+ menuitem.setAttribute("label", bundle.getString(item.label));
+ menuitem.setAttribute("accesskey", bundle.getString(item.accessKey));
+
+ if (addCommandAttribute) {
+ menuitem.setAttribute("command", "Browser:NewUserContextTab");
+ }
+
+ docfrag.appendChild(menuitem);
+ }
+
+ event.target.appendChild(docfrag);
+ return true;
+}
+
// Closes all popups that are ancestors of the node.
function closeMenus(node)
{
if ("tagName" in node) {
if (node.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
&& (node.tagName == "menupopup" || node.tagName == "popup"))
node.hidePopup();
--- a/browser/locales/en-US/chrome/browser/browser.dtd
+++ b/browser/locales/en-US/chrome/browser/browser.dtd
@@ -256,24 +256,16 @@ These should match what Safari and other
<!ENTITY inspectContextMenu.label "Inspect Element">
<!ENTITY inspectContextMenu.accesskey "Q">
<!ENTITY fileMenu.label "File">
<!ENTITY fileMenu.accesskey "F">
<!ENTITY newUserContext.label "New Container Tab">
<!ENTITY newUserContext.accesskey "C">
-<!ENTITY userContextPersonal.label "Personal">
-<!ENTITY userContextPersonal.accesskey "P">
-<!ENTITY userContextWork.label "Work">
-<!ENTITY userContextWork.accesskey "W">
-<!ENTITY userContextBanking.label "Banking">
-<!ENTITY userContextBanking.accesskey "B">
-<!ENTITY userContextShopping.label "Shopping">
-<!ENTITY userContextShopping.accesskey "S">
<!ENTITY newNavigatorCmd.label "New Window">
<!ENTITY newNavigatorCmd.key "N">
<!ENTITY newNavigatorCmd.accesskey "N">
<!ENTITY newPrivateWindow.label "New Private Window">
<!ENTITY newPrivateWindow.accesskey "W">
<!ENTITY newNonRemoteWindow.label "New Non-e10s Window">
<!ENTITY editMenu.label "Edit">
--- a/browser/locales/en-US/chrome/browser/browser.properties
+++ b/browser/locales/en-US/chrome/browser/browser.properties
@@ -761,8 +761,17 @@ tabgroups.migration.anonGroup = Group %S
tabgroups.migration.tabGroupBookmarkFolderName = Bookmarked Tab Groups
decoder.noCodecs.button = Learn how
decoder.noCodecs.accesskey = L
decoder.noCodecs.message = To play video, you may need to install Microsoft’s Media Feature Pack.
decoder.noCodecsXP.message = To play video, you may need to enable Adobe’s Primetime Content Decryption Module.
decoder.noCodecsLinux.message = To play video, you may need to install the required video codecs.
decoder.noHWAcceleration.message = To improve video quality, you may need to install Microsoft’s Media Feature Pack.
+
+userContextPersonal.label = Personal
+userContextPersonal.accesskey = P
+userContextWork.label = Work
+userContextWork.accesskey = W
+userContextBanking.label = Banking
+userContextBanking.accesskey = B
+userContextShopping.label = Shopping
+userContextShopping.accesskey = S