g element, or `null` if no match is found. */ findTriggerNode(e, localName) { let elements = [ e.explicitOriginalTarget, e.originalTarget.flattenedTreeParentNode, // Event might be in shadow DOM, check the host element. e.explicitOriginalTarget.flattenedTreeParentNode.getRootNode().host, e.originalTarget.flattenedTreeParentNode.getRootNode().host, ]; for (let el of elements) { if (el?.localName == localName) { return el; } } return null; } /** * Handle a command if it is a common one that is used in multiple pages. * Commands specific to a page should be handled in a subclass. * * @param {Event} e * The event to handle. */ handleCommandEvent(e) { switch (e.target.id) { case "sidebar-history-context-open-in-tab": this.topWindow.openTrustedLinkIn(this.triggerNode.url, "tab"); break; case "sidebar-history-context-forget-site": this.forgetAboutThisSite().catch(console.error); break; case "sidebar-history-context-open-in-window": case "sidebar-synced-tabs-context-open-in-window": this.topWindow.openTrustedLinkIn(this.triggerNode.url, "window", { private: false, }); break; case "sidebar-history-context-open-in-private-window": case "sidebar-synced-tabs-context-open-in-private-window": this.topWindow.openTrustedLinkIn(this.triggerNode.url, "window", { private: true, }); break; case "sidebar-history-context-copy-link": case "sidebar-synced-tabs-context-copy-link": lazy.BrowserUtils.copyLink( this.triggerNode.url, this.triggerNode.title ); break; case "sidebar-synced-tabs-context-bookmark-tab": case "sidebar-history-context-bookmark-page": this.topWindow.PlacesCommandHook.bookmarkLink( this.triggerNode.url, this.triggerNode.title ); break; } } async forgetAboutThisSite() { let host; if (PlacesUtils.nodeIsHost(this.triggerNode)) { host = this.triggerNode.query.domain; } else { host = Services.io.newURI(this.triggerNode.url).host; } let baseDomain; try { baseDomain = Services.eTLD.getBaseDomainFromHost(host); } catch (e) { // If there is no baseDomain we fall back to host } await this.topWindow.gDialogBox.open( "chrome://browser/content/places/clearDataForSite.xhtml", { host, hostOrBaseDomain: baseDomain ?? host } ); } /** * Clear out the document so the disconnectedCallback() will trigger properly * and all of the custom elements can cleanup. */ clearDocument() { this.ownerGlobal.document.body.textContent = ""; } /** * The common stylesheet for all sidebar pages. * * @returns {TemplateResult} */ stylesheet() { return html` `; } } PK