Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: libadblockplus-android/src/org/adblockplus/libadblockplus/android/AndroidWebRequest.java

Issue 29351744: Issue 4399 - Add WebView inheritor with ad blocking (Closed)
Patch Set: changed packages, now using AdblockEngine (original ABPEngine), improved demo app Created Oct. 25, 2016, 11:20 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.android; 18 package org.adblockplus.libadblockplus.android;
19 19
20 import java.io.BufferedReader; 20 import java.io.BufferedReader;
21 import java.io.InputStreamReader; 21 import java.io.InputStreamReader;
22 import java.net.HttpURLConnection; 22 import java.net.HttpURLConnection;
23 import java.net.URL; 23 import java.net.URL;
24 import java.util.HashSet; 24 import java.util.HashSet;
25 import java.util.List; 25 import java.util.List;
26 26
27 import org.adblockplus.libadblockplus.AdblockPlusException; 27 import org.adblockplus.libadblockplus.AdblockPlusException;
28 import org.adblockplus.libadblockplus.FilterEngine; 28 import org.adblockplus.libadblockplus.FilterEngine;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 connection.connect(); 85 connection.connect();
86 86
87 final ServerResponse response = new ServerResponse(); 87 final ServerResponse response = new ServerResponse();
88 response.setResponseStatus(connection.getResponseCode()); 88 response.setResponseStatus(connection.getResponseCode());
89 89
90 if (response.getResponseStatus() == 200) 90 if (response.getResponseStatus() == 200)
91 { 91 {
92 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"));
93 final StringBuilder sb = new StringBuilder(); 93 final StringBuilder sb = new StringBuilder();
94 94
95 if (!this.elemhideEnabled && isListedSubscriptionUrl(url)) 95 String line;
96 while ((line = reader.readLine()) != null)
96 { 97 {
97 Log.d(TAG, "Removing element hiding rules from: '" + url + "'"); 98 // We're only appending non-element-hiding filters here.
98 99 //
99 String line; 100 // See:
100 while ((line = reader.readLine()) != null) 101 // https://issues.adblockplus.org/ticket/303
102 //
103 // Follow-up issue for removing this hack:
104 // https://issues.adblockplus.org/ticket/1541
105 //
106 if (this.elemhideEnabled || !isListedSubscriptionUrl(url) || line.inde xOf('#') == -1)
101 { 107 {
102 // We're only appending non-element-hiding filters here. 108 sb.append(line);
103 // 109 sb.append('\n');
104 // See:
105 // https://issues.adblockplus.org/ticket/303
106 //
107 // Follow-up issue for removing this hack:
108 // https://issues.adblockplus.org/ticket/1541
109 //
110 if (line.indexOf('#') == -1)
111 {
112 sb.append(line);
113 sb.append('\n');
114 }
115 }
116 }
117 else
118 {
119 int character;
120
121 while ((character = reader.read()) != -1)
122 {
123 sb.append((char) character);
124 } 110 }
125 } 111 }
126 112
127 connection.disconnect(); 113 connection.disconnect();
128 114
129 response.setStatus(NsStatus.OK); 115 response.setStatus(NsStatus.OK);
130 response.setResponse(sb.toString()); 116 response.setResponse(sb.toString());
131 } 117 }
132 else 118 else
133 { 119 {
134 response.setStatus(NsStatus.ERROR_FAILURE); 120 response.setStatus(NsStatus.ERROR_FAILURE);
135 } 121 }
122 Log.d(TAG, "Downloading finished");
136 return response; 123 return response;
137 } 124 }
138 catch (final Throwable t) 125 catch (final Throwable t)
139 { 126 {
127 Log.e(TAG, "WebRequest failed", t);
140 throw new AdblockPlusException("WebRequest failed", t); 128 throw new AdblockPlusException("WebRequest failed", t);
141 } 129 }
142 } 130 }
143 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld