Index: mobile/android/thirdparty/org/adblockplus/browser/AddOnBridge.java |
=================================================================== |
--- a/mobile/android/thirdparty/org/adblockplus/browser/AddOnBridge.java |
+++ b/mobile/android/thirdparty/org/adblockplus/browser/AddOnBridge.java |
@@ -17,6 +17,9 @@ |
package org.adblockplus.browser; |
+import java.util.HashMap; |
+import java.util.Map; |
+ |
import android.annotation.SuppressLint; |
import android.os.Handler; |
import android.os.HandlerThread; |
@@ -134,45 +137,77 @@ |
callback)); |
} |
- private static void sendSubscriptionRequest(final AdblockPlusApiCallback callback, |
- final String action, final String url, final String title) |
+ 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
|
+ final Map<String, String> parameters) |
{ |
- final JSONObject obj = createRequestData(action); |
+ final JSONObject requestData = createRequestData(name); |
try |
{ |
- obj.put("url", url); |
- if (title != null) |
- { |
- obj.put("title", title); |
- } |
+ for (Map.Entry<String, String> entry : parameters.entrySet()) |
+ requestData.put(entry.getKey(), entry.getValue()); |
} |
catch (JSONException e) |
{ |
// we're only adding sane objects |
Log.e(TAG, "Creating request data failed with: " + e.getMessage(), e); |
} |
- GeckoAppShell.sendRequestToGecko(new ChainedRequest(obj, callback)); |
+ GeckoAppShell.sendRequestToGecko(new ChainedRequest(requestData, callback)); |
} |
public static void querySubscriptionListStatus(final AdblockPlusApiCallback callback, |
final String url) |
{ |
Log.d(TAG, "querySubscriptionListStatus for " + url); |
- sendSubscriptionRequest(callback, "isSubscriptionListed", url, null); |
+ final Map<String, String> parameters = new HashMap<String, String>(); |
+ parameters.put("url", url); |
+ callFunction(callback, "isSubscriptionListed", parameters); |
} |
public static void addSubscription(final AdblockPlusApiCallback callback, |
final String url, final String title) |
{ |
Log.d(TAG, "addSubscription for " + url + " (" + title + ")"); |
- sendSubscriptionRequest(callback, "addSubscription", url, title); |
+ final Map<String, String> parameters = new HashMap<String, String>(); |
+ parameters.put("url", url); |
+ parameters.put("title", title); |
+ callFunction(callback, "addSubscription", parameters); |
} |
public static void removeSubscription(final AdblockPlusApiCallback callback, |
final String url) |
{ |
Log.d(TAG, "removeSubscription for " + url); |
- sendSubscriptionRequest(callback, "removeSubscription", url, null); |
+ final Map<String, String> parameters = new HashMap<String, String>(); |
+ parameters.put("url", url); |
+ callFunction(callback, "removeSubscription", parameters); |
+ } |
+ |
+ public static void queryIsLocal(final AdblockPlusApiCallback callback, |
+ final String url) |
+ { |
+ Log.d(TAG, "queryIsLocal for " + url); |
+ final Map<String, String> parameters = new HashMap<String, String>(); |
+ parameters.put("url", url); |
+ callFunction(callback, "isLocal", parameters); |
+ } |
+ |
+ public static void queryIsPageWhitelisted(final AdblockPlusApiCallback callback, |
+ final String url) |
+ { |
+ Log.d(TAG, "queryIsPageWhitelisted for " + url); |
+ final Map<String, String> parameters = new HashMap<String, String>(); |
+ parameters.put("url", url); |
+ callFunction(callback, "isPageWhitelisted", parameters); |
+ } |
+ |
+ public static void whitelistSite(final AdblockPlusApiCallback callback, final String url, |
+ final boolean whitelisted) |
+ { |
+ Log.d(TAG, "whitelistSite for " + url); |
+ final Map<String, String> parameters = new HashMap<String, String>(); |
+ parameters.put("url", url); |
+ parameters.put("whitelisted", String.valueOf(whitelisted)); |
René Jeschke
2015/05/06 10:56:33
See comment in Api.jsm and above ... having a JSON
|
+ callFunction(callback, "whitelistSite", parameters); |
} |
private static class ChainedRequest extends GeckoRequest |