From ee89f8826564a59df4ed7dcd4fbbd21fac76ba99 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 16 Dec 2018 10:51:25 -0500 Subject: [PATCH] fix https://github.com/uBlockOrigin/uBlock-issues/issues/345 --- platform/firefox/vapi-webrequest.js | 41 ++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/platform/firefox/vapi-webrequest.js b/platform/firefox/vapi-webrequest.js index c2c1c9043..812c9655b 100644 --- a/platform/firefox/vapi-webrequest.js +++ b/platform/firefox/vapi-webrequest.js @@ -30,7 +30,7 @@ // https://github.com/gorhill/uBlock/issues/2950 // Firefox 56 does not normalize URLs to ASCII, uBO must do this itself. // https://bugzilla.mozilla.org/show_bug.cgi?id=945240 - let evalMustPunycode = function() { + const evalMustPunycode = function() { return vAPI.webextFlavor.soup.has('firefox') && vAPI.webextFlavor.major < 57; }; @@ -39,16 +39,16 @@ // The real actual webextFlavor value may not be set in stone, so listen // for possible future changes. - window.addEventListener('webextFlavor', function() { + window.addEventListener('webextFlavor', ( ) => { mustPunycode = evalMustPunycode(); }, { once: true }); - let denormalizeTypes = function(aa) { + const denormalizeTypes = function(aa) { if ( aa.length === 0 ) { return Array.from(vAPI.net.validTypes); } - let out = new Set(), - i = aa.length; + const out = new Set(); + let i = aa.length; while ( i-- ) { let type = aa[i]; if ( vAPI.net.validTypes.has(type) ) { @@ -57,13 +57,16 @@ if ( type === 'image' && vAPI.net.validTypes.has('imageset') ) { out.add('imageset'); } + if ( type === 'sub_frame' ) { + out.add('object'); + } } return Array.from(out); }; - let punycode = self.punycode; - let reAsciiHostname = /^https?:\/\/[0-9a-z_.:@-]+[/?#]/; - let parsedURL = new URL('about:blank'); + const punycode = self.punycode; + const reAsciiHostname = /^https?:\/\/[0-9a-z_.:@-]+[/?#]/; + const parsedURL = new URL('about:blank'); vAPI.net.normalizeDetails = function(details) { if ( mustPunycode && !reAsciiHostname.test(details.url) ) { @@ -74,11 +77,11 @@ ); } - let type = details.type; + const type = details.type; // https://github.com/gorhill/uBlock/issues/1493 - // Chromium 49+/WebExtensions support a new request type: `ping`, - // which is fired as a result of using `navigator.sendBeacon`. + // Chromium 49+/WebExtensions support a new request type: `ping`, + // which is fired as a result of using `navigator.sendBeacon`. if ( type === 'ping' ) { details.type = 'beacon'; return; @@ -88,10 +91,24 @@ details.type = 'image'; return; } + + // https://github.com/uBlockOrigin/uBlock-issues/issues/345 + // Re-categorize an embedded object as a `sub_frame` if its + // content type is that of a HTML document. + if ( type === 'object' && Array.isArray(details.responseHeaders) ) { + for ( const header of details.responseHeaders ) { + if ( header.name.toLowerCase() === 'content-type' ) { + if ( header.value.startsWith('text/html') ) { + details.type = 'sub_frame'; + } + break; + } + } + } }; vAPI.net.denormalizeFilters = function(filters) { - let urls = filters.urls || [ '' ]; + const urls = filters.urls || [ '' ]; let types = filters.types; if ( Array.isArray(types) ) { types = denormalizeTypes(types);