mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
code review re. #2067
This commit is contained in:
parent
8c3da95d65
commit
c6793eff98
@ -79,12 +79,10 @@ var onAllReady = function() {
|
|||||||
|
|
||||||
//quickProfiler.stop(0);
|
//quickProfiler.stop(0);
|
||||||
|
|
||||||
vAPI.onLoadAllCompleted();
|
|
||||||
µb.contextMenu.update(null);
|
µb.contextMenu.update(null);
|
||||||
µb.firstInstall = false;
|
µb.firstInstall = false;
|
||||||
|
|
||||||
vAPI.net.onBeforeReady = null;
|
vAPI.net.onReady();
|
||||||
vAPI.messaging.broadcast({ what: 'ublockOrigin-readyState-complete' });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -33,9 +33,59 @@ var exports = {};
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uBlock/issues/2067
|
||||||
|
// Experimental: Suspend tabs until uBO is fully ready.
|
||||||
|
|
||||||
|
vAPI.net.onReady = function() {
|
||||||
|
if ( µBlock.hiddenSettings.suspendTabsUntilReady !== true ) {
|
||||||
|
vAPI.onLoadAllCompleted();
|
||||||
|
}
|
||||||
|
var fn = onBeforeReady;
|
||||||
|
onBeforeReady = null;
|
||||||
|
if ( fn !== null ) {
|
||||||
|
fn('ready');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var onBeforeReady = (function() {
|
||||||
|
var suspendedTabs = new Set();
|
||||||
|
|
||||||
|
var forceReloadSuspendedTabs = function() {
|
||||||
|
var iter = suspendedTabs.values(),
|
||||||
|
entry;
|
||||||
|
for (;;) {
|
||||||
|
entry = iter.next();
|
||||||
|
if ( entry.done ) { break; }
|
||||||
|
vAPI.tabs.reload(entry.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return function(tabId) {
|
||||||
|
if (
|
||||||
|
vAPI.isBehindTheSceneTabId(tabId) ||
|
||||||
|
µBlock.hiddenSettings.suspendTabsUntilReady !== true
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ( tabId === 'ready' ) {
|
||||||
|
forceReloadSuspendedTabs();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
suspendedTabs.add(tabId);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
// Intercept and filter web requests.
|
// Intercept and filter web requests.
|
||||||
|
|
||||||
var onBeforeRequest = function(details) {
|
var onBeforeRequest = function(details) {
|
||||||
|
var tabId = details.tabId;
|
||||||
|
if ( onBeforeReady !== null && onBeforeReady(tabId) ) {
|
||||||
|
return { cancel: true };
|
||||||
|
}
|
||||||
|
|
||||||
// Special handling for root document.
|
// Special handling for root document.
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/1001
|
// https://github.com/chrisaljoudi/uBlock/issues/1001
|
||||||
// This must be executed regardless of whether the request is
|
// This must be executed regardless of whether the request is
|
||||||
@ -46,7 +96,6 @@ var onBeforeRequest = function(details) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Special treatment: behind-the-scene requests
|
// Special treatment: behind-the-scene requests
|
||||||
var tabId = details.tabId;
|
|
||||||
if ( vAPI.isBehindTheSceneTabId(tabId) ) {
|
if ( vAPI.isBehindTheSceneTabId(tabId) ) {
|
||||||
return onBeforeBehindTheSceneRequest(details);
|
return onBeforeBehindTheSceneRequest(details);
|
||||||
}
|
}
|
||||||
@ -138,13 +187,6 @@ var onBeforeRequest = function(details) {
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var onBeforeRootFrameRequest = function(details) {
|
var onBeforeRootFrameRequest = function(details) {
|
||||||
if (
|
|
||||||
vAPI.net.onBeforeReady instanceof Function &&
|
|
||||||
vAPI.net.onBeforeReady(details) === true
|
|
||||||
) {
|
|
||||||
return { cancel: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
var tabId = details.tabId,
|
var tabId = details.tabId,
|
||||||
requestURL = details.url,
|
requestURL = details.url,
|
||||||
µb = µBlock;
|
µb = µBlock;
|
||||||
@ -642,33 +684,6 @@ var headerIndexFromName = function(headerName, headers) {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// https://github.com/gorhill/uBlock/issues/2067
|
|
||||||
// Experimental: Suspend tabs until uBO is fully ready.
|
|
||||||
|
|
||||||
vAPI.net.onBeforeReady = function(details) {
|
|
||||||
if ( µBlock.hiddenSettings.suspendTabsUntilReady !== true ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var pageURL = details.url;
|
|
||||||
if ( /^https?:\/\//.test(pageURL) === false ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
details.tabId === -1 ||
|
|
||||||
details.type !== 'main_frame' ||
|
|
||||||
details.frameId !== 0
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
vAPI.tabs.replace(
|
|
||||||
details.tabId,
|
|
||||||
vAPI.getURL('document-suspended.html?url=') + encodeURIComponent(pageURL)
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
vAPI.net.onBeforeRequest = {
|
vAPI.net.onBeforeRequest = {
|
||||||
urls: [
|
urls: [
|
||||||
'http://*/*',
|
'http://*/*',
|
||||||
|
Loading…
Reference in New Issue
Block a user