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