Index: mobile/android/base/java/org/adblockplus/browser/ExtensionBridge.java |
=================================================================== |
rename from mobile/android/base/java/org/adblockplus/browser/AddOnBridge.java |
rename to mobile/android/base/java/org/adblockplus/browser/ExtensionBridge.java |
--- a/mobile/android/base/java/org/adblockplus/browser/AddOnBridge.java |
+++ b/mobile/android/base/java/org/adblockplus/browser/ExtensionBridge.java |
@@ -25,40 +25,39 @@ |
import android.content.SharedPreferences; |
import android.os.Handler; |
import android.os.HandlerThread; |
import android.util.Log; |
import org.json.JSONArray; |
import org.json.JSONException; |
import org.mozilla.gecko.EventDispatcher; |
-import org.mozilla.gecko.GeckoAppShell; |
import org.mozilla.gecko.util.BundleEventListener; |
import org.mozilla.gecko.util.EventCallback; |
import org.mozilla.gecko.util.GeckoBundle; |
@SuppressLint("DefaultLocale") |
-public class AddOnBridge |
+public class ExtensionBridge |
{ |
- private static final String TAG = "AdblockBrowser.AddOnBridge"; |
- private static final String REQUEST_NAME = "AdblockPlus:Api"; |
+ private static final String TAG = "AdblockBrowser.ExtensionBridge"; |
+ private static final String REQUEST_NAME = "Abb:Api"; |
// Handler+HandlerThread for posting delayed re-tries without interfering with |
// other threads (e.g. the UI or Gecko thread) |
private static final HandlerThread PRIVATE_HANDLER_THREAD; |
private static final Handler PRIVATE_HANDLER; |
// Global handler, for e.g. UI tasks |
private static final HandlerThread GLOBAL_HANDLER_THREAD; |
private static final Handler GLOBAL_HANDLER; |
// Sometimes, the app is killed before the extension is able to save all changes regarding |
- // AddOnBridge requests. Given that, we need to store the pending requests on SharedPrefs, |
+ // ExtensionBridge requests. Given that, we need to store the pending requests on SharedPrefs, |
// so we can resend them to the extension once the app restarts |
// See https://issues.adblockplus.org/ticket/2853 |
private static final AddOnEventListener ADD_ON_EVENT_LISTENER = new AddOnEventListener(); |
- private static final String ON_FILTERS_LOAD_EVENT = "Abb:OnFiltersLoad"; |
- private static final String ON_FILTERS_SAVE_EVENT = "Abb:OnFiltersSave"; |
+ private static final String ON_LOADED_EVENT = "Abb:OnLoaded"; |
+ private static final String ON_FILTERS_SAVED_EVENT = "Abb:OnFiltersSaved"; |
private static final List<GeckoBundle> PENDING_REQUESTS = new ArrayList<>(); |
private static final String PENDING_REQUESTS_PREFS_KEY = "PENDING_REQUESTS_PREFS_KEY"; |
private static SharedPreferences sharedPrefs; |
private static boolean filtersLoaded; |
static |
{ |
@@ -70,19 +69,19 @@ |
GLOBAL_HANDLER_THREAD = new HandlerThread("abp-global-handler"); |
GLOBAL_HANDLER_THREAD.setDaemon(true); |
GLOBAL_HANDLER_THREAD.start(); |
GLOBAL_HANDLER = new Handler(GLOBAL_HANDLER_THREAD.getLooper()); |
} |
public static void init(Context context) |
{ |
- sharedPrefs = context.getSharedPreferences(AddOnBridge.class.getName(), Context.MODE_PRIVATE); |
+ sharedPrefs = context.getSharedPreferences(ExtensionBridge.class.getName(), Context.MODE_PRIVATE); |
EventDispatcher.getInstance().registerGeckoThreadListener( |
- ADD_ON_EVENT_LISTENER, ON_FILTERS_LOAD_EVENT, ON_FILTERS_SAVE_EVENT); |
+ ADD_ON_EVENT_LISTENER, ON_LOADED_EVENT, ON_FILTERS_SAVED_EVENT); |
loadPendingRequests(); |
} |
public static void postToHandler(Runnable runnable) |
{ |
GLOBAL_HANDLER.post(runnable); |
} |
@@ -105,17 +104,17 @@ |
callFunction("set" + makeFirstCharacterUppercase(name), data, true, callback); |
} |
public static void querySubscriptionListStatus(String url, AdblockPlusApiCallback callback) |
{ |
Log.d(TAG, "querySubscriptionListStatus for " + url); |
final GeckoBundle data = new GeckoBundle(); |
data.putString("url", url); |
- callFunction("isSubscriptionListed", data, callback); |
+ callFunction("isSubscriptionEnabled", data, callback); |
} |
public static void addSubscription(String url, String title, AdblockPlusApiCallback callback) |
{ |
Log.d(TAG, "addSubscription for " + url + " (" + title + ")"); |
final GeckoBundle data = new GeckoBundle(); |
data.putString("url", url); |
if (title != null) |
@@ -123,49 +122,49 @@ |
data.putString("title", title); |
} |
callFunction("addSubscription", data, true, callback); |
} |
public static void queryActiveSubscriptions(AdblockPlusApiCallback callback) |
{ |
Log.d(TAG, "queryActiveSubscriptions"); |
- callFunction("getActiveSubscriptions", null, callback); |
+ callFunction("getEnabledSubscriptions", null, callback); |
} |
public static void removeSubscription(String url, AdblockPlusApiCallback callback) |
{ |
Log.d(TAG, "removeSubscription for " + url); |
final GeckoBundle data = new GeckoBundle(); |
data.putString("url", url); |
callFunction("removeSubscription", data, true, callback); |
} |
public static void queryWhitelistedWebsites(final AdblockPlusApiCallback callback) { |
Log.d(TAG, "queryWhitelistedWebsites"); |
- callFunction("getWhitelistedWebsites", null, callback); |
+ callFunction("getWhitelistedDomains", null, callback); |
} |
public static void queryIsWebsiteWhitelisted(String url, AdblockPlusApiCallback callback) |
{ |
Log.d(TAG, "queryIsWebsiteWhitelisted for " + url); |
final GeckoBundle data = new GeckoBundle(); |
data.putString("url", url); |
data.putString("host", UrlUtils.getHostFromUrl(url)); |
- callFunction("isWebsiteWhitelisted", data, callback); |
+ callFunction("isDomainWhitelisted", data, callback); |
} |
public static void whitelistWebsite(String url, boolean whitelisted, AdblockPlusApiCallback callback) |
{ |
Log.d(TAG, "whitelistWebsite for " + url); |
final GeckoBundle data = new GeckoBundle(); |
data.putString("url", UrlUtils.formatUrl(url)); |
data.putString("host", UrlUtils.getHostFromUrl(url)); |
- data.putBoolean("whitelisted", whitelisted); |
- callFunction("whitelistWebsite", data, true, callback); |
+ data.putBoolean("enable", whitelisted); |
+ callFunction("whitelistDomain", data, true, callback); |
} |
private static String makeFirstCharacterUppercase(String str) |
{ |
if (Character.isUpperCase(str.charAt(0))) |
{ |
return str; |
} |
@@ -343,23 +342,24 @@ |
}); |
} |
private static class AddOnEventListener implements BundleEventListener |
{ |
@Override |
public void handleMessage(String event, GeckoBundle message, EventCallback callback) |
{ |
- if (ON_FILTERS_LOAD_EVENT.equals(event)) |
+ Log.d(TAG, "handleMessage event: " + event + " message: " + message); |
+ if (ON_LOADED_EVENT.equals(event)) |
{ |
- // The filters have been loaded by the extension. Given that, we can send all pending requests |
+ // The extension has been loaded. Given that, we can send all pending requests |
filtersLoaded = true; |
sendPendingRequests(); |
} |
- else if (ON_FILTERS_SAVE_EVENT.equals(event)) |
+ else if (ON_FILTERS_SAVED_EVENT.equals(event)) |
{ |
// All changes have been saved by the extension. That way, we can clear our list of |
// pending requests |
// See https://issues.adblockplus.org/ticket/2853 |
clearPendingRequests(); |
} |
} |
} |