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.
5 #ifndef CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_
6 #define CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_
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"
21 class DictionaryValue;
25 class InterstitialPage;
29 #if defined(ENABLE_EXTENSIONS)
30 namespace extensions {
31 class ExperienceSamplingEvent;
35 // This class is responsible for showing/hiding the interstitial page that is
36 // shown when a certificate error happens.
37 // It deletes itself when the interstitial page is closed.
39 // This class should only be used on the UI thread because its implementation
40 // uses captive_portal::CaptivePortalService which can only be accessed on the
42 class SSLBlockingPage : public content::InterstitialPageDelegate,
43 public content::NotificationObserver {
45 // These represent the commands sent from the interstitial JavaScript. They
46 // are defined in chrome/browser/resources/ssl/ssl_errors_common.js.
47 // DO NOT reorder or change these without also changing the JavaScript!
48 enum SSLBlockingPageCommands {
57 enum SSLBlockingPageOptionsMask {
59 STRICT_ENFORCEMENT = 1 << 1,
60 EXPIRED_BUT_PREVIOUSLY_ALLOWED = 1 << 2
63 virtual ~SSLBlockingPage();
65 // Create an interstitial and show it.
68 // Creates an SSL blocking page. If the blocking page isn't shown, the caller
69 // is responsible for cleaning up the blocking page, otherwise the
70 // interstitial takes ownership when shown. |options_mask| must be a bitwise
71 // mask of SSLBlockingPageOptionsMask values.
72 SSLBlockingPage(content::WebContents* web_contents,
74 const net::SSLInfo& ssl_info,
75 const GURL& request_url,
77 const base::Callback<void(bool)>& callback);
79 // A method that sets strings in the specified dictionary from the passed
80 // vector so that they can be used to resource the ssl_roadblock.html/
81 // ssl_error.html files.
82 // Note: there can be up to 5 strings in |extra_info|.
83 static void SetExtraInfo(base::DictionaryValue* strings,
84 const std::vector<base::string16>& extra_info);
87 // InterstitialPageDelegate implementation.
88 virtual std::string GetHTMLContents() OVERRIDE;
89 virtual void CommandReceived(const std::string& command) OVERRIDE;
90 virtual void OverrideEntry(content::NavigationEntry* entry) OVERRIDE;
91 virtual void OverrideRendererPrefs(
92 content::RendererPreferences* prefs) OVERRIDE;
93 virtual void OnProceed() OVERRIDE;
94 virtual void OnDontProceed() OVERRIDE;
97 void NotifyDenyCertificate();
98 void NotifyAllowCertificate();
100 // Used to query the HistoryService to see if the URL is in history. For UMA.
101 void OnGotHistoryCount(bool success, int num_visits, base::Time first_visit);
103 // content::NotificationObserver:
104 virtual void Observe(
106 const content::NotificationSource& source,
107 const content::NotificationDetails& details) OVERRIDE;
109 base::Callback<void(bool)> callback_;
111 content::WebContents* web_contents_;
112 const int cert_error_;
113 const net::SSLInfo ssl_info_;
114 const GURL request_url_;
115 // Could the user successfully override the error?
116 // overridable_ will be set to false if strict_enforcement_ is true.
117 const bool overridable_;
118 // Has the site requested strict enforcement of certificate errors?
119 const bool strict_enforcement_;
120 content::InterstitialPage* interstitial_page_; // Owns us.
121 // Is the hostname for an internal network?
123 // How many times is this same URL in history?
125 // Used for getting num_visits_.
126 base::CancelableTaskTracker request_tracker_;
127 // Is captive portal detection enabled?
128 bool captive_portal_detection_enabled_;
129 // Did the probe complete before the interstitial was closed?
130 bool captive_portal_probe_completed_;
131 // Did the captive portal probe receive an error or get a non-HTTP response?
132 bool captive_portal_no_response_;
133 // Was a captive portal detected?
134 bool captive_portal_detected_;
135 // Did the user previously allow a bad certificate but the decision has now
137 const bool expired_but_previously_allowed_;
139 // For the FieldTrial: this contains the name of the condition.
140 std::string trial_condition_;
142 #if defined(ENABLE_EXTENSIONS)
143 // For Chrome Experience Sampling Platform: this maintains event state.
144 scoped_ptr<extensions::ExperienceSamplingEvent> sampling_event_;
147 content::NotificationRegistrar registrar_;
149 DISALLOW_COPY_AND_ASSIGN(SSLBlockingPage);
152 #endif // CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_