1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_WEBSITE_SETTINGS_H_
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_WEBSITE_SETTINGS_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h"
10 #include "base/task/cancelable_task_tracker.h"
11 #include "base/time/time.h"
12 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
13 #include "chrome/browser/history/history_service.h"
14 #include "components/content_settings/core/common/content_settings.h"
15 #include "components/content_settings/core/common/content_settings_types.h"
16 #include "content/public/common/signed_certificate_timestamp_id_and_status.h"
17 #include "ui/gfx/native_widget_types.h"
25 class ChromeSSLHostStateDelegate;
27 class HostContentSettingsMap;
29 class WebsiteSettingsUI;
31 // The |WebsiteSettings| provides information about a website's permissions,
32 // connection state and its identity. It owns a UI that displays the
33 // information and allows users to change the permissions. |WebsiteSettings|
34 // objects must be created on the heap. They destroy themselves after the UI is
36 class WebsiteSettings : public TabSpecificContentSettings::SiteDataObserver {
38 // Status of a connection to a website.
39 enum SiteConnectionStatus {
40 SITE_CONNECTION_STATUS_UNKNOWN = 0, // No status available.
41 SITE_CONNECTION_STATUS_ENCRYPTED, // Connection is encrypted.
42 SITE_CONNECTION_STATUS_MIXED_CONTENT, // Site has unencrypted content.
43 SITE_CONNECTION_STATUS_UNENCRYPTED, // Connection is not encrypted.
44 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR, // Connection error occured.
45 SITE_CONNECTION_STATUS_INTERNAL_PAGE, // Internal site.
48 // Validation status of a website's identity.
49 enum SiteIdentityStatus {
50 // No status about the website's identity available.
51 SITE_IDENTITY_STATUS_UNKNOWN = 0,
52 // The website provided a valid certificate.
53 SITE_IDENTITY_STATUS_CERT,
54 // The website provided a valid EV certificate.
55 SITE_IDENTITY_STATUS_EV_CERT,
56 // The website provided a valid certificate but no revocation check could be
58 SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN,
59 // Site identity could not be verified because the site did not provide a
60 // certificate. This is the expected state for HTTP connections.
61 SITE_IDENTITY_STATUS_NO_CERT,
62 // An error occured while verifying the site identity.
63 SITE_IDENTITY_STATUS_ERROR,
64 // The site is a trusted internal chrome page.
65 SITE_IDENTITY_STATUS_INTERNAL_PAGE,
66 // The profile has accessed data using an administrator-provided
67 // certificate, so the site might be able to intercept data.
68 SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT,
69 // The website provided a valid certificate, but the certificate or chain
70 // is using a deprecated signature algorithm.
71 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM,
74 // UMA statistics for WebsiteSettings. Do not reorder or remove existing
76 enum WebsiteSettingsAction {
77 WEBSITE_SETTINGS_OPENED = 0,
78 WEBSITE_SETTINGS_PERMISSIONS_TAB_SELECTED,
79 WEBSITE_SETTINGS_CONNECTION_TAB_SELECTED,
80 WEBSITE_SETTINGS_CONNECTION_TAB_SHOWN_IMMEDIATELY,
81 WEBSITE_SETTINGS_COOKIES_DIALOG_OPENED,
82 WEBSITE_SETTINGS_CHANGED_PERMISSION,
83 WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED,
84 WEBSITE_SETTINGS_TRANSPARENCY_VIEWER_OPENED,
85 WEBSITE_SETTINGS_CONNECTION_HELP_OPENED,
86 WEBSITE_SETTINGS_COUNT
89 // Creates a WebsiteSettings for the passed |url| using the given |ssl| status
90 // object to determine the status of the site's connection. The
91 // |WebsiteSettings| takes ownership of the |ui|.
92 WebsiteSettings(WebsiteSettingsUI* ui,
94 TabSpecificContentSettings* tab_specific_content_settings,
95 InfoBarService* infobar_service,
97 const content::SSLStatus& ssl,
98 content::CertStore* cert_store);
99 ~WebsiteSettings() override;
101 void RecordWebsiteSettingsAction(WebsiteSettingsAction action);
103 // This method is called when ever a permission setting is changed.
104 void OnSitePermissionChanged(ContentSettingsType type,
105 ContentSetting value);
107 // Callback used for requests to fetch the number of page visits from history
108 // service and the time of the first visit.
109 void OnGotVisitCountToHost(bool found_visits,
111 base::Time first_visit);
113 // This method is called by the UI when the UI is closing.
116 // This method is called when the revoke SSL error bypass button is pressed.
117 void OnRevokeSSLErrorBypassButtonPressed();
120 SiteConnectionStatus site_connection_status() const {
121 return site_connection_status_;
124 const GURL& site_url() const { return site_url_; }
126 SiteIdentityStatus site_identity_status() const {
127 return site_identity_status_;
130 base::string16 site_connection_details() const {
131 return site_connection_details_;
134 base::string16 site_identity_details() const {
135 return site_identity_details_;
138 base::string16 organization_name() const {
139 return organization_name_;
142 // SiteDataObserver implementation.
143 void OnSiteDataAccessed() override;
146 // Initializes the |WebsiteSettings|.
147 void Init(Profile* profile,
149 const content::SSLStatus& ssl);
151 // Sets (presents) the information about the site's permissions in the |ui_|.
152 void PresentSitePermissions();
154 // Sets (presents) the information about the site's data in the |ui_|.
155 void PresentSiteData();
157 // Sets (presents) the information about the site's identity and connection
159 void PresentSiteIdentity();
161 // Sets (presents) history information about the site in the |ui_|. Passing
162 // base::Time() as value for |first_visit| will clear the history information
164 void PresentHistoryInfo(base::Time first_visit);
166 // The website settings UI displays information and controls for site
167 // specific data (local stored objects like cookies), site specific
168 // permissions (location, popup, plugin, etc. permissions) and site specific
169 // information (identity, connection status, etc.).
170 WebsiteSettingsUI* ui_;
172 // The infobar service of the active tab.
173 InfoBarService* infobar_service_;
175 // The flag that controls whether an infobar is displayed after the website
176 // settings UI is closed or not.
179 // The Omnibox URL of the website for which to display site permissions and
183 // Status of the website's identity verification check.
184 SiteIdentityStatus site_identity_status_;
186 // For secure connection |cert_id_| is set to the ID of the server
187 // certificate. For non secure connections |cert_id_| is 0.
189 // For secure connection, |signed_certificate_timestamp_ids_| is the list of
190 // all Signed Certificate Timestamps and their validation status.
191 // Empty if no SCTs accompanied the certificate
192 content::SignedCertificateTimestampIDStatusList
193 signed_certificate_timestamp_ids_;
195 // Status of the connection to the website.
196 SiteConnectionStatus site_connection_status_;
198 // TODO(markusheintz): Move the creation of all the base::string16 typed UI
199 // strings below to the corresponding UI code, in order to prevent
200 // unnecessary UTF-8 string conversions.
202 // Details about the website's identity. If the website's identity has been
203 // verified then |site_identity_details_| contains who verified the identity.
204 // This string will be displayed in the UI.
205 base::string16 site_identity_details_;
207 // Set when the user has explicitly bypassed an SSL error for this host or
208 // explicitly denied it (the latter of which is not currently possible in the
209 // Chrome UI) and has a flag set to remember ssl decisions (explicit flag or
210 // in the experimental group). When |show_ssl_decision_revoke_button| is
211 // true, the connection area of the page info will include an option for the
212 // user to revoke their decision to bypass the SSL error for this host.
213 bool show_ssl_decision_revoke_button_;
215 // Details about the connection to the website. In case of an encrypted
216 // connection |site_connection_details_| contains encryption details, like
217 // encryption strength and ssl protocol version. This string will be
218 // displayed in the UI.
219 base::string16 site_connection_details_;
221 // For websites that provided an EV certificate |orgainization_name_|
222 // contains the organization name of the certificate. In all other cases
223 // |organization_name| is an empty string. This string will be displayed in
225 base::string16 organization_name_;
227 // The |CertStore| provides all X509Certificates.
228 content::CertStore* cert_store_;
230 // The |HostContentSettingsMap| is the service that provides and manages
231 // content settings (aka. site permissions).
232 HostContentSettingsMap* content_settings_;
234 // Used to request the number of page visits.
235 base::CancelableTaskTracker visit_count_task_tracker_;
237 // Service for managing SSL error page bypasses. Used to revoke bypass
238 // decisions by users.
239 ChromeSSLHostStateDelegate* chrome_ssl_host_state_delegate_;
241 bool did_revoke_user_ssl_decisions_;
243 DISALLOW_COPY_AND_ASSIGN(WebsiteSettings);
246 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_WEBSITE_SETTINGS_H_