From 619fe7ec67d88a2649361d07fddda9946a069873 Mon Sep 17 00:00:00 2001 From: Masatoshi Kimura Date: Thu, 31 Mar 2022 13:27:52 +0000 Subject: [PATCH] Bug 1754805 - Add "Open in New Container Tab" to places context menu. r=mak,fluent-reviewers,mcheang Differential Revision: https://phabricator.services.mozilla.com/D138454 --- browser/components/places/PlacesUIUtils.jsm | 39 ++++++++++++++++--- .../places/content/bookmarksSidebar.xhtml | 1 + .../components/places/content/controller.js | 7 ++++ .../places/content/historySidebar.xhtml | 1 + .../components/places/content/places.xhtml | 1 + .../content/placesContextMenu.inc.xhtml | 9 +++++ .../browser_bookmark_context_menu_contents.js | 5 +++ browser/locales/en-US/browser/places.ftl | 3 ++ 8 files changed, 61 insertions(+), 5 deletions(-) diff --git a/browser/components/places/PlacesUIUtils.jsm b/browser/components/places/PlacesUIUtils.jsm index 3b0a2d87a8f9..9a67741b654f 100644 --- a/browser/components/places/PlacesUIUtils.jsm +++ b/browser/components/places/PlacesUIUtils.jsm @@ -1072,19 +1072,19 @@ var PlacesUIUtils = { * Where to open the URL. * @param {object} aView * The associated view of the node being opened. - * @param {boolean} aPrivate + * @param {boolean} private * True if the window being opened is private. */ - openNodeIn: function PUIU_openNodeIn(aNode, aWhere, aView, aPrivate) { + openNodeIn: function PUIU_openNodeIn(aNode, aWhere, aView, private) { let window = aView.ownerWindow; - this._openNodeIn(aNode, aWhere, window, aPrivate); + this._openNodeIn(aNode, aWhere, window, { private }); }, _openNodeIn: function PUIU__openNodeIn( aNode, aWhere, aWindow, - aPrivate = false + { private = false, userContextId = 0 } = {} ) { if ( aNode && @@ -1106,7 +1106,8 @@ var PlacesUIUtils = { allowPopups: isJavaScriptURL, inBackground: this.loadBookmarksInBackground, allowInheritPrincipal: isJavaScriptURL, - private: aPrivate, + private, + userContextId, }); } }, @@ -1536,6 +1537,12 @@ var PlacesUIUtils = { document.getElementById("placesContext_open:newprivatewindow").hidden = PrivateBrowsingUtils.isWindowPrivate(window) || !PrivateBrowsingUtils.enabled; + document.getElementById( + "placesContext_open:newcontainertab" + ).hidden = !Services.prefs.getBoolPref( + "privacy.userContext.enabled", + false + ); } event.target.ownerGlobal.updateCommands("places"); @@ -1581,6 +1588,28 @@ var PlacesUIUtils = { } }, + createContainerTabMenu(event) { + let window = event.target.ownerGlobal; + return window.createUserContextMenu(event, { isContextMenu: true }); + }, + + openInContainerTab(event) { + let userContextId = parseInt( + event.target.getAttribute("data-usercontextid") + ); + let triggerNode = this.lastContextMenuTriggerNode; + let isManaged = !!triggerNode.closest("#managed-bookmarks"); + if (isManaged) { + let window = triggerNode.ownerGlobal; + window.openTrustedLinkIn(triggerNode.link, "tab", { userContextId }); + return; + } + let view = this.getViewForNode(triggerNode); + this._openNodeIn(view.selectedNode, "tab", view.ownerWindow, { + userContextId, + }); + }, + openSelectionInTabs(event) { let isManaged = !!event.target.parentNode.triggerNode.closest( "#managed-bookmarks" diff --git a/browser/components/places/content/bookmarksSidebar.xhtml b/browser/components/places/content/bookmarksSidebar.xhtml index bdb9396731af..a7ce1a209cb0 100644 --- a/browser/components/places/content/bookmarksSidebar.xhtml +++ b/browser/components/places/content/bookmarksSidebar.xhtml @@ -4,6 +4,7 @@ - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> + diff --git a/browser/components/places/content/controller.js b/browser/components/places/content/controller.js index ffcb9973fe2b..8cb94954b54b 100644 --- a/browser/components/places/content/controller.js +++ b/browser/components/places/content/controller.js @@ -447,6 +447,13 @@ PlacesController.prototype = { return false; } + if ( + aMenuItem.hasAttribute("hide-if-usercontext-disabled") && + !Services.prefs.getBoolPref("privacy.userContext.enabled", false) + ) { + return false; + } + let selectiontype = aMenuItem.getAttribute("selection-type") || "single|multiple"; diff --git a/browser/components/places/content/historySidebar.xhtml b/browser/components/places/content/historySidebar.xhtml index f2599a462481..0d16a37701d5 100644 --- a/browser/components/places/content/historySidebar.xhtml +++ b/browser/components/places/content/historySidebar.xhtml @@ -4,6 +4,7 @@ - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> + diff --git a/browser/components/places/content/places.xhtml b/browser/components/places/content/places.xhtml index fe5a80a400da..e19a58029828 100644 --- a/browser/components/places/content/places.xhtml +++ b/browser/components/places/content/places.xhtml @@ -5,6 +5,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. + diff --git a/browser/components/places/content/placesContextMenu.inc.xhtml b/browser/components/places/content/placesContextMenu.inc.xhtml index 96bb4ab46d5d..0dc2e14119c0 100644 --- a/browser/components/places/content/placesContextMenu.inc.xhtml +++ b/browser/components/places/content/placesContextMenu.inc.xhtml @@ -27,6 +27,15 @@ data-l10n-id="places-open-in-tab" selection-type="single" node-type="link"/> + + + { add_task(async function test_bookmark_contextmenu_contents() { let optionItems = [ "placesContext_open:newtab", + "placesContext_open:newcontainertab", "placesContext_open:newwindow", "placesContext_open:newprivatewindow", "placesContext_show_bookmark:info", @@ -379,6 +380,7 @@ add_task(async function test_sidebar_multiple_folders_contextmenu_contents() { add_task(async function test_sidebar_bookmark_contextmenu_contents() { let optionItems = [ "placesContext_open:newtab", + "placesContext_open:newcontainertab", "placesContext_open:newwindow", "placesContext_open:newprivatewindow", "placesContext_show_bookmark:info", @@ -416,6 +418,7 @@ add_task(async function test_sidebar_bookmark_contextmenu_contents() { add_task(async function test_sidebar_bookmark_search_contextmenu_contents() { let optionItems = [ "placesContext_open:newtab", + "placesContext_open:newcontainertab", "placesContext_open:newwindow", "placesContext_open:newprivatewindow", "placesContext_showInFolder", @@ -458,6 +461,7 @@ add_task(async function test_library_bookmark_contextmenu_contents() { let optionItems = [ "placesContext_open", "placesContext_open:newtab", + "placesContext_open:newcontainertab", "placesContext_open:newwindow", "placesContext_open:newprivatewindow", "placesContext_deleteBookmark", @@ -492,6 +496,7 @@ add_task(async function test_library_bookmark_search_contextmenu_contents() { let optionItems = [ "placesContext_open", "placesContext_open:newtab", + "placesContext_open:newcontainertab", "placesContext_open:newwindow", "placesContext_open:newprivatewindow", "placesContext_showInFolder", diff --git a/browser/locales/en-US/browser/places.ftl b/browser/locales/en-US/browser/places.ftl index a3355610a384..6950f9a638ed 100644 --- a/browser/locales/en-US/browser/places.ftl +++ b/browser/locales/en-US/browser/places.ftl @@ -8,6 +8,9 @@ places-open = places-open-in-tab = .label = Open in New Tab .accesskey = w +places-open-in-container-tab = + .label = Open in New Container Tab + .accesskey = i places-open-all-bookmarks = .label = Open All Bookmarks .accesskey = O