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

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

Issue 5365916275572736: Issue 2351 - Add a custom menu item for whitelisting the current site (Closed)
Patch Set: Minimally invasive approach Created May 6, 2015, 12:12 a.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/BrowserAppUtils.java
===================================================================
new file mode 100644
--- /dev/null
+++ b/mobile/android/thirdparty/org/adblockplus/browser/BrowserAppUtils.java
@@ -0,0 +1,89 @@
+package org.adblockplus.browser;
René Jeschke 2015/05/06 10:56:33 I added a copyright header to all new sources, sho
Felix Dahlke 2015/05/06 16:42:50 Done.
+
+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
René Jeschke 2015/05/06 10:56:33 Just a nit and a matter of taste, I guess: I tend
Felix Dahlke 2015/05/06 16:42:50 Done.
+{
+ 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();
René Jeschke 2015/05/06 10:56:33 Nit: A newline (before L20) would improve readabil
Felix Dahlke 2015/05/06 16:42:50 Done.
+ AddOnBridge.queryIsLocal(new AdblockPlusApiCallback()
+ {
+ @Override
+ public void onApiRequestSucceeded(NativeJSObject jsObject)
+ {
+ final boolean local = AddOnBridge.getBooleanFromJsObject(jsObject, "value", true);
+ ThreadUtils.postToUiThread(new Runnable() {
René Jeschke 2015/05/06 10:56:33 We are still using Allman bracing style in code th
Felix Dahlke 2015/05/06 16:42:50 Done.
+ @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());
+ }
+}

Powered by Google App Engine
This is Rietveld