| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 * |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 30 import org.adblockplus.libadblockplus.ServerResponse; | 30 import org.adblockplus.libadblockplus.ServerResponse; |
| 31 import org.adblockplus.libadblockplus.ServerResponse.NsStatus; | 31 import org.adblockplus.libadblockplus.ServerResponse.NsStatus; |
| 32 import org.adblockplus.libadblockplus.WebRequest; | 32 import org.adblockplus.libadblockplus.WebRequest; |
| 33 | 33 |
| 34 import android.util.Log; | 34 import android.util.Log; |
| 35 | 35 |
| 36 public class AndroidWebRequest extends WebRequest | 36 public class AndroidWebRequest extends WebRequest |
| 37 { | 37 { |
| 38 public final static String TAG = Utils.getTag(WebRequest.class); | 38 public final static String TAG = Utils.getTag(WebRequest.class); |
| 39 | 39 |
| 40 private final HashSet<String> subscriptionURLs = new HashSet<String>(); | 40 private final HashSet<String> subscriptionURLs = new HashSet<String>(); |
|
Felix Dahlke
2014/11/19 10:16:37
You're not using HashSet specific API, so why not
René Jeschke
2014/11/24 13:15:57
Because it it bloating the import statements above
Felix Dahlke
2014/11/27 05:41:57
Ah, fair enough. It's a bit unusual in Java-world
| |
| 41 | 41 |
| 42 private boolean isListedSubscriptionURL(final URL url) | 42 private boolean isListedSubscriptionUrl(final URL url) |
|
Felix Dahlke
2014/11/19 10:16:37
Seems we're usually capitalising acronyms as "Url"
René Jeschke
2014/11/24 13:15:57
Right, will change that.
| |
| 43 { | 43 { |
| 44 final String toCheck; | 44 String toCheck = url.toString(); |
| 45 | 45 |
| 46 if (url.getQuery() != null) | 46 final int idx = toCheck.indexOf('?'); |
|
Felix Dahlke
2014/11/19 10:16:37
Why cut the query string off manually again? As I
René Jeschke
2014/11/24 13:15:57
'getPath() only returns the path, I need the full
| |
| 47 if (idx != -1) | |
| 47 { | 48 { |
| 48 final String tmp = url.toString(); | 49 toCheck = toCheck.substring(0, idx); |
| 49 final int idx = tmp.indexOf('?'); | |
| 50 toCheck = idx != -1 ? tmp.substring(0, idx) : tmp; | |
| 51 } | |
| 52 else | |
| 53 { | |
| 54 toCheck = url.toString(); | |
| 55 } | 50 } |
| 56 | 51 |
| 57 return this.subscriptionURLs.contains(toCheck); | 52 return this.subscriptionURLs.contains(toCheck); |
| 58 } | 53 } |
| 59 | 54 |
| 60 protected void updateSubscriptionURLs(final FilterEngine engine) | 55 protected void updateSubscriptionURLs(final FilterEngine engine) |
| 61 { | 56 { |
| 62 for (final org.adblockplus.libadblockplus.Subscription s : engine.fetchAvail ableSubscriptions()) | 57 for (final org.adblockplus.libadblockplus.Subscription s : engine.fetchAvail ableSubscriptions()) |
|
Felix Dahlke
2014/11/19 10:16:37
fetchAvailableSubscriptions will show the list of
René Jeschke
2014/11/24 13:15:57
I really want to avoid connecting this hack with a
Felix Dahlke
2014/11/27 05:41:57
That's fair enough, yeah. In that case I suggest w
René Jeschke
2015/01/23 13:28:10
Done.
| |
| 63 { | 58 { |
| 64 this.subscriptionURLs.add(s.getProperty("url").toString()); | 59 this.subscriptionURLs.add(s.getProperty("url").toString()); |
| 65 } | 60 } |
| 61 this.subscriptionURLs.add(engine.getPref("subscriptions_exceptionsurl").toSt ring()); | |
| 66 } | 62 } |
| 67 | 63 |
| 68 @Override | 64 @Override |
| 69 public ServerResponse httpGET(final String urlStr, final List<HeaderEntry> hea ders) | 65 public ServerResponse httpGET(final String urlStr, final List<HeaderEntry> hea ders) |
| 70 { | 66 { |
| 71 try | 67 try |
| 72 { | 68 { |
| 73 final URL url = new URL(urlStr); | 69 final URL url = new URL(urlStr); |
| 74 Log.d(TAG, "Downloading from: " + url); | 70 Log.d(TAG, "Downloading from: " + url); |
| 75 | 71 |
| 76 final HttpURLConnection connection = (HttpURLConnection) url.openConnectio n(); | 72 final HttpURLConnection connection = (HttpURLConnection) url.openConnectio n(); |
| 77 connection.setRequestMethod("GET"); | 73 connection.setRequestMethod("GET"); |
| 78 connection.connect(); | 74 connection.connect(); |
| 79 | 75 |
| 80 final ServerResponse response = new ServerResponse(); | 76 final ServerResponse response = new ServerResponse(); |
| 81 response.setResponseStatus(connection.getResponseCode()); | 77 response.setResponseStatus(connection.getResponseCode()); |
| 82 | 78 |
| 83 if (response.getResponseStatus() == 200) | 79 if (response.getResponseStatus() == 200) |
| 84 { | 80 { |
| 85 final BufferedReader reader = new BufferedReader(new InputStreamReader(c onnection.getInputStream(), "UTF-8")); | 81 final BufferedReader reader = new BufferedReader(new InputStreamReader(c onnection.getInputStream(), "UTF-8")); |
| 86 final StringBuilder sb = new StringBuilder(); | 82 final StringBuilder sb = new StringBuilder(); |
| 87 | 83 |
| 88 if (isListedSubscriptionURL(url)) | 84 if (isListedSubscriptionUrl(url)) |
| 89 { | 85 { |
| 90 Log.d(TAG, "Enabling elemhide removal."); | 86 Log.d(TAG, "Removing element hiding rules from: '" + url + "'"); |
|
Felix Dahlke
2014/11/19 10:16:37
Maybe rather "Removing element hiding rules from "
René Jeschke
2014/11/24 13:15:57
I didn't want to spam the log output so I chose a
| |
| 91 | 87 |
| 92 String line; | 88 String line; |
| 93 while ((line = reader.readLine()) != null) | 89 while ((line = reader.readLine()) != null) |
| 94 { | 90 { |
| 95 // FIXME This is a hack! | |
|
Felix Dahlke
2014/11/19 10:16:37
Can we strike the "FIXME" part? :) We shouldn't ha
René Jeschke
2014/11/24 13:15:57
FIXME has the advantage that you get notified abou
Felix Dahlke
2014/11/27 05:41:57
Unless you have hundreds of FIXMEs and TODOs, whic
René Jeschke
2015/01/23 13:28:10
Ok, removed the 'FIXME', but left the rest of the
Felix Dahlke
2015/01/27 08:40:51
That's quite alright, I'm a fan of this comment. S
| |
| 96 // | |
| 97 // We're only appending non-element-hiding filters here. | 91 // We're only appending non-element-hiding filters here. |
| 98 // | 92 // |
| 99 // See: | 93 // See: |
| 100 // https://issues.adblockplus.org/ticket/303 | 94 // https://issues.adblockplus.org/ticket/303 |
| 101 // | 95 // |
| 102 // Follow-up issue for removing this hack: | 96 // Follow-up issue for removing this hack: |
| 103 // https://issues.adblockplus.org/ticket/1541 | 97 // https://issues.adblockplus.org/ticket/1541 |
| 104 // | 98 // |
| 105 if (line.indexOf('#') == -1) | 99 if (line.indexOf('#') == -1) |
| 106 { | 100 { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 129 response.setStatus(NsStatus.ERROR_FAILURE); | 123 response.setStatus(NsStatus.ERROR_FAILURE); |
| 130 } | 124 } |
| 131 return response; | 125 return response; |
| 132 } | 126 } |
| 133 catch (final Throwable t) | 127 catch (final Throwable t) |
| 134 { | 128 { |
| 135 throw new AdblockPlusException("WebRequest failed", t); | 129 throw new AdblockPlusException("WebRequest failed", t); |
| 136 } | 130 } |
| 137 } | 131 } |
| 138 } | 132 } |
| LEFT | RIGHT |