From 88e6200c78b934f5d0e14def9f17fffc579549b1 Mon Sep 17 00:00:00 2001 From: girst Date: Fri, 28 Jan 2022 15:02:41 +0100 Subject: [PATCH] Move contentAreaClick() to utils We use this opportunity to rename json to data, as per https://hg.mozilla.org/mozilla-central/rev/65905c6fcf34cd35ed433da3076eb8056b5d1a63 Note that we keep passing in the browser object, though. --- extension/lib/commands.coffee | 29 +---------------------------- extension/lib/utils.coffee | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/extension/lib/commands.coffee b/extension/lib/commands.coffee index 9c7f8da..ee91c29 100644 --- a/extension/lib/commands.coffee +++ b/extension/lib/commands.coffee @@ -16,10 +16,6 @@ translate = require('./translate') utils = require('./utils') viewportUtils = require('./viewport') -{PlacesUIUtils} = Cu.import('resource:///modules/PlacesUIUtils.jsm', {}) -{PrivateBrowsingUtils} = - Cu.import('resource://gre/modules/PrivateBrowsingUtils.jsm', {}) -{E10SUtils} = Cu.import('resource://gre/modules/E10SUtils.jsm', {}) {FORWARD, BACKWARD} = SelectionManager READER_VIEW_PREFIX = 'about:reader?url=' @@ -551,36 +547,13 @@ helper_follow_clickable = (options, args) -> vim._focusMarkerElement(elementIndex) if inTab - contentAreaClick = (json, browser) -> - # Note this function is shortened from the same-named one currently in - # mozilla-central/browser/actors/ClickHandlerParent.jsm. Keep in sync! - window = browser.ownerGlobal - params = { - charset: browser.characterSet, - referrerInfo: E10SUtils.deserializeReferrerInfo(json.referrerInfo), - allowMixedContent: json.allowMixedContent, # <=fx88 - isContentWindowPrivate: json.isContentWindowPrivate, - originPrincipal: json.originPrincipal, - originStoragePrincipal: json.originStoragePrincipal, - triggeringPrincipal: json.triggeringPrincipal, - csp: if json.csp then E10SUtils.deserializeCSP(json.csp) else null, - frameOuterWindowID: json.frameOuterWindowID, # <=fx79 - frameID: json.frameID, # >=fx80 - allowInheritPrincipal: true, - } - if json.originAttributes.userContextId - params.userContextId = json.originAttributes.userContextId - try if not PrivateBrowsingUtils.isWindowPrivate(window) - PlacesUIUtils.markPageAsFollowedLink(json.href) - window.openLinkIn(json.href, window.whereToOpenLink(json), params) - utils.nextTick(window, -> # `ContentClick.contentAreaClick` is what Firefox invokes when you click # 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) - contentAreaClick({ + utils.contentAreaClick({ href: marker.wrapper.href shiftKey: not inBackground ctrlKey: true diff --git a/extension/lib/utils.coffee b/extension/lib/utils.coffee index c0fa038..0064ebc 100644 --- a/extension/lib/utils.coffee +++ b/extension/lib/utils.coffee @@ -1,6 +1,10 @@ # This file contains lots of different helper functions. +{E10SUtils} = Cu.import('resource://gre/modules/E10SUtils.jsm', {}) {OS} = Components.utils.import('resource://gre/modules/osfile.jsm', {}) +{PlacesUIUtils} = Cu.import('resource:///modules/PlacesUIUtils.jsm', {}) +{PrivateBrowsingUtils} = + Cu.import('resource://gre/modules/PrivateBrowsingUtils.jsm', {}) nsIClipboardHelper = Cc['@mozilla.org/widget/clipboardhelper;1'] .getService(Ci.nsIClipboardHelper) @@ -303,6 +307,35 @@ onRemoved = (element, fn) -> return disconnect +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. + window = browser.ownerGlobal + + params = { + charset: browser.characterSet, + referrerInfo: E10SUtils.deserializeReferrerInfo(data.referrerInfo), + allowMixedContent: data.allowMixedContent, # <=fx88 + isContentWindowPrivate: data.isContentWindowPrivate, + originPrincipal: data.originPrincipal, + originStoragePrincipal: data.originStoragePrincipal, + triggeringPrincipal: data.triggeringPrincipal, + csp: if data.csp then E10SUtils.deserializeCSP(data.csp) else null, + frameOuterWindowID: data.frameOuterWindowID, # <=fx79 + frameID: data.frameID, # >=fx80 + allowInheritPrincipal: true, + } + + if data.originAttributes.userContextId + params.userContextId = data.originAttributes.userContextId + + try if not PrivateBrowsingUtils.isWindowPrivate(window) + PlacesUIUtils.markPageAsFollowedLink(data.href) + + window.openLinkIn(data.href, window.whereToOpenLink(data), params) + simulateMouseEvents = (element, sequence, browserOffset) -> window = element.ownerGlobal rect = element.getBoundingClientRect() @@ -765,6 +798,7 @@ module.exports = { listen listenOnce onRemoved + contentAreaClick simulateMouseEvents suppressEvent -- 2.39.3