mirror of https://github.com/gorhill/uBlock.git
better evaluate vAPI.webextFlavor
This commit is contained in:
parent
c695599860
commit
bf384e2bca
|
@ -33,26 +33,10 @@
|
|||
var chrome = self.chrome;
|
||||
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 =
|
||||
chrome.webRequest.ResourceType instanceof Object === false ||
|
||||
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
|
||||
// - Good idea, adopted: cleaner way to detect user-stylesheet support.
|
||||
vAPI.supportsUserStylesheets =
|
||||
|
@ -1147,7 +1131,25 @@ vAPI.cloud = (function() {
|
|||
var maxChunkCountPerItem = Math.floor(512 * 0.75) & ~(chunkCountPerFetch - 1);
|
||||
|
||||
// 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)
|
||||
// Firefox:
|
||||
|
@ -1155,19 +1157,6 @@ vAPI.cloud = (function() {
|
|||
// > You can store up to 100KB of data using this API/
|
||||
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 = {
|
||||
defaultDeviceName: window.navigator.platform,
|
||||
deviceName: vAPI.localStorage.getItem('deviceName') || ''
|
||||
|
@ -1226,7 +1215,6 @@ vAPI.cloud = (function() {
|
|||
};
|
||||
|
||||
var push = function(dataKey, data, callback) {
|
||||
initialize();
|
||||
|
||||
var bin = {
|
||||
'source': options.deviceName || options.defaultDeviceName,
|
||||
|
@ -1271,7 +1259,6 @@ vAPI.cloud = (function() {
|
|||
};
|
||||
|
||||
var pull = function(dataKey, callback) {
|
||||
initialize();
|
||||
|
||||
var assembleChunks = function(bin) {
|
||||
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
|
||||
|
||||
var setScriptDirection = function(language) {
|
||||
|
@ -77,10 +121,7 @@ setScriptDirection(vAPI.i18n('@@ui_locale'));
|
|||
// `window.open('', '_self').close()`.
|
||||
|
||||
vAPI.closePopup = function() {
|
||||
if (
|
||||
self.browser instanceof Object &&
|
||||
typeof self.browser.runtime.getBrowserInfo === 'function'
|
||||
) {
|
||||
if ( /^Mozilla-Firefox-/.test(vAPI.webextFlavor) ) {
|
||||
window.close();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -43,20 +43,17 @@ vAPI.net.registerListeners = function() {
|
|||
// https://github.com/gorhill/uBlock/issues/2950
|
||||
// Firefox 55 does not normalize URLs to ASCII, uBO must do this itself.
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=945240
|
||||
let mustPunycode = false;
|
||||
(function() {
|
||||
if (
|
||||
typeof browser === 'object' &&
|
||||
browser !== null &&
|
||||
browser.runtime instanceof Object &&
|
||||
typeof browser.runtime.getBrowserInfo === 'function'
|
||||
) {
|
||||
browser.runtime.getBrowserInfo().then(info => {
|
||||
mustPunycode = info.name === 'Firefox' &&
|
||||
/^5[0-6]\./.test(info.version);
|
||||
});
|
||||
}
|
||||
})();
|
||||
let evalMustPunycode = function() {
|
||||
return /^Mozilla-Firefox-5[0-6]/.test(vAPI.webextFlavor);
|
||||
};
|
||||
|
||||
let mustPunycode = evalMustPunycode();
|
||||
|
||||
// The real actual webextFlavor value may not be set in stone, so listen
|
||||
// for possible future changes.
|
||||
window.addEventListener('webextFlavor', function() {
|
||||
mustPunycode = evalMustPunycode();
|
||||
}, { once: true });
|
||||
|
||||
let wrApi = browser.webRequest;
|
||||
|
||||
|
|
|
@ -912,8 +912,7 @@ var updateFirst = function() {
|
|||
typeof browser === 'object' &&
|
||||
browser.runtime.getManifest();
|
||||
noRemoteResources =
|
||||
typeof vAPI.webextFlavor === 'string' &&
|
||||
vAPI.webextFlavor.startsWith('Mozilla-Firefox-') &&
|
||||
/^Mozilla-Firefox-/.test(vAPI.webextFlavor) &&
|
||||
manifest instanceof Object &&
|
||||
manifest.applications instanceof Object &&
|
||||
manifest.applications.gecko instanceof Object &&
|
||||
|
|
|
@ -1605,7 +1605,7 @@ FilterParser.prototype.translate = function() {
|
|||
this.dataStr = "connect-src https: http:";
|
||||
// https://bugs.chromium.org/p/chromium/issues/detail?id=669086
|
||||
// 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 *';
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -1126,20 +1126,17 @@ var injectCSP = function(pageStore, details) {
|
|||
|
||||
// https://github.com/gorhill/uMatrix/issues/967#issuecomment-373002011
|
||||
// This can be removed once Firefox 60 ESR is released.
|
||||
var cantMergeCSPHeaders = (function() {
|
||||
if (
|
||||
self.browser instanceof Object &&
|
||||
typeof self.browser.runtime.getBrowserInfo === 'function'
|
||||
) {
|
||||
self.browser.runtime.getBrowserInfo().then(function(info) {
|
||||
cantMergeCSPHeaders =
|
||||
info.vendor === 'Mozilla' &&
|
||||
info.name === 'Firefox' &&
|
||||
parseInt(info.version, 10) < 59;
|
||||
});
|
||||
}
|
||||
return false;
|
||||
})();
|
||||
var evalCantMergeCSPHeaders = function() {
|
||||
return /^Mozilla-Firefox-5[2-8]/.test(vAPI.webextFlavor);
|
||||
};
|
||||
|
||||
var cantMergeCSPHeaders = evalCantMergeCSPHeaders();
|
||||
|
||||
// The real actual webextFlavor value may not be set in stone, so listen
|
||||
// for possible future changes.
|
||||
window.addEventListener('webextFlavor', function() {
|
||||
cantMergeCSPHeaders = evalCantMergeCSPHeaders();
|
||||
}, { once: true });
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
Loading…
Reference in New Issue