Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 public static void setBoolean(final AdblockPlusApiCallback callback, final Str ing name, | 130 public static void setBoolean(final AdblockPlusApiCallback callback, final Str ing name, |
131 final boolean enable) | 131 final boolean enable) |
132 { | 132 { |
133 Log.d(TAG, "setBoolean " + enable + " for " + name); | 133 Log.d(TAG, "setBoolean " + enable + " for " + name); |
134 GeckoAppShell.sendRequestToGecko( | 134 GeckoAppShell.sendRequestToGecko( |
135 new ChainedRequest( | 135 new ChainedRequest( |
136 createRequestData("set" + makeFirstCharacterUppercase(name), enable) , | 136 createRequestData("set" + makeFirstCharacterUppercase(name), enable) , |
137 callback)); | 137 callback)); |
138 } | 138 } |
139 | 139 |
140 private static void callFunction(final AdblockPlusApiCallback callback, final String name, | 140 private static void callFunction(final AdblockPlusApiCallback callback, final String name, |
René Jeschke
2015/05/06 10:56:33
I must admit, that I would prefer
'final JSONObje
Felix Dahlke
2015/05/06 16:42:50
As discussed on IRC: A Map is not great, but we'd
| |
141 final Map<String, String> parameters) | 141 final Map<String, Object> parameters) |
142 { | 142 { |
143 final JSONObject requestData = createRequestData(name); | 143 final JSONObject requestData = createRequestData(name); |
144 try | 144 try |
145 { | 145 { |
146 for (Map.Entry<String, String> entry : parameters.entrySet()) | 146 for (Map.Entry<String, Object> entry : parameters.entrySet()) |
147 requestData.put(entry.getKey(), entry.getValue()); | 147 requestData.put(entry.getKey(), entry.getValue()); |
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(requestData, 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 final Map<String, String> parameters = new HashMap<String, String>(); | 161 final Map<String, Object> parameters = new HashMap<String, Object>(); |
162 parameters.put("url", url); | 162 parameters.put("url", url); |
163 callFunction(callback, "isSubscriptionListed", parameters); | 163 callFunction(callback, "isSubscriptionListed", parameters); |
164 } | 164 } |
165 | 165 |
166 public static void addSubscription(final AdblockPlusApiCallback callback, | 166 public static void addSubscription(final AdblockPlusApiCallback callback, |
167 final String url, final String title) | 167 final String url, final String title) |
168 { | 168 { |
169 Log.d(TAG, "addSubscription for " + url + " (" + title + ")"); | 169 Log.d(TAG, "addSubscription for " + url + " (" + title + ")"); |
170 final Map<String, String> parameters = new HashMap<String, String>(); | 170 final Map<String, Object> parameters = new HashMap<String, Object>(); |
171 parameters.put("url", url); | 171 parameters.put("url", url); |
172 parameters.put("title", title); | 172 parameters.put("title", title); |
173 callFunction(callback, "addSubscription", parameters); | 173 callFunction(callback, "addSubscription", parameters); |
174 } | 174 } |
175 | 175 |
176 public static void removeSubscription(final AdblockPlusApiCallback callback, | 176 public static void removeSubscription(final AdblockPlusApiCallback callback, |
177 final String url) | 177 final String url) |
178 { | 178 { |
179 Log.d(TAG, "removeSubscription for " + url); | 179 Log.d(TAG, "removeSubscription for " + url); |
180 final Map<String, String> parameters = new HashMap<String, String>(); | 180 final Map<String, Object> parameters = new HashMap<String, Object>(); |
181 parameters.put("url", url); | 181 parameters.put("url", url); |
182 callFunction(callback, "removeSubscription", parameters); | 182 callFunction(callback, "removeSubscription", parameters); |
183 } | 183 } |
184 | 184 |
185 public static void queryIsLocal(final AdblockPlusApiCallback callback, | 185 public static void queryIsLocal(final AdblockPlusApiCallback callback, |
186 final String url) | 186 final String url) |
187 { | 187 { |
188 Log.d(TAG, "queryIsLocal for " + url); | 188 Log.d(TAG, "queryIsLocal for " + url); |
189 final Map<String, String> parameters = new HashMap<String, String>(); | 189 final Map<String, Object> parameters = new HashMap<String, Object>(); |
190 parameters.put("url", url); | 190 parameters.put("url", url); |
191 callFunction(callback, "isLocal", parameters); | 191 callFunction(callback, "isLocal", parameters); |
192 } | 192 } |
193 | 193 |
194 public static void queryIsPageWhitelisted(final AdblockPlusApiCallback callbac k, | 194 public static void queryIsPageWhitelisted(final AdblockPlusApiCallback callbac k, |
195 final String url) | 195 final String url) |
196 { | 196 { |
197 Log.d(TAG, "queryIsPageWhitelisted for " + url); | 197 Log.d(TAG, "queryIsPageWhitelisted for " + url); |
198 final Map<String, String> parameters = new HashMap<String, String>(); | 198 final Map<String, Object> parameters = new HashMap<String, Object>(); |
199 parameters.put("url", url); | 199 parameters.put("url", url); |
200 callFunction(callback, "isPageWhitelisted", parameters); | 200 callFunction(callback, "isPageWhitelisted", parameters); |
201 } | 201 } |
202 | 202 |
203 public static void whitelistSite(final AdblockPlusApiCallback callback, final String url, | 203 public static void whitelistSite(final AdblockPlusApiCallback callback, final String url, |
204 final boolean whitelisted) | 204 final boolean whitelisted) |
205 { | 205 { |
206 Log.d(TAG, "whitelistSite for " + url); | 206 Log.d(TAG, "whitelistSite for " + url); |
207 final Map<String, String> parameters = new HashMap<String, String>(); | 207 final Map<String, Object> parameters = new HashMap<String, Object>(); |
208 parameters.put("url", url); | 208 parameters.put("url", url); |
209 parameters.put("whitelisted", String.valueOf(whitelisted)); | 209 parameters.put("whitelisted", whitelisted); |
René Jeschke
2015/05/06 10:56:33
See comment in Api.jsm and above ... having a JSON
| |
210 callFunction(callback, "whitelistSite", parameters); | 210 callFunction(callback, "whitelistSite", parameters); |
211 } | 211 } |
212 | 212 |
213 private static class ChainedRequest extends GeckoRequest | 213 private static class ChainedRequest extends GeckoRequest |
214 { | 214 { |
215 private final JSONObject value; | 215 private final JSONObject value; |
216 private final AdblockPlusApiCallback apiCallback; | 216 private final AdblockPlusApiCallback apiCallback; |
217 private final boolean checkForFiltersLoaded; | 217 private final boolean checkForFiltersLoaded; |
218 private final long creationTime; | 218 private final long creationTime; |
219 | 219 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 this.invokeSuccessCallback(jsObject); | 327 this.invokeSuccessCallback(jsObject); |
328 } | 328 } |
329 else | 329 else |
330 { | 330 { |
331 this.invokeFailureCallback(jsObject); | 331 this.invokeFailureCallback(jsObject); |
332 } | 332 } |
333 } | 333 } |
334 } | 334 } |
335 } | 335 } |
336 } | 336 } |
LEFT | RIGHT |