diff --git a/platform/chromium/vapi-cachestorage.js b/platform/chromium/vapi-cachestorage.js index e95d22e54..78979feb9 100644 --- a/platform/chromium/vapi-cachestorage.js +++ b/platform/chromium/vapi-cachestorage.js @@ -1,7 +1,7 @@ /******************************************************************************* uBlock Origin - a browser extension to block requests. - Copyright (C) 2016-2017 The uBlock Origin authors + Copyright (C) 2016-2018 The uBlock Origin authors 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 @@ -39,6 +39,14 @@ // indexedDB. vAPI.cacheStorage = (function() { + + // Firefox-specific: we use indexedDB because chrome.storage.local() has + // poor performance in Firefox. See: + // https://bugzilla.mozilla.org/show_bug.cgi?id=1371255 + if ( vAPI.webextFlavor.soup.has('firefox') === false ) { + return vAPI.cacheStorage; + } + const STORAGE_NAME = 'uBlock0CacheStorage'; var db; var pending = []; diff --git a/platform/chromium/vapi-usercss.js b/platform/chromium/vapi-usercss.js new file mode 100644 index 000000000..25e6e10cc --- /dev/null +++ b/platform/chromium/vapi-usercss.js @@ -0,0 +1,32 @@ +/******************************************************************************* + + uBlock Origin - a browser extension to block requests. + Copyright (C) 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +'use strict'; + +// This file can be replaced by platform-specific code. If a platform is +// known to NOT support user stylsheets, vAPI.supportsUserStylesheets can be +// set to `false`. + +// Chromium 66 and above supports user stylesheets: +// https://github.com/gorhill/uBlock/issues/3588 + +vAPI.supportsUserStylesheets = + /\bChrom(?:e|ium)\/(?:6[6789]|[789]|1\d\d)/.test(navigator.userAgent); diff --git a/platform/chromium/vapi-usercss.pseudo.js b/platform/chromium/vapi-usercss.pseudo.js index 142bab49e..d23336ef8 100644 --- a/platform/chromium/vapi-usercss.pseudo.js +++ b/platform/chromium/vapi-usercss.pseudo.js @@ -21,20 +21,10 @@ 'use strict'; -// For content pages +// Packaging this file is optional: it is not necessary to package it if the +// platform is known to support user stylesheets. -// Abort execution if our global vAPI object does not exist. -// https://github.com/chrisaljoudi/uBlock/issues/456 -// https://github.com/gorhill/uBlock/issues/2029 - -// 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) -) { +if ( typeof vAPI === 'object' && vAPI.userStylesheet === undefined ) { // >>>>>>>> start of HUGE-IF-BLOCK /******************************************************************************/ diff --git a/platform/chromium/vapi-usercss.real.js b/platform/chromium/vapi-usercss.real.js index 493a4b246..9703fd9dd 100644 --- a/platform/chromium/vapi-usercss.real.js +++ b/platform/chromium/vapi-usercss.real.js @@ -21,12 +21,10 @@ 'use strict'; -// For content pages +// Packaging this file is optional: it is not necessary to package it if the +// platform is known to not support user stylesheets. -if ( - typeof vAPI === 'object' && - vAPI.userStylesheet === undefined -) { +if ( typeof vAPI === 'object' && vAPI.supportsUserStylesheets ) { // >>>>>>>> start of HUGE-IF-BLOCK /******************************************************************************/ diff --git a/platform/debian/vapi-usercss.js b/platform/debian/vapi-usercss.js new file mode 100644 index 000000000..3013e50eb --- /dev/null +++ b/platform/debian/vapi-usercss.js @@ -0,0 +1,32 @@ +/******************************************************************************* + + uBlock Origin - a browser extension to block requests. + Copyright (C) 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +'use strict'; + +// This file can be replaced by platform-specific code. If a platform is +// known to NOT support user stylsheets, vAPI.supportsUserStylesheets can be +// set to `false`. + +// Chromium 66 and above supports user stylesheets: +// https://github.com/gorhill/uBlock/issues/3588 + +vAPI.supportsUserStylesheets = + /\bChrom(?:e|ium)\/(?:6[6789]|[789]|1\d\d)|\bFirefox\/\d/.test(navigator.userAgent); diff --git a/platform/webext/vapi-usercss.js b/platform/webext/vapi-usercss.js new file mode 100644 index 000000000..0daf2f7d2 --- /dev/null +++ b/platform/webext/vapi-usercss.js @@ -0,0 +1,26 @@ +/******************************************************************************* + + uBlock Origin - a browser extension to block requests. + Copyright (C) 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +'use strict'; + +// User stylesheets are always supported with Firefox/webext . + +vAPI.supportsUserStylesheets = true; diff --git a/tools/make-chromium.sh b/tools/make-chromium.sh index dbec5535f..4bc039165 100755 --- a/tools/make-chromium.sh +++ b/tools/make-chromium.sh @@ -24,14 +24,17 @@ cp platform/chromium/*.json $DES/ cp LICENSE.txt $DES/ echo "*** uBlock0.chromium: concatenating content scripts" -cat $DES/js/vapi-usercss.pseudo.js > /tmp/contentscript.js +cat $DES/js/vapi-usercss.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/vapi-usercss.pseudo.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.pseudo.js +rm $DES/js/vapi-usercss.js rm $DES/js/vapi-usercss.real.js +rm $DES/js/vapi-usercss.pseudo.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 e7207b20d..4a1648673 100755 --- a/tools/make-webext.sh +++ b/tools/make-webext.sh @@ -26,16 +26,19 @@ cp LICENSE.txt $DES/ cp platform/webext/manifest.json $DES/ cp platform/webext/polyfill.js $DES/js/ +cp platform/webext/vapi-usercss.js $DES/js/ cp platform/webext/vapi-webrequest.js $DES/js/ -cp platform/webext/vapi-cachestorage.js $DES/js/ echo "*** uBlock0.webext: concatenating content scripts" -cat $DES/js/vapi-usercss.real.js > /tmp/contentscript.js +cat $DES/js/vapi-usercss.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.pseudo.js +rm $DES/js/vapi-usercss.js rm $DES/js/vapi-usercss.real.js +rm $DES/js/vapi-usercss.pseudo.js # Webext-specific rm $DES/img/icon_128.png