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