LEFT | RIGHT |
(no file at all) | |
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 |
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.browser; | 18 package org.adblockplus.browser; |
19 | 19 |
| 20 import java.util.HashMap; |
| 21 import java.util.Map; |
| 22 |
20 import android.annotation.SuppressLint; | 23 import android.annotation.SuppressLint; |
21 import android.os.Handler; | 24 import android.os.Handler; |
22 import android.os.HandlerThread; | 25 import android.os.HandlerThread; |
23 import android.util.Log; | 26 import android.util.Log; |
24 | 27 |
25 import org.json.JSONException; | 28 import org.json.JSONException; |
26 import org.json.JSONObject; | 29 import org.json.JSONObject; |
27 import org.mozilla.gecko.GeckoAppShell; | 30 import org.mozilla.gecko.GeckoAppShell; |
28 import org.mozilla.gecko.util.GeckoRequest; | 31 import org.mozilla.gecko.util.GeckoRequest; |
29 import org.mozilla.gecko.util.NativeJSObject; | 32 import org.mozilla.gecko.util.NativeJSObject; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 public static void setBoolean(final AdblockPlusApiCallback callback, final Str
ing name, | 130 public static void setBoolean(final AdblockPlusApiCallback callback, final Str
ing name, |
128 final boolean enable) | 131 final boolean enable) |
129 { | 132 { |
130 Log.d(TAG, "setBoolean " + enable + " for " + name); | 133 Log.d(TAG, "setBoolean " + enable + " for " + name); |
131 GeckoAppShell.sendRequestToGecko( | 134 GeckoAppShell.sendRequestToGecko( |
132 new ChainedRequest( | 135 new ChainedRequest( |
133 createRequestData("set" + makeFirstCharacterUppercase(name), enable)
, | 136 createRequestData("set" + makeFirstCharacterUppercase(name), enable)
, |
134 callback)); | 137 callback)); |
135 } | 138 } |
136 | 139 |
137 private static void sendSubscriptionRequest(final AdblockPlusApiCallback callb
ack, | 140 private static void callFunction(final AdblockPlusApiCallback callback, final
String name, |
138 final String action, final String url, final String title) | 141 final Map<String, Object> parameters) |
139 { | 142 { |
140 final JSONObject obj = createRequestData(action); | 143 final JSONObject requestData = createRequestData(name); |
141 try | 144 try |
142 { | 145 { |
143 obj.put("url", url); | 146 for (Map.Entry<String, Object> entry : parameters.entrySet()) |
144 if (title != null) | 147 requestData.put(entry.getKey(), entry.getValue()); |
145 { | |
146 obj.put("title", title); | |
147 } | |
148 } | 148 } |
149 catch (JSONException e) | 149 catch (JSONException e) |
150 { | 150 { |
151 // we're only adding sane objects | 151 // we're only adding sane objects |
152 Log.e(TAG, "Creating request data failed with: " + e.getMessage(), e); | 152 Log.e(TAG, "Creating request data failed with: " + e.getMessage(), e); |
153 } | 153 } |
154 GeckoAppShell.sendRequestToGecko(new ChainedRequest(obj, callback)); | 154 GeckoAppShell.sendRequestToGecko(new ChainedRequest(requestData, callback)); |
155 } | 155 } |
156 | 156 |
157 public static void querySubscriptionListStatus(final AdblockPlusApiCallback ca
llback, | 157 public static void querySubscriptionListStatus(final AdblockPlusApiCallback ca
llback, |
158 final String url) | 158 final String url) |
159 { | 159 { |
160 Log.d(TAG, "querySubscriptionListStatus for " + url); | 160 Log.d(TAG, "querySubscriptionListStatus for " + url); |
161 sendSubscriptionRequest(callback, "isSubscriptionListed", url, null); | 161 final Map<String, Object> parameters = new HashMap<String, Object>(); |
| 162 parameters.put("url", url); |
| 163 callFunction(callback, "isSubscriptionListed", parameters); |
162 } | 164 } |
163 | 165 |
164 public static void addSubscription(final AdblockPlusApiCallback callback, | 166 public static void addSubscription(final AdblockPlusApiCallback callback, |
165 final String url, final String title) | 167 final String url, final String title) |
166 { | 168 { |
167 Log.d(TAG, "addSubscription for " + url + " (" + title + ")"); | 169 Log.d(TAG, "addSubscription for " + url + " (" + title + ")"); |
168 sendSubscriptionRequest(callback, "addSubscription", url, title); | 170 final Map<String, Object> parameters = new HashMap<String, Object>(); |
| 171 parameters.put("url", url); |
| 172 parameters.put("title", title); |
| 173 callFunction(callback, "addSubscription", parameters); |
169 } | 174 } |
170 | 175 |
171 public static void removeSubscription(final AdblockPlusApiCallback callback, | 176 public static void removeSubscription(final AdblockPlusApiCallback callback, |
172 final String url) | 177 final String url) |
173 { | 178 { |
174 Log.d(TAG, "removeSubscription for " + url); | 179 Log.d(TAG, "removeSubscription for " + url); |
175 sendSubscriptionRequest(callback, "removeSubscription", url, null); | 180 final Map<String, Object> parameters = new HashMap<String, Object>(); |
| 181 parameters.put("url", url); |
| 182 callFunction(callback, "removeSubscription", parameters); |
| 183 } |
| 184 |
| 185 public static void queryIsLocal(final AdblockPlusApiCallback callback, |
| 186 final String url) |
| 187 { |
| 188 Log.d(TAG, "queryIsLocal for " + url); |
| 189 final Map<String, Object> parameters = new HashMap<String, Object>(); |
| 190 parameters.put("url", url); |
| 191 callFunction(callback, "isLocal", parameters); |
| 192 } |
| 193 |
| 194 public static void queryIsPageWhitelisted(final AdblockPlusApiCallback callbac
k, |
| 195 final String url) |
| 196 { |
| 197 Log.d(TAG, "queryIsPageWhitelisted for " + url); |
| 198 final Map<String, Object> parameters = new HashMap<String, Object>(); |
| 199 parameters.put("url", url); |
| 200 callFunction(callback, "isPageWhitelisted", parameters); |
| 201 } |
| 202 |
| 203 public static void whitelistSite(final AdblockPlusApiCallback callback, final
String url, |
| 204 final boolean whitelisted) |
| 205 { |
| 206 Log.d(TAG, "whitelistSite for " + url); |
| 207 final Map<String, Object> parameters = new HashMap<String, Object>(); |
| 208 parameters.put("url", url); |
| 209 parameters.put("whitelisted", whitelisted); |
| 210 callFunction(callback, "whitelistSite", parameters); |
176 } | 211 } |
177 | 212 |
178 private static class ChainedRequest extends GeckoRequest | 213 private static class ChainedRequest extends GeckoRequest |
179 { | 214 { |
180 private final JSONObject value; | 215 private final JSONObject value; |
181 private final AdblockPlusApiCallback apiCallback; | 216 private final AdblockPlusApiCallback apiCallback; |
182 private final boolean checkForFiltersLoaded; | 217 private final boolean checkForFiltersLoaded; |
183 private final long creationTime; | 218 private final long creationTime; |
184 | 219 |
185 public ChainedRequest(final JSONObject value, final AdblockPlusApiCallback c
allback, | 220 public ChainedRequest(final JSONObject value, final AdblockPlusApiCallback c
allback, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 this.invokeSuccessCallback(jsObject); | 327 this.invokeSuccessCallback(jsObject); |
293 } | 328 } |
294 else | 329 else |
295 { | 330 { |
296 this.invokeFailureCallback(jsObject); | 331 this.invokeFailureCallback(jsObject); |
297 } | 332 } |
298 } | 333 } |
299 } | 334 } |
300 } | 335 } |
301 } | 336 } |
LEFT | RIGHT |