Skip to content

Commit

Permalink
Merge pull request gorhill#80 from NanoAdblocker/sync-1.14.23.12
Browse files Browse the repository at this point in the history
Sync 1.14.23.12
  • Loading branch information
jspenguin2017 authored Jan 3, 2018
2 parents da788f3 + c656dc4 commit 2a2e8c7
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 27 deletions.
14 changes: 7 additions & 7 deletions src/_locales/ro/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
"description": "English: Click: disable\/enable uBlock₀ for this site.\n\nCtrl+click: disable uBlock₀ only on this page."
},
"popupPowerSwitchInfo1": {
"message": "Dați clic pentru a dezactiva uBlock₀ pentru acest sait.\n\nDați Ctrl+clic pentru a dezactiva uBlock₀ doar pe această pagină.",
"message": "Clic ca să dezactivezi uBo pentru acest site.\n\nCtrl+clic ca sa dezactivezi uBo doar pe această pagină.",
"description": "Message to be read by screen readers"
},
"popupPowerSwitchInfo2": {
"message": "Dați clic pentru a activa uBlock₀ pentru acest sait.",
"message": "Dați clic pentru a activa uBlock₀ pentru acest site.",
"description": "Message to be read by screen readers"
},
"popupBlockedRequestPrompt": {
Expand Down Expand Up @@ -108,23 +108,23 @@
"description": "Tooltip for the no-large-media per-site switch"
},
"popupTipNoLargeMedia1": {
"message": "Dați clic pentru a bloca elementele media de mari dimensiuni pentru acest sait",
"message": "Dați clic pentru a bloca elementele media de mari dimensiuni pentru acest site",
"description": "Tooltip for the no-large-media per-site switch"
},
"popupTipNoLargeMedia2": {
"message": "Dați clic pentru a nu mai bloca elementele media de mari dimensiuni pentru acest sait",
"message": "Dați clic pentru a nu mai bloca elementele media de mari dimensiuni pentru acest site",
"description": "Tooltip for the no-large-media per-site switch"
},
"popupTipNoCosmeticFiltering": {
"message": "Comută filtrarea vizuală pentru acest sait",
"description": "Tooltip for the no-cosmetic-filtering per-site switch"
},
"popupTipNoCosmeticFiltering1": {
"message": "Dați clic pentru a dezactiva filtrele vizuale pentru acest sait",
"message": "Dați clic pentru a dezactiva filtrele vizuale pentru acest site",
"description": "Tooltip for the no-cosmetic-filtering per-site switch"
},
"popupTipNoCosmeticFiltering2": {
"message": "Dați clic pentru a activa filtrele vizuale pentru acest sait",
"message": "Dați clic pentru a activa filtrele vizuale pentru acest site",
"description": "Tooltip for the no-cosmetic-filtering per-site switch"
},
"popupTipNoRemoteFonts": {
Expand All @@ -136,7 +136,7 @@
"description": "Tooltip for the no-remote-fonts per-site switch"
},
"popupTipNoRemoteFonts2": {
"message": "Dați clic pentru a nu mai bloca fonturile externe pentru acest sait",
"message": "Dați clic pentru a nu mai bloca fonturile externe pentru acest site",
"description": "Tooltip for the no-remote-fonts per-site switch"
},
"popupTipGlobalRules": {
Expand Down
1 change: 1 addition & 0 deletions src/background.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<script src="js/pagestore.js"></script>
<script src="js/tab.js"></script>
<script src="js/traffic.js"></script>
<script src="js/text-encode.js"></script>
<script src="js/contextmenu.js"></script>
<script src="js/reverselookup.js"></script>
<script src="js/rpcreceiver.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion src/js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,8 @@ vAPI.domSurveyor = (function() {
{
what: 'retrieveContentScriptParameters',
url: window.location.href,
isRootFrame: window === window.top
isRootFrame: window === window.top,
charset: document.characterSet
},
bootstrapPhase1
);
Expand Down
5 changes: 4 additions & 1 deletion src/js/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,10 @@ var onMessage = function(request, sender, callback) {
µb.cosmeticFilteringEngine.retrieveDomainSelectors(request, response);
// If response body filtering is supported, than the scriptlets have
// already been injected.
if ( µb.canFilterResponseBody === false ) {
if (
µb.canFilterResponseBody === false ||
µb.textEncode.normalizeCharset(request.charset) === undefined
) {
response.scriptlets = µb.scriptletFilteringEngine.retrieve(request);
}
if ( request.isRootFrame && µb.logger.isEnabled() ) {
Expand Down
190 changes: 190 additions & 0 deletions src/js/text-encode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/*******************************************************************************
uBlock Origin - a browser extension to block requests.
Copyright (C) 2018 Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uBlock
*/

'use strict';

/******************************************************************************/

µBlock.textEncode = (function() {

var normalizedCharset = new Map([
[ 'utf8', 'utf-8' ],
[ 'unicode-1-1-utf-8', 'utf-8' ],
[ 'utf-8', 'utf-8' ],
[ 'windows-1250', 'windows-1250' ],
[ 'cp1250', 'windows-1250' ],
[ 'x-cp1250', 'windows-1250' ],
[ 'windows-1251', 'windows-1251' ],
[ 'cp1251', 'windows-1251' ],
[ 'x-cp1251', 'windows-1251' ],
]);

// http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT
var cp1250_range0 = new Uint8Array([
/* 0x0100 */ 0x00, 0x00, 0xC3, 0xE3, 0xA5, 0xB9, 0xC6, 0xE6,
/* 0x0108 */ 0x00, 0x00, 0x00, 0x00, 0xC8, 0xE8, 0xCF, 0xEF,
/* 0x0110 */ 0xD0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0118 */ 0xCA, 0xEA, 0xCC, 0xEC, 0x00, 0x00, 0x00, 0x00,
/* 0x0120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0130 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0138 */ 0x00, 0xC5, 0xE5, 0x00, 0x00, 0xBC, 0xBE, 0x00,
/* 0x0140 */ 0x00, 0xA3, 0xB3, 0xD1, 0xF1, 0x00, 0x00, 0xD2,
/* 0x0148 */ 0xF2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0150 */ 0xD5, 0xF5, 0x00, 0x00, 0xC0, 0xE0, 0x00, 0x00,
/* 0x0158 */ 0xD8, 0xF8, 0x8C, 0x9C, 0x00, 0x00, 0xAA, 0xBA,
/* 0x0160 */ 0x8A, 0x9A, 0xDE, 0xFE, 0x8D, 0x9D, 0x00, 0x00,
/* 0x0168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD9, 0xF9,
/* 0x0170 */ 0xDB, 0xFB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0178 */ 0x00, 0x8F, 0x9F, 0xAF, 0xBF, 0x8E, 0x9E, 0x00
]);

// http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT
var cp1251_range0 = new Uint8Array([
/* 0x0400 */ 0x00, 0xA8, 0x80, 0x81, 0xAA, 0xBD, 0xB2, 0xAF,
/* 0x0408 */ 0xA3, 0x8A, 0x8C, 0x8E, 0x8D, 0x00, 0xA1, 0x8F,
/* 0x0410 */ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
/* 0x0418 */ 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
/* 0x0420 */ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
/* 0x0428 */ 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
/* 0x0430 */ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
/* 0x0438 */ 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
/* 0x0440 */ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
/* 0x0448 */ 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
/* 0x0450 */ 0x00, 0xB8, 0x90, 0x83, 0xBA, 0xBE, 0xB3, 0xBF,
/* 0x0458 */ 0xBC, 0x9A, 0x9C, 0x9E, 0x9D, 0x00, 0xA2, 0x9F,
/* 0x0460 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0468 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0470 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0478 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0480 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0488 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x0490 */ 0xA5, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
]);

var cp125x_range0 = new Uint8Array([
/* 0x2010 */ 0x00, 0x00, 0x00, 0x96, 0x97, 0x00, 0x00, 0x00,
/* 0x2018 */ 0x91, 0x92, 0x82, 0x00, 0x93, 0x94, 0x84, 0x00,
/* 0x2020 */ 0x86, 0x87, 0x95, 0x00, 0x00, 0x00, 0x85, 0x00,
/* 0x2028 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x2030 */ 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
/* 0x2038 */ 0x00, 0x8B, 0x9B, 0x00, 0x00, 0x00, 0x00, 0x00
]);

var encoders = {
'windows-1250': function(buf) {
var i = 0, n = buf.byteLength, o = 0, c;
while ( i < n ) {
c = buf[i++];
if ( c < 0x80 ) {
buf[o++] = c;
} else {
if ( (c & 0xE0) === 0xC0 ) {
c = (c & 0x1F) << 6;
c |= (buf[i++] & 0x3F);
} else if ( (c & 0xF0) === 0xE0 ) {
c = (c & 0x0F) << 12;
c |= (buf[i++] & 0x3F) << 6;
c |= (buf[i++] & 0x3F);
} else if ( (c & 0xF8) === 0xF0 ) {
c = (c & 0x07) << 18;
c |= (buf[i++] & 0x3F) << 12;
c |= (buf[i++] & 0x3F) << 6;
c |= (buf[i++] & 0x3F);
}
if ( c < 0x100 ) {
buf[o++] = c;
} else if ( c >= 0x100 && c < 0x180 ) {
buf[o++] = cp1250_range0[c - 0x100];
} else if ( c >= 0x2010 && c < 0x2040 ) {
buf[o++] = cp125x_range0[c - 0x2010];
} else if ( c === 0x02C7 ) {
buf[o++] = 0xA1;
} else if ( c === 0x02D8 ) {
buf[o++] = 0xA2;
} else if ( c === 0x02D9 ) {
buf[o++] = 0xFF;
} else if ( c === 0x02DB ) {
buf[o++] = 0xB2;
} else if ( c === 0x02DD ) {
buf[o++] = 0xBD;
} else if ( c === 0x20AC ) {
buf[o++] = 0x88;
} else if ( c === 0x2122 ) {
buf[o++] = 0x99;
}
}
}
return buf.slice(0, o);
},
'windows-1251': function(buf) {
var i = 0, n = buf.byteLength, o = 0, c;
while ( i < n ) {
c = buf[i++];
if ( c < 0x80 ) {
buf[o++] = c;
} else {
if ( (c & 0xE0) === 0xC0 ) {
c = (c & 0x1F) << 6;
c |= (buf[i++] & 0x3F);
} else if ( (c & 0xF0) === 0xE0 ) {
c = (c & 0x0F) << 12;
c |= (buf[i++] & 0x3F) << 6;
c |= (buf[i++] & 0x3F);
} else if ( (c & 0xF8) === 0xF0 ) {
c = (c & 0x07) << 18;
c |= (buf[i++] & 0x3F) << 12;
c |= (buf[i++] & 0x3F) << 6;
c |= (buf[i++] & 0x3F);
}
if ( c < 0x100 ) {
buf[o++] = c;
} else if ( c >= 0x400 && c < 0x4A0 ) {
buf[o++] = cp1251_range0[c - 0x400];
} else if ( c >= 0x2010 && c < 0x2040 ) {
buf[o++] = cp125x_range0[c - 0x2010];
} else if ( c === 0x20AC ) {
buf[o++] = 0x88;
} else if ( c === 0x2116 ) {
buf[o++] = 0xB9;
} else if ( c === 0x2122 ) {
buf[o++] = 0x99;
}
}
}
return buf.slice(0, o);
}
};

return {
encode: function(charset, buf) {
return encoders.hasOwnProperty(charset) ?
encoders[charset](buf) :
buf;
},
normalizeCharset: function(charset) {
if ( charset === undefined ) {
return 'utf-8';
}
return normalizedCharset.get(charset.toLowerCase());
}
};
})();
38 changes: 20 additions & 18 deletions src/js/traffic.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2017 Raymond Hill
Copyright (C) 2014-2018 Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -511,7 +511,7 @@ var onHeadersReceived = function(details) {
}

if ( isDoc && µb.canFilterResponseBody ) {
filterDocument(details);
filterDocument(pageStore, details);
}

// https://github.com/gorhill/uBlock/issues/2813
Expand Down Expand Up @@ -579,6 +579,9 @@ var filterDocument = (function() {
domParser, xmlSerializer,
textDecoderCharset, textDecoder, textEncoder;

var reContentTypeDocument = /^(?:text\/html|application\/xhtml+xml)/i,
reContentTypeCharset = /charset=['"]?([^'" ]+)/i;

// Purpose of following helper is to disconnect from watching the stream
// if all the following conditions are fulfilled:
// - Only need to inject scriptlets.
Expand Down Expand Up @@ -750,30 +753,31 @@ var filterDocument = (function() {
return;
}

// If the charset of the document was not utf-8, we need to change it
// to utf-8.
if ( textDecoderCharset !== undefined ) {
var meta = doc.createElement('meta');
meta.setAttribute('charset', 'utf-8');
doc.head.insertBefore(meta, doc.head.firstChild);
}

// https://stackoverflow.com/questions/6088972/get-doctype-of-an-html-as-string-with-javascript/10162353#10162353
var doctypeStr = doc.doctype instanceof Object ?
xmlSerializer.serializeToString(doc.doctype) + '\n' :
'';

streamClose(
filterer,
textEncoder.encode(doctypeStr + doc.documentElement.outerHTML)
// https://github.com/gorhill/uBlock/issues/3391
var encodedStream = textEncoder.encode(
doctypeStr +
doc.documentElement.outerHTML
);
if ( textDecoderCharset !== undefined ) {
encodedStream = µb.textEncode.encode(
textDecoderCharset,
encodedStream
);
}

streamClose(filterer, encodedStream);
};

var onStreamError = function() {
filterers.delete(this);
};

return function(details) {
return function(pageStore, details) {
var hostname = µb.URI.hostnameFromURI(details.url);
if ( hostname === '' ) { return; }

Expand Down Expand Up @@ -807,7 +811,8 @@ var filterDocument = (function() {
if ( reContentTypeDocument.test(contentType) === false ) { return; }
var match = reContentTypeCharset.exec(contentType);
if ( match !== null ) {
var charset = match[1].toLowerCase();
var charset = µb.textEncode.normalizeCharset(match[1]);
if ( charset === undefined ) { return; }
if ( charset !== 'utf-8' ) {
request.charset = charset;
}
Expand All @@ -825,9 +830,6 @@ var filterDocument = (function() {
};
})();

var reContentTypeDocument = /^(?:text\/html|application\/xhtml+xml)/i;
var reContentTypeCharset = /charset=['"]?([^'" ]+)/i;

/******************************************************************************/

var injectCSP = function(pageStore, details) {
Expand Down

0 comments on commit 2a2e8c7

Please sign in to comment.