mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
code review for 3c85c03194
: simplify counting of script resources
This commit is contained in:
parent
0ed3e8cd30
commit
96525cffa5
@ -388,8 +388,12 @@ var onMessage = function(request, sender, callback) {
|
|||||||
pageStore = µb.pageStoreFromTabId(request.tabId);
|
pageStore = µb.pageStoreFromTabId(request.tabId);
|
||||||
if ( pageStore !== null ) {
|
if ( pageStore !== null ) {
|
||||||
pageStore.hiddenElementCount = 0;
|
pageStore.hiddenElementCount = 0;
|
||||||
pageStore.inlineScriptCount = 0;
|
pageStore.scriptCount = 0;
|
||||||
µb.scriptlets.injectDeep(request.tabId, 'dom-survey');
|
vAPI.tabs.injectScript(request.tabId, {
|
||||||
|
allFrames: true,
|
||||||
|
file: '/js/scriptlets/dom-survey.js',
|
||||||
|
runAt: 'document_end'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -494,7 +498,7 @@ var onMessage = function(request, sender, callback) {
|
|||||||
if ( pageStore === null ) { break; }
|
if ( pageStore === null ) { break; }
|
||||||
let tabContext = µb.tabContextManager.lookup(tabId);
|
let tabContext = µb.tabContextManager.lookup(tabId);
|
||||||
if ( tabContext === null ) { break; }
|
if ( tabContext === null ) { break; }
|
||||||
if ( pageStore.filterScripting(tabContext.rootHostname) ) {
|
if ( pageStore.filterScripting(tabContext.rootHostname, undefined) ) {
|
||||||
vAPI.tabs.injectScript(
|
vAPI.tabs.injectScript(
|
||||||
tabId,
|
tabId,
|
||||||
{
|
{
|
||||||
@ -1263,7 +1267,7 @@ var domSurveyFinalReport = function(tabId) {
|
|||||||
what: 'domSurveyFinalReport',
|
what: 'domSurveyFinalReport',
|
||||||
tabId: tabId,
|
tabId: tabId,
|
||||||
affectedElementCount: pageStore.hiddenElementCount,
|
affectedElementCount: pageStore.hiddenElementCount,
|
||||||
scriptCount: pageStore.scriptCount + pageStore.inlineScriptCount,
|
scriptCount: pageStore.scriptCount,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1312,14 +1316,14 @@ var onMessage = function(request, sender, callback) {
|
|||||||
if ( request.filteredElementCount ) {
|
if ( request.filteredElementCount ) {
|
||||||
pageStore.hiddenElementCount += request.filteredElementCount;
|
pageStore.hiddenElementCount += request.filteredElementCount;
|
||||||
}
|
}
|
||||||
if ( request.inlineScriptCount ) {
|
if ( request.scriptCount ) {
|
||||||
pageStore.inlineScriptCount += request.inlineScriptCount;
|
pageStore.scriptCount += request.scriptCount;
|
||||||
}
|
}
|
||||||
let broadcastKey = tabId + '-domSurveyReport';
|
let broadcastKey = tabId + '-domSurveyReport';
|
||||||
if ( broadcastTimers.has(broadcastKey) === false ) {
|
if ( broadcastTimers.has(broadcastKey) === false ) {
|
||||||
broadcastTimers.set(broadcastKey, vAPI.setTimeout(
|
broadcastTimers.set(broadcastKey, vAPI.setTimeout(
|
||||||
( ) => { domSurveyFinalReport(tabId); },
|
( ) => { domSurveyFinalReport(tabId); },
|
||||||
250
|
53
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,6 @@ PageStore.prototype.init = function(tabId, context) {
|
|||||||
this.hiddenElementCount = ''; // Empty string means "unknown"
|
this.hiddenElementCount = ''; // Empty string means "unknown"
|
||||||
this.remoteFontCount = 0;
|
this.remoteFontCount = 0;
|
||||||
this.scriptCount = 0;
|
this.scriptCount = 0;
|
||||||
this.inlineScriptCount = 0;
|
|
||||||
this.popupBlockedCount = 0;
|
this.popupBlockedCount = 0;
|
||||||
this.largeMediaCount = 0;
|
this.largeMediaCount = 0;
|
||||||
this.largeMediaTimer = null;
|
this.largeMediaTimer = null;
|
||||||
@ -616,11 +615,11 @@ PageStore.prototype.filterRequest = function(context) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( requestType === 'script' ) {
|
if (
|
||||||
this.scriptCount += 1;
|
requestType === 'script' &&
|
||||||
if ( this.filterScripting(context.rootHostname) === 1 ) {
|
this.filterScripting(context.rootHostname, true) === 1
|
||||||
return 1;
|
) {
|
||||||
}
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cacheableResult = this.cacheableResults[requestType] === true;
|
var cacheableResult = this.cacheableResults[requestType] === true;
|
||||||
@ -720,9 +719,12 @@ PageStore.prototype.filterFont = function(context) {
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
PageStore.prototype.filterScripting = function(rootHostname) {
|
PageStore.prototype.filterScripting = function(rootHostname, netFiltering) {
|
||||||
|
if ( netFiltering === undefined ) {
|
||||||
|
netFiltering = this.getNetFilteringSwitch();
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
this.getNetFilteringSwitch() === false ||
|
netFiltering === false ||
|
||||||
µb.hnSwitches.evaluateZ('no-scripting', rootHostname) === false
|
µb.hnSwitches.evaluateZ('no-scripting', rootHostname) === false
|
||||||
) {
|
) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -47,6 +47,8 @@
|
|||||||
inlineScriptCount = 1;
|
inlineScriptCount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let scriptTags = document.querySelectorAll('script[src]');
|
||||||
|
|
||||||
let filteredElementCount = 0;
|
let filteredElementCount = 0;
|
||||||
if ( vAPI.domFilterer ) {
|
if ( vAPI.domFilterer ) {
|
||||||
filteredElementCount = vAPI.domFilterer.getFilteredElementCount();
|
filteredElementCount = vAPI.domFilterer.getFilteredElementCount();
|
||||||
@ -58,7 +60,7 @@
|
|||||||
what: 'domSurveyTransientReport',
|
what: 'domSurveyTransientReport',
|
||||||
pageURL: window.location.href,
|
pageURL: window.location.href,
|
||||||
filteredElementCount: filteredElementCount,
|
filteredElementCount: filteredElementCount,
|
||||||
inlineScriptCount: inlineScriptCount,
|
scriptCount: inlineScriptCount + scriptTags.length,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
|
@ -913,8 +913,8 @@ var injectCSP = function(pageStore, details) {
|
|||||||
let builtinDirectives = [];
|
let builtinDirectives = [];
|
||||||
|
|
||||||
context.requestType = 'script';
|
context.requestType = 'script';
|
||||||
if ( pageStore.filterScripting(context.rootHostname) === 1 ) {
|
if ( pageStore.filterScripting(context.rootHostname, true) === 1 ) {
|
||||||
builtinDirectives.push("script-src *");
|
builtinDirectives.push("script-src http: https:");
|
||||||
if ( loggerEnabled === true ) {
|
if ( loggerEnabled === true ) {
|
||||||
logger.writeOne(
|
logger.writeOne(
|
||||||
tabId,
|
tabId,
|
||||||
|
Loading…
Reference in New Issue
Block a user