+ // Display `domainSettingsFragment`.
+ supportFragmentManager.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.domain_settings_javascript_switch);
+ Switch firstPartyCookiesSwitch = view.findViewById(R.id.domain_settings_first_party_cookies_switch);
+ Switch thirdPartyCookiesSwitch = view.findViewById(R.id.domain_settings_third_party_cookies_switch);
+ Switch domStorageSwitch = view.findViewById(R.id.domain_settings_dom_storage_switch);
+ Switch formDataSwitch = view.findViewById(R.id.domain_settings_form_data_switch); // Form data can be removed once the minimum API >= 26.
+ Switch easyListSwitch = view.findViewById(R.id.domain_settings_easylist_switch);
+ Switch easyPrivacySwitch = view.findViewById(R.id.domain_settings_easyprivacy_switch);
+ Switch fanboysAnnoyanceSwitch = view.findViewById(R.id.domain_settings_fanboys_annoyance_list_switch);
+ Switch fanboysSocialBlockingSwitch = view.findViewById(R.id.domain_settings_fanboys_social_blocking_list_switch);
+ Spinner userAgentSpinner = view.findViewById(R.id.domain_settings_user_agent_spinner);
+ EditText customUserAgentEditText = view.findViewById(R.id.domain_settings_custom_user_agent_edittext);
+ Spinner fontSizeSpinner = view.findViewById(R.id.domain_settings_font_size_spinner);
+ Spinner swipeToRefreshSpinner = view.findViewById(R.id.domain_settings_swipe_to_refresh_spinner);
+ Spinner displayWebpageImagesSpinner = view.findViewById(R.id.domain_settings_display_webpage_images_spinner);
+ Spinner nightModeSpinner = view.findViewById(R.id.domain_settings_night_mode_spinner);
+ Switch pinnedSslCertificateSwitch = view.findViewById(R.id.domain_settings_pinned_ssl_certificate_switch);
+ RadioButton savedSslCertificateRadioButton = view.findViewById(R.id.saved_ssl_certificate_radiobutton);
+ RadioButton currentWebsiteCertificateRadioButton = view.findViewById(R.id.current_website_certificate_radiobutton);
+
+ // 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();
+ int userAgentPosition = userAgentSpinner.getSelectedItemPosition();
+ int fontSizePosition = fontSizeSpinner.getSelectedItemPosition();
+ int swipeToRefreshInt = swipeToRefreshSpinner.getSelectedItemPosition();
+ int displayWebpageImagesInt = displayWebpageImagesSpinner.getSelectedItemPosition();
+ int nightModeInt = nightModeSpinner.getSelectedItemPosition();
+ boolean pinnedSslCertificate = pinnedSslCertificateSwitch.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.
+ if (savedSslCertificateRadioButton.isChecked()) { // The current certificate is being used.
+ // Update the database except for the certificate.
+ domainsDatabaseHelper.updateDomainExceptCertificate(DomainsActivity.currentDomainDatabaseId, domainNameString, javaScriptEnabled, firstPartyCookiesEnabled, thirdPartyCookiesEnabled,
+ domStorageEnabled, formDataEnabled, easyListEnabled, easyPrivacyEnabled, fanboysAnnoyanceEnabled, fanboysSocialBlockingEnabled, userAgentName, fontSizeInt, swipeToRefreshInt, nightModeInt,
+ displayWebpageImagesInt, pinnedSslCertificate);
+ } else if (currentWebsiteCertificateRadioButton.isChecked()) { // The certificate is being updated with the current website certificate.
+ // 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.updateDomainWithCertificate(currentDomainDatabaseId, domainNameString, javaScriptEnabled, firstPartyCookiesEnabled, thirdPartyCookiesEnabled, domStorageEnabled,
+ formDataEnabled, easyListEnabled, easyPrivacyEnabled, fanboysAnnoyanceEnabled, fanboysSocialBlockingEnabled, userAgentName, fontSizeInt, swipeToRefreshInt, nightModeInt,
+ displayWebpageImagesInt, pinnedSslCertificate, issuedToCommonName, issuedToOrganization, issuedToOrganizationalUnit, issuedByCommonName, issuedByOrganization, issuedByOrganizationalUnit,
+ startDateLong, endDateLong);
+
+ } else { // No certificate is selected.
+ // Update the database, with PINNED_SSL_CERTIFICATE set to false.
+ domainsDatabaseHelper.updateDomainExceptCertificate(currentDomainDatabaseId, domainNameString, javaScriptEnabled, firstPartyCookiesEnabled, thirdPartyCookiesEnabled, domStorageEnabled,
+ formDataEnabled, easyListEnabled, easyPrivacyEnabled, fanboysAnnoyanceEnabled, fanboysSocialBlockingEnabled, userAgentName, fontSizeInt, swipeToRefreshInt, nightModeInt,
+ displayWebpageImagesInt,false);
+ }