- // Set a green background on `urlTextBox` to indicate that custom domain settings are being used. We have to use the deprecated `.getColor()` until the minimum API >= 23.
- urlAppBarFrameLayout.setBackgroundColor(getResources().getColor(R.color.green_100));
- } else { // The URL we are loading does not have custom domain settings. Load the defaults.
- // Get the shared preference values. `this` references the current context.
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
-
- // Store the values from `sharedPreferences` in variables.
- javaScriptEnabled = sharedPreferences.getBoolean("javascript_enabled", false);
- firstPartyCookiesEnabled = sharedPreferences.getBoolean("first_party_cookies_enabled", false);
- thirdPartyCookiesEnabled = sharedPreferences.getBoolean("third_party_cookies_enabled", false);
- domStorageEnabled = sharedPreferences.getBoolean("dom_storage_enabled", false);
- saveFormDataEnabled = sharedPreferences.getBoolean("save_form_data_enabled", false);
- String userAgentString = sharedPreferences.getString("user_agent", "PrivacyBrowser/1.0");
- String customUserAgentString = sharedPreferences.getString("custom_user_agent", "PrivacyBrowser/1.0");
- String defaultFontSizeString = sharedPreferences.getString("default_font_size", "100");
-
- // Apply the default settings.
- mainWebView.getSettings().setJavaScriptEnabled(javaScriptEnabled);
- cookieManager.setAcceptCookie(firstPartyCookiesEnabled);
- mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled);
- mainWebView.getSettings().setSaveFormData(saveFormDataEnabled);
- mainWebView.getSettings().setTextZoom(Integer.valueOf(defaultFontSizeString));
-
- // Set third-party cookies status if API >= 21.
- if (Build.VERSION.SDK_INT >= 21) {
- cookieManager.setAcceptThirdPartyCookies(mainWebView, thirdPartyCookiesEnabled);
+ // If `hostName` is not `null`, check all the subdomains of `hostName` against wildcard domains in `domainCursor`.
+ if (hostName != null) {
+ while (hostName.contains(".") && !hostHasDomainSettings) { // Stop checking if we run out of `.` or if we already know that `hostHasDomainSettings` is `true`.
+ if (domainSettingsSet.contains("*." + hostName)) { // Check the host name prepended by `*.`.
+ hostHasDomainSettings = true;
+ domainNameInDatabase = "*." + hostName;
+ }
+
+ // Strip out the lowest subdomain of `host`.
+ hostName = hostName.substring(hostName.indexOf(".") + 1);
+ }