diff options
Diffstat (limited to 'src/js/messaging.js')
-rw-r--r-- | src/js/messaging.js | 99 |
1 files changed, 68 insertions, 31 deletions
diff --git a/src/js/messaging.js b/src/js/messaging.js index 52242b3..5f39af4 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -45,6 +45,7 @@ import { dnrRulesetFromRawLists } from './static-dnr-filtering.js'; import { i18n$ } from './i18n.js'; import { redirectEngine } from './redirect-engine.js'; import * as sfp from './static-filtering-parser.js'; +import * as s14e from './s14e-serializer.js'; import { permanentFirewall, @@ -63,8 +64,6 @@ import { isNetworkURI, } from './uri-utils.js'; -import './benchmarks.js'; - /******************************************************************************/ // https://github.com/uBlockOrigin/uBlock-issues/issues/710 @@ -364,11 +363,12 @@ const popupDataFromTabId = function(tabId, tabTitle) { colorBlindFriendly: µbus.colorBlindFriendly, cosmeticFilteringSwitch: false, firewallPaneMinimized: µbus.firewallPaneMinimized, - globalAllowedRequestCount: µb.localSettings.allowedRequestCount, - globalBlockedRequestCount: µb.localSettings.blockedRequestCount, + globalAllowedRequestCount: µb.requestStats.allowedCount, + globalBlockedRequestCount: µb.requestStats.blockedCount, fontSize: µbhs.popupFontSize, godMode: µbhs.filterAuthorMode, netFilteringSwitch: false, + userFiltersAreEnabled: µb.userFiltersAreEnabled(), rawURL: tabContext.rawURL, pageURL: tabContext.normalURL, pageHostname: rootHostname, @@ -378,6 +378,7 @@ const popupDataFromTabId = function(tabId, tabTitle) { popupPanelDisabledSections: µbhs.popupPanelDisabledSections, popupPanelLockedSections: µbhs.popupPanelLockedSections, popupPanelHeightMode: µbhs.popupPanelHeightMode, + popupPanelOrientation: µbhs.popupPanelOrientation, tabId, tabTitle, tooltipsDisabled: µbus.tooltipsDisabled, @@ -715,15 +716,15 @@ const retrieveContentScriptParameters = async function(sender, request) { // https://github.com/uBlockOrigin/uBlock-issues/issues/688#issuecomment-748179731 // For non-network URIs, scriptlet injection is deferred to here. The // effective URL is available here in `request.url`. - if ( logger.enabled || request.needScriptlets ) { - const scriptletDetails = scriptletFilteringEngine.injectNow(request); + if ( logger.enabled ) { + const scriptletDetails = scriptletFilteringEngine.retrieve(request); if ( scriptletDetails !== undefined ) { scriptletFilteringEngine.toLogger(request, scriptletDetails); - if ( request.needScriptlets ) { - response.scriptletDetails = scriptletDetails; - } } } + if ( request.needScriptlets ) { + scriptletFilteringEngine.injectNow(request); + } // https://github.com/NanoMeow/QuickReports/issues/6#issuecomment-414516623 // Inject as early as possible to make the cosmetic logger code less @@ -795,6 +796,17 @@ const onMessage = function(request, sender, callback) { µb.maybeGoodPopup.url = request.url; break; + case 'messageToLogger': + if ( logger.enabled !== true ) { break; } + logger.writeOne({ + tabId: sender.tabId, + realm: 'message', + type: request.type || 'info', + keywords: [ 'scriptlet' ], + text: request.text, + }); + break; + case 'shouldRenderNoscriptTags': if ( pageStore === null ) { break; } const fctxt = µb.filteringContext.fromTabId(sender.tabId); @@ -913,21 +925,6 @@ const fromBase64 = function(encoded) { return Promise.resolve(u8array !== undefined ? u8array : encoded); }; -const toBase64 = function(data) { - const value = data instanceof Uint8Array - ? denseBase64.encode(data) - : data; - return Promise.resolve(value); -}; - -const compress = function(json) { - return lz4Codec.encode(json, toBase64); -}; - -const decompress = function(encoded) { - return lz4Codec.decode(encoded, fromBase64); -}; - const onMessage = function(request, sender, callback) { // Cloud storage support is optional. if ( µb.cloudStorageSupported !== true ) { @@ -949,15 +946,25 @@ const onMessage = function(request, sender, callback) { return; case 'cloudPull': - request.decode = decompress; + request.decode = encoded => { + if ( s14e.isSerialized(encoded) ) { + return s14e.deserializeAsync(encoded, { thread: true }); + } + // Legacy decoding: needs to be kept around for the foreseeable future. + return lz4Codec.decode(encoded, fromBase64); + }; return vAPI.cloud.pull(request).then(result => { callback(result); }); case 'cloudPush': - if ( µb.hiddenSettings.cloudStorageCompression ) { - request.encode = compress; - } + request.encode = data => { + const options = { + compress: µb.hiddenSettings.cloudStorageCompression, + thread: true, + }; + return s14e.serializeAsync(data, options); + }; return vAPI.cloud.push(request).then(result => { callback(result); }); @@ -1444,11 +1451,23 @@ const onMessage = function(request, sender, callback) { case 'readUserFilters': return µb.loadUserFilters().then(result => { - result.trustedSource = µb.isTrustedList(µb.userFiltersPath); + result.enabled = µb.selectedFilterLists.includes(µb.userFiltersPath); + result.trusted = µb.isTrustedList(µb.userFiltersPath); callback(result); }); case 'writeUserFilters': + if ( request.enabled ) { + µb.applyFilterListSelection({ + toSelect: [ µb.userFiltersPath ], + merge: true, + }); + } else { + µb.applyFilterListSelection({ + toRemove: [ µb.userFiltersPath ], + }); + } + µb.changeUserSettings('userFiltersTrusted', request.trusted || false); return µb.saveUserFilters(request.content).then(result => { callback(result); }); @@ -1839,8 +1858,26 @@ const onMessage = function(request, sender, callback) { return; case 'snfeBenchmark': - µb.benchmarkStaticNetFiltering({ redirectEngine }).then(result => { - callback(result); + import('/js/benchmarks.js').then(module => { + module.benchmarkStaticNetFiltering({ redirectEngine }).then(result => { + callback(result); + }); + }); + return; + + case 'cfeBenchmark': + import('/js/benchmarks.js').then(module => { + module.benchmarkCosmeticFiltering().then(result => { + callback(result); + }); + }); + return; + + case 'sfeBenchmark': + import('/js/benchmarks.js').then(module => { + module.benchmarkScriptletFiltering().then(result => { + callback(result); + }); }); return; |