Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / ssl / ssl_blocking_page.h
blob212baa32cbd4d246828673cbd3932baa6fc1ecb3
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_
8 #include <string>
9 #include <vector>
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/interstitials/security_interstitial_page.h"
16 #include "net/ssl/ssl_info.h"
17 #include "url/gurl.h"
19 // Constants for the HTTPSErrorReporter Finch experiment
20 extern const char kHTTPSErrorReporterFinchExperimentName[];
21 extern const char kHTTPSErrorReporterFinchGroupShowPossiblySend[];
22 extern const char kHTTPSErrorReporterFinchGroupDontShowDontSend[];
23 extern const char kHTTPSErrorReporterFinchParamName[];
25 #if defined(ENABLE_EXTENSIONS)
26 namespace extensions {
27 class ExperienceSamplingEvent;
29 #endif
31 class SafeBrowsingUIManager;
32 class SSLErrorClassification;
34 // This class is responsible for showing/hiding the interstitial page that is
35 // shown when a certificate error happens.
36 // It deletes itself when the interstitial page is closed.
37 class SSLBlockingPage : public SecurityInterstitialPage {
38 public:
39 enum SSLBlockingPageOptionsMask {
40 // Indicates whether or not the user could (assuming perfect knowledge)
41 // successfully override the error and still get the security guarantees
42 // of TLS.
43 OVERRIDABLE = 1 << 0,
44 // Indicates whether or not the site the user is trying to connect to has
45 // requested strict enforcement of certificate validation (e.g. with HTTP
46 // Strict-Transport-Security).
47 STRICT_ENFORCEMENT = 1 << 1,
48 // Indicates whether a user decision had been previously made but the
49 // decision has expired.
50 EXPIRED_BUT_PREVIOUSLY_ALLOWED = 1 << 2
53 // Interstitial type, used in tests.
54 static InterstitialPageDelegate::TypeID kTypeForTesting;
56 ~SSLBlockingPage() override;
58 // Creates an SSL blocking page. If the blocking page isn't shown, the caller
59 // is responsible for cleaning up the blocking page, otherwise the
60 // interstitial takes ownership when shown. |options_mask| must be a bitwise
61 // mask of SSLBlockingPageOptionsMask values.
62 SSLBlockingPage(content::WebContents* web_contents,
63 int cert_error,
64 const net::SSLInfo& ssl_info,
65 const GURL& request_url,
66 int options_mask,
67 const base::Time& time_triggered,
68 SafeBrowsingUIManager* safe_browsing_ui_manager,
69 const base::Callback<void(bool)>& callback);
71 // InterstitialPageDelegate method:
72 InterstitialPageDelegate::TypeID GetTypeForTesting() const override;
74 // Returns true if |options_mask| refers to an overridable SSL error.
75 static bool IsOptionsOverridable(int options_mask);
77 // Allows tests to be notified when an invalid cert chain report has
78 // been sent (or not sent).
79 void SetCertificateReportCallbackForTesting(const base::Closure& callback);
81 protected:
82 // InterstitialPageDelegate implementation.
83 void CommandReceived(const std::string& command) override;
84 void OverrideEntry(content::NavigationEntry* entry) override;
85 void OverrideRendererPrefs(content::RendererPreferences* prefs) override;
86 void OnProceed() override;
87 void OnDontProceed() override;
89 // SecurityInterstitialPage implementation:
90 bool ShouldCreateNewNavigation() const override;
91 void PopulateInterstitialStrings(
92 base::DictionaryValue* load_time_data) override;
94 void PopulateExtendedReportingOption(base::DictionaryValue* load_time_data);
96 private:
97 void NotifyDenyCertificate();
98 void NotifyAllowCertificate();
100 std::string GetUmaHistogramPrefix() const;
101 std::string GetSamplingEventName() const;
103 // Send a report about an invalid certificate to the server. Takes
104 // care of calling certificate_report_callback_for_testing_.
105 void FinishCertCollection();
107 base::Callback<void(bool)> callback_;
109 const int cert_error_;
110 const net::SSLInfo ssl_info_;
111 // There are two ways for the user to override an interstitial:
113 // overridable_) By clicking on "Advanced" and then "Proceed".
114 // - This corresponds to "the user can override using the UI".
115 // danger_overridable_) By typing the word "danger".
116 // - This is an undocumented workaround.
117 // - This can be set to "false" dynamically to prevent the behaviour.
118 const bool overridable_;
119 bool danger_overridable_;
120 // Has the site requested strict enforcement of certificate errors?
121 const bool strict_enforcement_;
122 // Did the user previously allow a bad certificate but the decision has now
123 // expired?
124 const bool expired_but_previously_allowed_;
125 scoped_ptr<SSLErrorClassification> ssl_error_classification_;
127 // The time at which the interstitial was triggered. The interstitial
128 // calculates all times relative to this.
129 const base::Time time_triggered_;
131 // For reporting invalid SSL certificates as part of Safe Browsing
132 // Extended Reporting.
133 SafeBrowsingUIManager* safe_browsing_ui_manager_;
135 // This callback is run when an extended reporting certificate chain
136 // report has been sent, or when it is decided that it should not be
137 // sent (for example, when in incognito mode).
138 base::Closure certificate_report_callback_for_testing_;
140 // Which type of interstitial this is.
141 enum SSLInterstitialReason {
142 SSL_REASON_SSL,
143 SSL_REASON_BAD_CLOCK
144 } interstitial_reason_;
146 DISALLOW_COPY_AND_ASSIGN(SSLBlockingPage);
149 #endif // CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_