LEFT | RIGHT |
(no file at all) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH |
| 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 18 package org.adblockplus.browser; |
| 19 |
| 20 import android.util.Log; |
| 21 import android.view.MenuItem; |
| 22 |
| 23 import org.mozilla.gecko.Tab; |
| 24 import org.mozilla.gecko.Tabs; |
| 25 import org.mozilla.gecko.util.NativeJSObject; |
| 26 import org.mozilla.gecko.util.ThreadUtils; |
| 27 |
| 28 public class BrowserAppUtils |
| 29 { |
| 30 private static final String TAG = "AdblockBrowser.BrowserAppUtils"; |
| 31 |
| 32 public static void updateBlockAdsMenuItem(final MenuItem item) |
| 33 { |
| 34 final Tab selectedTab = Tabs.getInstance().getSelectedTab(); |
| 35 if (selectedTab == null) |
| 36 return; |
| 37 final String url = selectedTab.getURL(); |
| 38 |
| 39 AddOnBridge.queryIsLocal(new AdblockPlusApiCallback() |
| 40 { |
| 41 @Override |
| 42 public void onApiRequestSucceeded(NativeJSObject jsObject) |
| 43 { |
| 44 final boolean local = AddOnBridge.getBooleanFromJsObject(jsObject, "valu
e", true); |
| 45 ThreadUtils.postToUiThread(new Runnable() |
| 46 { |
| 47 @Override |
| 48 public void run() |
| 49 { |
| 50 item.setEnabled(!local); |
| 51 } |
| 52 }); |
| 53 } |
| 54 |
| 55 @Override |
| 56 public void onApiRequestFailed(String errorMessage) |
| 57 { |
| 58 Log.e(TAG, "queryIsLocal failed: " + errorMessage); |
| 59 } |
| 60 }, url); |
| 61 |
| 62 AddOnBridge.queryIsPageWhitelisted(new AdblockPlusApiCallback() |
| 63 { |
| 64 @Override |
| 65 public void onApiRequestSucceeded(NativeJSObject jsObject) |
| 66 { |
| 67 final boolean whitelisted = AddOnBridge.getBooleanFromJsObject(jsObject,
"value", false); |
| 68 ThreadUtils.postToUiThread(new Runnable() |
| 69 { |
| 70 @Override |
| 71 public void run() |
| 72 { |
| 73 item.setChecked(!whitelisted); |
| 74 } |
| 75 }); |
| 76 } |
| 77 |
| 78 @Override |
| 79 public void onApiRequestFailed(String errorMessage) |
| 80 { |
| 81 Log.e(TAG, "queryIsPageWhitelisted failed: " + errorMessage); |
| 82 } |
| 83 }, url); |
| 84 } |
| 85 |
| 86 public static void updateCurrentTabWhitelisting(final MenuItem item) |
| 87 { |
| 88 final Tab selectedTab = Tabs.getInstance().getSelectedTab(); |
| 89 if (selectedTab == null) |
| 90 return; |
| 91 final String url = selectedTab.getURL(); |
| 92 |
| 93 AddOnBridge.whitelistSite(new AdblockPlusApiCallback() |
| 94 { |
| 95 @Override |
| 96 public void onApiRequestSucceeded(NativeJSObject jsObject) |
| 97 { |
| 98 ThreadUtils.postToUiThread(new Runnable() |
| 99 { |
| 100 @Override |
| 101 public void run() |
| 102 { |
| 103 selectedTab.doReload(); |
| 104 } |
| 105 }); |
| 106 } |
| 107 |
| 108 @Override |
| 109 public void onApiRequestFailed(String errorMessage) |
| 110 { |
| 111 Log.e(TAG, "whitelistSite failed: " + errorMessage); |
| 112 } |
| 113 }, url, item.isChecked()); |
| 114 } |
| 115 |
| 116 private BrowserAppUtils() |
| 117 { |
| 118 // Shouldn't be instantiated. |
| 119 } |
| 120 } |
LEFT | RIGHT |