Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / website_settings / website_settings.h
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.
4
5 #ifndef CHROME_BROWSER_UI_WEBSITE_SETTINGS_WEBSITE_SETTINGS_H_
6 #define CHROME_BROWSER_UI_WEBSITE_SETTINGS_WEBSITE_SETTINGS_H_
7
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"
18 #include "url/gurl.h"
19
20 namespace content {
21 class CertStore;
22 struct SSLStatus;
23 }
24
25 class ChromeSSLHostStateDelegate;
26 class InfoBarService;
27 class HostContentSettingsMap;
28 class Profile;
29 class WebsiteSettingsUI;
30
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
35 // closed.
36 class WebsiteSettings : public TabSpecificContentSettings::SiteDataObserver {
37  public:
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.
46   };
47
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
57     // performed.
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,
72   };
73
74   // UMA statistics for WebsiteSettings. Do not reorder or remove existing
75   // fields.
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
87   };
88
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,
93                   Profile* profile,
94                   TabSpecificContentSettings* tab_specific_content_settings,
95                   InfoBarService* infobar_service,
96                   const GURL& url,
97                   const content::SSLStatus& ssl,
98                   content::CertStore* cert_store);
99   ~WebsiteSettings() override;
100
101   void RecordWebsiteSettingsAction(WebsiteSettingsAction action);
102
103   // This method is called when ever a permission setting is changed.
104   void OnSitePermissionChanged(ContentSettingsType type,
105                                ContentSetting value);
106
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,
110                              int visit_count,
111                              base::Time first_visit);
112
113   // This method is called by the UI when the UI is closing.
114   void OnUIClosing();
115
116   // This method is called when the revoke SSL error bypass button is pressed.
117   void OnRevokeSSLErrorBypassButtonPressed();
118
119   // Accessors.
120   SiteConnectionStatus site_connection_status() const {
121     return site_connection_status_;
122   }
123
124   const GURL& site_url() const { return site_url_; }
125
126   SiteIdentityStatus site_identity_status() const {
127     return site_identity_status_;
128   }
129
130   base::string16 site_connection_details() const {
131     return site_connection_details_;
132   }
133
134   base::string16 site_identity_details() const {
135     return site_identity_details_;
136   }
137
138   base::string16 organization_name() const {
139     return organization_name_;
140   }
141
142   // SiteDataObserver implementation.
143   void OnSiteDataAccessed() override;
144
145  private:
146   // Initializes the |WebsiteSettings|.
147   void Init(Profile* profile,
148             const GURL& url,
149             const content::SSLStatus& ssl);
150
151   // Sets (presents) the information about the site's permissions in the |ui_|.
152   void PresentSitePermissions();
153
154   // Sets (presents) the information about the site's data in the |ui_|.
155   void PresentSiteData();
156
157   // Sets (presents) the information about the site's identity and connection
158   // in the |ui_|.
159   void PresentSiteIdentity();
160
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
163   // in the UI.
164   void PresentHistoryInfo(base::Time first_visit);
165
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_;
171
172   // The infobar service of the active tab.
173   InfoBarService* infobar_service_;
174
175   // The flag that controls whether an infobar is displayed after the website
176   // settings UI is closed or not.
177   bool show_info_bar_;
178
179   // The Omnibox URL of the website for which to display site permissions and
180   // site information.
181   GURL site_url_;
182
183   // Status of the website's identity verification check.
184   SiteIdentityStatus site_identity_status_;
185
186   // For secure connection |cert_id_| is set to the ID of the server
187   // certificate. For non secure connections |cert_id_| is 0.
188   int cert_id_;
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_;
194
195   // Status of the connection to the website.
196   SiteConnectionStatus site_connection_status_;
197
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.
201
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_;
206
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_;
214
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_;
220
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
224   // the UI.
225   base::string16 organization_name_;
226
227   // The |CertStore| provides all X509Certificates.
228   content::CertStore* cert_store_;
229
230   // The |HostContentSettingsMap| is the service that provides and manages
231   // content settings (aka. site permissions).
232   HostContentSettingsMap* content_settings_;
233
234   // Used to request the number of page visits.
235   base::CancelableTaskTracker visit_count_task_tracker_;
236
237   // Service for managing SSL error page bypasses. Used to revoke bypass
238   // decisions by users.
239   ChromeSSLHostStateDelegate* chrome_ssl_host_state_delegate_;
240
241   bool did_revoke_user_ssl_decisions_;
242
243   DISALLOW_COPY_AND_ASSIGN(WebsiteSettings);
244 };
245
246 #endif  // CHROME_BROWSER_UI_WEBSITE_SETTINGS_WEBSITE_SETTINGS_H_