• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/time/time.h"
14 #include "chrome/browser/history/history_service.h"
15 #include "content/public/browser/interstitial_page_delegate.h"
16 #include "net/ssl/ssl_info.h"
17 #include "url/gurl.h"
18 
19 namespace base {
20 class DictionaryValue;
21 }
22 
23 namespace content {
24 class InterstitialPage;
25 class WebContents;
26 }
27 
28 // This class is responsible for showing/hiding the interstitial page that is
29 // shown when a certificate error happens.
30 // It deletes itself when the interstitial page is closed.
31 //
32 // This class should only be used on the UI thread because its implementation
33 // uses captive_portal::CaptivePortalService which can only be accessed on the
34 // UI thread.
35 class SSLBlockingPage : public content::InterstitialPageDelegate,
36                         public content::NotificationObserver {
37  public:
38   // These represent the commands sent from the interstitial JavaScript. They
39   // are defined in chrome/browser/resources/ssl/ssl_errors_common.js.
40   // DO NOT reorder or change these without also changing the JavaScript!
41   enum SSLBlockingPageCommands {
42    CMD_DONT_PROCEED = 0,
43    CMD_PROCEED = 1,
44    CMD_MORE = 2,
45    CMD_RELOAD = 3,
46    CMD_HELP = 4
47   };
48 
49   SSLBlockingPage(
50       content::WebContents* web_contents,
51       int cert_error,
52       const net::SSLInfo& ssl_info,
53       const GURL& request_url,
54       bool overridable,
55       bool strict_enforcement,
56       const base::Callback<void(bool)>& callback);
57   virtual ~SSLBlockingPage();
58 
59   // A method that sets strings in the specified dictionary from the passed
60   // vector so that they can be used to resource the ssl_roadblock.html/
61   // ssl_error.html files.
62   // Note: there can be up to 5 strings in |extra_info|.
63   static void SetExtraInfo(base::DictionaryValue* strings,
64                            const std::vector<base::string16>& extra_info);
65 
66  protected:
67   // InterstitialPageDelegate implementation.
68   virtual std::string GetHTMLContents() OVERRIDE;
69   virtual void CommandReceived(const std::string& command) OVERRIDE;
70   virtual void OverrideEntry(content::NavigationEntry* entry) OVERRIDE;
71   virtual void OverrideRendererPrefs(
72       content::RendererPreferences* prefs) OVERRIDE;
73   virtual void OnProceed() OVERRIDE;
74   virtual void OnDontProceed() OVERRIDE;
75 
76  private:
77   void NotifyDenyCertificate();
78   void NotifyAllowCertificate();
79 
80   // These fetch the appropriate HTML page, depending on the
81   // SSLInterstitialVersion Finch trial.
82   std::string GetHTMLContentsV1();
83   std::string GetHTMLContentsV2();
84 
85   // Used to query the HistoryService to see if the URL is in history. For UMA.
86   void OnGotHistoryCount(HistoryService::Handle handle,
87                          bool success,
88                          int num_visits,
89                          base::Time first_visit);
90 
91   // content::NotificationObserver:
92   virtual void Observe(
93       int type,
94       const content::NotificationSource& source,
95       const content::NotificationDetails& details) OVERRIDE;
96 
97   base::Callback<void(bool)> callback_;
98 
99   content::WebContents* web_contents_;
100   int cert_error_;
101   const net::SSLInfo ssl_info_;
102   GURL request_url_;
103   // Could the user successfully override the error?
104   bool overridable_;
105   // Has the site requested strict enforcement of certificate errors?
106   bool strict_enforcement_;
107   content::InterstitialPage* interstitial_page_;  // Owns us.
108   // Is the hostname for an internal network?
109   bool internal_;
110   // How many times is this same URL in history?
111   int num_visits_;
112   // Used for getting num_visits_.
113   CancelableRequestConsumer request_consumer_;
114   // Is captive portal detection enabled?
115   bool captive_portal_detection_enabled_;
116   // Did the probe complete before the interstitial was closed?
117   bool captive_portal_probe_completed_;
118   // Did the captive portal probe receive an error or get a non-HTTP response?
119   bool captive_portal_no_response_;
120   // Was a captive portal detected?
121   bool captive_portal_detected_;
122 
123   // For the FieldTrial: this contains the name of the condition.
124   std::string trialCondition_;
125 
126   content::NotificationRegistrar registrar_;
127 
128   DISALLOW_COPY_AND_ASSIGN(SSLBlockingPage);
129 };
130 
131 #endif  // CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_
132