Bug 1936231 - Remove inline event handlers from placesContext menu. r=places-reviewers,mak

Differential Revision: https://phabricator.services.mozilla.com/D231703
This commit is contained in:
Tom Schuster
2024-12-13 14:24:24 +00:00
parent 4530e94e83
commit 4f3940189e
4 changed files with 53 additions and 13 deletions

View File

@@ -1392,7 +1392,7 @@ export var PlacesUIUtils = {
let menupopup = event.target;
if (menupopup.id != "placesContext") {
// Ignore any popupshowing events from submenus
return true;
return;
}
PlacesUIUtils.lastContextMenuTriggerNode = menupopup.triggerNode;
@@ -1417,21 +1417,23 @@ export var PlacesUIUtils = {
let isManaged = !!menupopup.triggerNode.closest("#managed-bookmarks");
if (isManaged) {
this.managedPlacesContextShowing(event);
return true;
return;
}
menupopup._view = this.getViewForNode(menupopup.triggerNode);
if (!menupopup._view) {
// This can happen if we try to invoke the context menu on
// an uninitialized places toolbar. Just bail out:
event.preventDefault();
return false;
return;
}
if (!this.openInTabClosesMenu) {
menupopup.ownerDocument
.getElementById("placesContext_open:newtab")
.setAttribute("closemenu", "single");
}
return menupopup._view.buildContextMenu(menupopup);
if (!menupopup._view.buildContextMenu(menupopup)) {
event.preventDefault();
}
},
placesContextHiding(event) {

View File

@@ -2,9 +2,9 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
<menupopup id="placesContext"
onpopupshowing="return PlacesUIUtils.placesContextShowing(event);"
onpopuphiding="PlacesUIUtils.placesContextHiding(event);">
<menupopup id="placesContext">
<script src="chrome://browser/content/places/placesContextMenu.js" />
<menuitem id="placesContext_open"
command="placesCmd_open"
data-l10n-id="places-open"
@@ -13,12 +13,10 @@
node-type="link"
hide-if-single-click-opens="true"/>
<menuitem id="placesContext_openBookmarkContainer:tabs"
oncommand="PlacesUIUtils.openSelectionInTabs(event);"
data-l10n-id="places-open-all-bookmarks"
selection-type="single|none"
node-type="folder|query_tag"/>
<menuitem id="placesContext_openBookmarkLinks:tabs"
oncommand="PlacesUIUtils.openSelectionInTabs(event);"
data-l10n-id="places-open-all-bookmarks"
selection-type="multiple"
node-type="link_bookmark|separator"/>
@@ -33,17 +31,14 @@
node-type="link"
hide-if-private-browsing="true"
hide-if-usercontext-disabled="true">
<menupopup oncommand="PlacesUIUtils.openInContainerTab(event);"
onpopupshowing="return PlacesUIUtils.createContainerTabMenu(event);" />
<menupopup id="placesContext_open_newcontainertab_popup"/>
</menu>
<menuitem id="placesContext_openContainer:tabs"
oncommand="PlacesUIUtils.openSelectionInTabs(event);"
data-l10n-id="places-open-all-in-tabs"
selection-type="single|none"
node-type="query"
hide-if-node-type="query_tag"/>
<menuitem id="placesContext_openLinks:tabs"
oncommand="PlacesUIUtils.openSelectionInTabs(event);"
data-l10n-id="places-open-all-in-tabs"
selection-type="multiple"
node-type="link"

View File

@@ -0,0 +1,42 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint-env mozilla/browser-window */
document.addEventListener(
"DOMContentLoaded",
() => {
const placesContext = document.getElementById("placesContext");
placesContext.addEventListener("popupshowing", event =>
PlacesUIUtils.placesContextShowing(event)
);
placesContext.addEventListener("popuphiding", event =>
PlacesUIUtils.placesContextHiding(event)
);
placesContext.addEventListener("command", event => {
switch (event.target.id) {
case "placesContext_openBookmarkContainer:tabs":
case "placesContext_openBookmarkLinks:tabs":
case "placesContext_openContainer:tabs":
case "placesContext_openLinks:tabs":
PlacesUIUtils.openSelectionInTabs(event);
break;
}
});
const containerPopup = document.getElementById(
"placesContext_open_newcontainertab_popup"
);
containerPopup.addEventListener("command", event =>
PlacesUIUtils.openInContainerTab(event)
);
containerPopup.addEventListener("popupshowing", event =>
PlacesUIUtils.createContainerTabMenu(event)
);
},
{ once: true }
);

View File

@@ -21,6 +21,7 @@ browser.jar:
* content/browser/places/bookmarksSidebar.xhtml (content/bookmarksSidebar.xhtml)
content/browser/places/bookmarksSidebar.js (content/bookmarksSidebar.js)
content/browser/places/editBookmark.js (content/editBookmark.js)
content/browser/places/placesContextMenu.js (content/placesContextMenu.js)
#ifdef NIGHTLY_BUILD
content/browser/places/interactionsViewer.css (metadataViewer/interactionsViewer.css)
content/browser/places/interactionsViewer.html (metadataViewer/interactionsViewer.html)