mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
better evaluate vAPI.webextFlavor
This commit is contained in:
parent
c695599860
commit
bf384e2bca
6 changed files with 88 additions and 67 deletions
|
|
@ -33,26 +33,10 @@
|
||||||
var chrome = self.chrome;
|
var chrome = self.chrome;
|
||||||
var manifest = chrome.runtime.getManifest();
|
var manifest = chrome.runtime.getManifest();
|
||||||
|
|
||||||
vAPI.chrome = true;
|
|
||||||
vAPI.chromiumVersion = (function(){
|
|
||||||
var matches = /\bChrom(?:e|ium)\/(\d+)\b/.exec(navigator.userAgent);
|
|
||||||
return matches !== null ? parseInt(matches[1], 10) : NaN;
|
|
||||||
})();
|
|
||||||
|
|
||||||
vAPI.cantWebsocket =
|
vAPI.cantWebsocket =
|
||||||
chrome.webRequest.ResourceType instanceof Object === false ||
|
chrome.webRequest.ResourceType instanceof Object === false ||
|
||||||
chrome.webRequest.ResourceType.WEBSOCKET !== 'websocket';
|
chrome.webRequest.ResourceType.WEBSOCKET !== 'websocket';
|
||||||
|
|
||||||
vAPI.webextFlavor = '';
|
|
||||||
if (
|
|
||||||
self.browser instanceof Object &&
|
|
||||||
typeof self.browser.runtime.getBrowserInfo === 'function'
|
|
||||||
) {
|
|
||||||
self.browser.runtime.getBrowserInfo().then(function(info) {
|
|
||||||
vAPI.webextFlavor = info.vendor + '-' + info.name + '-' + info.version;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://issues.adblockplus.org/ticket/5695
|
// https://issues.adblockplus.org/ticket/5695
|
||||||
// - Good idea, adopted: cleaner way to detect user-stylesheet support.
|
// - Good idea, adopted: cleaner way to detect user-stylesheet support.
|
||||||
vAPI.supportsUserStylesheets =
|
vAPI.supportsUserStylesheets =
|
||||||
|
|
@ -1147,7 +1131,25 @@ vAPI.cloud = (function() {
|
||||||
var maxChunkCountPerItem = Math.floor(512 * 0.75) & ~(chunkCountPerFetch - 1);
|
var maxChunkCountPerItem = Math.floor(512 * 0.75) & ~(chunkCountPerFetch - 1);
|
||||||
|
|
||||||
// Mind chrome.storage.sync.QUOTA_BYTES_PER_ITEM (8192 at time of writing)
|
// Mind chrome.storage.sync.QUOTA_BYTES_PER_ITEM (8192 at time of writing)
|
||||||
var maxChunkSize = chrome.storage.sync.QUOTA_BYTES_PER_ITEM || 8192;
|
// https://github.com/gorhill/uBlock/issues/3006
|
||||||
|
// For Firefox, we will use a lower ratio to allow for more overhead for
|
||||||
|
// the infrastructure. Unfortunately this leads to less usable space for
|
||||||
|
// actual data, but all of this is provided for free by browser vendors,
|
||||||
|
// so we need to accept and deal with these limitations.
|
||||||
|
var evalMaxChunkSize = function() {
|
||||||
|
return Math.floor(
|
||||||
|
(chrome.storage.sync.QUOTA_BYTES_PER_ITEM || 8192) *
|
||||||
|
(vAPI.webextFlavor.startsWith('Mozilla-Firefox-') ? 0.6 : 0.75)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
var maxChunkSize = evalMaxChunkSize();
|
||||||
|
|
||||||
|
// The real actual webextFlavor value may not be set in stone, so listen
|
||||||
|
// for possible future changes.
|
||||||
|
window.addEventListener('webextFlavor', function() {
|
||||||
|
maxChunkSize = evalMaxChunkSize();
|
||||||
|
}, { once: true });
|
||||||
|
|
||||||
// Mind chrome.storage.sync.QUOTA_BYTES (128 kB at time of writing)
|
// Mind chrome.storage.sync.QUOTA_BYTES (128 kB at time of writing)
|
||||||
// Firefox:
|
// Firefox:
|
||||||
|
|
@ -1155,19 +1157,6 @@ vAPI.cloud = (function() {
|
||||||
// > You can store up to 100KB of data using this API/
|
// > You can store up to 100KB of data using this API/
|
||||||
var maxStorageSize = chrome.storage.sync.QUOTA_BYTES || 102400;
|
var maxStorageSize = chrome.storage.sync.QUOTA_BYTES || 102400;
|
||||||
|
|
||||||
// Flavor-specific handling needs to be done here. Reason: to allow time
|
|
||||||
// for vAPI.webextFlavor to be properly set.
|
|
||||||
// https://github.com/gorhill/uBlock/issues/3006
|
|
||||||
// For Firefox, we will use a lower ratio to allow for more overhead for
|
|
||||||
// the infrastructure. Unfortunately this leads to less usable space for
|
|
||||||
// actual data, but all of this is provided for free by browser vendors,
|
|
||||||
// so we need to accept and deal with these limitations.
|
|
||||||
var initialize = function() {
|
|
||||||
var ratio = vAPI.webextFlavor.startsWith('Mozilla-Firefox-') ? 0.6 : 0.75;
|
|
||||||
maxChunkSize = Math.floor(maxChunkSize * ratio);
|
|
||||||
initialize = function(){};
|
|
||||||
};
|
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
defaultDeviceName: window.navigator.platform,
|
defaultDeviceName: window.navigator.platform,
|
||||||
deviceName: vAPI.localStorage.getItem('deviceName') || ''
|
deviceName: vAPI.localStorage.getItem('deviceName') || ''
|
||||||
|
|
@ -1226,7 +1215,6 @@ vAPI.cloud = (function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
var push = function(dataKey, data, callback) {
|
var push = function(dataKey, data, callback) {
|
||||||
initialize();
|
|
||||||
|
|
||||||
var bin = {
|
var bin = {
|
||||||
'source': options.deviceName || options.defaultDeviceName,
|
'source': options.deviceName || options.defaultDeviceName,
|
||||||
|
|
@ -1271,7 +1259,6 @@ vAPI.cloud = (function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
var pull = function(dataKey, callback) {
|
var pull = function(dataKey, callback) {
|
||||||
initialize();
|
|
||||||
|
|
||||||
var assembleChunks = function(bin) {
|
var assembleChunks = function(bin) {
|
||||||
if ( chrome.runtime.lastError ) {
|
if ( chrome.runtime.lastError ) {
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,50 @@ vAPI.setTimeout = vAPI.setTimeout || self.setTimeout.bind(self);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.webextFlavor = (function() {
|
||||||
|
var ua = navigator.userAgent,
|
||||||
|
match, reEx;
|
||||||
|
var dispatch = function() {
|
||||||
|
window.dispatchEvent(new CustomEvent('webextFlavor'));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Order of tests is important!
|
||||||
|
|
||||||
|
// Asynchronous
|
||||||
|
if (
|
||||||
|
self.browser instanceof Object &&
|
||||||
|
typeof self.browser.runtime.getBrowserInfo === 'function'
|
||||||
|
) {
|
||||||
|
self.browser.runtime.getBrowserInfo().then(function(info) {
|
||||||
|
vAPI.webextFlavor =
|
||||||
|
info.vendor + '-' + info.name + '-' + info.version;
|
||||||
|
dispatch();
|
||||||
|
});
|
||||||
|
match = /Firefox\/([\d.]+)/.exec(ua);
|
||||||
|
return match !== null ? 'Mozilla-Firefox-' + match[1] : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Synchronous
|
||||||
|
/* Don't starve potential listeners: */ vAPI.setTimeout(dispatch, 97);
|
||||||
|
match = /OPR\/([\d.]+)/.exec(ua);
|
||||||
|
if ( match !== null ) {
|
||||||
|
reEx = /Chrom(?:e|ium)\/([\d.]+)/;
|
||||||
|
if ( reEx.test(ua) ) { match = reEx.exec(ua); }
|
||||||
|
return 'Opera-Chromium-' + match[1];
|
||||||
|
}
|
||||||
|
match = /Chromium\/([\d.]+)/.exec(ua);
|
||||||
|
if ( match !== null ) {
|
||||||
|
return 'Chromium-Chromium-' + match[1];
|
||||||
|
}
|
||||||
|
match = /Chrome\/([\d.]+)/.exec(ua);
|
||||||
|
if ( match !== null ) {
|
||||||
|
return 'Google-Chromium-' + match[1];
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
})();
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
// http://www.w3.org/International/questions/qa-scripts#directions
|
// http://www.w3.org/International/questions/qa-scripts#directions
|
||||||
|
|
||||||
var setScriptDirection = function(language) {
|
var setScriptDirection = function(language) {
|
||||||
|
|
@ -77,10 +121,7 @@ setScriptDirection(vAPI.i18n('@@ui_locale'));
|
||||||
// `window.open('', '_self').close()`.
|
// `window.open('', '_self').close()`.
|
||||||
|
|
||||||
vAPI.closePopup = function() {
|
vAPI.closePopup = function() {
|
||||||
if (
|
if ( /^Mozilla-Firefox-/.test(vAPI.webextFlavor) ) {
|
||||||
self.browser instanceof Object &&
|
|
||||||
typeof self.browser.runtime.getBrowserInfo === 'function'
|
|
||||||
) {
|
|
||||||
window.close();
|
window.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,20 +43,17 @@ vAPI.net.registerListeners = function() {
|
||||||
// https://github.com/gorhill/uBlock/issues/2950
|
// https://github.com/gorhill/uBlock/issues/2950
|
||||||
// Firefox 55 does not normalize URLs to ASCII, uBO must do this itself.
|
// Firefox 55 does not normalize URLs to ASCII, uBO must do this itself.
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=945240
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=945240
|
||||||
let mustPunycode = false;
|
let evalMustPunycode = function() {
|
||||||
(function() {
|
return /^Mozilla-Firefox-5[0-6]/.test(vAPI.webextFlavor);
|
||||||
if (
|
};
|
||||||
typeof browser === 'object' &&
|
|
||||||
browser !== null &&
|
let mustPunycode = evalMustPunycode();
|
||||||
browser.runtime instanceof Object &&
|
|
||||||
typeof browser.runtime.getBrowserInfo === 'function'
|
// The real actual webextFlavor value may not be set in stone, so listen
|
||||||
) {
|
// for possible future changes.
|
||||||
browser.runtime.getBrowserInfo().then(info => {
|
window.addEventListener('webextFlavor', function() {
|
||||||
mustPunycode = info.name === 'Firefox' &&
|
mustPunycode = evalMustPunycode();
|
||||||
/^5[0-6]\./.test(info.version);
|
}, { once: true });
|
||||||
});
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
let wrApi = browser.webRequest;
|
let wrApi = browser.webRequest;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -912,8 +912,7 @@ var updateFirst = function() {
|
||||||
typeof browser === 'object' &&
|
typeof browser === 'object' &&
|
||||||
browser.runtime.getManifest();
|
browser.runtime.getManifest();
|
||||||
noRemoteResources =
|
noRemoteResources =
|
||||||
typeof vAPI.webextFlavor === 'string' &&
|
/^Mozilla-Firefox-/.test(vAPI.webextFlavor) &&
|
||||||
vAPI.webextFlavor.startsWith('Mozilla-Firefox-') &&
|
|
||||||
manifest instanceof Object &&
|
manifest instanceof Object &&
|
||||||
manifest.applications instanceof Object &&
|
manifest.applications instanceof Object &&
|
||||||
manifest.applications.gecko instanceof Object &&
|
manifest.applications.gecko instanceof Object &&
|
||||||
|
|
|
||||||
|
|
@ -1605,7 +1605,7 @@ FilterParser.prototype.translate = function() {
|
||||||
this.dataStr = "connect-src https: http:";
|
this.dataStr = "connect-src https: http:";
|
||||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=669086
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=669086
|
||||||
// TODO: remove when most users are beyond Chromium v56
|
// TODO: remove when most users are beyond Chromium v56
|
||||||
if ( vAPI.chromiumVersion < 57 ) {
|
if ( /-Chromium-(?:4|5[0-6])/.test(vAPI.webextFlavor) ) {
|
||||||
this.dataStr += '; frame-src *';
|
this.dataStr += '; frame-src *';
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1126,20 +1126,17 @@ var injectCSP = function(pageStore, details) {
|
||||||
|
|
||||||
// https://github.com/gorhill/uMatrix/issues/967#issuecomment-373002011
|
// https://github.com/gorhill/uMatrix/issues/967#issuecomment-373002011
|
||||||
// This can be removed once Firefox 60 ESR is released.
|
// This can be removed once Firefox 60 ESR is released.
|
||||||
var cantMergeCSPHeaders = (function() {
|
var evalCantMergeCSPHeaders = function() {
|
||||||
if (
|
return /^Mozilla-Firefox-5[2-8]/.test(vAPI.webextFlavor);
|
||||||
self.browser instanceof Object &&
|
};
|
||||||
typeof self.browser.runtime.getBrowserInfo === 'function'
|
|
||||||
) {
|
var cantMergeCSPHeaders = evalCantMergeCSPHeaders();
|
||||||
self.browser.runtime.getBrowserInfo().then(function(info) {
|
|
||||||
cantMergeCSPHeaders =
|
// The real actual webextFlavor value may not be set in stone, so listen
|
||||||
info.vendor === 'Mozilla' &&
|
// for possible future changes.
|
||||||
info.name === 'Firefox' &&
|
window.addEventListener('webextFlavor', function() {
|
||||||
parseInt(info.version, 10) < 59;
|
cantMergeCSPHeaders = evalCantMergeCSPHeaders();
|
||||||
});
|
}, { once: true });
|
||||||
}
|
|
||||||
return false;
|
|
||||||
})();
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue