// 'homepage' is used in `onCreate()`, `onNavigationItemSelected()`, and `applyAppSettings()`.
private String homepage;
- // `javaScriptDisabledSearchURL` is used in `loadURLFromTextBox()` and `applyAppSettings()`.
- private String javaScriptDisabledSearchURL;
-
- // `javaScriptEnabledSearchURL` is used in `loadURLFromTextBox()` and `applyAppSettings()`.
- private String javaScriptEnabledSearchURL;
+ // `searchURL` is used in `loadURLFromTextBox()` and `applyAppSettings()`.
+ private String searchURL;
// `adBlockerEnabled` is used in `onCreate()` and `applyAppSettings()`.
private boolean adBlockerEnabled;
@SuppressWarnings("deprecation")
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
- // Use an external email program if the link begins with `mailto:`.
- if (url.startsWith("mailto:")) {
+ if (url.startsWith("mailto:")) { // Load the URL in an external email program because it begins with `mailto:`.
// We use `ACTION_SENDTO` instead of `ACTION_SEND` so that only email programs are launched.
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
// Make it so.
startActivity(emailIntent);
+
+ // Returning `true` indicates the application is handling the URL.
return true;
} else { // Load the URL in Privacy Browser.
- loadUrl(url);
- return true;
+ // Apply the domain settings for the new URL.
+ applyDomainSettings(url);
+
+ // Returning `false` causes the current `WebView` to handle the URL and prevents it from adding redirects to the history list.
+ return false;
}
}
privacyBrowserRuntime.exec("rm -rf " + privateDataDirectoryString + "/cache");
// Delete the `app_webview` folder, which contains an additional `WebView` cache. See `https://code.google.com/p/android/issues/detail?id=233826&thanks=233826&ts=1486670530`.
- privacyBrowserRuntime.exec("rm -rf " + privacyBrowserRuntime + "/app_webview");
+ privacyBrowserRuntime.exec("rm -rf " + privateDataDirectoryString + "/app_webview");
} catch (IOException e) {
// Do nothing if an error is thrown.
}
// Hide zoom controls.
mainWebView.getSettings().setDisplayZoomControls(false);
+ // Set `mainWebView` to use a wide viewport. Otherwise, some web pages will be scrunched and some content will render outside the screen.
+ mainWebView.getSettings().setUseWideViewPort(true);
+
+ // Set `mainWebView` to load in overview mode (zoomed out to the maximum width).
+ mainWebView.getSettings().setLoadWithOverviewMode(true);
+
// Initialize cookieManager.
cookieManager = CookieManager.getInstance();
privacyBrowserRuntime.exec("rm -rf " + privateDataDirectoryString + "/cache");
// Delete the `app_webview` folder, which contains an additional `WebView` cache. See `https://code.google.com/p/android/issues/detail?id=233826&thanks=233826&ts=1486670530`.
- privacyBrowserRuntime.exec("rm -rf " + privacyBrowserRuntime + "/app_webview");
+ privacyBrowserRuntime.exec("rm -rf " + privateDataDirectoryString + "/app_webview");
} catch (IOException e) {
// Do nothing if an error is thrown.
}
String unformattedUrlString = urlTextBox.getText().toString().trim();
// Check to see if `unformattedUrlString` is a valid URL. Otherwise, convert it into a search.
- if ((Patterns.WEB_URL.matcher(unformattedUrlString).matches()) || (unformattedUrlString.contains("localhost"))) {
+ if ((Patterns.WEB_URL.matcher(unformattedUrlString).matches()) || (unformattedUrlString.startsWith("http://")) || (unformattedUrlString.startsWith("https://"))) {
// Add `http://` at the beginning if it is missing. Otherwise the app will segfault.
if (!unformattedUrlString.startsWith("http")) {
unformattedUrlString = "http://" + unformattedUrlString;
// Sanitize the search input and convert it to a search.
final String encodedUrlString = URLEncoder.encode(unformattedUrlString, "UTF-8");
- // Use the correct search URL.
- if (javaScriptEnabled) { // JavaScript is enabled.
- formattedUrlString = javaScriptEnabledSearchURL + encodedUrlString;
- } else { // JavaScript is disabled.
- formattedUrlString = javaScriptDisabledSearchURL + encodedUrlString;
- }
+ // Add the base search URL.
+ formattedUrlString = searchURL + encodedUrlString;
}
loadUrl(formattedUrlString);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
// Store the values from `sharedPreferences` in variables.
- String javaScriptDisabledSearchString = sharedPreferences.getString("javascript_disabled_search", "https://duckduckgo.com/html/?q=");
- String javaScriptDisabledSearchCustomURLString = sharedPreferences.getString("javascript_disabled_search_custom_url", "");
- String javaScriptEnabledSearchString = sharedPreferences.getString("javascript_enabled_search", "https://duckduckgo.com/?q=");
- String javaScriptEnabledSearchCustomURLString = sharedPreferences.getString("javascript_enabled_search_custom_url", "");
String homepageString = sharedPreferences.getString("homepage", "https://duckduckgo.com");
String torHomepageString = sharedPreferences.getString("tor_homepage", "https://3g2upl4pq6kufc4m.onion");
- String torJavaScriptDisabledSearchString = sharedPreferences.getString("tor_javascript_disabled_search", "https://3g2upl4pq6kufc4m.onion/html/?q=");
- String torJavaScriptDisabledSearchCustomURLString = sharedPreferences.getString("tor_javascript_disabled_search_custom_url", "");
- String torJavaScriptEnabledSearchString = sharedPreferences.getString("tor_javascript_enabled_search", "https://3g2upl4pq6kufc4m.onion/?q=");
- String torJavaScriptEnabledSearchCustomURLString = sharedPreferences.getString("tor_javascript_enabled_search_custom_url", "");
+ String torSearchString = sharedPreferences.getString("tor_search", "https://3g2upl4pq6kufc4m.onion/html/?q=");
+ String torSearchCustomURLString = sharedPreferences.getString("tor_search_custom_url", "");
+ String searchString = sharedPreferences.getString("search", "https://duckduckgo.com/html/?q=");
+ String searchCustomURLString = sharedPreferences.getString("search_custom_url", "");
adBlockerEnabled = sharedPreferences.getBoolean("block_ads", true);
incognitoModeEnabled = sharedPreferences.getBoolean("incognito_mode", false);
boolean doNotTrackEnabled = sharedPreferences.getBoolean("do_not_track", false);
formattedUrlString = homepage;
}
- // Set JavaScript disabled search.
- if (torJavaScriptDisabledSearchString.equals("Custom URL")) { // Get the custom URL string.
- javaScriptDisabledSearchURL = torJavaScriptDisabledSearchCustomURLString;
+ // Set the search URL.
+ if (torSearchString.equals("Custom URL")) { // Get the custom URL string.
+ searchURL = torSearchCustomURLString;
} else { // Use the string from the pre-built list.
- javaScriptDisabledSearchURL = torJavaScriptDisabledSearchString;
- }
-
- // Set JavaScript enabled search.
- if (torJavaScriptEnabledSearchString.equals("Custom URL")) { // Get the custom URL string.
- javaScriptEnabledSearchURL = torJavaScriptEnabledSearchCustomURLString;
- } else { // Use the string from the pre-built list.
- javaScriptEnabledSearchURL = torJavaScriptEnabledSearchString;
+ searchURL = torSearchString;
}
// Set the proxy. `this` refers to the current activity where an `AlertDialog` might be displayed.
formattedUrlString = homepage;
}
- // Set JavaScript disabled search.
- if (javaScriptDisabledSearchString.equals("Custom URL")) { // Get the custom URL string.
- javaScriptDisabledSearchURL = javaScriptDisabledSearchCustomURLString;
+ // Set the search URL.
+ if (searchString.equals("Custom URL")) { // Get the custom URL string.
+ searchURL = searchCustomURLString;
} else { // Use the string from the pre-built list.
- javaScriptDisabledSearchURL = javaScriptDisabledSearchString;
- }
-
- // Set JavaScript enabled search.
- if (javaScriptEnabledSearchString.equals("Custom URL")) { // Get the custom URL string.
- javaScriptEnabledSearchURL = javaScriptEnabledSearchCustomURLString;
- } else { // Use the string from the pre-built list.
- javaScriptEnabledSearchURL = javaScriptEnabledSearchString;
+ searchURL = searchString;
}
// Reset the proxy to default. The host is `""` and the port is `"0"`.
// Reset `inFullScreenBrowsingMode` to `false`.
inFullScreenBrowsingMode = false;
- // Show the `appBar`.
- appBar.show();
+ // Show the `appBar` if `findOnPageLinearLayout` is not visible.
+ if (findOnPageLinearLayout.getVisibility() == View.GONE) {
+ appBar.show();
+ }
// Show the `BannerAd` in the free flavor.
if (BuildConfig.FLAVOR.contentEquals("free")) {