| 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-2015 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 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 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>(); |
| 41 private final boolean elemhideEnabled; |
| 42 |
| 43 AndroidWebRequest(boolean enableElemhide) |
| 44 { |
| 45 this.elemhideEnabled = enableElemhide; |
| 46 } |
| 47 |
| 48 AndroidWebRequest() |
| 49 { |
| 50 this(false); |
| 51 } |
| 41 | 52 |
| 42 private boolean isListedSubscriptionUrl(final URL url) | 53 private boolean isListedSubscriptionUrl(final URL url) |
| 43 { | 54 { |
| 44 String toCheck = url.toString(); | 55 String toCheck = url.toString(); |
| 45 | 56 |
| 46 final int idx = toCheck.indexOf('?'); | 57 final int idx = toCheck.indexOf('?'); |
| 47 if (idx != -1) | 58 if (idx != -1) |
| 48 { | 59 { |
| 49 toCheck = toCheck.substring(0, idx); | 60 toCheck = toCheck.substring(0, idx); |
| 50 } | 61 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 74 connection.connect(); | 85 connection.connect(); |
| 75 | 86 |
| 76 final ServerResponse response = new ServerResponse(); | 87 final ServerResponse response = new ServerResponse(); |
| 77 response.setResponseStatus(connection.getResponseCode()); | 88 response.setResponseStatus(connection.getResponseCode()); |
| 78 | 89 |
| 79 if (response.getResponseStatus() == 200) | 90 if (response.getResponseStatus() == 200) |
| 80 { | 91 { |
| 81 final BufferedReader reader = new BufferedReader(new InputStreamReader(c
onnection.getInputStream(), "UTF-8")); | 92 final BufferedReader reader = new BufferedReader(new InputStreamReader(c
onnection.getInputStream(), "UTF-8")); |
| 82 final StringBuilder sb = new StringBuilder(); | 93 final StringBuilder sb = new StringBuilder(); |
| 83 | 94 |
| 84 if (isListedSubscriptionUrl(url)) | 95 if (!this.elemhideEnabled && isListedSubscriptionUrl(url)) |
| 85 { | 96 { |
| 86 Log.d(TAG, "Removing element hiding rules from: '" + url + "'"); | 97 Log.d(TAG, "Removing element hiding rules from: '" + url + "'"); |
| 87 | 98 |
| 88 String line; | 99 String line; |
| 89 while ((line = reader.readLine()) != null) | 100 while ((line = reader.readLine()) != null) |
| 90 { | 101 { |
| 91 // We're only appending non-element-hiding filters here. | 102 // We're only appending non-element-hiding filters here. |
| 92 // | 103 // |
| 93 // See: | 104 // See: |
| 94 // https://issues.adblockplus.org/ticket/303 | 105 // https://issues.adblockplus.org/ticket/303 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 123 response.setStatus(NsStatus.ERROR_FAILURE); | 134 response.setStatus(NsStatus.ERROR_FAILURE); |
| 124 } | 135 } |
| 125 return response; | 136 return response; |
| 126 } | 137 } |
| 127 catch (final Throwable t) | 138 catch (final Throwable t) |
| 128 { | 139 { |
| 129 throw new AdblockPlusException("WebRequest failed", t); | 140 throw new AdblockPlusException("WebRequest failed", t); |
| 130 } | 141 } |
| 131 } | 142 } |
| 132 } | 143 } |
| OLD | NEW |