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: 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
« no previous file with comments | « mobile/android/thirdparty/org/adblockplus/browser/AddOnBridge.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
+ }
+}
« no previous file with comments | « mobile/android/thirdparty/org/adblockplus/browser/AddOnBridge.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld