Index: mobile/android/thirdparty/org/adblockplus/browser/BrowserAppUtils.java |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/mobile/android/thirdparty/org/adblockplus/browser/BrowserAppUtils.java |
@@ -0,0 +1,120 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-2015 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+package org.adblockplus.browser; |
+ |
+import android.util.Log; |
+import android.view.MenuItem; |
+ |
+import org.mozilla.gecko.Tab; |
+import org.mozilla.gecko.Tabs; |
+import org.mozilla.gecko.util.NativeJSObject; |
+import org.mozilla.gecko.util.ThreadUtils; |
+ |
+public class BrowserAppUtils |
+{ |
+ private static final String TAG = "AdblockBrowser.BrowserAppUtils"; |
+ |
+ public static void updateBlockAdsMenuItem(final MenuItem item) |
+ { |
+ final Tab selectedTab = Tabs.getInstance().getSelectedTab(); |
+ if (selectedTab == null) |
+ return; |
+ final String url = selectedTab.getURL(); |
+ |
+ AddOnBridge.queryIsLocal(new AdblockPlusApiCallback() |
+ { |
+ @Override |
+ public void onApiRequestSucceeded(NativeJSObject jsObject) |
+ { |
+ final boolean local = AddOnBridge.getBooleanFromJsObject(jsObject, "value", true); |
+ ThreadUtils.postToUiThread(new Runnable() |
+ { |
+ @Override |
+ public void run() |
+ { |
+ item.setEnabled(!local); |
+ } |
+ }); |
+ } |
+ |
+ @Override |
+ public void onApiRequestFailed(String errorMessage) |
+ { |
+ Log.e(TAG, "queryIsLocal failed: " + errorMessage); |
+ } |
+ }, url); |
+ |
+ AddOnBridge.queryIsPageWhitelisted(new AdblockPlusApiCallback() |
+ { |
+ @Override |
+ public void onApiRequestSucceeded(NativeJSObject jsObject) |
+ { |
+ final boolean whitelisted = AddOnBridge.getBooleanFromJsObject(jsObject, "value", false); |
+ ThreadUtils.postToUiThread(new Runnable() |
+ { |
+ @Override |
+ public void run() |
+ { |
+ item.setChecked(!whitelisted); |
+ } |
+ }); |
+ } |
+ |
+ @Override |
+ public void onApiRequestFailed(String errorMessage) |
+ { |
+ Log.e(TAG, "queryIsPageWhitelisted failed: " + errorMessage); |
+ } |
+ }, url); |
+ } |
+ |
+ public static void updateCurrentTabWhitelisting(final MenuItem item) |
+ { |
+ final Tab selectedTab = Tabs.getInstance().getSelectedTab(); |
+ if (selectedTab == null) |
+ return; |
+ final String url = selectedTab.getURL(); |
+ |
+ AddOnBridge.whitelistSite(new AdblockPlusApiCallback() |
+ { |
+ @Override |
+ public void onApiRequestSucceeded(NativeJSObject jsObject) |
+ { |
+ ThreadUtils.postToUiThread(new Runnable() |
+ { |
+ @Override |
+ public void run() |
+ { |
+ selectedTab.doReload(); |
+ } |
+ }); |
+ } |
+ |
+ @Override |
+ public void onApiRequestFailed(String errorMessage) |
+ { |
+ Log.e(TAG, "whitelistSite failed: " + errorMessage); |
+ } |
+ }, url, item.isChecked()); |
+ } |
+ |
+ private BrowserAppUtils() |
+ { |
+ // Shouldn't be instantiated. |
+ } |
+} |