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 18 matching lines...) Expand all Loading... |
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>(); |
41 | 41 |
42 private boolean isListedSubscriptionURL(final URL url) | 42 private boolean isListedSubscriptionUrl(final URL url) |
43 { | 43 { |
44 final String toCheck; | 44 String toCheck = url.toString(); |
45 | 45 |
46 if (url.getQuery() != null) | 46 final int idx = toCheck.indexOf('?'); |
| 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()) |
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 + "'"); |
91 | 87 |
92 String line; | 88 String line; |
93 while ((line = reader.readLine()) != null) | 89 while ((line = reader.readLine()) != null) |
94 { | 90 { |
95 // We're only appending non-element-hiding filters here. | 91 // We're only appending non-element-hiding filters here. |
96 // See: https://issues.adblockplus.org/ticket/303 | 92 // |
| 93 // See: |
| 94 // https://issues.adblockplus.org/ticket/303 |
| 95 // |
| 96 // Follow-up issue for removing this hack: |
| 97 // https://issues.adblockplus.org/ticket/1541 |
| 98 // |
97 if (line.indexOf('#') == -1) | 99 if (line.indexOf('#') == -1) |
98 { | 100 { |
99 sb.append(line); | 101 sb.append(line); |
100 sb.append('\n'); | 102 sb.append('\n'); |
101 } | 103 } |
102 } | 104 } |
103 } | 105 } |
104 else | 106 else |
105 { | 107 { |
106 int character; | 108 int character; |
(...skipping 14 matching lines...) Expand all Loading... |
121 response.setStatus(NsStatus.ERROR_FAILURE); | 123 response.setStatus(NsStatus.ERROR_FAILURE); |
122 } | 124 } |
123 return response; | 125 return response; |
124 } | 126 } |
125 catch (final Throwable t) | 127 catch (final Throwable t) |
126 { | 128 { |
127 throw new AdblockPlusException("WebRequest failed", t); | 129 throw new AdblockPlusException("WebRequest failed", t); |
128 } | 130 } |
129 } | 131 } |
130 } | 132 } |
LEFT | RIGHT |