]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/MainWebView.java
Fix a crash when a resource request has a null host and ad blocking is enabled. ...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / MainWebView.java
index 000cfad6e5899b85dd7b470fb0409ba94cd8cfab..2e5503b639c752084ff3d11305defe99fd0b1613 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * Copyright 2015-2016 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2015-2017 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
@@ -127,7 +127,6 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN
     public static SslCertificate sslCertificate;
 
 
-
     // `drawerLayout` is used in `onCreate()`, `onNewIntent()`, and `onBackPressed()`.
     private DrawerLayout drawerLayout;
 
@@ -529,14 +528,16 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN
                     // Create a variable to track if this is an ad server.
                     boolean requestHostIsAdServer = false;
 
-                    // Check all the subdomains of `requestHost`.
-                    while (requestHost.contains(".")) {
-                        if (adServersSet.contains(requestHost)) {
-                            requestHostIsAdServer = true;
-                        }
+                    // Check all the subdomains of `requestHost` if it is not null.
+                    if (requestHost != null) {
+                        while (requestHost.contains(".")) {
+                            if (adServersSet.contains(requestHost)) {
+                                requestHostIsAdServer = true;
+                            }
 
-                        // Strip out the lowest subdomain of `requestHost`.
-                        requestHost = requestHost.substring(requestHost.indexOf(".") + 1);
+                            // Strip out the lowest subdomain of `requestHost`.
+                            requestHost = requestHost.substring(requestHost.indexOf(".") + 1);
+                        }
                     }
 
                     if (requestHostIsAdServer) {  // It is an ad server.
@@ -1518,7 +1519,7 @@ public class MainWebView extends AppCompatActivity implements NavigationView.OnN
         String fileName = downloadFileNameEditText.getText().toString();
 
         // Once we have `WRITE_EXTERNAL_STORAGE` permissions we can use `setDestinationInExternalPublicDir`.
-        if (Build.VERSION.SDK_INT >= 23) { // If API >= 23, set the download save in the the `DIRECTORY_DOWNLOADS` using `fileName`.
+        if (Build.VERSION.SDK_INT >= 23) { // If API >= 23, set the download location to `/sdcard/Android/data/com.stoutner.privacybrowser.standard/files` named `fileName`.
             downloadRequest.setDestinationInExternalFilesDir(this, "/", fileName);
         } else { // Only set the title using `fileName`.
             downloadRequest.setTitle(fileName);