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

Delta Between Two Patch Sets: mobile/android/thirdparty/org/adblockplus/browser/BrowserAppUtils.java

Issue 5365916275572736: Issue 2351 - Add a custom menu item for whitelisting the current site (Closed)
Left Patch Set: Minimally invasive approach Created May 6, 2015, 12:12 a.m.
Right Patch Set: Address comments, rename location, change item label Created May 6, 2015, 4:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « mobile/android/thirdparty/org/adblockplus/browser/AddOnBridge.java ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
1 package org.adblockplus.browser; 18 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 19
3 import android.util.Log; 20 import android.util.Log;
4 import android.view.MenuItem; 21 import android.view.MenuItem;
5 22
6 import org.mozilla.gecko.Tab; 23 import org.mozilla.gecko.Tab;
7 import org.mozilla.gecko.Tabs; 24 import org.mozilla.gecko.Tabs;
8 import org.mozilla.gecko.util.NativeJSObject; 25 import org.mozilla.gecko.util.NativeJSObject;
9 import org.mozilla.gecko.util.ThreadUtils; 26 import org.mozilla.gecko.util.ThreadUtils;
10 27
11 public class BrowserAppUtils 28 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 { 29 {
13 private static final String TAG = "AdblockBrowser.BrowserAppUtils"; 30 private static final String TAG = "AdblockBrowser.BrowserAppUtils";
14 31
15 public static void updateBlockAdsMenuItem(final MenuItem item) 32 public static void updateBlockAdsMenuItem(final MenuItem item)
16 { 33 {
17 final Tab selectedTab = Tabs.getInstance().getSelectedTab(); 34 final Tab selectedTab = Tabs.getInstance().getSelectedTab();
18 if (selectedTab == null) 35 if (selectedTab == null)
19 return; 36 return;
20 final String url = selectedTab.getURL(); 37 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.
38
21 AddOnBridge.queryIsLocal(new AdblockPlusApiCallback() 39 AddOnBridge.queryIsLocal(new AdblockPlusApiCallback()
22 { 40 {
23 @Override 41 @Override
24 public void onApiRequestSucceeded(NativeJSObject jsObject) 42 public void onApiRequestSucceeded(NativeJSObject jsObject)
25 { 43 {
26 final boolean local = AddOnBridge.getBooleanFromJsObject(jsObject, "valu e", true); 44 final boolean local = AddOnBridge.getBooleanFromJsObject(jsObject, "valu e", true);
27 ThreadUtils.postToUiThread(new Runnable() { 45 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.
46 {
28 @Override 47 @Override
29 public void run() { 48 public void run()
49 {
30 item.setEnabled(!local); 50 item.setEnabled(!local);
31 } 51 }
32 }); 52 });
33 } 53 }
34 54
35 @Override 55 @Override
36 public void onApiRequestFailed(String errorMessage) 56 public void onApiRequestFailed(String errorMessage)
37 { 57 {
38 Log.e(TAG, "queryIsLocal failed: " + errorMessage); 58 Log.e(TAG, "queryIsLocal failed: " + errorMessage);
39 } 59 }
40 }, url); 60 }, url);
61
41 AddOnBridge.queryIsPageWhitelisted(new AdblockPlusApiCallback() 62 AddOnBridge.queryIsPageWhitelisted(new AdblockPlusApiCallback()
42 { 63 {
43 @Override 64 @Override
44 public void onApiRequestSucceeded(NativeJSObject jsObject) 65 public void onApiRequestSucceeded(NativeJSObject jsObject)
45 { 66 {
46 final boolean whitelisted = AddOnBridge.getBooleanFromJsObject(jsObject, "value", false); 67 final boolean whitelisted = AddOnBridge.getBooleanFromJsObject(jsObject, "value", false);
47 ThreadUtils.postToUiThread(new Runnable() { 68 ThreadUtils.postToUiThread(new Runnable()
69 {
48 @Override 70 @Override
49 public void run() { 71 public void run()
72 {
50 item.setChecked(!whitelisted); 73 item.setChecked(!whitelisted);
51 } 74 }
52 }); 75 });
53 } 76 }
54 77
55 @Override 78 @Override
56 public void onApiRequestFailed(String errorMessage) 79 public void onApiRequestFailed(String errorMessage)
57 { 80 {
58 Log.e(TAG, "queryIsPageWhitelisted failed: " + errorMessage); 81 Log.e(TAG, "queryIsPageWhitelisted failed: " + errorMessage);
59 } 82 }
60 }, url); 83 }, url);
61 } 84 }
62 85
63 public static void updateCurrentTabWhitelisting(final MenuItem item) 86 public static void updateCurrentTabWhitelisting(final MenuItem item)
64 { 87 {
65 final Tab selectedTab = Tabs.getInstance().getSelectedTab(); 88 final Tab selectedTab = Tabs.getInstance().getSelectedTab();
66 if (selectedTab == null) 89 if (selectedTab == null)
67 return; 90 return;
68 final String url = selectedTab.getURL(); 91 final String url = selectedTab.getURL();
92
69 AddOnBridge.whitelistSite(new AdblockPlusApiCallback() 93 AddOnBridge.whitelistSite(new AdblockPlusApiCallback()
70 { 94 {
71 @Override 95 @Override
72 public void onApiRequestSucceeded(NativeJSObject jsObject) 96 public void onApiRequestSucceeded(NativeJSObject jsObject)
73 { 97 {
74 ThreadUtils.postToUiThread(new Runnable() { 98 ThreadUtils.postToUiThread(new Runnable()
99 {
75 @Override 100 @Override
76 public void run() { 101 public void run()
102 {
77 selectedTab.doReload(); 103 selectedTab.doReload();
78 } 104 }
79 }); 105 });
80 } 106 }
81 107
82 @Override 108 @Override
83 public void onApiRequestFailed(String errorMessage) 109 public void onApiRequestFailed(String errorMessage)
84 { 110 {
85 Log.e(TAG, "whitelistSite failed: " + errorMessage); 111 Log.e(TAG, "whitelistSite failed: " + errorMessage);
86 } 112 }
87 }, url, item.isChecked()); 113 }, url, item.isChecked());
88 } 114 }
115
116 private BrowserAppUtils()
117 {
118 // Shouldn't be instantiated.
119 }
89 } 120 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld