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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 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.
2
3 import android.util.Log;
4 import android.view.MenuItem;
5
6 import org.mozilla.gecko.Tab;
7 import org.mozilla.gecko.Tabs;
8 import org.mozilla.gecko.util.NativeJSObject;
9 import org.mozilla.gecko.util.ThreadUtils;
10
11 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.
12 {
13 private static final String TAG = "AdblockBrowser.BrowserAppUtils";
14
15 public static void updateBlockAdsMenuItem(final MenuItem item)
16 {
17 final Tab selectedTab = Tabs.getInstance().getSelectedTab();
18 if (selectedTab == null)
19 return;
20 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.
21 AddOnBridge.queryIsLocal(new AdblockPlusApiCallback()
22 {
23 @Override
24 public void onApiRequestSucceeded(NativeJSObject jsObject)
25 {
26 final boolean local = AddOnBridge.getBooleanFromJsObject(jsObject, "valu e", true);
27 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.
28 @Override
29 public void run() {
30 item.setEnabled(!local);
31 }
32 });
33 }
34
35 @Override
36 public void onApiRequestFailed(String errorMessage)
37 {
38 Log.e(TAG, "queryIsLocal failed: " + errorMessage);
39 }
40 }, url);
41 AddOnBridge.queryIsPageWhitelisted(new AdblockPlusApiCallback()
42 {
43 @Override
44 public void onApiRequestSucceeded(NativeJSObject jsObject)
45 {
46 final boolean whitelisted = AddOnBridge.getBooleanFromJsObject(jsObject, "value", false);
47 ThreadUtils.postToUiThread(new Runnable() {
48 @Override
49 public void run() {
50 item.setChecked(!whitelisted);
51 }
52 });
53 }
54
55 @Override
56 public void onApiRequestFailed(String errorMessage)
57 {
58 Log.e(TAG, "queryIsPageWhitelisted failed: " + errorMessage);
59 }
60 }, url);
61 }
62
63 public static void updateCurrentTabWhitelisting(final MenuItem item)
64 {
65 final Tab selectedTab = Tabs.getInstance().getSelectedTab();
66 if (selectedTab == null)
67 return;
68 final String url = selectedTab.getURL();
69 AddOnBridge.whitelistSite(new AdblockPlusApiCallback()
70 {
71 @Override
72 public void onApiRequestSucceeded(NativeJSObject jsObject)
73 {
74 ThreadUtils.postToUiThread(new Runnable() {
75 @Override
76 public void run() {
77 selectedTab.doReload();
78 }
79 });
80 }
81
82 @Override
83 public void onApiRequestFailed(String errorMessage)
84 {
85 Log.e(TAG, "whitelistSite failed: " + errorMessage);
86 }
87 }, url, item.isChecked());
88 }
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld