OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 #include "ios/chrome/browser/ssl/ios_ssl_blocking_page.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "base/metrics/histogram.h" | |
10 #include "base/prefs/pref_service.h" | |
11 #include "base/strings/string_number_conversions.h" | |
12 #include "base/strings/utf_string_conversions.h" | |
13 #include "components/security_interstitials/core/metrics_helper.h" | |
14 #include "components/security_interstitials/core/ssl_error_ui.h" | |
15 #include "ios/chrome/browser/interstitials/ios_chrome_controller_client.h" | |
16 #include "ios/chrome/browser/interstitials/ios_chrome_metrics_helper.h" | |
17 #include "ios/chrome/browser/pref_names.h" | |
18 #include "ios/chrome/grit/ios_strings.h" | |
19 #include "ios/public/provider/chrome/browser/browser_constants.h" | |
20 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state. h" | |
21 #include "ios/web/public/web_state/web_state.h" | |
22 #include "net/base/net_errors.h" | |
23 #include "ui/base/l10n/l10n_util.h" | |
24 #include "url/gurl.h" | |
25 | |
26 using security_interstitials::SSLErrorUI; | |
27 | |
28 namespace { | |
29 // Events for UMA. Do not reorder or change! | |
30 enum SSLExpirationAndDecision { | |
31 EXPIRED_AND_PROCEED, | |
32 EXPIRED_AND_DO_NOT_PROCEED, | |
33 NOT_EXPIRED_AND_PROCEED, | |
34 NOT_EXPIRED_AND_DO_NOT_PROCEED, | |
35 END_OF_SSL_EXPIRATION_AND_DECISION, | |
36 }; | |
37 | |
38 // Rappor prefix, which is used for both overridable and non-overridable | |
39 // interstitials so we don't leak the "overridable" bit. | |
40 const char kSSLRapporPrefix[] = "ssl2"; | |
droger
2016/01/06 17:28:03
Probably not for this CL, but it seems that it wou
sdefresne
2016/01/06 17:31:02
https://code.google.com/p/chromium/issues/detail?i
| |
41 | |
42 void RecordSSLExpirationPageEventState(bool expired_but_previously_allowed, | |
43 bool proceed, | |
44 bool overridable) { | |
45 SSLExpirationAndDecision event; | |
46 if (expired_but_previously_allowed && proceed) | |
47 event = EXPIRED_AND_PROCEED; | |
48 else if (expired_but_previously_allowed && !proceed) | |
49 event = EXPIRED_AND_DO_NOT_PROCEED; | |
50 else if (!expired_but_previously_allowed && proceed) | |
51 event = NOT_EXPIRED_AND_PROCEED; | |
52 else | |
53 event = NOT_EXPIRED_AND_DO_NOT_PROCEED; | |
54 | |
55 if (overridable) { | |
56 UMA_HISTOGRAM_ENUMERATION( | |
57 "interstitial.ssl.expiration_and_decision.overridable", event, | |
58 END_OF_SSL_EXPIRATION_AND_DECISION); | |
59 } else { | |
60 UMA_HISTOGRAM_ENUMERATION( | |
61 "interstitial.ssl.expiration_and_decision.nonoverridable", event, | |
62 END_OF_SSL_EXPIRATION_AND_DECISION); | |
63 } | |
64 } | |
65 } // namespace | |
66 | |
67 // Note that we always create a navigation entry with SSL errors. | |
68 // No error happening loading a sub-resource triggers an interstitial so far. | |
69 IOSSSLBlockingPage::IOSSSLBlockingPage( | |
70 web::WebState* web_state, | |
71 int cert_error, | |
72 const net::SSLInfo& ssl_info, | |
73 const GURL& request_url, | |
74 int options_mask, | |
75 const base::Time& time_triggered, | |
76 const base::Callback<void(bool)>& callback) | |
77 : IOSSecurityInterstitialPage(web_state, request_url), | |
78 callback_(callback), | |
79 ssl_info_(ssl_info), | |
80 overridable_(IsOverridable(options_mask)), | |
81 expired_but_previously_allowed_( | |
82 (options_mask & SSLErrorUI::EXPIRED_BUT_PREVIOUSLY_ALLOWED) != 0), | |
83 controller_(new IOSChromeControllerClient(web_state)) { | |
84 // Get the language and override prefs for the SSLErrorUI. | |
85 std::string languages; | |
86 ios::ChromeBrowserState* browser_state = | |
87 ios::ChromeBrowserState::FromBrowserState(web_state->GetBrowserState()); | |
88 if (browser_state) { | |
89 languages = browser_state->GetPrefs()->GetString(prefs::kAcceptLanguages); | |
90 } | |
91 if (overridable_) | |
92 options_mask |= SSLErrorUI::SOFT_OVERRIDE_ENABLED; | |
93 else | |
94 options_mask &= ~SSLErrorUI::SOFT_OVERRIDE_ENABLED; | |
95 | |
96 // Set up the metrics helper for the SSLErrorUI. | |
97 security_interstitials::MetricsHelper::ReportDetails reporting_info; | |
98 reporting_info.metric_prefix = | |
99 overridable_ ? "ssl_overridable" : "ssl_nonoverridable"; | |
100 reporting_info.rappor_prefix = kSSLRapporPrefix; | |
101 reporting_info.rappor_report_type = rappor::UMA_RAPPOR_TYPE; | |
102 IOSChromeMetricsHelper* ios_chrome_metrics_helper = | |
103 new IOSChromeMetricsHelper(web_state, request_url, reporting_info); | |
104 controller_->set_metrics_helper(make_scoped_ptr(ios_chrome_metrics_helper)); | |
105 | |
106 ssl_error_ui_.reset(new SSLErrorUI(request_url, cert_error, ssl_info, | |
107 options_mask, time_triggered, languages, | |
108 controller_.get())); | |
109 | |
110 // Creating an interstitial without showing (e.g. from chrome://interstitials) | |
111 // it leaks memory, so don't create it here. | |
112 } | |
113 | |
114 bool IOSSSLBlockingPage::ShouldCreateNewNavigation() const { | |
115 return true; | |
116 } | |
117 | |
118 IOSSSLBlockingPage::~IOSSSLBlockingPage() { | |
119 if (!callback_.is_null()) { | |
120 // The page is closed without the user having chosen what to do, default to | |
121 // deny. | |
122 RecordSSLExpirationPageEventState(expired_but_previously_allowed_, false, | |
123 overridable_); | |
124 NotifyDenyCertificate(); | |
125 } | |
126 } | |
127 | |
128 void IOSSSLBlockingPage::AfterShow() { | |
129 controller_->SetWebInterstitial(web_interstitial()); | |
130 } | |
131 | |
132 void IOSSSLBlockingPage::PopulateInterstitialStrings( | |
133 base::DictionaryValue* load_time_data) const { | |
134 ssl_error_ui_->PopulateStringsForHTML(load_time_data); | |
135 // Spoofing attempts have a custom message on iOS. | |
136 // This code will no longer be necessary once UIWebView is gone. | |
137 if (ssl_info_.cert->subject().GetDisplayName() == ios::kSpoofingAttemptFlag) { | |
138 load_time_data->SetString( | |
139 "errorCode", base::string16(base::ASCIIToUTF16("Unverified URL"))); | |
140 load_time_data->SetString( | |
141 "tabTitle", l10n_util::GetStringUTF16( | |
142 IDS_IOS_INTERSTITIAL_HEADING_SPOOFING_ATTEMPT_ERROR)); | |
143 load_time_data->SetString( | |
144 "heading", l10n_util::GetStringUTF16( | |
145 IDS_IOS_INTERSTITIAL_HEADING_SPOOFING_ATTEMPT_ERROR)); | |
146 load_time_data->SetString( | |
147 "primaryParagraph", | |
148 l10n_util::GetStringUTF16( | |
149 IDS_IOS_INTERSTITIAL_SUMMARY_SPOOFING_ATTEMPT_ERROR)); | |
150 load_time_data->SetString( | |
151 "explanationParagraph", | |
152 l10n_util::GetStringUTF16( | |
153 IDS_IOS_INTERSTITIAL_DETAILS_SPOOFING_ATTEMPT_ERROR)); | |
154 load_time_data->SetString("finalParagraph", base::string16()); | |
155 } | |
156 } | |
157 | |
158 // This handles the commands sent from the interstitial JavaScript. | |
159 void IOSSSLBlockingPage::CommandReceived(const std::string& command) { | |
160 if (command == "\"pageLoadComplete\"") { | |
161 // content::WaitForRenderFrameReady sends this message when the page | |
162 // load completes. Ignore it. | |
163 return; | |
164 } | |
165 | |
166 int cmd = 0; | |
167 bool retval = base::StringToInt(command, &cmd); | |
168 DCHECK(retval); | |
169 ssl_error_ui_->HandleCommand( | |
170 static_cast<security_interstitials::SecurityInterstitialCommands>(cmd)); | |
171 } | |
172 | |
173 void IOSSSLBlockingPage::OnProceed() { | |
174 RecordSSLExpirationPageEventState(expired_but_previously_allowed_, true, | |
175 overridable_); | |
176 | |
177 // Accepting the certificate resumes the loading of the page. | |
178 DCHECK(!callback_.is_null()); | |
179 callback_.Run(true); | |
180 callback_.Reset(); | |
181 } | |
182 | |
183 void IOSSSLBlockingPage::OnDontProceed() { | |
184 RecordSSLExpirationPageEventState(expired_but_previously_allowed_, false, | |
185 overridable_); | |
186 | |
187 NotifyDenyCertificate(); | |
188 } | |
189 | |
190 void IOSSSLBlockingPage::NotifyDenyCertificate() { | |
191 // It's possible that callback_ may not exist if the user clicks "Proceed" | |
192 // followed by pressing the back button before the interstitial is hidden. | |
193 // In that case the certificate will still be treated as allowed. | |
194 if (callback_.is_null()) | |
195 return; | |
196 | |
197 callback_.Run(false); | |
198 callback_.Reset(); | |
199 } | |
200 | |
201 // static | |
202 bool IOSSSLBlockingPage::IsOverridable(int options_mask) { | |
203 const bool is_overridable = | |
204 (options_mask & SSLErrorUI::SOFT_OVERRIDE_ENABLED) && | |
205 !(options_mask & SSLErrorUI::STRICT_ENFORCEMENT); | |
206 return is_overridable; | |
207 } | |
OLD | NEW |