aboutsummaryrefslogtreecommitdiffstats
path: root/platform/chromium
diff options
context:
space:
mode:
authorgorhill <rhill@raymondhill.net>2015-06-11 15:08:17 -0400
committergorhill <rhill@raymondhill.net>2015-06-11 15:08:17 -0400
commit6d023e2a528a4836d5223c07b338aaa5292a929e (patch)
treeaae9755b187e8d1ce1d3f91dec674cd44c410a81 /platform/chromium
parent1a4418cd10f052e05602b4dfa252ddd6fbab4ff9 (diff)
downloaduBlock-6d023e2a528a4836d5223c07b338aaa5292a929e.zip
uBlock-6d023e2a528a4836d5223c07b338aaa5292a929e.tar.gz
uBlock-6d023e2a528a4836d5223c07b338aaa5292a929e.tar.bz2
Chrome API limitations: better block late than never (re. font switch)
Diffstat (limited to 'platform/chromium')
-rw-r--r--platform/chromium/vapi-background.js44
1 files changed, 43 insertions, 1 deletions
diff --git a/platform/chromium/vapi-background.js b/platform/chromium/vapi-background.js
index 8dc54c8..9bb91cb 100644
--- a/platform/chromium/vapi-background.js
+++ b/platform/chromium/vapi-background.js
@@ -697,6 +697,16 @@ vAPI.net.registerListeners = function() {
details.type = 'object';
};
+ var headerValue = function(headers, name) {
+ var i = headers.length;
+ while ( i-- ) {
+ if ( headers[i].name.toLowerCase() === name ) {
+ return headers[i].value.trim();
+ }
+ }
+ return '';
+ };
+
var onBeforeRequestClient = this.onBeforeRequest.callback;
var onBeforeRequest = function(details) {
normalizeRequestDetails(details);
@@ -718,15 +728,47 @@ vAPI.net.registerListeners = function() {
);
var onHeadersReceivedClient = this.onHeadersReceived.callback;
+ var onHeadersReceivedClientTypes = this.onHeadersReceived.types.slice(0);
+ var onHeadersReceivedTypes = onHeadersReceivedClientTypes.slice(0);
+ if (
+ onHeadersReceivedTypes.length !== 0 &&
+ onHeadersReceivedTypes.indexOf('other') === -1
+ ) {
+ onHeadersReceivedTypes.push('other');
+ }
var onHeadersReceived = function(details) {
normalizeRequestDetails(details);
+ // Hack to work around Chromium API limitations, where requests of
+ // type `font` are returned as `other`. For example, our normalization
+ // fail at transposing `other` into `font` for URLs which are outside
+ // what is expected. At least when headers are received we can check
+ // for content type `font/*`. Blocking at onHeadersReceived time is
+ // less worst than not blocking at all. Also, ideally vAPI shouldn't
+ // know about uBlock, but we have to deal with reality here. Also,
+ // due to Chromium bug, `other` always become `object` in case it
+ // could not be normalized into something else.
+ if ( details.type === 'object' ) {
+ if ( headerValue(details.responseHeaders, 'content-type').lastIndexOf('font/', 0) === 0 ) {
+ details.type = 'font';
+ var r = onBeforeRequestClient(details);
+ if ( typeof r === 'object' && r.cancel === true ) {
+ return { cancel: true };
+ }
+ }
+ if (
+ onHeadersReceivedClientTypes.length !== 0 &&
+ onHeadersReceivedClientTypes.indexOf(details.type) === -1
+ ) {
+ return;
+ }
+ }
return onHeadersReceivedClient(details);
};
chrome.webRequest.onHeadersReceived.addListener(
onHeadersReceived,
{
'urls': this.onHeadersReceived.urls || ['<all_urls>'],
- 'types': this.onHeadersReceived.types || []
+ 'types': onHeadersReceivedTypes
},
this.onHeadersReceived.extra
);