Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include <cctype> | |
18 #include <climits> | 19 #include <climits> |
20 #include <cstdio> | |
19 | 21 |
20 #include <emscripten.h> | 22 #include <emscripten.h> |
21 | 23 |
22 #include "RegExpFilter.h" | 24 #include "RegExpFilter.h" |
23 #include "../StringScanner.h" | 25 #include "../StringScanner.h" |
24 #include "../StringMap.h" | 26 #include "../StringMap.h" |
25 | 27 |
26 namespace | 28 namespace |
27 { | 29 { |
28 enum | 30 enum |
29 { | 31 { |
30 TYPE_OTHER = 0x1, | 32 TYPE_OTHER = 0x1, |
31 TYPE_SCRIPT = 0x2, | 33 TYPE_SCRIPT = 0x2, |
32 TYPE_IMAGE = 0x4, | 34 TYPE_IMAGE = 0x4, |
33 TYPE_STYLESHEET = 0x8, | 35 TYPE_STYLESHEET = 0x8, |
34 TYPE_OBJECT = 0x10, | 36 TYPE_OBJECT = 0x10, |
35 TYPE_SUBDOCUMENT = 0x20, | 37 TYPE_SUBDOCUMENT = 0x20, |
36 TYPE_DOCUMENT = 0x40, | 38 TYPE_DOCUMENT = 0x40, |
37 TYPE_PING = 0x400, | 39 TYPE_PING = 0x400, |
38 TYPE_XMLHTTPREQUEST = 0x800, | 40 TYPE_XMLHTTPREQUEST = 0x800, |
39 TYPE_OBJECT_SUBREQUEST = 0x1000, | 41 TYPE_OBJECT_SUBREQUEST = 0x1000, |
40 TYPE_MEDIA = 0x4000, | 42 TYPE_MEDIA = 0x4000, |
41 TYPE_FONT = 0x8000, | 43 TYPE_FONT = 0x8000, |
42 TYPE_POPUP = 0x8000000, | 44 TYPE_POPUP = 0x8000000, |
43 TYPE_GENERICBLOCK = 0x10000000, | 45 TYPE_GENERICBLOCK = 0x10000000, |
44 TYPE_GENERICHIDE = 0x20000000, | 46 TYPE_GENERICHIDE = 0x20000000, |
45 TYPE_ELEMHIDE = 0x40000000, | 47 TYPE_ELEMHIDE = 0x40000000, |
46 }; | 48 }; |
47 | 49 |
48 StringMap<int> typeMap { | 50 StringMap<int> typeMap { |
sergei
2017/03/30 11:09:17
BTW, it would be better to add const here. I think
| |
49 {u"other"_str, TYPE_OTHER}, | 51 {u"other"_str, TYPE_OTHER}, |
50 {u"script"_str, TYPE_SCRIPT}, | 52 {u"script"_str, TYPE_SCRIPT}, |
51 {u"image"_str, TYPE_IMAGE}, | 53 {u"image"_str, TYPE_IMAGE}, |
52 {u"stylesheet"_str, TYPE_STYLESHEET}, | 54 {u"stylesheet"_str, TYPE_STYLESHEET}, |
53 {u"object"_str, TYPE_OBJECT}, | 55 {u"object"_str, TYPE_OBJECT}, |
54 {u"subdocument"_str, TYPE_SUBDOCUMENT}, | 56 {u"subdocument"_str, TYPE_SUBDOCUMENT}, |
55 {u"document"_str, TYPE_DOCUMENT}, | 57 {u"document"_str, TYPE_DOCUMENT}, |
56 {u"xbl"_str, TYPE_OTHER}, // Backwards compat | 58 {u"xbl"_str, TYPE_OTHER}, // Backwards compat |
57 {u"ping"_str, TYPE_PING}, | 59 {u"ping"_str, TYPE_PING}, |
58 {u"xmlhttprequest"_str, TYPE_XMLHTTPREQUEST}, | 60 {u"xmlhttprequest"_str, TYPE_XMLHTTPREQUEST}, |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 done = scanner.done(); | 337 done = scanner.done(); |
336 if (scanner.next() == u'|') | 338 if (scanner.next() == u'|') |
337 { | 339 { |
338 if (scanner.position() > start) | 340 if (scanner.position() > start) |
339 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ; | 341 AddSitekey(DependentString(sitekeys, start, scanner.position() - start)) ; |
340 start = scanner.position() + 1; | 342 start = scanner.position() + 1; |
341 } | 343 } |
342 } | 344 } |
343 } | 345 } |
344 | 346 |
345 void RegExpFilter::InitJSTypes() | 347 void RegExpFilter::GenerateCustomBindings() |
346 { | 348 { |
sergei
2017/03/30 11:09:18
BTW, what about having of this method under `#ifde
Wladimir Palant
2017/03/30 12:58:58
Why? The compiler will remove it if not needed.
sergei
2017/04/04 14:49:30
Generally yes, but I'm not sure that compiler can
Wladimir Palant
2017/04/04 15:41:48
I sincerely disagee - we are adding EMSCRIPTEN_KEE
sergei
2017/04/11 16:29:20
I'm pretty sure that compiler is not removing this
Wladimir Palant
2017/04/11 18:22:44
That's actually me doing something stupid - this f
| |
347 EM_ASM(exports.RegExpFilter.typeMap = {};); | 349 printf("exports.RegExpFilter.typeMap = {\n"); |
350 | |
351 OwnedString type; | |
352 char type_cstr[256]; | |
348 for (auto it = typeMap.begin(); it != typeMap.end(); ++it) | 353 for (auto it = typeMap.begin(); it != typeMap.end(); ++it) |
349 EM_ASM_ARGS(exports.RegExpFilter.typeMap[readString($0).replace("-", "_").to UpperCase()] = $1, &(it->first), it->second); | 354 { |
355 type = it->first; | |
356 for (int i = 0; i < type.length(); i++) | |
357 { | |
358 if (type[i] == '-') | |
359 type_cstr[i] = '_'; | |
360 else | |
361 type_cstr[i] = toupper(type[i]); | |
sergei
2017/03/30 11:09:17
Just wonder, does compiler generate a warning here
Wladimir Palant
2017/03/30 12:58:58
Nope, for me it doesn't.
| |
362 } | |
363 type_cstr[type.length()] = 0; | |
364 printf(" %s: %i,\n", type_cstr, it->second); | |
365 } | |
366 printf("};\n"); | |
350 } | 367 } |
sergei
2017/03/30 11:09:17
This implementation smells but since it's only to
Wladimir Palant
2017/03/30 12:58:58
Yes, this isn't runtime code.
| |
351 | 368 |
352 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const | 369 RegExpFilter::DomainMap* RegExpFilter::GetDomains() const |
353 { | 370 { |
354 if (!mData.DomainsParsingDone()) | 371 if (!mData.DomainsParsingDone()) |
355 { | 372 { |
356 ParseDomains(mData.GetDomainsSource(mText), u'|'); | 373 ParseDomains(mData.GetDomainsSource(mText), u'|'); |
357 mData.SetDomainsParsingDone(); | 374 mData.SetDomainsParsingDone(); |
358 } | 375 } |
359 return ActiveFilter::GetDomains(); | 376 return ActiveFilter::GetDomains(); |
360 } | 377 } |
(...skipping 19 matching lines...) Expand all Loading... | |
380 return false; | 397 return false; |
381 } | 398 } |
382 | 399 |
383 if (!mData.RegExpParsingDone()) | 400 if (!mData.RegExpParsingDone()) |
384 { | 401 { |
385 const OwnedString pattern(mData.GetRegExpSource(mText)); | 402 const OwnedString pattern(mData.GetRegExpSource(mText)); |
386 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ; | 403 mData.SetRegExp(GenerateRegExp(RegExpFromSource(pattern), mData.mMatchCase)) ; |
387 } | 404 } |
388 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location); | 405 return EM_ASM_INT(return regexps.test($0, $1), mData.mRegexpId, &location); |
389 } | 406 } |
OLD | NEW |