From efcab145978b1d8227848d95b3e2a0202da3ac03 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 12 Apr 2018 12:17:38 -0400 Subject: [PATCH] Squashed commit of the following: commit ab2b328cf1360a751fa1c58b8521f907eeb1ec50 Author: Raymond Hill Date: Thu Apr 12 12:08:30 2018 -0400 fix #3588 commit c4ae7638dfa5a5c7ddec2f9dd2d2988450082542 Author: Raymond Hill Date: Thu Apr 12 09:08:56 2018 -0400 detect user stylesheets support from content scripts (#3588) --- platform/chromium/vapi-background.js | 13 ++++++------- .../{vapi-usercss.js => vapi-usercss.pseudo.js} | 15 ++++++++++++--- .../vapi-usercss.real.js} | 11 ++++++++--- tools/make-chromium.sh | 7 +++++-- tools/make-webext.sh | 6 +++--- 5 files changed, 34 insertions(+), 18 deletions(-) rename platform/chromium/{vapi-usercss.js => vapi-usercss.pseudo.js} (97%) rename platform/{webext/vapi-usercss.js => chromium/vapi-usercss.real.js} (97%) diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js index 1ba429c94..b4d1fed01 100644 --- a/platform/chromium/vapi-background.js +++ b/platform/chromium/vapi-background.js @@ -39,10 +39,7 @@ vAPI.cantWebsocket = // https://issues.adblockplus.org/ticket/5695 // - Good idea, adopted: cleaner way to detect user-stylesheet support. -vAPI.supportsUserStylesheets = - chrome.extensionTypes instanceof Object && - chrome.extensionTypes.CSSOrigin instanceof Object && - 'USER' in chrome.extensionTypes.CSSOrigin; +vAPI.supportsUserStylesheets = vAPI.webextFlavor.soup.has('user_stylesheet'); vAPI.insertCSS = chrome.tabs.insertCSS; var noopFunc = function(){}; @@ -843,9 +840,11 @@ vAPI.messaging.onPortMessage = (function() { details.code = cssText; cssPromises.push(chrome.tabs.insertCSS(tabId, details)); } - for ( cssText of msg.remove ) { - details.code = cssText; - cssPromises.push(chrome.tabs.removeCSS(tabId, details)); + if ( typeof chrome.tabs.removeCSS === 'function' ) { + for ( cssText of msg.remove ) { + details.code = cssText; + cssPromises.push(chrome.tabs.removeCSS(tabId, details)); + } } if ( typeof callback === 'function' ) { Promise.all(cssPromises).then(() => { diff --git a/platform/chromium/vapi-usercss.js b/platform/chromium/vapi-usercss.pseudo.js similarity index 97% rename from platform/chromium/vapi-usercss.js rename to platform/chromium/vapi-usercss.pseudo.js index df050cc97..142bab49e 100644 --- a/platform/chromium/vapi-usercss.js +++ b/platform/chromium/vapi-usercss.pseudo.js @@ -1,7 +1,7 @@ /******************************************************************************* uBlock Origin - a browser extension to block requests. - Copyright (C) 2017 Raymond Hill + Copyright (C) 2017-2018 Raymond Hill This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,7 +27,15 @@ // https://github.com/chrisaljoudi/uBlock/issues/456 // https://github.com/gorhill/uBlock/issues/2029 -if ( typeof vAPI === 'object' ) { // >>>>>>>> start of HUGE-IF-BLOCK +// https://github.com/gorhill/uBlock/issues/3588 +// Chromium 66+ supports user stylesheets. Testing support against a regex is +// (unfortunately) necessary from content scripts. + +if ( + typeof vAPI === 'object' && + /\bEdge\/\d+|\bChrom(?:e|ium)\/(?:[45][0-9]|6[0-5])/.test(navigator.userAgent) +) { +// >>>>>>>> start of HUGE-IF-BLOCK /******************************************************************************/ /******************************************************************************/ @@ -543,4 +551,5 @@ vAPI.DOMFilterer.prototype = { /******************************************************************************/ /******************************************************************************/ -} // <<<<<<<< end of HUGE-IF-BLOCK +// <<<<<<<< end of HUGE-IF-BLOCK +} diff --git a/platform/webext/vapi-usercss.js b/platform/chromium/vapi-usercss.real.js similarity index 97% rename from platform/webext/vapi-usercss.js rename to platform/chromium/vapi-usercss.real.js index 9db9bce1b..493a4b246 100644 --- a/platform/webext/vapi-usercss.js +++ b/platform/chromium/vapi-usercss.real.js @@ -1,7 +1,7 @@ /******************************************************************************* uBlock Origin - a browser extension to block requests. - Copyright (C) 2017 Raymond Hill + Copyright (C) 2017-2018 Raymond Hill This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,7 +23,11 @@ // For content pages -if ( typeof vAPI === 'object' ) { // >>>>>>>> start of HUGE-IF-BLOCK +if ( + typeof vAPI === 'object' && + vAPI.userStylesheet === undefined +) { +// >>>>>>>> start of HUGE-IF-BLOCK /******************************************************************************/ /******************************************************************************/ @@ -237,4 +241,5 @@ vAPI.DOMFilterer.prototype = { /******************************************************************************/ /******************************************************************************/ -} // <<<<<<<< end of HUGE-IF-BLOCK +// <<<<<<<< end of HUGE-IF-BLOCK +} diff --git a/tools/make-chromium.sh b/tools/make-chromium.sh index 2f3f06cab..dbec5535f 100755 --- a/tools/make-chromium.sh +++ b/tools/make-chromium.sh @@ -24,11 +24,14 @@ cp platform/chromium/*.json $DES/ cp LICENSE.txt $DES/ echo "*** uBlock0.chromium: concatenating content scripts" -cat $DES/js/vapi-usercss.js > /tmp/contentscript.js +cat $DES/js/vapi-usercss.pseudo.js > /tmp/contentscript.js +echo >> /tmp/contentscript.js +grep -v "^'use strict';$" $DES/js/vapi-usercss.real.js >> /tmp/contentscript.js echo >> /tmp/contentscript.js grep -v "^'use strict';$" $DES/js/contentscript.js >> /tmp/contentscript.js mv /tmp/contentscript.js $DES/js/contentscript.js -rm $DES/js/vapi-usercss.js +rm $DES/js/vapi-usercss.pseudo.js +rm $DES/js/vapi-usercss.real.js # Chrome store-specific cp -R $DES/_locales/nb $DES/_locales/no diff --git a/tools/make-webext.sh b/tools/make-webext.sh index 37a23b3a9..e7207b20d 100755 --- a/tools/make-webext.sh +++ b/tools/make-webext.sh @@ -28,14 +28,14 @@ cp platform/webext/manifest.json $DES/ cp platform/webext/polyfill.js $DES/js/ cp platform/webext/vapi-webrequest.js $DES/js/ cp platform/webext/vapi-cachestorage.js $DES/js/ -cp platform/webext/vapi-usercss.js $DES/js/ echo "*** uBlock0.webext: concatenating content scripts" -cat $DES/js/vapi-usercss.js > /tmp/contentscript.js +cat $DES/js/vapi-usercss.real.js > /tmp/contentscript.js echo >> /tmp/contentscript.js grep -v "^'use strict';$" $DES/js/contentscript.js >> /tmp/contentscript.js mv /tmp/contentscript.js $DES/js/contentscript.js -rm $DES/js/vapi-usercss.js +rm $DES/js/vapi-usercss.pseudo.js +rm $DES/js/vapi-usercss.real.js # Webext-specific rm $DES/img/icon_128.png