| 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/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/history/history_service_factory.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/renderer_preferences_util.h" | 15 #include "chrome/browser/renderer_preferences_util.h" |
| 15 #include "chrome/browser/ssl/ssl_error_info.h" | 16 #include "chrome/browser/ssl/ssl_error_info.h" |
| 16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
| 18 #include "content/public/browser/cert_store.h" | 19 #include "content/public/browser/cert_store.h" |
| 19 #include "content/public/browser/interstitial_page.h" | 20 #include "content/public/browser/interstitial_page.h" |
| 20 #include "content/public/browser/navigation_controller.h" | 21 #include "content/public/browser/navigation_controller.h" |
| 21 #include "content/public/browser/navigation_entry.h" | 22 #include "content/public/browser/navigation_entry.h" |
| 22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 PROCEED_DATE, | 64 PROCEED_DATE, |
| 64 PROCEED_AUTHORITY, | 65 PROCEED_AUTHORITY, |
| 65 DONT_PROCEED_OVERRIDABLE, | 66 DONT_PROCEED_OVERRIDABLE, |
| 66 DONT_PROCEED_NAME, | 67 DONT_PROCEED_NAME, |
| 67 DONT_PROCEED_DATE, | 68 DONT_PROCEED_DATE, |
| 68 DONT_PROCEED_AUTHORITY, | 69 DONT_PROCEED_AUTHORITY, |
| 69 MORE, | 70 MORE, |
| 70 SHOW_UNDERSTAND, | 71 SHOW_UNDERSTAND, |
| 71 SHOW_INTERNAL_HOSTNAME, | 72 SHOW_INTERNAL_HOSTNAME, |
| 72 PROCEED_INTERNAL_HOSTNAME, | 73 PROCEED_INTERNAL_HOSTNAME, |
| 74 SHOW_NEW_SITE, |
| 75 PROCEED_NEW_SITE, |
| 73 UNUSED_BLOCKING_PAGE_EVENT, | 76 UNUSED_BLOCKING_PAGE_EVENT, |
| 74 }; | 77 }; |
| 75 | 78 |
| 76 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) { | 79 void RecordSSLBlockingPageEventStats(SSLBlockingPageEvent event) { |
| 77 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl", | 80 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl", |
| 78 event, | 81 event, |
| 79 UNUSED_BLOCKING_PAGE_EVENT); | 82 UNUSED_BLOCKING_PAGE_EVENT); |
| 80 } | 83 } |
| 81 | 84 |
| 82 void RecordSSLBlockingPageDetailedStats( | 85 void RecordSSLBlockingPageDetailedStats( |
| 83 bool proceed, | 86 bool proceed, |
| 84 int cert_error, | 87 int cert_error, |
| 85 bool overridable, | 88 bool overridable, |
| 86 bool internal, | 89 bool internal, |
| 87 const base::TimeTicks& start_time) { | 90 const base::TimeTicks& start_time, |
| 91 int num_visits) { |
| 88 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", | 92 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl_error_type", |
| 89 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM); | 93 SSLErrorInfo::NetErrorToErrorType(cert_error), SSLErrorInfo::END_OF_ENUM); |
| 90 if (start_time.is_null() || !overridable) { | 94 if (start_time.is_null() || !overridable) { |
| 91 // A null start time will occur if the page never came into focus. | 95 // A null start time will occur if the page never came into focus. |
| 92 // Overridable is false if the user didn't have any option except to turn | 96 // Overridable is false if the user didn't have any option except to turn |
| 93 // back. In either case, we don't want to record some of our metrics. | 97 // back. In either case, we don't want to record some of our metrics. |
| 94 return; | 98 return; |
| 95 } | 99 } |
| 100 if (num_visits == 0) |
| 101 RecordSSLBlockingPageEventStats(SHOW_NEW_SITE); |
| 96 if (proceed) { | 102 if (proceed) { |
| 97 RecordSSLBlockingPageEventStats(PROCEED_OVERRIDABLE); | 103 RecordSSLBlockingPageEventStats(PROCEED_OVERRIDABLE); |
| 98 if (internal) | 104 if (internal) |
| 99 RecordSSLBlockingPageEventStats(PROCEED_INTERNAL_HOSTNAME); | 105 RecordSSLBlockingPageEventStats(PROCEED_INTERNAL_HOSTNAME); |
| 106 if (num_visits == 0) |
| 107 RecordSSLBlockingPageEventStats(PROCEED_NEW_SITE); |
| 100 } else if (!proceed) { | 108 } else if (!proceed) { |
| 101 RecordSSLBlockingPageEventStats(DONT_PROCEED_OVERRIDABLE); | 109 RecordSSLBlockingPageEventStats(DONT_PROCEED_OVERRIDABLE); |
| 102 } | 110 } |
| 103 SSLErrorInfo::ErrorType type = SSLErrorInfo::NetErrorToErrorType(cert_error); | 111 SSLErrorInfo::ErrorType type = SSLErrorInfo::NetErrorToErrorType(cert_error); |
| 104 switch (type) { | 112 switch (type) { |
| 105 case SSLErrorInfo::CERT_COMMON_NAME_INVALID: { | 113 case SSLErrorInfo::CERT_COMMON_NAME_INVALID: { |
| 106 if (proceed) | 114 if (proceed) |
| 107 RecordSSLBlockingPageEventStats(PROCEED_NAME); | 115 RecordSSLBlockingPageEventStats(PROCEED_NAME); |
| 108 else | 116 else |
| 109 RecordSSLBlockingPageEventStats(DONT_PROCEED_NAME); | 117 RecordSSLBlockingPageEventStats(DONT_PROCEED_NAME); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 bool overridable, | 159 bool overridable, |
| 152 bool strict_enforcement, | 160 bool strict_enforcement, |
| 153 const base::Callback<void(bool)>& callback) | 161 const base::Callback<void(bool)>& callback) |
| 154 : callback_(callback), | 162 : callback_(callback), |
| 155 web_contents_(web_contents), | 163 web_contents_(web_contents), |
| 156 cert_error_(cert_error), | 164 cert_error_(cert_error), |
| 157 ssl_info_(ssl_info), | 165 ssl_info_(ssl_info), |
| 158 request_url_(request_url), | 166 request_url_(request_url), |
| 159 overridable_(overridable), | 167 overridable_(overridable), |
| 160 strict_enforcement_(strict_enforcement), | 168 strict_enforcement_(strict_enforcement), |
| 161 internal_(false) { | 169 internal_(false), |
| 170 num_visits_(-1) { |
| 162 trialCondition_ = base::FieldTrialList::FindFullName(kStudyName); | 171 trialCondition_ = base::FieldTrialList::FindFullName(kStudyName); |
| 163 | 172 |
| 173 // For UMA stats. |
| 164 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) | 174 if (net::IsHostnameNonUnique(request_url_.HostNoBrackets())) |
| 165 internal_ = true; | 175 internal_ = true; |
| 166 | |
| 167 RecordSSLBlockingPageEventStats(SHOW_ALL); | 176 RecordSSLBlockingPageEventStats(SHOW_ALL); |
| 168 if (overridable_ && !strict_enforcement_) { | 177 if (overridable_ && !strict_enforcement_) { |
| 169 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); | 178 RecordSSLBlockingPageEventStats(SHOW_OVERRIDABLE); |
| 170 if (internal_) | 179 if (internal_) |
| 171 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); | 180 RecordSSLBlockingPageEventStats(SHOW_INTERNAL_HOSTNAME); |
| 181 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
| 182 Profile::FromBrowserContext(web_contents->GetBrowserContext()), |
| 183 Profile::EXPLICIT_ACCESS); |
| 184 if (history_service) { |
| 185 history_service->GetVisibleVisitCountToHost( |
| 186 request_url_, |
| 187 &request_consumer_, |
| 188 base::Bind(&SSLBlockingPage::OnGotHistoryCount, |
| 189 base::Unretained(this))); |
| 190 } |
| 172 } | 191 } |
| 173 | 192 |
| 174 interstitial_page_ = InterstitialPage::Create( | 193 interstitial_page_ = InterstitialPage::Create( |
| 175 web_contents_, true, request_url, this); | 194 web_contents_, true, request_url, this); |
| 176 display_start_time_ = TimeTicks(); | 195 display_start_time_ = TimeTicks(); |
| 177 interstitial_page_->Show(); | 196 interstitial_page_->Show(); |
| 178 } | 197 } |
| 179 | 198 |
| 180 SSLBlockingPage::~SSLBlockingPage() { | 199 SSLBlockingPage::~SSLBlockingPage() { |
| 181 if (!callback_.is_null()) { | 200 if (!callback_.is_null()) { |
| 182 RecordSSLBlockingPageDetailedStats(false, | 201 RecordSSLBlockingPageDetailedStats(false, |
| 183 cert_error_, | 202 cert_error_, |
| 184 overridable_ && !strict_enforcement_, | 203 overridable_ && !strict_enforcement_, |
| 185 internal_, | 204 internal_, |
| 186 display_start_time_); | 205 display_start_time_, |
| 206 num_visits_); |
| 187 // The page is closed without the user having chosen what to do, default to | 207 // The page is closed without the user having chosen what to do, default to |
| 188 // deny. | 208 // deny. |
| 189 NotifyDenyCertificate(); | 209 NotifyDenyCertificate(); |
| 190 } | 210 } |
| 191 } | 211 } |
| 192 | 212 |
| 193 std::string SSLBlockingPage::GetHTMLContents() { | 213 std::string SSLBlockingPage::GetHTMLContents() { |
| 194 // Let's build the html error page. | 214 // Let's build the html error page. |
| 195 DictionaryValue strings; | 215 DictionaryValue strings; |
| 196 SSLErrorInfo error_info = | 216 SSLErrorInfo error_info = |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 Profile* profile = Profile::FromBrowserContext( | 323 Profile* profile = Profile::FromBrowserContext( |
| 304 web_contents_->GetBrowserContext()); | 324 web_contents_->GetBrowserContext()); |
| 305 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); | 325 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); |
| 306 } | 326 } |
| 307 | 327 |
| 308 void SSLBlockingPage::OnProceed() { | 328 void SSLBlockingPage::OnProceed() { |
| 309 RecordSSLBlockingPageDetailedStats(true, | 329 RecordSSLBlockingPageDetailedStats(true, |
| 310 cert_error_, | 330 cert_error_, |
| 311 overridable_ && !strict_enforcement_, | 331 overridable_ && !strict_enforcement_, |
| 312 internal_, | 332 internal_, |
| 313 display_start_time_); | 333 display_start_time_, |
| 334 num_visits_); |
| 314 // Accepting the certificate resumes the loading of the page. | 335 // Accepting the certificate resumes the loading of the page. |
| 315 NotifyAllowCertificate(); | 336 NotifyAllowCertificate(); |
| 316 } | 337 } |
| 317 | 338 |
| 318 void SSLBlockingPage::OnDontProceed() { | 339 void SSLBlockingPage::OnDontProceed() { |
| 319 RecordSSLBlockingPageDetailedStats(false, | 340 RecordSSLBlockingPageDetailedStats(false, |
| 320 cert_error_, | 341 cert_error_, |
| 321 overridable_ && !strict_enforcement_, | 342 overridable_ && !strict_enforcement_, |
| 322 internal_, | 343 internal_, |
| 323 display_start_time_); | 344 display_start_time_, |
| 345 num_visits_); |
| 324 NotifyDenyCertificate(); | 346 NotifyDenyCertificate(); |
| 325 } | 347 } |
| 326 | 348 |
| 327 void SSLBlockingPage::NotifyDenyCertificate() { | 349 void SSLBlockingPage::NotifyDenyCertificate() { |
| 328 // It's possible that callback_ may not exist if the user clicks "Proceed" | 350 // It's possible that callback_ may not exist if the user clicks "Proceed" |
| 329 // followed by pressing the back button before the interstitial is hidden. | 351 // followed by pressing the back button before the interstitial is hidden. |
| 330 // In that case the certificate will still be treated as allowed. | 352 // In that case the certificate will still be treated as allowed. |
| 331 if (callback_.is_null()) | 353 if (callback_.is_null()) |
| 332 return; | 354 return; |
| 333 | 355 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 351 "moreInfo1", "moreInfo2", "moreInfo3", "moreInfo4", "moreInfo5" | 373 "moreInfo1", "moreInfo2", "moreInfo3", "moreInfo4", "moreInfo5" |
| 352 }; | 374 }; |
| 353 int i; | 375 int i; |
| 354 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { | 376 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { |
| 355 strings->SetString(keys[i], extra_info[i]); | 377 strings->SetString(keys[i], extra_info[i]); |
| 356 } | 378 } |
| 357 for (; i < 5; i++) { | 379 for (; i < 5; i++) { |
| 358 strings->SetString(keys[i], std::string()); | 380 strings->SetString(keys[i], std::string()); |
| 359 } | 381 } |
| 360 } | 382 } |
| 383 |
| 384 void SSLBlockingPage::OnGotHistoryCount(HistoryService::Handle handle, |
| 385 bool success, |
| 386 int num_visits, |
| 387 base::Time first_visit) { |
| 388 num_visits_ = num_visits; |
| 389 } |
| OLD | NEW |