From 74ba1b9df0da15efabeaeecee83929b81ab02d75 Mon Sep 17 00:00:00 2001 From: girst Date: Sun, 25 Feb 2024 15:28:58 +0100 Subject: [PATCH] improve contentAreaClick This adds a few missing options used by BrowserUtils.whereToOpenLink, as well as finally passing CSP and ReferrerInfo. Unlike Mozilla, we call contentAreaClick directly from the parent process (they from ClickHandlerChild), so we don't need to serialize/deserialize these objects. However, they get CSP from event.originalTarget.ownerDocument and try to init ReferrerInfo from initWithNode(event.composedTarget), neither of which we have access to from the parent process. Note that referrerInfo.initWithDocument() was introduced with mozilla69: https://hg.mozilla.org/mozilla-central/rev/b5df2e6d8478cb4aea88d109259714ca2772b6cd#l1.29 --- extension/lib/commands.coffee | 13 ++++++++++--- extension/lib/utils.coffee | 10 +++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index 46e20da..85c7f15 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -549,19 +549,26 @@ helper_follow_clickable = (options, args) -> # links using the mouse. Using that instead of simply # `gBrowser.loadOneTab(url, options)` gives better interoperability with # other add-ons, such as Tree Style Tab and BackTrack Tab History. - reset = prefs.root.tmp('browser.tabs.loadInBackground', true) + referrerInfo = Cc['@mozilla.org/referrer-info;1'] + .createInstance(Ci.nsIReferrerInfo) + referrerInfo.initWithDocument(window.document) + loadInBackground = prefs.root.get('browser.tabs.loadInBackground') + utils.contentAreaClick({ href: marker.wrapper.href - shiftKey: not inBackground + shiftKey: inBackground != loadInBackground ctrlKey: true metaKey: true + altKey: false + button: 0 # primary + csp: window.document.csp + referrerInfo originAttributes: helper_add_user_context_id( vim.browser.ownerGlobal.gBrowser, window.document.nodePrincipal?.originAttributes ? {} ) triggeringPrincipal: window.document.nodePrincipal }, vim.browser) - reset() ) # The point of “clicking” scrollable elements is focusing them (which is diff --git a/extension/lib/utils.coffee b/extension/lib/utils.coffee index 650e18f..2c19847 100644 --- a/extension/lib/utils.coffee +++ b/extension/lib/utils.coffee @@ -1,7 +1,5 @@ # This file contains lots of different helper functions. -{E10SUtils} = ChromeUtils - .importESModule('resource://gre/modules/E10SUtils.sys.mjs') {PlacesUIUtils} = ChromeUtils .importESModule('resource:///modules/PlacesUIUtils.sys.mjs') {PrivateBrowsingUtils} = ChromeUtils @@ -311,17 +309,19 @@ contentAreaClick = (data, browser) -> # This function is adapted from the same-named one currently in # mozilla-central/browser/actors/ClickHandlerParent.jsm. Keep in sync! # Note: Our version is shortened substantially and unlike Mozilla, we pass in - # the browser object instead of extracting it from the browsingContext. + # the browser object instead of extracting it from the browsingContext. Also, + # our version is only invoked from the parent process, so we can pass + # data.csp and data.referrerInfo without calling the E10SUtils helpers. window = browser.ownerGlobal params = { charset: browser.characterSet, - referrerInfo: E10SUtils.deserializeReferrerInfo(data.referrerInfo), + referrerInfo: data.referrerInfo # passed unserialized isContentWindowPrivate: data.isContentWindowPrivate, originPrincipal: data.originPrincipal, originStoragePrincipal: data.originStoragePrincipal, triggeringPrincipal: data.triggeringPrincipal, - csp: if data.csp then E10SUtils.deserializeCSP(data.csp) else null, + csp: data.csp # passed unserialized frameID: data.frameID, allowInheritPrincipal: true, openerBrowser: browser, -- 2.39.3