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

Unified Diff: mobile/android/thirdparty/org/adblockplus/browser/AddOnBridge.java

Issue 5365916275572736: Issue 2351 - Add a custom menu item for whitelisting the current site (Closed)
Patch Set: Address comments, rename location, change item label Created May 6, 2015, 4:41 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,
+ final Map<String, Object> 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, Object> 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, Object> parameters = new HashMap<String, Object>();
+ 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, Object> parameters = new HashMap<String, Object>();
+ 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, Object> parameters = new HashMap<String, Object>();
+ 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, Object> parameters = new HashMap<String, Object>();
+ 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, Object> parameters = new HashMap<String, Object>();
+ 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, Object> parameters = new HashMap<String, Object>();
+ parameters.put("url", url);
+ parameters.put("whitelisted", whitelisted);
+ callFunction(callback, "whitelistSite", parameters);
}
private static class ChainedRequest extends GeckoRequest
« no previous file with comments | « mobile/android/base/strings.xml.in ('k') | mobile/android/thirdparty/org/adblockplus/browser/BrowserAppUtils.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld