Home | History | Annotate | Download | only in website_settings
      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 "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 InfoBarService;
     26 class HostContentSettingsMap;
     27 class Profile;
     28 class WebsiteSettingsUI;
     29 
     30 // The |WebsiteSettings| provides information about a website's permissions,
     31 // connection state and its identity. It owns a UI that displays the
     32 // information and allows users to change the permissions. |WebsiteSettings|
     33 // objects must be created on the heap. They destroy themselves after the UI is
     34 // closed.
     35 class WebsiteSettings : public TabSpecificContentSettings::SiteDataObserver {
     36  public:
     37   // Status of a connection to a website.
     38   enum SiteConnectionStatus {
     39     SITE_CONNECTION_STATUS_UNKNOWN = 0,      // No status available.
     40     SITE_CONNECTION_STATUS_ENCRYPTED,        // Connection is encrypted.
     41     SITE_CONNECTION_STATUS_MIXED_CONTENT,    // Site has unencrypted content.
     42     SITE_CONNECTION_STATUS_UNENCRYPTED,      // Connection is not encrypted.
     43     SITE_CONNECTION_STATUS_ENCRYPTED_ERROR,  // Connection error occured.
     44     SITE_CONNECTION_STATUS_INTERNAL_PAGE,    // Internal site.
     45   };
     46 
     47   // Validation status of a website's identity.
     48   enum SiteIdentityStatus {
     49     // No status about the website's identity available.
     50     SITE_IDENTITY_STATUS_UNKNOWN = 0,
     51     // The website provided a valid certificate.
     52     SITE_IDENTITY_STATUS_CERT,
     53     // The website provided a valid EV certificate.
     54     SITE_IDENTITY_STATUS_EV_CERT,
     55     // The website provided a valid certificate but no revocation check could be
     56     // performed.
     57     SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN,
     58     // Site identity could not be verified because the site did not provide a
     59     // certificate. This is the expected state for HTTP connections.
     60     SITE_IDENTITY_STATUS_NO_CERT,
     61     // An error occured while verifying the site identity.
     62     SITE_IDENTITY_STATUS_ERROR,
     63     // The site is a trusted internal chrome page.
     64     SITE_IDENTITY_STATUS_INTERNAL_PAGE,
     65     // The profile has accessed data using an administrator-provided
     66     // certificate, so the site might be able to intercept data.
     67     SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT,
     68   };
     69 
     70   // Creates a WebsiteSettings for the passed |url| using the given |ssl| status
     71   // object to determine the status of the site's connection. The
     72   // |WebsiteSettings| takes ownership of the |ui|.
     73   WebsiteSettings(WebsiteSettingsUI* ui,
     74                   Profile* profile,
     75                   TabSpecificContentSettings* tab_specific_content_settings,
     76                   InfoBarService* infobar_service,
     77                   const GURL& url,
     78                   const content::SSLStatus& ssl,
     79                   content::CertStore* cert_store);
     80   virtual ~WebsiteSettings();
     81 
     82   // This method is called when ever a permission setting is changed.
     83   void OnSitePermissionChanged(ContentSettingsType type,
     84                                ContentSetting value);
     85 
     86   // Callback used for requests to fetch the number of page visits from history
     87   // service and the time of the first visit.
     88   void OnGotVisitCountToHost(HistoryService::Handle handle,
     89                              bool found_visits,
     90                              int visit_count,
     91                              base::Time first_visit);
     92 
     93   // This method is called by the UI when the UI is closing.
     94   void OnUIClosing();
     95 
     96   // Accessors.
     97   SiteConnectionStatus site_connection_status() const {
     98     return site_connection_status_;
     99   }
    100 
    101   SiteIdentityStatus site_identity_status() const {
    102     return site_identity_status_;
    103   }
    104 
    105   base::string16 site_connection_details() const {
    106     return site_connection_details_;
    107   }
    108 
    109   base::string16 site_identity_details() const {
    110     return site_identity_details_;
    111   }
    112 
    113   base::string16 organization_name() const {
    114     return organization_name_;
    115   }
    116 
    117   // SiteDataObserver implementation.
    118   virtual void OnSiteDataAccessed() OVERRIDE;
    119 
    120  private:
    121   // Initializes the |WebsiteSettings|.
    122   void Init(Profile* profile,
    123             const GURL& url,
    124             const content::SSLStatus& ssl);
    125 
    126   // Sets (presents) the information about the site's permissions in the |ui_|.
    127   void PresentSitePermissions();
    128 
    129   // Sets (presents) the information about the site's data in the |ui_|.
    130   void PresentSiteData();
    131 
    132   // Sets (presents) the information about the site's identity and connection
    133   // in the |ui_|.
    134   void PresentSiteIdentity();
    135 
    136   // Sets (presents) history information about the site in the |ui_|. Passing
    137   // base::Time() as value for |first_visit| will clear the history information
    138   // in the UI.
    139   void PresentHistoryInfo(base::Time first_visit);
    140 
    141   // The website settings UI displays information and controls for site
    142   // specific data (local stored objects like cookies), site specific
    143   // permissions (location, popup, plugin, etc.  permissions) and site specific
    144   // information (identity, connection status, etc.).
    145   WebsiteSettingsUI* ui_;
    146 
    147   // The infobar service of the active tab.
    148   InfoBarService* infobar_service_;
    149 
    150   // The flag that controls whether an infobar is displayed after the website
    151   // settings UI is closed or not.
    152   bool show_info_bar_;
    153 
    154   // The Omnibox URL of the website for which to display site permissions and
    155   // site information.
    156   GURL site_url_;
    157 
    158   // Status of the website's identity verification check.
    159   SiteIdentityStatus site_identity_status_;
    160 
    161   // For secure connection |cert_id_| is set to the ID of the server
    162   // certificate. For non secure connections |cert_id_| is 0.
    163   int cert_id_;
    164   // For secure connection, |signed_certificate_timestamp_ids_| is the list of
    165   // all Signed Certificate Timestamps and their validation status.
    166   // Empty if no SCTs accompanied the certificate
    167   content::SignedCertificateTimestampIDStatusList
    168       signed_certificate_timestamp_ids_;
    169 
    170   // Status of the connection to the website.
    171   SiteConnectionStatus site_connection_status_;
    172 
    173   // TODO(markusheintz): Move the creation of all the base::string16 typed UI
    174   // strings below to the corresponding UI code, in order to prevent
    175   // unnecessary UTF-8 string conversions.
    176 
    177   // Details about the website's identity. If the website's identity has been
    178   // verified then |site_identity_details_| contains who verified the identity.
    179   // This string will be displayed in the UI.
    180   base::string16 site_identity_details_;
    181 
    182   // Details about the connection to the website. In case of an encrypted
    183   // connection |site_connection_details_| contains encryption details, like
    184   // encryption strength and ssl protocol version. This string will be
    185   // displayed in the UI.
    186   base::string16 site_connection_details_;
    187 
    188   // For websites that provided an EV certificate |orgainization_name_|
    189   // contains the organization name of the certificate. In all other cases
    190   // |organization_name| is an empty string. This string will be displayed in
    191   // the UI.
    192   base::string16 organization_name_;
    193 
    194   // The |CertStore| provides all X509Certificates.
    195   content::CertStore* cert_store_;
    196 
    197   // The |HostContentSettingsMap| is the service that provides and manages
    198   // content settings (aka. site permissions).
    199   HostContentSettingsMap* content_settings_;
    200 
    201   // Used to request the number of page visits.
    202   CancelableRequestConsumer visit_count_request_consumer_;
    203 
    204   DISALLOW_COPY_AND_ASSIGN(WebsiteSettings);
    205 };
    206 
    207 #endif  // CHROME_BROWSER_UI_WEBSITE_SETTINGS_WEBSITE_SETTINGS_H_
    208