better manage platform-specific code for user-stylesheet support

This commit is contained in:
Raymond Hill 2018-04-26 11:36:22 -04:00
parent 6a0120340c
commit e5f2e9701d
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
8 changed files with 116 additions and 24 deletions

View File

@ -1,7 +1,7 @@
/******************************************************************************* /*******************************************************************************
uBlock Origin - a browser extension to block requests. 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 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 it under the terms of the GNU General Public License as published by
@ -39,6 +39,14 @@
// indexedDB. // indexedDB.
vAPI.cacheStorage = (function() { 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'; const STORAGE_NAME = 'uBlock0CacheStorage';
var db; var db;
var pending = []; var pending = [];

View File

@ -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);

View File

@ -21,20 +21,10 @@
'use strict'; '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. if ( typeof vAPI === 'object' && vAPI.userStylesheet === undefined ) {
// 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)
) {
// >>>>>>>> start of HUGE-IF-BLOCK // >>>>>>>> start of HUGE-IF-BLOCK
/******************************************************************************/ /******************************************************************************/

View File

@ -21,12 +21,10 @@
'use strict'; '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 ( if ( typeof vAPI === 'object' && vAPI.supportsUserStylesheets ) {
typeof vAPI === 'object' &&
vAPI.userStylesheet === undefined
) {
// >>>>>>>> start of HUGE-IF-BLOCK // >>>>>>>> start of HUGE-IF-BLOCK
/******************************************************************************/ /******************************************************************************/

View File

@ -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);

View File

@ -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;

View File

@ -24,14 +24,17 @@ cp platform/chromium/*.json $DES/
cp LICENSE.txt $DES/ cp LICENSE.txt $DES/
echo "*** uBlock0.chromium: concatenating content scripts" 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 echo >> /tmp/contentscript.js
grep -v "^'use strict';$" $DES/js/vapi-usercss.real.js >> /tmp/contentscript.js grep -v "^'use strict';$" $DES/js/vapi-usercss.real.js >> /tmp/contentscript.js
echo >> /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 grep -v "^'use strict';$" $DES/js/contentscript.js >> /tmp/contentscript.js
mv /tmp/contentscript.js $DES/js/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.real.js
rm $DES/js/vapi-usercss.pseudo.js
# Chrome store-specific # Chrome store-specific
cp -R $DES/_locales/nb $DES/_locales/no cp -R $DES/_locales/nb $DES/_locales/no

View File

@ -26,16 +26,19 @@ cp LICENSE.txt $DES/
cp platform/webext/manifest.json $DES/ cp platform/webext/manifest.json $DES/
cp platform/webext/polyfill.js $DES/js/ 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-webrequest.js $DES/js/
cp platform/webext/vapi-cachestorage.js $DES/js/
echo "*** uBlock0.webext: concatenating content scripts" 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 echo >> /tmp/contentscript.js
grep -v "^'use strict';$" $DES/js/contentscript.js >> /tmp/contentscript.js grep -v "^'use strict';$" $DES/js/contentscript.js >> /tmp/contentscript.js
mv /tmp/contentscript.js $DES/js/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.real.js
rm $DES/js/vapi-usercss.pseudo.js
# Webext-specific # Webext-specific
rm $DES/img/icon_128.png rm $DES/img/icon_128.png