|
|
@ -38,8 +38,20 @@ public class Adguard {
|
|
|
|
// https://github.com/AdguardTeam/FiltersRegistry/blob/master/filters/filter_17_TrackParam/filter.txt
|
|
|
|
// https://github.com/AdguardTeam/FiltersRegistry/blob/master/filters/filter_17_TrackParam/filter.txt
|
|
|
|
// https://github.com/AdguardTeam/TestCases/tree/master/public/Filters/removeparam-rules
|
|
|
|
// https://github.com/AdguardTeam/TestCases/tree/master/public/Filters/removeparam-rules
|
|
|
|
|
|
|
|
|
|
|
|
private static final List<String> ADGUARD_IGNORE = Collections.unmodifiableList(Arrays.asList(
|
|
|
|
private static final List<String> ALL_CONTENT = Collections.unmodifiableList(Arrays.asList(
|
|
|
|
"cookie", "font", "image", "media", "script", "subdocument", "stylesheet", "xmlhttprequest"
|
|
|
|
"document",
|
|
|
|
|
|
|
|
"subdocument",
|
|
|
|
|
|
|
|
"font",
|
|
|
|
|
|
|
|
"image",
|
|
|
|
|
|
|
|
"media",
|
|
|
|
|
|
|
|
"object",
|
|
|
|
|
|
|
|
"other",
|
|
|
|
|
|
|
|
"ping",
|
|
|
|
|
|
|
|
"script",
|
|
|
|
|
|
|
|
"stylesheet",
|
|
|
|
|
|
|
|
"websocket",
|
|
|
|
|
|
|
|
"xmlhttprequest",
|
|
|
|
|
|
|
|
"popup"
|
|
|
|
));
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Nullable
|
|
|
@ -95,6 +107,7 @@ public class Adguard {
|
|
|
|
String remove = null;
|
|
|
|
String remove = null;
|
|
|
|
boolean important = false;
|
|
|
|
boolean important = false;
|
|
|
|
boolean matches = true;
|
|
|
|
boolean matches = true;
|
|
|
|
|
|
|
|
List<String> contents = new ArrayList<>();
|
|
|
|
for (String modifier : modifiers) {
|
|
|
|
for (String modifier : modifiers) {
|
|
|
|
int equal = modifier.indexOf('=');
|
|
|
|
int equal = modifier.indexOf('=');
|
|
|
|
String name = (equal < 0 ? modifier : modifier.substring(0, equal));
|
|
|
|
String name = (equal < 0 ? modifier : modifier.substring(0, equal));
|
|
|
@ -159,21 +172,53 @@ public class Adguard {
|
|
|
|
important = true;
|
|
|
|
important = true;
|
|
|
|
Log.w("Adguard important=" + param);
|
|
|
|
Log.w("Adguard important=" + param);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (!"document".equals(name) &&
|
|
|
|
if (name.startsWith("~")) {
|
|
|
|
!"image".equals(name) &&
|
|
|
|
name = name.substring(1);
|
|
|
|
!"script".equals(name) &&
|
|
|
|
for (String content : ALL_CONTENT)
|
|
|
|
!(name.startsWith("~") && !name.equals("~document"))) {
|
|
|
|
if (!name.equals(content))
|
|
|
|
if (!ADGUARD_IGNORE.contains(name))
|
|
|
|
contents.add(content);
|
|
|
|
Log.w("Adguard ignoring=" + name);
|
|
|
|
} else
|
|
|
|
remove = null;
|
|
|
|
contents.add(name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (remove == null || !matches)
|
|
|
|
if (remove == null || !matches)
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $removeparam rules that do not have any content type modifiers will match only requests where content type is document.
|
|
|
|
|
|
|
|
if (contents.size() == 0)
|
|
|
|
|
|
|
|
contents.add("document");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> recognized = new ArrayList<>();
|
|
|
|
|
|
|
|
String mime = Helper.guessMimeType(uri.getLastPathSegment());
|
|
|
|
|
|
|
|
if (mime.startsWith("audio/") || mime.startsWith("video/"))
|
|
|
|
|
|
|
|
recognized.add("media");
|
|
|
|
|
|
|
|
else if (mime.startsWith("image/"))
|
|
|
|
|
|
|
|
recognized.add("image");
|
|
|
|
|
|
|
|
else if ("text/css".equals(mime))
|
|
|
|
|
|
|
|
recognized.add("stylesheet");
|
|
|
|
|
|
|
|
else if ("application/javascript".equals(mime))
|
|
|
|
|
|
|
|
recognized.add("script");
|
|
|
|
|
|
|
|
else if (mime.startsWith("font/"))
|
|
|
|
|
|
|
|
recognized.add("font");
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
recognized.addAll(Arrays.asList("document", "subdocument", "xmlhttprequest"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean found = false;
|
|
|
|
|
|
|
|
for (String content : recognized)
|
|
|
|
|
|
|
|
if (contents.contains(content)) {
|
|
|
|
|
|
|
|
found = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
|
|
|
|
Log.i("Adguard skipping mime=" + mime +
|
|
|
|
|
|
|
|
" recognized=" + TextUtils.join(", ", recognized) +
|
|
|
|
|
|
|
|
" contents=" + TextUtils.join(", ", contents) +
|
|
|
|
|
|
|
|
" line=" + line);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
boolean except = false;
|
|
|
|
boolean except = false;
|
|
|
|
matches = TextUtils.isEmpty(pattern);
|
|
|
|
matches = TextUtils.isEmpty(pattern);
|
|
|
|
if (!matches) {
|
|
|
|
if (!matches) {
|
|
|
|