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/time/time.h"
11 #include "chrome/browser/common/cancelable_request.h"
12 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
13 #include "chrome/browser/history/history_service.h"
14 #include "chrome/common/content_settings.h"
15 #include "chrome/common/content_settings_types.h"
16 #include "ui/gfx/native_widget_types.h"
25 class HostContentSettingsMap;
27 class WebsiteSettingsUI;
29 // The |WebsiteSettings| provides information about a website's permissions,
30 // connection state and its identity. It owns a UI that displays the
31 // information and allows users to change the permissions. |WebsiteSettings|
32 // objects must be created on the heap. They destroy themselves after the UI is
34 class WebsiteSettings : public TabSpecificContentSettings::SiteDataObserver {
36 // Status of a connection to a website.
37 enum SiteConnectionStatus {
38 SITE_CONNECTION_STATUS_UNKNOWN = 0, // No status available.
39 SITE_CONNECTION_STATUS_ENCRYPTED, // Connection is encrypted.
40 SITE_CONNECTION_STATUS_MIXED_CONTENT, // Site has unencrypted content.
41 SITE_CONNECTION_STATUS_UNENCRYPTED, // Connection is not encrypted.
42 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR, // Connection error occured.
43 SITE_CONNECTION_STATUS_INTERNAL_PAGE, // Internal site.
46 // Validation status of a website's identity.
47 enum SiteIdentityStatus {
48 // No status about the website's identity available.
49 SITE_IDENTITY_STATUS_UNKNOWN = 0,
50 // The website provided a valid certificate.
51 SITE_IDENTITY_STATUS_CERT,
52 // The website provided a valid EV certificate.
53 SITE_IDENTITY_STATUS_EV_CERT,
54 // The website provided a valid certificate but no revocation check could be
56 SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN,
57 // Site identity could not be verified because the site did not provide a
58 // certificate. This is the expected state for HTTP connections.
59 SITE_IDENTITY_STATUS_NO_CERT,
60 // An error occured while verifying the site identity.
61 SITE_IDENTITY_STATUS_ERROR,
62 // The site is a trusted internal chrome page.
63 SITE_IDENTITY_STATUS_INTERNAL_PAGE,
64 // The profile has accessed data using an administrator-provided
65 // certificate, so the site might be able to intercept data.
66 SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT,
69 // Creates a WebsiteSettings for the passed |url| using the given |ssl| status
70 // object to determine the status of the site's connection. The
71 // |WebsiteSettings| takes ownership of the |ui|.
72 WebsiteSettings(WebsiteSettingsUI* ui,
74 TabSpecificContentSettings* tab_specific_content_settings,
75 InfoBarService* infobar_service,
77 const content::SSLStatus& ssl,
78 content::CertStore* cert_store);
79 virtual ~WebsiteSettings();
81 // This method is called when ever a permission setting is changed.
82 void OnSitePermissionChanged(ContentSettingsType type,
83 ContentSetting value);
85 // Callback used for requests to fetch the number of page visits from history
86 // service and the time of the first visit.
87 void OnGotVisitCountToHost(HistoryService::Handle handle,
90 base::Time first_visit);
92 // This method is called by the UI when the UI is closing.
96 SiteConnectionStatus site_connection_status() const {
97 return site_connection_status_;
100 SiteIdentityStatus site_identity_status() const {
101 return site_identity_status_;
104 string16 site_connection_details() const {
105 return site_connection_details_;
108 string16 site_identity_details() const {
109 return site_identity_details_;
112 string16 organization_name() const {
113 return organization_name_;
116 // SiteDataObserver implementation.
117 virtual void OnSiteDataAccessed() OVERRIDE;
120 // Initializes the |WebsiteSettings|.
121 void Init(Profile* profile,
123 const content::SSLStatus& ssl);
125 // Sets (presents) the information about the site's permissions in the |ui_|.
126 void PresentSitePermissions();
128 // Sets (presents) the information about the site's data in the |ui_|.
129 void PresentSiteData();
131 // Sets (presents) the information about the site's identity and connection
133 void PresentSiteIdentity();
135 // Sets (presents) history information about the site in the |ui_|. Passing
136 // base::Time() as value for |first_visit| will clear the history information
138 void PresentHistoryInfo(base::Time first_visit);
140 // The website settings UI displays information and controls for site
141 // specific data (local stored objects like cookies), site specific
142 // permissions (location, popup, plugin, etc. permissions) and site specific
143 // information (identity, connection status, etc.).
144 WebsiteSettingsUI* ui_;
146 // The infobar service of the active tab.
147 InfoBarService* infobar_service_;
149 // The flag that controls whether an infobar is displayed after the website
150 // settings UI is closed or not.
153 // The Omnibox URL of the website for which to display site permissions and
157 // Status of the website's identity verification check.
158 SiteIdentityStatus site_identity_status_;
160 // For secure connection |cert_id_| is set to the ID of the server
161 // certificate. For non secure connections |cert_id_| is 0.
164 // Status of the connection to the website.
165 SiteConnectionStatus site_connection_status_;
167 // TODO(markusheintz): Move the creation of all the string16 typed UI
168 // strings below to the corresponding UI code, in order to prevent
169 // unnecessary UTF-8 string conversions.
171 // Details about the website's identity. If the website's identity has been
172 // verified then |site_identity_details_| contains who verified the identity.
173 // This string will be displayed in the UI.
174 string16 site_identity_details_;
176 // Details about the connection to the website. In case of an encrypted
177 // connection |site_connection_details_| contains encryption details, like
178 // encryption strength and ssl protocol version. This string will be
179 // displayed in the UI.
180 string16 site_connection_details_;
182 // For websites that provided an EV certificate |orgainization_name_|
183 // contains the organization name of the certificate. In all other cases
184 // |organization_name| is an empty string. This string will be displayed in
186 string16 organization_name_;
188 // The |CertStore| provides all X509Certificates.
189 content::CertStore* cert_store_;
191 // The |HostContentSettingsMap| is the service that provides and manages
192 // content settings (aka. site permissions).
193 HostContentSettingsMap* content_settings_;
195 // Used to request the number of page visits.
196 CancelableRequestConsumer visit_count_request_consumer_;
198 DISALLOW_COPY_AND_ASSIGN(WebsiteSettings);
201 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_WEBSITE_SETTINGS_H_