| Index: src/org/adblockplus/brazil/RequestHandler.java |
| =================================================================== |
| --- a/src/org/adblockplus/brazil/RequestHandler.java |
| +++ b/src/org/adblockplus/brazil/RequestHandler.java |
| @@ -34,6 +34,7 @@ |
| import org.adblockplus.ChunkedOutputStream; |
| import org.adblockplus.android.AdblockPlus; |
| +import org.apache.commons.lang.StringUtils; |
| import org.literateprograms.BoyerMoore; |
| import sunlabs.brazil.server.Request; |
| @@ -98,32 +99,17 @@ |
| public boolean respond(Request request) throws IOException |
| { |
| boolean block = false; |
| - String reqHost = null; |
| - String refHost = null; |
| - |
| - String referrer = request.getRequestHeader("referer"); |
| try |
| { |
| - reqHost = (new URL(request.url)).getHost(); |
| - if (referrer != null) |
| - refHost = (new URL(referrer)).getHost(); |
| - } |
| - catch (MalformedURLException e) |
| - { |
| - // We are transparent, it's not our deal if it's malformed. |
| - } |
| - |
| - try |
| - { |
| - block = application.matches(request.url, request.query, reqHost, refHost, request.getRequestHeader("accept")); |
| + block = application.matches(request.url, request.query, request.getRequestHeader("referer"), request.getRequestHeader("accept")); |
| } |
| catch (Exception e) |
| { |
| Log.e(prefix, "Filter error", e); |
| } |
| - request.log(Server.LOG_LOG, prefix, block + ": " + request.url + " ("+ refHost +")"); |
| + request.log(Server.LOG_LOG, prefix, block + ": " + request.url); |
| int count = request.server.requestCount; |
| if (shouldLogHeaders) |
| @@ -210,9 +196,20 @@ |
| // Detect if we need to add ElemHide filters |
| String type = request.responseHeaders.get("Content-Type"); |
| - String selectors = null; |
| + String[] selectors = null; |
| if (type != null && type.toLowerCase().startsWith("text/html")) |
| { |
| + String reqHost = ""; |
| + |
| + try |
| + { |
| + reqHost = (new URL(request.url)).getHost(); |
| + } |
| + catch (MalformedURLException e) |
| + { |
| + // We are transparent, it's not our deal if it's malformed. |
| + } |
| + |
| selectors = application.getSelectorsForDomain(reqHost); |
| } |
| // If no filters are applicable just pass through the response |
| @@ -304,12 +301,13 @@ |
| List<Integer> matches = matcher.match(buf, 0, count); |
| if (!matches.isEmpty()) |
| { |
| - // TODO Do we need to set encoding here? |
| - byte[] addon = selectors.getBytes(); |
| // Add filters right before match |
| int m = matches.get(0); |
| out.write(buf, 0, m); |
| - out.write(addon); |
| + out.write("<style type=\"text/css\">\n".getBytes()); |
| + // TODO Do we need to set encoding here? |
|
Wladimir Palant
2013/09/12 11:31:14
Yes, pretty certainly. We need to get the encoding
|
| + out.write(StringUtils.join(selectors, ",\r\n").getBytes()); |
| + out.write("{ display: none !important }</style>\n".getBytes()); |
| out.write(buf, m, count - m); |
| sent = true; |
| continue; |