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 #include "chrome/browser/ssl/ssl_blocking_page.h" | 5 #include "chrome/browser/ssl/ssl_blocking_page.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 #endif | 50 #endif |
51 | 51 |
52 using base::ASCIIToUTF16; | 52 using base::ASCIIToUTF16; |
53 using base::TimeTicks; | 53 using base::TimeTicks; |
54 using content::InterstitialPage; | 54 using content::InterstitialPage; |
55 using content::NavigationController; | 55 using content::NavigationController; |
56 using content::NavigationEntry; | 56 using content::NavigationEntry; |
57 | 57 |
58 namespace { | 58 namespace { |
59 | 59 |
60 // Constants for the M37 Finch trial. | |
61 const char kInterstitialTrialName[] = "SSLInterstitialVersion"; | |
62 const char kCondV1[] = "V1"; | |
63 const char kCondV1LayoutV2Text[] = "V1LayoutV2Text"; | |
64 const char kCondV2[] = "V2"; // Also the default. | |
65 const char kCondV2Guard[] = "V2WithGuard"; | |
66 const char kCondV2Yellow[] = "V2Yellow"; | |
67 | |
68 const char* GetTrialCondition() { | |
Dan Beam
2014/06/20 21:28:20
nit: makes the code smaller and easier to read
felt
2014/06/21 00:23:16
Done.
| |
69 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
70 switches::kSSLInterstitialV1) || | |
71 base::FieldTrialList::FindFullName(kInterstitialTrialName) == kCondV1) { | |
72 return kCondV1; | |
73 } | |
74 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
75 switches::kSSLInterstitialV2) || | |
76 base::FieldTrialList::FindFullName(kInterstitialTrialName) == kCondV2) { | |
77 return kCondV2; | |
78 } | |
79 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
80 switches::kSSLInterstitialV1WithV2Text) || | |
81 base::FieldTrialList::FindFullName(kInterstitialTrialName) | |
82 == kCondV1LayoutV2Text) { | |
83 return kCondV1LayoutV2Text; | |
84 } | |
85 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
86 switches::kSSLInterstitialV2Guard) || | |
87 base::FieldTrialList::FindFullName(kInterstitialTrialName) | |
88 == kCondV2Guard) { | |
89 return kCondV2Guard; | |
90 } | |
91 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
92 switches::kSSLInterstitialV2Yellow) || | |
93 base::FieldTrialList::FindFullName(kInterstitialTrialName) | |
94 == kCondV2Yellow) { | |
95 return kCondV2Yellow; | |
96 } | |
97 return kCondV2; | |
98 } | |
99 | |
60 // Events for UMA. Do not reorder or change! | 100 // Events for UMA. Do not reorder or change! |
61 enum SSLBlockingPageEvent { | 101 enum SSLBlockingPageEvent { |
62 SHOW_ALL, | 102 SHOW_ALL, |
63 SHOW_OVERRIDABLE, | 103 SHOW_OVERRIDABLE, |
64 PROCEED_OVERRIDABLE, | 104 PROCEED_OVERRIDABLE, |
65 PROCEED_NAME, | 105 PROCEED_NAME, |
66 PROCEED_DATE, | 106 PROCEED_DATE, |
67 PROCEED_AUTHORITY, | 107 PROCEED_AUTHORITY, |
68 DONT_PROCEED_OVERRIDABLE, | 108 DONT_PROCEED_OVERRIDABLE, |
69 DONT_PROCEED_NAME, | 109 DONT_PROCEED_NAME, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 cert_error_(cert_error), | 233 cert_error_(cert_error), |
194 ssl_info_(ssl_info), | 234 ssl_info_(ssl_info), |
195 request_url_(request_url), | 235 request_url_(request_url), |
196 overridable_(overridable), | 236 overridable_(overridable), |
197 strict_enforcement_(strict_enforcement), | 237 strict_enforcement_(strict_enforcement), |
198 internal_(false), | 238 internal_(false), |
199 num_visits_(-1), | 239 num_visits_(-1), |
200 captive_portal_detection_enabled_(false), | 240 captive_portal_detection_enabled_(false), |
201 captive_portal_probe_completed_(false), | 241 captive_portal_probe_completed_(false), |
202 captive_portal_no_response_(false), | 242 captive_portal_no_response_(false), |
203 captive_portal_detected_(false) { | 243 captive_portal_detected_(false), |
244 trial_condition_(GetTrialCondition()) { | |
204 Profile* profile = Profile::FromBrowserContext( | 245 Profile* profile = Profile::FromBrowserContext( |
205 web_contents->GetBrowserContext()); | 246 web_contents->GetBrowserContext()); |
206 // For UMA stats. | 247 // For UMA stats. |
207 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) | 248 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) |
208 internal_ = true; | 249 internal_ = true; |
209 RecordSSLBlockingPageEventStats(SHOW_ALL); | 250 RecordSSLBlockingPageEventStats(SHOW_ALL); |
210 if (overridable_ && !strict_enforcement_) { | 251 if (overridable_ && !strict_enforcement_) { |
211 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); | 252 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); |
212 if (internal_) | 253 if (internal_) |
213 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); | 254 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 captive_portal_probe_completed_, | 289 captive_portal_probe_completed_, |
249 captive_portal_no_response_, | 290 captive_portal_no_response_, |
250 captive_portal_detected_); | 291 captive_portal_detected_); |
251 // The page is closed without the user having chosen what to do, default to | 292 // The page is closed without the user having chosen what to do, default to |
252 // deny. | 293 // deny. |
253 NotifyDenyCertificate(); | 294 NotifyDenyCertificate(); |
254 } | 295 } |
255 } | 296 } |
256 | 297 |
257 std::string SSLBlockingPage::GetHTMLContents() { | 298 std::string SSLBlockingPage::GetHTMLContents() { |
258 if (CommandLine::ForCurrentProcess()->HasSwitch( | 299 if (trial_condition_ == kCondV1 || trial_condition_ == kCondV1LayoutV2Text) |
259 switches::kSSLInterstitialVersionV1) || | |
260 base::FieldTrialList::FindFullName("SSLInterstitialVersion") == "V1") { | |
261 return GetHTMLContentsV1(); | 300 return GetHTMLContentsV1(); |
262 } | |
263 return GetHTMLContentsV2(); | 301 return GetHTMLContentsV2(); |
264 } | 302 } |
265 | 303 |
266 std::string SSLBlockingPage::GetHTMLContentsV1() { | 304 std::string SSLBlockingPage::GetHTMLContentsV1() { |
267 base::DictionaryValue strings; | 305 base::DictionaryValue strings; |
268 int resource_id; | 306 int resource_id; |
269 if (overridable_ && !strict_enforcement_) { | 307 if (overridable_ && !strict_enforcement_) { |
270 // Let's build the overridable error page. | 308 // Let's build the overridable error page. |
271 SSLErrorInfo error_info = | 309 SSLErrorInfo error_info = |
272 SSLErrorInfo::CreateError( | 310 SSLErrorInfo::CreateError( |
273 SSLErrorInfo::NetErrorToErrorType(cert_error_), | 311 SSLErrorInfo::NetErrorToErrorType(cert_error_), |
274 ssl_info_.cert.get(), | 312 ssl_info_.cert.get(), |
275 request_url_); | 313 request_url_); |
314 resource_id = IDR_SSL_ROAD_BLOCK_HTML; | |
315 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | |
316 strings.SetString("errorType", "overridable"); | |
317 if (trial_condition_ == kCondV1LayoutV2Text) { | |
318 base::string16 url(ASCIIToUTF16(request_url_.host())); | |
319 strings.SetString( | |
320 "headLine", l10n_util::GetStringUTF16(IDS_SSL_V2_HEADING)); | |
321 strings.SetString( | |
322 "description", | |
323 l10n_util::GetStringFUTF16(IDS_SSL_V2_PRIMARY_PARAGRAPH, url)); | |
324 strings.SetString( | |
325 "moreInfoTitle", | |
326 l10n_util::GetStringUTF16(IDS_SSL_V2_OPEN_DETAILS_BUTTON)); | |
327 strings.SetString("moreInfo1", error_info.details()); | |
328 strings.SetString("moreInfo2", std::string()); | |
329 strings.SetString("moreInfo3", std::string()); | |
330 strings.SetString("moreInfo4", std::string()); | |
331 strings.SetString("moreInfo5", std::string()); | |
Dan Beam
2014/06/20 21:28:20
^ don't these need to be base::string16()?
felt
2014/06/21 00:23:15
Done, although it doesn't really matter for the em
| |
332 strings.SetString( | |
333 "exit", | |
334 l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_SAFETY_BUTTON)); | |
335 strings.SetString( | |
336 "title", l10n_util::GetStringUTF16(IDS_SSL_V2_TITLE)); | |
337 strings.SetString( | |
338 "proceed", | |
339 l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_PROCEED_LINK_TEXT)); | |
340 strings.SetString( | |
341 "reasonForNotProceeding", std::string()); | |
342 } else { | |
343 strings.SetString("headLine", error_info.title()); | |
344 strings.SetString("description", error_info.details()); | |
345 strings.SetString("moreInfoTitle", | |
346 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); | |
347 SetExtraInfo(&strings, error_info.extra_information()); | |
276 | 348 |
277 resource_id = IDR_SSL_ROAD_BLOCK_HTML; | 349 strings.SetString( |
278 strings.SetString("headLine", error_info.title()); | 350 "exit", l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_PAGE_EXIT)); |
279 strings.SetString("description", error_info.details()); | 351 strings.SetString( |
280 strings.SetString("moreInfoTitle", | 352 "title", l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_PAGE_TITLE)); |
281 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); | 353 strings.SetString( |
282 SetExtraInfo(&strings, error_info.extra_information()); | 354 "proceed", |
283 | 355 l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_PAGE_PROCEED)); |
284 strings.SetString( | 356 strings.SetString( |
285 "exit", l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_PAGE_EXIT)); | 357 "reasonForNotProceeding", l10n_util::GetStringUTF16( |
286 strings.SetString( | 358 IDS_SSL_OVERRIDABLE_PAGE_SHOULD_NOT_PROCEED)); |
Dan Beam
2014/06/20 21:28:20
opt nit:
strings.SetString("reasonForNotProceed
felt
2014/06/21 00:23:15
sure
| |
287 "title", l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_PAGE_TITLE)); | 359 } |
288 strings.SetString( | |
289 "proceed", l10n_util::GetStringUTF16(IDS_SSL_OVERRIDABLE_PAGE_PROCEED)); | |
290 strings.SetString( | |
291 "reasonForNotProceeding", l10n_util::GetStringUTF16( | |
292 IDS_SSL_OVERRIDABLE_PAGE_SHOULD_NOT_PROCEED)); | |
293 strings.SetString("errorType", "overridable"); | |
294 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | |
295 } else { | 360 } else { |
296 // Let's build the blocking error page. | 361 // Let's build the blocking error page. |
297 resource_id = IDR_SSL_BLOCKING_HTML; | 362 resource_id = IDR_SSL_BLOCKING_HTML; |
298 | 363 |
299 // Strings that are not dependent on the URL. | 364 // Strings that are not dependent on the URL. |
300 strings.SetString( | 365 strings.SetString( |
301 "title", l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); | 366 "title", l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); |
302 strings.SetString( | 367 strings.SetString( |
303 "reloadMsg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); | 368 "reloadMsg", l10n_util::GetStringUTF16(IDS_ERRORPAGES_BUTTON_RELOAD)); |
304 strings.SetString( | 369 strings.SetString( |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 resource_id)); | 470 resource_id)); |
406 return webui::GetI18nTemplateHtml(html, &strings); | 471 return webui::GetI18nTemplateHtml(html, &strings); |
407 } | 472 } |
408 | 473 |
409 std::string SSLBlockingPage::GetHTMLContentsV2() { | 474 std::string SSLBlockingPage::GetHTMLContentsV2() { |
410 base::DictionaryValue load_time_data; | 475 base::DictionaryValue load_time_data; |
411 base::string16 url(ASCIIToUTF16(request_url_.host())); | 476 base::string16 url(ASCIIToUTF16(request_url_.host())); |
412 if (base::i18n::IsRTL()) | 477 if (base::i18n::IsRTL()) |
413 base::i18n::WrapStringWithLTRFormatting(&url); | 478 base::i18n::WrapStringWithLTRFormatting(&url); |
414 webui::SetFontAndTextDirection(&load_time_data); | 479 webui::SetFontAndTextDirection(&load_time_data); |
480 load_time_data.SetString("trialCondition", trial_condition_); | |
415 | 481 |
416 // Shared values for both the overridable and non-overridable versions. | 482 // Shared values for both the overridable and non-overridable versions. |
417 load_time_data.SetBoolean("ssl", true); | 483 load_time_data.SetBoolean("ssl", true); |
418 load_time_data.SetBoolean( | 484 load_time_data.SetBoolean( |
419 "overridable", overridable_ && !strict_enforcement_); | 485 "overridable", overridable_ && !strict_enforcement_); |
420 load_time_data.SetString( | 486 load_time_data.SetString( |
421 "tabTitle", l10n_util::GetStringUTF16(IDS_SSL_V2_TITLE)); | 487 "tabTitle", l10n_util::GetStringUTF16(IDS_SSL_V2_TITLE)); |
422 load_time_data.SetString( | 488 load_time_data.SetString( |
423 "heading", l10n_util::GetStringUTF16(IDS_SSL_V2_HEADING)); | 489 "heading", l10n_util::GetStringUTF16(IDS_SSL_V2_HEADING)); |
424 load_time_data.SetString( | 490 load_time_data.SetString( |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 // sure we don't clear the captive portal flag, since the interstitial was | 703 // sure we don't clear the captive portal flag, since the interstitial was |
638 // potentially caused by the captive portal. | 704 // potentially caused by the captive portal. |
639 captive_portal_detected_ = captive_portal_detected_ || | 705 captive_portal_detected_ = captive_portal_detected_ || |
640 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); | 706 (results->result == captive_portal::RESULT_BEHIND_CAPTIVE_PORTAL); |
641 // Also keep track of non-HTTP portals and error cases. | 707 // Also keep track of non-HTTP portals and error cases. |
642 captive_portal_no_response_ = captive_portal_no_response_ || | 708 captive_portal_no_response_ = captive_portal_no_response_ || |
643 (results->result == captive_portal::RESULT_NO_RESPONSE); | 709 (results->result == captive_portal::RESULT_NO_RESPONSE); |
644 } | 710 } |
645 #endif | 711 #endif |
646 } | 712 } |
OLD | NEW |