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