]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Add on-the-fly blocklist controls. https://redmine.stoutner.com/issues/279
authorSoren Stoutner <soren@stoutner.com>
Fri, 13 Jul 2018 02:11:13 +0000 (19:11 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 13 Jul 2018 02:11:13 +0000 (19:11 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/activities/RequestsActivity.java
app/src/main/java/com/stoutner/privacybrowser/helpers/OrbotProxyHelper.java
app/src/main/res/menu/webview_options_menu.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences.xml

index e7d7c66184203bdf289349e6ece38aba6650fcdc..26a6a403a68256af7eb0bdfac55acc56edb545ca 100644 (file)
@@ -283,7 +283,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     // `fullScreenVideoFrameLayout` is used in `onCreate()` and `onConfigurationChanged()`.
     private FrameLayout fullScreenVideoFrameLayout;
 
-    // `swipeRefreshLayout` is used in `onCreate()`, `onPrepareOptionsMenu()`, `onOptionsMenuSelected()`, and `onRestart()`.
+    // `swipeRefreshLayout` is used in `onCreate()`, `onPrepareOptionsMenu()`, `onOptionsItemSelected()`, and `onRestart()`.
     private SwipeRefreshLayout swipeRefreshLayout;
 
     // `urlAppBarRelativeLayout` is used in `onCreate()` and `applyDomainSettings()`.
@@ -325,7 +325,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     // `searchURL` is used in `loadURLFromTextBox()` and `applyAppSettings()`.
     private String searchURL;
 
-    // The block list variables are used in `onCreate()` and `applyAppSettings()`.
+    // The block list variables are used in `onCreate()`, `onPrepareOptionsMenu()`, `onOptionsItemSelected()`, and `applyAppSettings()`.
     private boolean easyListEnabled;
     private boolean easyPrivacyEnabled;
     private boolean fanboysAnnoyanceListEnabled;
@@ -1691,6 +1691,10 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         MenuItem clearCookiesMenuItem = menu.findItem(R.id.clear_cookies);
         MenuItem clearDOMStorageMenuItem = menu.findItem(R.id.clear_dom_storage);
         MenuItem clearFormDataMenuItem = menu.findItem(R.id.clear_form_data);  // Form data can be removed once the minimum API >= 26.
+        MenuItem easyListMenuItem = menu.findItem(R.id.easylist);
+        MenuItem easyPrivacyMenuItem = menu.findItem(R.id.easyprivacy);
+        MenuItem fanboysAnnoyanceListMenuItem = menu.findItem(R.id.fanboys_annoyance_list);
+        MenuItem fanboysSocialBlockingListMenuItem = menu.findItem(R.id.fanboys_social_blocking_list);
         MenuItem fontSizeMenuItem = menu.findItem(R.id.font_size);
         MenuItem swipeToRefreshMenuItem = menu.findItem(R.id.swipe_to_refresh);
         MenuItem displayImagesMenuItem = menu.findItem(R.id.display_images);
@@ -1707,44 +1711,51 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         toggleThirdPartyCookiesMenuItem.setChecked(thirdPartyCookiesEnabled);
         toggleDomStorageMenuItem.setChecked(domStorageEnabled);
         toggleSaveFormDataMenuItem.setChecked(saveFormDataEnabled);  // Form data can be removed once the minimum API >= 26.
+        easyListMenuItem.setChecked(easyListEnabled);
+        easyPrivacyMenuItem.setChecked(easyPrivacyEnabled);
+        fanboysAnnoyanceListMenuItem.setChecked(fanboysAnnoyanceListEnabled);
+        fanboysSocialBlockingListMenuItem.setChecked(fanboysSocialBlockingListEnabled);
         swipeToRefreshMenuItem.setChecked(swipeRefreshLayout.isEnabled());
         displayImagesMenuItem.setChecked(mainWebView.getSettings().getLoadsImagesAutomatically());
 
         // Enable third-party cookies if first-party cookies are enabled.
         toggleThirdPartyCookiesMenuItem.setEnabled(firstPartyCookiesEnabled);
 
-        // Enable `DOM Storage` if JavaScript is enabled.
+        // Enable DOM Storage if JavaScript is enabled.
         toggleDomStorageMenuItem.setEnabled(javaScriptEnabled);
 
-        // Enable `Clear Cookies` if there are any.
+        // Enable Clear Cookies if there are any.
         clearCookiesMenuItem.setEnabled(cookieManager.hasCookies());
 
-        // Get a count of the number of files in the `Local Storage` directory.
+        // Get a count of the number of files in the Local Storage directory.
         File localStorageDirectory = new File (privateDataDirectoryString + "/app_webview/Local Storage/");
         int localStorageDirectoryNumberOfFiles = 0;
         if (localStorageDirectory.exists()) {
             localStorageDirectoryNumberOfFiles = localStorageDirectory.list().length;
         }
 
-        // Get a count of the number of files in the `IndexedDB` directory.
+        // Get a count of the number of files in the IndexedDB directory.
         File indexedDBDirectory = new File (privateDataDirectoryString + "/app_webview/IndexedDB");
         int indexedDBDirectoryNumberOfFiles = 0;
         if (indexedDBDirectory.exists()) {
             indexedDBDirectoryNumberOfFiles = indexedDBDirectory.list().length;
         }
 
-        // Enable `Clear DOM Storage` if there is any.
+        // Enable Clear DOM Storage if there is any.
         clearDOMStorageMenuItem.setEnabled(localStorageDirectoryNumberOfFiles > 0 || indexedDBDirectoryNumberOfFiles > 0);
 
-        // Enable `Clear Form Data` is there is any.  This can be removed once the minimum API >= 26.
+        // Enable Clear Form Data is there is any.  This can be removed once the minimum API >= 26.
         if (Build.VERSION.SDK_INT < 26) {
             WebViewDatabase mainWebViewDatabase = WebViewDatabase.getInstance(this);
             clearFormDataMenuItem.setEnabled(mainWebViewDatabase.hasFormData());
         }
 
-        // Enable `Clear Data` if any of the submenu items are enabled.
+        // Enable Clear Data if any of the submenu items are enabled.
         clearDataMenuItem.setEnabled(clearCookiesMenuItem.isEnabled() || clearDOMStorageMenuItem.isEnabled() || clearFormDataMenuItem.isEnabled());
 
+        // Disable Fanboy's Social Blocking List if Fanboy's Annoyance List is checked.
+        fanboysSocialBlockingListMenuItem.setEnabled(!fanboysAnnoyanceListEnabled);
+
         // Initialize font size variables.
         int fontSize = mainWebView.getSettings().getTextZoom();
         String fontSizeTitle;
@@ -2132,6 +2143,54 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                 startActivity(viewSourceIntent);
                 return true;
 
+            case R.id.easylist:
+                // Toggle the EasyList status.
+                easyListEnabled = !easyListEnabled;
+
+                // Update the menu checkbox.
+                menuItem.setChecked(easyListEnabled);
+
+                // Reload the main WebView.
+                mainWebView.reload();
+                return true;
+
+            case R.id.easyprivacy:
+                // Toggle the EasyPrivacy status.
+                easyPrivacyEnabled = !easyPrivacyEnabled;
+
+                // Update the menu checkbox.
+                menuItem.setChecked(easyPrivacyEnabled);
+
+                // Reload the main WebView.
+                mainWebView.reload();
+                return true;
+
+            case R.id.fanboys_annoyance_list:
+                // Toggle Fanboy's Annoyance List status.
+                fanboysAnnoyanceListEnabled = !fanboysAnnoyanceListEnabled;
+
+                // Update the menu checkbox.
+                menuItem.setChecked(fanboysAnnoyanceListEnabled);
+
+                // Update the staus of Fanboy's Social Blocking List.
+                MenuItem fanboysSocialBlockingListMenuItem = mainMenu.findItem(R.id.fanboys_social_blocking_list);
+                fanboysSocialBlockingListMenuItem.setEnabled(!fanboysAnnoyanceListEnabled);
+
+                // Reload the main WebView.
+                mainWebView.reload();
+                return true;
+
+            case R.id.fanboys_social_blocking_list:
+                // Toggle Fanboy's Social Blocking List status.
+                fanboysSocialBlockingListEnabled = !fanboysSocialBlockingListEnabled;
+
+                // Update teh menu checkbox.
+                menuItem.setChecked(fanboysSocialBlockingListEnabled);
+
+                // Reload the main WebView.
+                mainWebView.reload();
+                return true;
+
             case R.id.share:
                 // Setup the share string.
                 String shareString = webViewTitle + " – " + urlTextBox.getText().toString();
index 492697fd8b0ea3e12b5b2a2efd4a0c1f0a1b03be..dcf641298e1204bfddafbd5b70864229edbc1fbc 100644 (file)
@@ -82,7 +82,8 @@ public class RequestsActivity extends AppCompatActivity implements ViewRequestDi
         appBar.setCustomView(R.layout.requests_spinner);
         appBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_HOME_AS_UP);
 
-        // Initialize the resource array lists.
+        // Initialize the resource array lists.  A list is needed for all the resource requests, or the activity can crash if `MainWebViewActivity.resourceRequests` is modified after the activity loads.
+        List<String[]> allResourceRequests = new ArrayList<>();
         List<String[]> defaultResourceRequests = new ArrayList<>();
         List<String[]> allowedResourceRequests = new ArrayList<>();
         List<String[]> blockedResourceRequests = new ArrayList<>();
@@ -91,14 +92,26 @@ public class RequestsActivity extends AppCompatActivity implements ViewRequestDi
         for (String[] request : MainWebViewActivity.resourceRequests) {
             switch (Integer.valueOf(request[MainWebViewActivity.REQUEST_DISPOSITION])) {
                 case MainWebViewActivity.REQUEST_DEFAULT:
+                    // Add the request to the list of all requests.
+                    allResourceRequests.add(request);
+
+                    // Add the request to the list of default requests.
                     defaultResourceRequests.add(request);
                     break;
 
                 case MainWebViewActivity.REQUEST_ALLOWED:
+                    // Add the request to the list of all requests.
+                    allResourceRequests.add(request);
+
+                    // Add the request to the list of allowed requests.
                     allowedResourceRequests.add(request);
                     break;
 
                 case MainWebViewActivity.REQUEST_BLOCKED:
+                    // Add the request to the list of all requests.
+                    allResourceRequests.add(request);
+
+                    // Add the request to the list of blocked requests.
                     blockedResourceRequests.add(request);
                     break;
             }
@@ -106,7 +119,7 @@ public class RequestsActivity extends AppCompatActivity implements ViewRequestDi
 
         // Setup a matrix cursor for the resource lists.
         MatrixCursor spinnerCursor = new MatrixCursor(new String[]{"_id", "Requests"});
-        spinnerCursor.addRow(new Object[]{0, getString(R.string.all) + " - " + MainWebViewActivity.resourceRequests.size()});
+        spinnerCursor.addRow(new Object[]{0, getString(R.string.all) + " - " + allResourceRequests.size()});
         spinnerCursor.addRow(new Object[]{1, getString(R.string.default_label) + " - " + defaultResourceRequests.size()});
         spinnerCursor.addRow(new Object[]{2, getString(R.string.allowed_plural) + " - " + allowedResourceRequests.size()});
         spinnerCursor.addRow(new Object[]{3, getString(R.string.blocked_plural) + " - " + blockedResourceRequests.size()});
@@ -137,7 +150,7 @@ public class RequestsActivity extends AppCompatActivity implements ViewRequestDi
                 switch (position) {
                     case 0:  // All requests.
                         // Get an adapter for all the request.
-                        ArrayAdapter<String[]> allResourceRequestsArrayAdapter = new RequestsArrayAdapter(getApplicationContext(), MainWebViewActivity.resourceRequests);
+                        ArrayAdapter<String[]> allResourceRequestsArrayAdapter = new RequestsArrayAdapter(getApplicationContext(), allResourceRequests);
 
                         // Display the adapter in the list view.
                         resourceRequestsListView.setAdapter(allResourceRequestsArrayAdapter);
@@ -176,7 +189,7 @@ public class RequestsActivity extends AppCompatActivity implements ViewRequestDi
         });
 
         // Create an array adapter with the list of the resource requests.
-        ArrayAdapter<String[]> resourceRequestsArrayAdapter = new RequestsArrayAdapter(getApplicationContext(), MainWebViewActivity.resourceRequests);
+        ArrayAdapter<String[]> resourceRequestsArrayAdapter = new RequestsArrayAdapter(getApplicationContext(), allResourceRequests);
 
         // Populate the list view with the resource requests adapter.
         resourceRequestsListView.setAdapter(resourceRequestsArrayAdapter);
index 4f6cff18aa649e595487cfa636a8416e9c5446bf..a3607dad9ebaa98bd9f947871aeb4c9cca997098 100644 (file)
@@ -40,10 +40,14 @@ import java.lang.reflect.Method;
 public class OrbotProxyHelper {
     public static void setProxy(Context privacyBrowserContext, Activity parentActivity, String proxyHost, String proxyPort) {
         // Set the proxy values
-        System.setProperty("http.proxyHost", proxyHost);
-        System.setProperty("http.proxyPort", proxyPort);
-        System.setProperty("https.proxyHost", proxyHost);
-        System.setProperty("https.proxyPort", proxyPort);
+        System.setProperty("proxyHost", proxyHost);
+        System.setProperty("proxyPort", proxyPort);
+
+        // These entries shouldn't be needed if the above general settings are applied.  But I leave them in here for troubleshooting just in case.
+        //System.setProperty("http.proxyHost", proxyHost);
+        //System.setProperty("http.proxyPort", proxyPort);
+        //System.setProperty("https.proxyHost", proxyHost);
+        //System.setProperty("https.proxyPort", proxyPort);
 
         // Use reflection to apply the new proxy values.
         try {
index ba51a60046c72d86f50e82f35db13038b5010ca7..862539e0565850f2f760bcd6108052f89baf56f5 100644 (file)
         </menu>
     </item>
 
+    <item
+        android:id="@+id/blocklists"
+        android:title="@string/blocklists"
+        android:orderInCategory="800"
+        app:showAsAction="never" >
+
+        <menu>
+            <item
+                android:id="@+id/easylist"
+                android:title="@string/easylist"
+                android:orderInCategory="810"
+                android:checkable="true"
+                app:showAsAction="never" />
+
+            <item
+                android:id="@+id/easyprivacy"
+                android:title="@string/easyprivacy"
+                android:orderInCategory="820"
+                android:checkable="true"
+                app:showAsAction="never" />
+
+            <item
+                android:id="@+id/fanboys_annoyance_list"
+                android:title="@string/options_fanboys_annoyance_list"
+                android:orderInCategory="830"
+                android:checkable="true"
+                app:showAsAction="never" />
+
+            <item
+                android:id="@+id/fanboys_social_blocking_list"
+                android:title="@string/options_fanboys_social_blocking_list"
+                android:orderInCategory="840"
+                android:checkable="true"
+                app:showAsAction="never" />
+        </menu>
+    </item>
+
     <item
         android:id="@+id/layout"
         android:title="@string/layout"
-        android:orderInCategory="800"
+        android:orderInCategory="900"
         app:showAsAction="never" >
 
         <menu>
             <item
                 android:id="@+id/font_size"
                 android:title="@string/font_size"
-                android:orderInCategory="810"
+                android:orderInCategory="910"
                 app:showAsAction="never" >
 
                 <menu>
                         <item
                             android:id="@+id/font_size_twenty_five_percent"
                             android:title="@string/twenty_five_percent"
-                            android:orderInCategory="811"
+                            android:orderInCategory="911"
                             app:showAsAction="never" />
 
                         <item
                             android:id="@+id/font_size_fifty_percent"
                             android:title="@string/fifty_percent"
-                            android:orderInCategory="812"
+                            android:orderInCategory="912"
                             app:showAsAction="never" />
 
                         <item
                             android:id="@+id/font_size_seventy_five_percent"
                             android:title="@string/seventy_five_percent"
-                            android:orderInCategory="813"
+                            android:orderInCategory="913"
                             app:showAsAction="never" />
 
                         <item
                             android:id="@+id/font_size_one_hundred_percent"
                             android:title="@string/one_hundred_percent"
-                            android:orderInCategory="814"
+                            android:orderInCategory="914"
                             app:showAsAction="never" />
 
                         <item
                             android:id="@+id/font_size_one_hundred_twenty_five_percent"
                             android:title="@string/one_hundred_twenty_five_percent"
-                            android:orderInCategory="815"
+                            android:orderInCategory="915"
                             app:showAsAction="never" />
 
                         <item
                             android:id="@+id/font_size_one_hundred_fifty_percent"
                             android:title="@string/one_hundred_fifty_percent"
-                            android:orderInCategory="816"
+                            android:orderInCategory="916"
                             app:showAsAction="never" />
 
                         <item
                             android:id="@+id/font_size_one_hundred_seventy_five_percent"
                             android:title="@string/one_hundred_seventy_five_percent"
-                            android:orderInCategory="817"
+                            android:orderInCategory="917"
                             app:showAsAction="never" />
 
                         <item
                             android:id="@+id/font_size_two_hundred_percent"
                             android:title="@string/two_hundred_percent"
-                            android:orderInCategory="818"
+                            android:orderInCategory="918"
                             app:showAsAction="never" />
                     </group>
                 </menu>
             <item
                 android:id="@+id/swipe_to_refresh"
                 android:title="@string/swipe_to_refresh_options_menu"
-                android:orderInCategory="820"
+                android:orderInCategory="920"
                 android:checkable="true"
                 app:showAsAction="never" />
 
             <item
                 android:id="@+id/display_images"
                 android:title="@string/display_images"
-                android:orderInCategory="830"
+                android:orderInCategory="930"
                 android:checkable="true"
                 app:showAsAction="never" />
 
             <item
                 android:id="@+id/view_source"
                 android:title="@string/view_source"
-                android:orderInCategory="840"
+                android:orderInCategory="940"
                 app:showAsAction="never" />
         </menu>
     </item>
     <item
         android:id="@+id/share"
         android:title="@string/share"
-        android:orderInCategory="900"
+        android:orderInCategory="1000"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/find_on_page"
         android:title="@string/find_on_page"
-        android:orderInCategory="1000"
+        android:orderInCategory="1100"
         app:showAsAction="never|collapseActionView" />
     <item
         android:id="@+id/print"
         android:title="@string/print"
-        android:orderInCategory="1100"
+        android:orderInCategory="1200"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/add_to_homescreen"
         android:title="@string/add_to_home_screen"
-        android:orderInCategory="1200"
+        android:orderInCategory="1300"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/refresh"
         android:title="@string/refresh"
-        android:orderInCategory="1300"
+        android:orderInCategory="1400"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/ad_consent"
         android:title="@string/ad_consent"
-        android:orderInCategory="1400"
+        android:orderInCategory="1500"
         app:showAsAction="never" />
 </menu>
\ No newline at end of file
index a9ebd4c7b2e7c391beeaea0e3c8bf01960ac4c2c..5bbcecbc7c633538ff3a28f44ee8ea575e3bdc53 100644 (file)
         <string name="clear_cookies">Clear Cookies</string>
         <string name="clear_dom_storage">Clear DOM Storage</string>
         <string name="clear_form_data">Clear Form Data</string>
+    <string name="options_fanboys_annoyance_list">Fanboy’s Annoyance List</string>
+    <string name="options_fanboys_social_blocking_list">Fanboy’s Social Blocking List</string>
     <string name="layout">Layout</string>
         <string name="font_size">Font Size</string>
             <string name="twenty_five_percent">25%</string>
         <string name="easylist_summary">Main ad blocking list.</string>
         <string name="easyprivacy">EasyPrivacy</string>
         <string name="easyprivacy_summary">Main tracker blocking list.</string>
-        <string name="fanboy_annoyance_list">Fanboy’s annoyance list</string>
-        <string name="fanboy_annoyance_list_summary">Block annoying popups and links.  Includes Fanboy’s social blocking lists.</string>
-        <string name="fanboy_social_blocking_list">Fanboy’s social blocking list</string>
-        <string name="fanboy_social_blocking_list_summary">Blocks third-party social media content.</string>
+        <string name="fanboys_annoyance_list">Fanboy’s annoyance list</string>
+        <string name="fanboys_annoyance_list_summary">Block annoying popups and links.  Includes Fanboy’s social blocking lists.</string>
+        <string name="fanboys_social_blocking_list">Fanboy’s social blocking list</string>
+        <string name="fanboys_social_blocking_list_summary">Blocks third-party social media content.</string>
     <string name="tor">Tor</string>
         <string name="proxy_through_orbot">Proxy through Orbot</string>
         <string name="proxy_through_orbot_summary">Proxy all web traffic through Orbot on localhost:8118.</string>
index 55547577ef374f85aca51f97fd9779bf88e9d6f5..c3687d0c1555e4c686d68976e878b5316f6d2f4b 100644 (file)
 
         <SwitchPreference
             android:key="fanboy_annoyance_list"
-            android:title="@string/fanboy_annoyance_list"
-            android:summary="@string/fanboy_annoyance_list_summary"
+            android:title="@string/fanboys_annoyance_list"
+            android:summary="@string/fanboys_annoyance_list_summary"
             android:defaultValue="true" />
 
         <SwitchPreference
             android:key="fanboy_social_blocking_list"
-            android:title="@string/fanboy_social_blocking_list"
-            android:summary="@string/fanboy_social_blocking_list_summary"
+            android:title="@string/fanboys_social_blocking_list"
+            android:summary="@string/fanboys_social_blocking_list_summary"
             android:defaultValue="true" />
     </PreferenceCategory>