| 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 | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 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     item.setEnabled(false); | 
|  | 40     item.setChecked(true); | 
| 39 | 41 | 
| 40     AddOnBridge.queryIsLocal(new AdblockPlusApiCallback() | 42     if (UrlUtils.isSchemeHttpOrHttps(url)) | 
| 41     { | 43     { | 
| 42       @Override | 44       AddOnBridge.queryIsWebsiteWhitelisted(new AdblockPlusApiCallback() | 
| 43       public void onApiRequestSucceeded(NativeJSObject jsObject) |  | 
| 44       { | 45       { | 
| 45         final boolean local = AddOnBridge.getBooleanFromJsObject(jsObject, "valu
     e", true); | 46         @Override | 
| 46         ThreadUtils.postToUiThread(new Runnable() | 47         public void onApiRequestSucceeded(NativeJSObject jsObject) | 
| 47         { | 48         { | 
| 48           @Override | 49           final boolean whitelisted = AddOnBridge.getBooleanFromJsObject(jsObjec
     t, "value", false); | 
| 49           public void run() | 50           ThreadUtils.postToUiThread(new Runnable() | 
| 50           { | 51           { | 
| 51             item.setEnabled(!local); | 52             @Override | 
| 52           } | 53             public void run() | 
| 53         }); | 54             { | 
| 54       } | 55               item.setEnabled(true); | 
|  | 56               item.setChecked(!whitelisted); | 
|  | 57             } | 
|  | 58           }); | 
|  | 59         } | 
| 55 | 60 | 
| 56       @Override | 61         @Override | 
| 57       public void onApiRequestFailed(String errorMessage) | 62         public void onApiRequestFailed(String errorMessage) | 
| 58       { |  | 
| 59         Log.e(TAG, "queryIsLocal failed: " + errorMessage); |  | 
| 60       } |  | 
| 61     }, url); |  | 
| 62 |  | 
| 63     AddOnBridge.queryIsPageWhitelisted(new AdblockPlusApiCallback() |  | 
| 64     { |  | 
| 65       @Override |  | 
| 66       public void onApiRequestSucceeded(NativeJSObject jsObject) |  | 
| 67       { |  | 
| 68         final boolean whitelisted = AddOnBridge.getBooleanFromJsObject(jsObject,
      "value", false); |  | 
| 69         ThreadUtils.postToUiThread(new Runnable() |  | 
| 70         { | 63         { | 
| 71           @Override | 64           Log.e(TAG, "queryIsWebsiteWhitelisted failed: " + errorMessage); | 
| 72           public void run() | 65         } | 
| 73           { | 66       }, url); | 
| 74             item.setChecked(!whitelisted); | 67     } | 
| 75           } |  | 
| 76         }); |  | 
| 77       } |  | 
| 78 |  | 
| 79       @Override |  | 
| 80       public void onApiRequestFailed(String errorMessage) |  | 
| 81       { |  | 
| 82         Log.e(TAG, "queryIsPageWhitelisted failed: " + errorMessage); |  | 
| 83       } |  | 
| 84     }, url); |  | 
| 85   } | 68   } | 
| 86 | 69 | 
| 87   public static void updateCurrentTabWhitelisting(final MenuItem item) | 70   public static void updateCurrentTabWhitelisting(final MenuItem item) | 
| 88   { | 71   { | 
| 89     final Tab selectedTab = Tabs.getInstance().getSelectedTab(); | 72     final Tab selectedTab = Tabs.getInstance().getSelectedTab(); | 
| 90     if (selectedTab == null) | 73     if (selectedTab == null) | 
| 91       return; | 74       return; | 
| 92     final String url = selectedTab.getURL(); | 75     final String url = selectedTab.getURL(); | 
| 93 | 76 | 
| 94     AddOnBridge.whitelistSite(new AdblockPlusApiCallback() | 77     AddOnBridge.whitelistWebsite(new AdblockPlusApiCallback() | 
| 95     { | 78     { | 
| 96       @Override | 79       @Override | 
| 97       public void onApiRequestSucceeded(NativeJSObject jsObject) | 80       public void onApiRequestSucceeded(NativeJSObject jsObject) | 
| 98       { | 81       { | 
| 99         ThreadUtils.postToUiThread(new Runnable() | 82         ThreadUtils.postToUiThread(new Runnable() | 
| 100         { | 83         { | 
| 101           @Override | 84           @Override | 
| 102           public void run() | 85           public void run() | 
| 103           { | 86           { | 
| 104             selectedTab.doReload(false); | 87             selectedTab.doReload(false); | 
| 105           } | 88           } | 
| 106         }); | 89         }); | 
| 107       } | 90       } | 
| 108 | 91 | 
| 109       @Override | 92       @Override | 
| 110       public void onApiRequestFailed(String errorMessage) | 93       public void onApiRequestFailed(String errorMessage) | 
| 111       { | 94       { | 
| 112         Log.e(TAG, "whitelistSite failed: " + errorMessage); | 95         Log.e(TAG, "whitelistWebsite failed: " + errorMessage); | 
| 113       } | 96       } | 
| 114     }, url, item.isChecked()); | 97     }, url, item.isChecked()); | 
| 115   } | 98   } | 
| 116 | 99 | 
| 117   public static boolean wasInstalledFromPlayStore(final Context context) | 100   public static boolean wasInstalledFromPlayStore(final Context context) | 
| 118   { | 101   { | 
| 119     final String installer = context.getPackageManager().getInstallerPackageName
     (context.getPackageName()); | 102     final String installer = context.getPackageManager().getInstallerPackageName
     (context.getPackageName()); | 
| 120     return "com.android.vending".equals(installer); | 103     return "com.android.vending".equals(installer); | 
| 121   } | 104   } | 
| 122 | 105 | 
| 123   private BrowserAppUtils() | 106   private BrowserAppUtils() | 
| 124   { | 107   { | 
| 125     // Shouldn't be instantiated. | 108     // Shouldn't be instantiated. | 
| 126   } | 109   } | 
| 127 } | 110 } | 
| OLD | NEW | 
|---|