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/interstitials/security_interstitial_metrics_helper.h"
16 #include "chrome/browser/interstitials/security_interstitial_page.h"
17 #include "net/ssl/ssl_info.h"
20 #if defined(ENABLE_EXTENSIONS)
21 namespace extensions
{
22 class ExperienceSamplingEvent
;
26 class SSLErrorClassification
;
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 class SSLBlockingPage
: public SecurityInterstitialPage
{
33 // These represent the commands sent from the interstitial JavaScript. They
34 // are defined in chrome/browser/resources/ssl/ssl_errors_common.js.
35 // DO NOT reorder or change these without also changing the JavaScript!
36 enum SSLBlockingPageCommands
{
45 enum SSLBlockingPageOptionsMask
{
46 // Indicates whether or not the user could (assuming perfect knowledge)
47 // successfully override the error and still get the security guarantees
50 // Indicates whether or not the site the user is trying to connect to has
51 // requested strict enforcement of certificate validation (e.g. with HTTP
52 // Strict-Transport-Security).
53 STRICT_ENFORCEMENT
= 1 << 1,
54 // Indicates whether a user decision had been previously made but the
55 // decision has expired.
56 EXPIRED_BUT_PREVIOUSLY_ALLOWED
= 1 << 2
59 // Interstitial type, used in tests.
60 static const void* kTypeForTesting
;
62 ~SSLBlockingPage() override
;
64 // Creates an SSL blocking page. If the blocking page isn't shown, the caller
65 // is responsible for cleaning up the blocking page, otherwise the
66 // interstitial takes ownership when shown. |options_mask| must be a bitwise
67 // mask of SSLBlockingPageOptionsMask values.
68 SSLBlockingPage(content::WebContents
* web_contents
,
70 const net::SSLInfo
& ssl_info
,
71 const GURL
& request_url
,
73 const base::Callback
<void(bool)>& callback
);
75 // SecurityInterstitialPage method:
76 const void* GetTypeForTesting() const override
;
78 // Returns true if |options_mask| refers to an overridable SSL error.
79 static bool IsOptionsOverridable(int options_mask
);
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
;
95 void NotifyDenyCertificate();
96 void NotifyAllowCertificate();
98 std::string
GetUmaHistogramPrefix() const;
99 std::string
GetSamplingEventName() const;
101 base::Callback
<void(bool)> callback_
;
103 const int cert_error_
;
104 const net::SSLInfo ssl_info_
;
105 // There are two ways for the user to override an interstitial:
107 // overridable_) By clicking on "Advanced" and then "Proceed".
108 // - This corresponds to "the user can override using the UI".
109 // danger_overridable_) By typing the word "danger".
110 // - This is an undocumented workaround.
111 // - This can be set to "false" dynamically to prevent the behaviour.
112 const bool overridable_
;
113 bool danger_overridable_
;
114 // Has the site requested strict enforcement of certificate errors?
115 const bool strict_enforcement_
;
116 // Did the user previously allow a bad certificate but the decision has now
118 const bool expired_but_previously_allowed_
;
119 scoped_ptr
<SSLErrorClassification
> ssl_error_classification_
;
120 scoped_ptr
<SecurityInterstitialMetricsHelper
> metrics_helper_
;
122 // Which type of interstitial this is.
123 enum SSLInterstitialReason
{
126 } interstitial_reason_
;
128 DISALLOW_COPY_AND_ASSIGN(SSLBlockingPage
);
131 #endif // CHROME_BROWSER_SSL_SSL_BLOCKING_PAGE_H_