- // Save the current domain settings if operating in two-paned mode and a domain is currently selected.
- if (DomainsActivity.twoPanedMode && DomainsActivity.deleteMenuItem.isEnabled()) {
- View domainSettingsFragmentView = supportFragmentManager.findFragmentById(R.id.domain_settings_fragment_container).getView();
- assert domainSettingsFragmentView != null;
-
- // Get handles for the domain settings.
- EditText domainNameEditText = (EditText) domainSettingsFragmentView.findViewById(R.id.domain_settings_name_edittext);
- Switch javaScriptEnabledSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_javascript_switch);
- Switch firstPartyCookiesEnabledSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_first_party_cookies_switch);
- Switch thirdPartyCookiesEnabledSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_third_party_cookies_switch);
- Switch domStorageEnabledSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_dom_storage_switch);
- Switch formDataEnabledSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_form_data_switch);
- Spinner userAgentSpinner = (Spinner) domainSettingsFragmentView.findViewById(R.id.domain_settings_user_agent_spinner);
- EditText customUserAgentEditText = (EditText) domainSettingsFragmentView.findViewById(R.id.domain_settings_custom_user_agent_edittext);
- Spinner fontSizeSpinner = (Spinner) domainSettingsFragmentView.findViewById(R.id.domain_settings_font_size_spinner);
- Spinner displayWebpageImagesSpinner = (Spinner) domainSettingsFragmentView.findViewById(R.id.domain_settings_display_webpage_images_spinner);
- Spinner nightModeSpinner = (Spinner) domainSettingsFragmentView.findViewById(R.id.domain_settings_night_mode_spinner);
- Switch pinnedSslCertificateSwitch = (Switch) domainSettingsFragmentView.findViewById(R.id.domain_settings_pinned_ssl_certificate_switch);
- RadioButton savedSslCertificateRadioButton = (RadioButton) domainSettingsFragmentView.findViewById(R.id.saved_ssl_certificate_radiobutton);
- RadioButton currentWebsiteCertificateRadioButton = (RadioButton) domainSettingsFragmentView.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(DomainsActivity.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(DomainsActivity.currentDomainDatabaseId, domainNameString, javaScriptEnabledBoolean, firstPartyCookiesEnabledBoolean, thirdPartyCookiesEnabledBoolean, domStorageEnabledEnabledBoolean,
- formDataEnabledBoolean, userAgentString, fontSizeInt, displayWebpageImagesInt, nightModeInt, false);
- }
- }