+ // Display the domain settings fragment.
+ getSupportFragmentManager().beginTransaction().replace(R.id.domains_listview_fragment_container, domainSettingsFragment).commit();
+ }
+ }
+
+ public void saveDomainSettings(View view, Resources resources) {
+ // Get handles for the domain settings.
+ EditText domainNameEditText = view.findViewById(R.id.domain_settings_name_edittext);
+ Switch javaScriptSwitch = view.findViewById(R.id.javascript_switch);
+ Switch firstPartyCookiesSwitch = view.findViewById(R.id.first_party_cookies_switch);
+ Switch thirdPartyCookiesSwitch = view.findViewById(R.id.third_party_cookies_switch);
+ Switch domStorageSwitch = view.findViewById(R.id.dom_storage_switch);
+ Switch formDataSwitch = view.findViewById(R.id.form_data_switch); // Form data can be removed once the minimum API >= 26.
+ Switch easyListSwitch = view.findViewById(R.id.easylist_switch);
+ Switch easyPrivacySwitch = view.findViewById(R.id.easyprivacy_switch);
+ Switch fanboysAnnoyanceSwitch = view.findViewById(R.id.fanboys_annoyance_list_switch);
+ Switch fanboysSocialBlockingSwitch = view.findViewById(R.id.fanboys_social_blocking_list_switch);
+ Switch ultraPrivacySwitch = view.findViewById(R.id.ultraprivacy_switch);
+ Switch blockAllThirdPartyRequestsSwitch = view.findViewById(R.id.block_all_third_party_requests_switch);
+ Spinner userAgentSpinner = view.findViewById(R.id.user_agent_spinner);
+ EditText customUserAgentEditText = view.findViewById(R.id.custom_user_agent_edittext);
+ Spinner fontSizeSpinner = view.findViewById(R.id.font_size_spinner);
+ Spinner swipeToRefreshSpinner = view.findViewById(R.id.swipe_to_refresh_spinner);
+ Spinner displayWebpageImagesSpinner = view.findViewById(R.id.display_webpage_images_spinner);
+ Spinner nightModeSpinner = view.findViewById(R.id.night_mode_spinner);
+ Switch pinnedSslCertificateSwitch = view.findViewById(R.id.pinned_ssl_certificate_switch);
+ RadioButton currentWebsiteCertificateRadioButton = view.findViewById(R.id.current_website_certificate_radiobutton);
+ Switch pinnedIpAddressesSwitch = view.findViewById(R.id.pinned_ip_addresses_switch);
+ RadioButton currentIpAddressesRadioButton = view.findViewById(R.id.current_ip_addresses_radiobutton);
+ TextView currentIpAddressesTextView = view.findViewById(R.id.current_ip_addresses_textview);
+
+ // Extract the data for the domain settings.
+ String domainNameString = domainNameEditText.getText().toString();
+ boolean javaScriptEnabled = javaScriptSwitch.isChecked();
+ boolean firstPartyCookiesEnabled = firstPartyCookiesSwitch.isChecked();
+ boolean thirdPartyCookiesEnabled = thirdPartyCookiesSwitch.isChecked();
+ boolean domStorageEnabled = domStorageSwitch.isChecked();
+ boolean formDataEnabled = formDataSwitch.isChecked(); // Form data can be removed once the minimum API >= 26.
+ boolean easyListEnabled = easyListSwitch.isChecked();
+ boolean easyPrivacyEnabled = easyPrivacySwitch.isChecked();
+ boolean fanboysAnnoyanceEnabled = fanboysAnnoyanceSwitch.isChecked();
+ boolean fanboysSocialBlockingEnabled = fanboysSocialBlockingSwitch.isChecked();
+ boolean ultraPrivacyEnabled = ultraPrivacySwitch.isChecked();
+ boolean blockAllThirdPartyRequests = blockAllThirdPartyRequestsSwitch.isChecked();
+ int userAgentPosition = userAgentSpinner.getSelectedItemPosition();
+ int fontSizePosition = fontSizeSpinner.getSelectedItemPosition();
+ int swipeToRefreshInt = swipeToRefreshSpinner.getSelectedItemPosition();
+ int displayWebpageImagesInt = displayWebpageImagesSpinner.getSelectedItemPosition();
+ int nightModeInt = nightModeSpinner.getSelectedItemPosition();
+ boolean pinnedSslCertificate = pinnedSslCertificateSwitch.isChecked();
+ boolean pinnedIpAddress = pinnedIpAddressesSwitch.isChecked();
+
+ // Initialize the user agent name string.
+ String userAgentName;
+
+ // Set the user agent name.
+ switch (userAgentPosition) {
+ case MainWebViewActivity.DOMAINS_SYSTEM_DEFAULT_USER_AGENT:
+ // Set the user agent name to be `System default user agent`.
+ userAgentName = resources.getString(R.string.system_default_user_agent);
+ break;
+
+ case MainWebViewActivity.DOMAINS_CUSTOM_USER_AGENT:
+ // Set the user agent name to be the custom user agent.
+ userAgentName = customUserAgentEditText.getText().toString();
+ break;
+
+ default:
+ // Get the array of user agent names.
+ String[] userAgentNameArray = resources.getStringArray(R.array.user_agent_names);
+
+ // Set the user agent name from the array. The domain spinner has one more entry than the name array, so the position must be decremented.
+ userAgentName = userAgentNameArray[userAgentPosition - 1];
+ }
+
+ // Get the font size integer.
+ int fontSizeInt = Integer.parseInt(resources.getStringArray(R.array.domain_settings_font_size_entry_values)[fontSizePosition]);
+
+ // Save the domain settings.
+ domainsDatabaseHelper.updateDomain(DomainsActivity.currentDomainDatabaseId, domainNameString, javaScriptEnabled, firstPartyCookiesEnabled, thirdPartyCookiesEnabled,
+ domStorageEnabled, formDataEnabled, easyListEnabled, easyPrivacyEnabled, fanboysAnnoyanceEnabled, fanboysSocialBlockingEnabled, ultraPrivacyEnabled, blockAllThirdPartyRequests,
+ userAgentName, fontSizeInt, swipeToRefreshInt, nightModeInt, displayWebpageImagesInt, pinnedSslCertificate, pinnedIpAddress);
+
+ // Update the pinned SSL certificate if a new one is checked.
+ if (currentWebsiteCertificateRadioButton.isChecked()) {
+ // Get the current website SSL certificate.
+ SslCertificate currentWebsiteSslCertificate = MainWebViewActivity.sslCertificate;
+
+ // Store the values from the SSL certificate.
+ String issuedToCommonName = currentWebsiteSslCertificate.getIssuedTo().getCName();
+ String issuedToOrganization = currentWebsiteSslCertificate.getIssuedTo().getOName();
+ String issuedToOrganizationalUnit = currentWebsiteSslCertificate.getIssuedTo().getUName();
+ String issuedByCommonName = currentWebsiteSslCertificate.getIssuedBy().getCName();
+ String issuedByOrganization = currentWebsiteSslCertificate.getIssuedBy().getOName();
+ String issuedByOrganizationalUnit = currentWebsiteSslCertificate.getIssuedBy().getUName();
+ long startDateLong = currentWebsiteSslCertificate.getValidNotBeforeDate().getTime();
+ long endDateLong = currentWebsiteSslCertificate.getValidNotAfterDate().getTime();
+
+ // Update the database.
+ domainsDatabaseHelper.updatePinnedSslCertificate(currentDomainDatabaseId, issuedToCommonName, issuedToOrganization, issuedToOrganizationalUnit, issuedByCommonName, issuedByOrganization,
+ issuedByOrganizationalUnit, startDateLong, endDateLong);
+ }
+
+ // Update the pinned IP addresses if new ones are checked.
+ if (currentIpAddressesRadioButton.isChecked()) {
+ // Get the current IP addresses.
+ String currentIpAddresses = currentIpAddressesTextView.getText().toString();
+
+ // Update the database.
+ domainsDatabaseHelper.updatePinnedIpAddresses(currentDomainDatabaseId, currentIpAddresses);
+ }