| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
| 10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
| 13 #include "chrome/browser/cert_store.h" | 13 #include "chrome/browser/cert_store.h" |
| 14 #include "chrome/browser/dom_operation_notification_details.h" | 14 #include "chrome/browser/dom_operation_notification_details.h" |
| 15 #include "chrome/browser/ssl/ssl_cert_error_handler.h" |
| 15 #include "chrome/browser/ssl/ssl_error_info.h" | 16 #include "chrome/browser/ssl/ssl_error_info.h" |
| 16 #include "chrome/browser/tab_contents/navigation_controller.h" | 17 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 17 #include "chrome/browser/tab_contents/navigation_entry.h" | 18 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 18 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
| 19 #include "chrome/common/jstemplate_builder.h" | 20 #include "chrome/common/jstemplate_builder.h" |
| 20 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/pref_service.h" | 23 #include "chrome/common/pref_service.h" |
| 23 #include "grit/browser_resources.h" | 24 #include "grit/browser_resources.h" |
| 24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 enum SSLBlockingPageEvent { | 29 enum SSLBlockingPageEvent { |
| 29 SHOW, | 30 SHOW, |
| 30 PROCEED, | 31 PROCEED, |
| 31 DONT_PROCEED, | 32 DONT_PROCEED, |
| 32 }; | 33 }; |
| 33 | 34 |
| 34 void RecordSSLBlockingPageStats(SSLBlockingPageEvent event) { | 35 void RecordSSLBlockingPageStats(SSLBlockingPageEvent event) { |
| 35 static LinearHistogram histogram("interstial.ssl", 0, 2, 3); | 36 static LinearHistogram histogram("interstial.ssl", 0, 2, 3); |
| 36 histogram.SetFlags(kUmaTargetedHistogramFlag); | 37 histogram.SetFlags(kUmaTargetedHistogramFlag); |
| 37 histogram.Add(event); | 38 histogram.Add(event); |
| 38 } | 39 } |
| 39 | 40 |
| 40 } // namespace | 41 } // namespace |
| 41 | 42 |
| 42 // Note that we always create a navigation entry with SSL errors. | 43 // Note that we always create a navigation entry with SSL errors. |
| 43 // No error happening loading a sub-resource triggers an interstitial so far. | 44 // No error happening loading a sub-resource triggers an interstitial so far. |
| 44 SSLBlockingPage::SSLBlockingPage(SSLManager::CertError* error, | 45 SSLBlockingPage::SSLBlockingPage(SSLCertErrorHandler* handler, |
| 45 Delegate* delegate) | 46 Delegate* delegate) |
| 46 : InterstitialPage(error->GetTabContents(), true, error->request_url()), | 47 : InterstitialPage(handler->GetTabContents(), true, handler->request_url()), |
| 47 error_(error), | 48 handler_(handler), |
| 48 delegate_(delegate), | 49 delegate_(delegate), |
| 49 delegate_has_been_notified_(false) { | 50 delegate_has_been_notified_(false) { |
| 50 RecordSSLBlockingPageStats(SHOW); | 51 RecordSSLBlockingPageStats(SHOW); |
| 51 } | 52 } |
| 52 | 53 |
| 53 SSLBlockingPage::~SSLBlockingPage() { | 54 SSLBlockingPage::~SSLBlockingPage() { |
| 54 if (!delegate_has_been_notified_) { | 55 if (!delegate_has_been_notified_) { |
| 55 // The page is closed without the user having chosen what to do, default to | 56 // The page is closed without the user having chosen what to do, default to |
| 56 // deny. | 57 // deny. |
| 57 NotifyDenyCertificate(); | 58 NotifyDenyCertificate(); |
| 58 } | 59 } |
| 59 } | 60 } |
| 60 | 61 |
| 61 std::string SSLBlockingPage::GetHTMLContents() { | 62 std::string SSLBlockingPage::GetHTMLContents() { |
| 62 // Let's build the html error page. | 63 // Let's build the html error page. |
| 63 DictionaryValue strings; | 64 DictionaryValue strings; |
| 64 SSLErrorInfo error_info = delegate_->GetSSLErrorInfo(error_); | 65 SSLErrorInfo error_info = delegate_->GetSSLErrorInfo(handler_); |
| 65 strings.SetString(L"title", | 66 strings.SetString(L"title", |
| 66 l10n_util::GetString(IDS_SSL_BLOCKING_PAGE_TITLE)); | 67 l10n_util::GetString(IDS_SSL_BLOCKING_PAGE_TITLE)); |
| 67 strings.SetString(L"headLine", error_info.title()); | 68 strings.SetString(L"headLine", error_info.title()); |
| 68 strings.SetString(L"description", error_info.details()); | 69 strings.SetString(L"description", error_info.details()); |
| 69 | 70 |
| 70 strings.SetString(L"moreInfoTitle", | 71 strings.SetString(L"moreInfoTitle", |
| 71 l10n_util::GetString(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); | 72 l10n_util::GetString(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); |
| 72 SetExtraInfo(&strings, error_info.extra_information()); | 73 SetExtraInfo(&strings, error_info.extra_information()); |
| 73 | 74 |
| 74 strings.SetString(L"proceed", | 75 strings.SetString(L"proceed", |
| 75 l10n_util::GetString(IDS_SSL_BLOCKING_PAGE_PROCEED)); | 76 l10n_util::GetString(IDS_SSL_BLOCKING_PAGE_PROCEED)); |
| 76 strings.SetString(L"exit", | 77 strings.SetString(L"exit", |
| 77 l10n_util::GetString(IDS_SSL_BLOCKING_PAGE_EXIT)); | 78 l10n_util::GetString(IDS_SSL_BLOCKING_PAGE_EXIT)); |
| 78 | 79 |
| 79 strings.SetString(L"textdirection", | 80 strings.SetString(L"textdirection", |
| 80 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? | 81 (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ? |
| 81 L"rtl" : L"ltr"); | 82 L"rtl" : L"ltr"); |
| 82 | 83 |
| 83 static const StringPiece html( | 84 static const StringPiece html( |
| 84 ResourceBundle::GetSharedInstance().GetRawDataResource( | 85 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 85 IDR_SSL_ROAD_BLOCK_HTML)); | 86 IDR_SSL_ROAD_BLOCK_HTML)); |
| 86 | 87 |
| 87 return jstemplate_builder::GetTemplateHtml(html, &strings, "template_root"); | 88 return jstemplate_builder::GetTemplateHtml(html, &strings, "template_root"); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void SSLBlockingPage::UpdateEntry(NavigationEntry* entry) { | 91 void SSLBlockingPage::UpdateEntry(NavigationEntry* entry) { |
| 91 const net::SSLInfo& ssl_info = error_->ssl_info(); | 92 const net::SSLInfo& ssl_info = handler_->ssl_info(); |
| 92 int cert_id = CertStore::GetSharedInstance()->StoreCert( | 93 int cert_id = CertStore::GetSharedInstance()->StoreCert( |
| 93 ssl_info.cert, tab()->render_view_host()->process()->pid()); | 94 ssl_info.cert, tab()->render_view_host()->process()->pid()); |
| 94 | 95 |
| 95 entry->ssl().set_security_style(SECURITY_STYLE_AUTHENTICATION_BROKEN); | 96 entry->ssl().set_security_style(SECURITY_STYLE_AUTHENTICATION_BROKEN); |
| 96 entry->ssl().set_cert_id(cert_id); | 97 entry->ssl().set_cert_id(cert_id); |
| 97 entry->ssl().set_cert_status(ssl_info.cert_status); | 98 entry->ssl().set_cert_status(ssl_info.cert_status); |
| 98 entry->ssl().set_security_bits(ssl_info.security_bits); | 99 entry->ssl().set_security_bits(ssl_info.security_bits); |
| 99 NotificationService::current()->Notify( | 100 NotificationService::current()->Notify( |
| 100 NotificationType::SSL_VISIBLE_STATE_CHANGED, | 101 NotificationType::SSL_VISIBLE_STATE_CHANGED, |
| 101 Source<NavigationController>(&tab()->controller()), | 102 Source<NavigationController>(&tab()->controller()), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 123 void SSLBlockingPage::DontProceed() { | 124 void SSLBlockingPage::DontProceed() { |
| 124 RecordSSLBlockingPageStats(DONT_PROCEED); | 125 RecordSSLBlockingPageStats(DONT_PROCEED); |
| 125 | 126 |
| 126 NotifyDenyCertificate(); | 127 NotifyDenyCertificate(); |
| 127 InterstitialPage::DontProceed(); | 128 InterstitialPage::DontProceed(); |
| 128 } | 129 } |
| 129 | 130 |
| 130 void SSLBlockingPage::NotifyDenyCertificate() { | 131 void SSLBlockingPage::NotifyDenyCertificate() { |
| 131 DCHECK(!delegate_has_been_notified_); | 132 DCHECK(!delegate_has_been_notified_); |
| 132 | 133 |
| 133 delegate_->OnDenyCertificate(error_); | 134 delegate_->OnDenyCertificate(handler_); |
| 134 delegate_has_been_notified_ = true; | 135 delegate_has_been_notified_ = true; |
| 135 } | 136 } |
| 136 | 137 |
| 137 void SSLBlockingPage::NotifyAllowCertificate() { | 138 void SSLBlockingPage::NotifyAllowCertificate() { |
| 138 DCHECK(!delegate_has_been_notified_); | 139 DCHECK(!delegate_has_been_notified_); |
| 139 | 140 |
| 140 delegate_->OnAllowCertificate(error_); | 141 delegate_->OnAllowCertificate(handler_); |
| 141 delegate_has_been_notified_ = true; | 142 delegate_has_been_notified_ = true; |
| 142 } | 143 } |
| 143 | 144 |
| 144 // static | 145 // static |
| 145 void SSLBlockingPage::SetExtraInfo( | 146 void SSLBlockingPage::SetExtraInfo( |
| 146 DictionaryValue* strings, | 147 DictionaryValue* strings, |
| 147 const std::vector<std::wstring>& extra_info) { | 148 const std::vector<std::wstring>& extra_info) { |
| 148 DCHECK(extra_info.size() < 5); // We allow 5 paragraphs max. | 149 DCHECK(extra_info.size() < 5); // We allow 5 paragraphs max. |
| 149 const std::wstring keys[5] = { | 150 const std::wstring keys[5] = { |
| 150 L"moreInfo1", L"moreInfo2", L"moreInfo3", L"moreInfo4", L"moreInfo5" | 151 L"moreInfo1", L"moreInfo2", L"moreInfo3", L"moreInfo4", L"moreInfo5" |
| 151 }; | 152 }; |
| 152 int i; | 153 int i; |
| 153 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { | 154 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { |
| 154 strings->SetString(keys[i], extra_info[i]); | 155 strings->SetString(keys[i], extra_info[i]); |
| 155 } | 156 } |
| 156 for (;i < 5; i++) { | 157 for (;i < 5; i++) { |
| 157 strings->SetString(keys[i], L""); | 158 strings->SetString(keys[i], L""); |
| 158 } | 159 } |
| 159 } | 160 } |
| OLD | NEW |