+ private void saveDomainSettings() {
+ // Get handles for the domain settings.
+ EditText domainNameEditText = findViewById(R.id.domain_settings_name_edittext);
+ Switch javaScriptEnabledSwitch = findViewById(R.id.domain_settings_javascript_switch);
+ Switch firstPartyCookiesEnabledSwitch = findViewById(R.id.domain_settings_first_party_cookies_switch);
+ Switch thirdPartyCookiesEnabledSwitch = findViewById(R.id.domain_settings_third_party_cookies_switch);
+ Switch domStorageEnabledSwitch = findViewById(R.id.domain_settings_dom_storage_switch);
+ Switch formDataEnabledSwitch = findViewById(R.id.domain_settings_form_data_switch);
+ Spinner userAgentSpinner = findViewById(R.id.domain_settings_user_agent_spinner);
+ EditText customUserAgentEditText = findViewById(R.id.domain_settings_custom_user_agent_edittext);
+ Spinner fontSizeSpinner = findViewById(R.id.domain_settings_font_size_spinner);
+ Spinner displayWebpageImagesSpinner = findViewById(R.id.domain_settings_display_webpage_images_spinner);
+ Spinner nightModeSpinner = findViewById(R.id.domain_settings_night_mode_spinner);
+ Switch pinnedSslCertificateSwitch = findViewById(R.id.domain_settings_pinned_ssl_certificate_switch);
+ RadioButton savedSslCertificateRadioButton = findViewById(R.id.saved_ssl_certificate_radiobutton);
+ RadioButton currentWebsiteCertificateRadioButton = findViewById(R.id.current_website_certificate_radiobutton);
+
+ // Extract the data for the domain settings.
+ String domainNameString = domainNameEditText.getText().toString();
+ boolean javaScriptEnabledBoolean = javaScriptEnabledSwitch.isChecked();
+ boolean firstPartyCookiesEnabledBoolean = firstPartyCookiesEnabledSwitch.isChecked();
+ boolean thirdPartyCookiesEnabledBoolean = thirdPartyCookiesEnabledSwitch.isChecked();
+ boolean domStorageEnabledEnabledBoolean = domStorageEnabledSwitch.isChecked();
+ boolean formDataEnabledBoolean = formDataEnabledSwitch.isChecked();
+ int userAgentPositionInt = userAgentSpinner.getSelectedItemPosition();
+ int fontSizePositionInt = fontSizeSpinner.getSelectedItemPosition();
+ int displayWebpageImagesInt = displayWebpageImagesSpinner.getSelectedItemPosition();
+ int nightModeInt = nightModeSpinner.getSelectedItemPosition();
+ boolean pinnedSslCertificate = pinnedSslCertificateSwitch.isChecked();
+
+ // Get the data for the `Spinners` from the entry values string arrays.
+ String userAgentString = getResources().getStringArray(R.array.domain_settings_user_agent_entry_values)[userAgentPositionInt];
+ int fontSizeInt = Integer.parseInt(getResources().getStringArray(R.array.domain_settings_font_size_entry_values)[fontSizePositionInt]);
+
+ // Check to see if we are using a custom user agent.
+ if (userAgentString.equals("Custom user agent")) {
+ // Set `userAgentString` to the custom user agent string.
+ userAgentString = customUserAgentEditText.getText().toString();
+ }
+
+ // 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, javaScriptEnabledBoolean, firstPartyCookiesEnabledBoolean, thirdPartyCookiesEnabledBoolean, domStorageEnabledEnabledBoolean,
+ formDataEnabledBoolean, userAgentString, fontSizeInt, displayWebpageImagesInt, nightModeInt, 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, javaScriptEnabledBoolean, firstPartyCookiesEnabledBoolean, thirdPartyCookiesEnabledBoolean, domStorageEnabledEnabledBoolean, formDataEnabledBoolean,
+ userAgentString, fontSizeInt, displayWebpageImagesInt, nightModeInt, 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, javaScriptEnabledBoolean, firstPartyCookiesEnabledBoolean, thirdPartyCookiesEnabledBoolean, domStorageEnabledEnabledBoolean, formDataEnabledBoolean,
+ userAgentString, fontSizeInt, displayWebpageImagesInt, nightModeInt, false);
+ }
+ }
+
+ private void populateDomainsListView(final int highlightedDomainDatabaseId) {
+ // get a handle for the current `domains_listview`.
+ domainsListView = findViewById(R.id.domains_listview);
+