Skip to content

Commit

Permalink
Fix #3069, and consequently #3374, #3378.
Browse files Browse the repository at this point in the history
A new filtering class has been created: "static extended filtering".
This new class is an umbrella class for more specialized filtering
engines:
- Cosmetic filtering
- Scriptlet filtering
- HTML filtering

HTML filtering is available only on platforms which support modifying
the response body on the fly, so only Firefox 57+ at the moment.

With the ability to modify the response body, HTML filtering has
been introduced: removing elements from the DOM before the source
data has been parsed by the browser.

A consequence of HTML filtering ability is to bring back script tag
filtering feature.
  • Loading branch information
gorhill committed Dec 28, 2017
1 parent d2df01d commit a9f68fe
Show file tree
Hide file tree
Showing 18 changed files with 1,841 additions and 1,048 deletions.
6 changes: 5 additions & 1 deletion platform/webext/vapi-webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ vAPI.net = {
onBeforeRequest: {},
onBeforeMaybeSpuriousCSPReport: {},
onHeadersReceived: {},
nativeCSPReportFiltering: true
nativeCSPReportFiltering: true,
webRequest: browser.webRequest,
canFilterResponseBody:
typeof browser.webRequest === 'object' &&
typeof browser.webRequest.filterResponseData === 'function'
};

/******************************************************************************/
Expand Down
3 changes: 3 additions & 0 deletions src/background.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
<script src="js/dynamic-net-filtering.js"></script>
<script src="js/static-net-filtering.js"></script>
<script src="js/url-net-filtering.js"></script>
<script src="js/static-ext-filtering.js"></script>
<script src="js/cosmetic-filtering.js"></script>
<script src="js/scriptlet-filtering.js"></script>
<script src="js/html-filtering.js"></script>
<script src="js/hnswitches.js"></script>
<script src="js/ublock.js"></script>
<script src="js/messaging.js"></script>
Expand Down
9 changes: 4 additions & 5 deletions src/js/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ api.removeObserver = function(observer) {
};

var fireNotification = function(topic, details) {
var result;
var result, r;
for ( var i = 0; i < observers.length; i++ ) {
if ( observers[i](topic, details) === false ) {
result = false;
}
r = observers[i](topic, details);
if ( r !== undefined ) { result = r; }
}
return result;
};
Expand Down Expand Up @@ -955,7 +954,7 @@ var updateNext = function() {
fireNotification(
'before-asset-updated',
{ assetKey: assetKey, type: assetEntry.content }
) !== false
) === true
) {
return assetKey;
}
Expand Down
5 changes: 3 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var µBlock = (function() { // jshint ignore:line
// Features detection.
privacySettingsSupported: vAPI.browserSettings instanceof Object,
cloudStorageSupported: vAPI.cloud instanceof Object,
canFilterResponseBody: vAPI.net.canFilterResponseBody === true,

// https://github.com/chrisaljoudi/uBlock/issues/180
// Whitelist directives need to be loaded once the PSL is available
Expand All @@ -120,8 +121,8 @@ var µBlock = (function() { // jshint ignore:line

// read-only
systemSettings: {
compiledMagic: 'vrgorlgelgws',
selfieMagic: 'pxpclstriajk'
compiledMagic: 'puuijtkfpspv',
selfieMagic: 'puuijtkfpspv'
},

restoreBackupSettings: {
Expand Down
21 changes: 4 additions & 17 deletions src/js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1379,20 +1379,9 @@ vAPI.domSurveyor = (function() {

// Library of resources is located at:
// https://github.com/gorhill/uBlock/blob/master/assets/ublock/resources.txt
if ( cfeDetails.scripts ) {
// Have the injected script tag remove itself when execution completes:
// to keep DOM as clean as possible.
var text = cfeDetails.scripts +
"\n" +
"(function() {\n" +
" var c = document.currentScript,\n" +
" p = c && c.parentNode;\n" +
" if ( p ) {\n" +
" p.removeChild(c);\n" +
" }\n" +
"})();";
vAPI.injectScriptlet(document, text);
vAPI.injectedScripts = text;
if ( response.scriptlets ) {
vAPI.injectScriptlet(document, response.scriptlets);
vAPI.injectedScripts = response.scriptlets;
}

if ( vAPI.domSurveyor instanceof Object ) {
Expand All @@ -1414,13 +1403,11 @@ vAPI.domSurveyor = (function() {
};

// This starts bootstrap process.
var url = window.location.href;
vAPI.messaging.send(
'contentscript',
{
what: 'retrieveContentScriptParameters',
pageURL: url,
locationURL: url,
url: window.location.href,
isRootFrame: window === window.top
},
bootstrapPhase1
Expand Down
Loading

3 comments on commit a9f68fe

@uBlock-user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With 1.14.23.15 scriptlet filters don't add up to the total cosmetic filter number anymore. Is this intended, if so where will they be counted from now onwards ?

@gorhill
Copy link
Owner Author

@gorhill gorhill commented on a9f68fe Jan 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended

Yes.

where will they be counted from now onwards

I haven't decided yet between two options: not counting them, or reporting "extended filters" instead of "cosmetic filters" (cosmetic filters are a subset of extended filters).

@uBlock-user
Copy link
Contributor

@uBlock-user uBlock-user commented on a9f68fe Jan 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or you could report both like

"x network filters + x cosmetic filters from + x scriptlets or extended from:"

Please sign in to comment.