Home | History | Annotate | Download | only in ssl
      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_SSL_SSL_BLOCKING_PAGE_H_
      6 #define CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/callback.h"
     12 #include "base/strings/string16.h"
     13 #include "base/task/cancelable_task_tracker.h"
     14 #include "base/time/time.h"
     15 #include "chrome/browser/history/history_service.h"
     16 #include "content/public/browser/interstitial_page_delegate.h"
     17 #include "net/ssl/ssl_info.h"
     18 #include "url/gurl.h"
     19 
     20 namespace base {
     21 class DictionaryValue;
     22 }
     23 
     24 namespace content {
     25 class InterstitialPage;
     26 class WebContents;
     27 }
     28 
     29 #if defined(ENABLE_EXTENSIONS)
     30 namespace extensions {
     31 class ExperienceSamplingEvent;
     32 }
     33 #endif
     34 
     35 class SSLErrorClassification;
     36 
     37 // This class is responsible for showing/hiding the interstitial page that is
     38 // shown when a certificate error happens.
     39 // It deletes itself when the interstitial page is closed.
     40 class SSLBlockingPage : public content::InterstitialPageDelegate {
     41  public:
     42   // These represent the commands sent from the interstitial JavaScript. They
     43   // are defined in chrome/browser/resources/ssl/ssl_errors_common.js.
     44   // DO NOT reorder or change these without also changing the JavaScript!
     45   enum SSLBlockingPageCommands {
     46     CMD_DONT_PROCEED = 0,
     47     CMD_PROCEED = 1,
     48     CMD_MORE = 2,
     49     CMD_RELOAD = 3,
     50     CMD_HELP = 4,
     51     CMD_CLOCK = 5
     52   };
     53 
     54   enum SSLBlockingPageOptionsMask {
     55     OVERRIDABLE = 1 << 0,
     56     STRICT_ENFORCEMENT = 1 << 1,
     57     EXPIRED_BUT_PREVIOUSLY_ALLOWED = 1 << 2
     58   };
     59 
     60   virtual ~SSLBlockingPage();
     61 
     62   // Create an interstitial and show it.
     63   void Show();
     64 
     65   // Creates an SSL blocking page. If the blocking page isn't shown, the caller
     66   // is responsible for cleaning up the blocking page, otherwise the
     67   // interstitial takes ownership when shown. |options_mask| must be a bitwise
     68   // mask of SSLBlockingPageOptionsMask values.
     69   SSLBlockingPage(content::WebContents* web_contents,
     70                   int cert_error,
     71                   const net::SSLInfo& ssl_info,
     72                   const GURL& request_url,
     73                   int options_mask,
     74                   const base::Callback<void(bool)>& callback);
     75 
     76   // A method that sets strings in the specified dictionary from the passed
     77   // vector so that they can be used to resource the ssl_roadblock.html/
     78   // ssl_error.html files.
     79   // Note: there can be up to 5 strings in |extra_info|.
     80   static void SetExtraInfo(base::DictionaryValue* strings,
     81                            const std::vector<base::string16>& extra_info);
     82 
     83  protected:
     84   // InterstitialPageDelegate implementation.
     85   virtual std::string GetHTMLContents() OVERRIDE;
     86   virtual void CommandReceived(const std::string& command) OVERRIDE;
     87   virtual void OverrideEntry(content::NavigationEntry* entry) OVERRIDE;
     88   virtual void OverrideRendererPrefs(
     89       content::RendererPreferences* prefs) OVERRIDE;
     90   virtual void OnProceed() OVERRIDE;
     91   virtual void OnDontProceed() OVERRIDE;
     92 
     93  private:
     94   void NotifyDenyCertificate();
     95   void NotifyAllowCertificate();
     96 
     97   // Used to query the HistoryService to see if the URL is in history. For UMA.
     98   void OnGotHistoryCount(bool success, int num_visits, base::Time first_visit);
     99 
    100   base::Callback<void(bool)> callback_;
    101 
    102   content::WebContents* web_contents_;
    103   const int cert_error_;
    104   const net::SSLInfo ssl_info_;
    105   const GURL request_url_;
    106   // Could the user successfully override the error?
    107   // overridable_ will be set to false if strict_enforcement_ is true.
    108   const bool overridable_;
    109   // Has the site requested strict enforcement of certificate errors?
    110   const bool strict_enforcement_;
    111   content::InterstitialPage* interstitial_page_;  // Owns us.
    112   // Is the hostname for an internal network?
    113   bool internal_;
    114   // How many times is this same URL in history?
    115   int num_visits_;
    116   // Used for getting num_visits_.
    117   base::CancelableTaskTracker request_tracker_;
    118   // Did the user previously allow a bad certificate but the decision has now
    119   // expired?
    120   const bool expired_but_previously_allowed_;
    121   scoped_ptr<SSLErrorClassification> ssl_error_classification_;
    122 
    123 #if defined(ENABLE_EXTENSIONS)
    124   // For Chrome Experience Sampling Platform: this maintains event state.
    125   scoped_ptr<extensions::ExperienceSamplingEvent> sampling_event_;
    126 #endif
    127 
    128   content::NotificationRegistrar registrar_;
    129 
    130   DISALLOW_COPY_AND_ASSIGN(SSLBlockingPage);
    131 };
    132 
    133 #endif  // CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_
    134