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/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" 17 #include "url/gurl.h" 18 19 namespace content { 20 class CertStore; 21 struct SSLStatus; 22 } 23 24 class InfoBarService; 25 class HostContentSettingsMap; 26 class Profile; 27 class WebsiteSettingsUI; 28 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 33 // closed. 34 class WebsiteSettings : public TabSpecificContentSettings::SiteDataObserver { 35 public: 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. 44 }; 45 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 55 // performed. 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, 67 }; 68 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, 73 Profile* profile, 74 TabSpecificContentSettings* tab_specific_content_settings, 75 InfoBarService* infobar_service, 76 const GURL& url, 77 const content::SSLStatus& ssl, 78 content::CertStore* cert_store); 79 virtual ~WebsiteSettings(); 80 81 // This method is called when ever a permission setting is changed. 82 void OnSitePermissionChanged(ContentSettingsType type, 83 ContentSetting value); 84 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, 88 bool found_visits, 89 int visit_count, 90 base::Time first_visit); 91 92 // This method is called by the UI when the UI is closing. 93 void OnUIClosing(); 94 95 // Accessors. 96 SiteConnectionStatus site_connection_status() const { 97 return site_connection_status_; 98 } 99 100 SiteIdentityStatus site_identity_status() const { 101 return site_identity_status_; 102 } 103 104 base::string16 site_connection_details() const { 105 return site_connection_details_; 106 } 107 108 base::string16 site_identity_details() const { 109 return site_identity_details_; 110 } 111 112 base::string16 organization_name() const { 113 return organization_name_; 114 } 115 116 // SiteDataObserver implementation. 117 virtual void OnSiteDataAccessed() OVERRIDE; 118 119 private: 120 // Initializes the |WebsiteSettings|. 121 void Init(Profile* profile, 122 const GURL& url, 123 const content::SSLStatus& ssl); 124 125 // Sets (presents) the information about the site's permissions in the |ui_|. 126 void PresentSitePermissions(); 127 128 // Sets (presents) the information about the site's data in the |ui_|. 129 void PresentSiteData(); 130 131 // Sets (presents) the information about the site's identity and connection 132 // in the |ui_|. 133 void PresentSiteIdentity(); 134 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 137 // in the UI. 138 void PresentHistoryInfo(base::Time first_visit); 139 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_; 145 146 // The infobar service of the active tab. 147 InfoBarService* infobar_service_; 148 149 // The flag that controls whether an infobar is displayed after the website 150 // settings UI is closed or not. 151 bool show_info_bar_; 152 153 // The Omnibox URL of the website for which to display site permissions and 154 // site information. 155 GURL site_url_; 156 157 // Status of the website's identity verification check. 158 SiteIdentityStatus site_identity_status_; 159 160 // For secure connection |cert_id_| is set to the ID of the server 161 // certificate. For non secure connections |cert_id_| is 0. 162 int cert_id_; 163 164 // Status of the connection to the website. 165 SiteConnectionStatus site_connection_status_; 166 167 // TODO(markusheintz): Move the creation of all the base::string16 typed UI 168 // strings below to the corresponding UI code, in order to prevent 169 // unnecessary UTF-8 string conversions. 170 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 base::string16 site_identity_details_; 175 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 base::string16 site_connection_details_; 181 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 185 // the UI. 186 base::string16 organization_name_; 187 188 // The |CertStore| provides all X509Certificates. 189 content::CertStore* cert_store_; 190 191 // The |HostContentSettingsMap| is the service that provides and manages 192 // content settings (aka. site permissions). 193 HostContentSettingsMap* content_settings_; 194 195 // Used to request the number of page visits. 196 CancelableRequestConsumer visit_count_request_consumer_; 197 198 DISALLOW_COPY_AND_ASSIGN(WebsiteSettings); 199 }; 200 201 #endif // CHROME_BROWSER_UI_WEBSITE_SETTINGS_WEBSITE_SETTINGS_H_ 202