From bad1506f2084401fc12b7dd16d7b81b9c9b818e8 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 16 Jul 2021 10:29:39 -0400 Subject: [PATCH] Move chromium-specific code path to chromium directory --- platform/chromium/vapi-background-ext.js | 53 ++++++++++++++++++++---- platform/common/vapi-background.js | 44 -------------------- 2 files changed, 46 insertions(+), 51 deletions(-) diff --git a/platform/chromium/vapi-background-ext.js b/platform/chromium/vapi-background-ext.js index 66a7d2689..690c941ae 100644 --- a/platform/chromium/vapi-background-ext.js +++ b/platform/chromium/vapi-background-ext.js @@ -25,10 +25,52 @@ /******************************************************************************/ -(( ) => { - // https://github.com/uBlockOrigin/uBlock-issues/issues/407 - if ( vAPI.webextFlavor.soup.has('chromium') === false ) { return; } +// https://github.com/uBlockOrigin/uBlock-issues/issues/1659 +// Chromium fails to dispatch onCreatedNavigationTarget() events sometimes, +// so we synthetize these missing events when this happens. +vAPI.Tabs = class extends vAPI.Tabs { + constructor() { + super(); + this.tabIds = new Set(); + browser.tabs.onCreated.addListener(tab => { + this.onCreatedHandler(tab); + }); + } + onCreatedHandler(tab) { + if ( typeof tab.openerTabId === 'number' ) { return; } + if ( tab.index !== 0 ) { return; } + if ( tab.url !== '' ) { return; } + this.tabIds.add(tab.id); + } + onCreatedNavigationTargetHandler(details) { + this.tabIds.delete(details.tabId); + super.onCreatedNavigationTargetHandler(details); + } + onCommittedHandler(details) { + if ( details.frameId === 0 && this.tabIds.has(details.tabId) ) { + this.tabIds.delete(details.tabId); + webext.tabs.get(details.tabId).then(tab => { + if ( tab === null ) { return; } + this.onCreatedNavigationTargetHandler({ + tabId: tab.id, + sourceTabId: tab.id, + sourceFrameId: 0, + url: tab.url, + }); + }); + } + super.onCommittedHandler(details); + } + onRemovedHandler(tabId, details) { + this.tabIds.delete(tabId); + super.onRemovedHandler(tabId, details); + } +}; + +/******************************************************************************/ + +{ const extToTypeMap = new Map([ ['eot','font'],['otf','font'],['svg','font'],['ttf','font'],['woff','font'],['woff2','font'], ['mp3','media'],['mp4','media'],['webm','media'], @@ -134,7 +176,7 @@ this.suspendedTabIds.clear(); } }; -})(); +} /******************************************************************************/ @@ -143,9 +185,6 @@ // setting "Predict network actions to improve page load performance". vAPI.prefetching = (( ) => { - // https://github.com/uBlockOrigin/uBlock-issues/issues/407 - if ( vAPI.webextFlavor.soup.has('chromium') === false ) { return; } - let listening = false; const onHeadersReceived = function(details) { diff --git a/platform/common/vapi-background.js b/platform/common/vapi-background.js index c06aaf280..811a4095e 100644 --- a/platform/common/vapi-background.js +++ b/platform/common/vapi-background.js @@ -640,50 +640,6 @@ vAPI.Tabs = class { } }; -// https://github.com/uBlockOrigin/uBlock-issues/issues/1659 -// Chromium fails to dispatch onCreatedNavigationTarget() events sometimes, -// so we synthetize these missing events when this happens. -if ( vAPI.webextFlavor.soup.has('chromium') ) { - vAPI.Tabs = class extends vAPI.Tabs { - constructor() { - super(); - this.tabIds = new Set(); - browser.tabs.onCreated.addListener(tab => { - this.onCreatedHandler(tab); - }); - } - onCreatedHandler(tab) { - if ( typeof tab.openerTabId === 'number' ) { return; } - if ( tab.index !== 0 ) { return; } - if ( tab.url !== '' ) { return; } - this.tabIds.add(tab.id); - } - onCreatedNavigationTargetHandler(details) { - this.tabIds.delete(details.tabId); - super.onCreatedNavigationTargetHandler(details); - } - onCommittedHandler(details) { - if ( details.frameId === 0 && this.tabIds.has(details.tabId) ) { - this.tabIds.delete(details.tabId); - webext.tabs.get(details.tabId).then(tab => { - if ( tab === null ) { return; } - this.onCreatedNavigationTargetHandler({ - tabId: tab.id, - sourceTabId: tab.id, - sourceFrameId: 0, - url: tab.url, - }); - }); - } - super.onCommittedHandler(details); - } - onRemovedHandler(tabId, details) { - this.tabIds.delete(tabId); - super.onRemovedHandler(tabId, details); - } - }; -} - /******************************************************************************/ /******************************************************************************/