| 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/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/string_piece.h" | 9 #include "base/string_piece.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 // Note that we always create a navigation entry with SSL errors. | 50 // Note that we always create a navigation entry with SSL errors. |
| 51 // No error happening loading a sub-resource triggers an interstitial so far. | 51 // No error happening loading a sub-resource triggers an interstitial so far. |
| 52 SSLBlockingPage::SSLBlockingPage( | 52 SSLBlockingPage::SSLBlockingPage( |
| 53 content::WebContents* web_contents, | 53 content::WebContents* web_contents, |
| 54 int cert_error, | 54 int cert_error, |
| 55 const net::SSLInfo& ssl_info, | 55 const net::SSLInfo& ssl_info, |
| 56 const GURL& request_url, | 56 const GURL& request_url, |
| 57 bool overridable, | 57 bool overridable, |
| 58 bool strict_enforcement, |
| 58 const base::Callback<void(bool)>& callback) | 59 const base::Callback<void(bool)>& callback) |
| 59 : callback_(callback), | 60 : callback_(callback), |
| 60 web_contents_(web_contents), | 61 web_contents_(web_contents), |
| 61 cert_error_(cert_error), | 62 cert_error_(cert_error), |
| 62 ssl_info_(ssl_info), | 63 ssl_info_(ssl_info), |
| 63 request_url_(request_url), | 64 request_url_(request_url), |
| 64 overridable_(overridable) { | 65 overridable_(overridable), |
| 66 strict_enforcement_(strict_enforcement) { |
| 65 RecordSSLBlockingPageStats(SHOW); | 67 RecordSSLBlockingPageStats(SHOW); |
| 66 interstitial_page_ = InterstitialPage::Create( | 68 interstitial_page_ = InterstitialPage::Create( |
| 67 web_contents_, true, request_url, this); | 69 web_contents_, true, request_url, this); |
| 68 interstitial_page_->Show(); | 70 interstitial_page_->Show(); |
| 69 } | 71 } |
| 70 | 72 |
| 71 SSLBlockingPage::~SSLBlockingPage() { | 73 SSLBlockingPage::~SSLBlockingPage() { |
| 72 if (!callback_.is_null()) { | 74 if (!callback_.is_null()) { |
| 73 // The page is closed without the user having chosen what to do, default to | 75 // The page is closed without the user having chosen what to do, default to |
| 74 // deny. | 76 // deny. |
| 75 NotifyDenyCertificate(); | 77 NotifyDenyCertificate(); |
| 76 } | 78 } |
| 77 } | 79 } |
| 78 | 80 |
| 79 std::string SSLBlockingPage::GetHTMLContents() { | 81 std::string SSLBlockingPage::GetHTMLContents() { |
| 80 // Let's build the html error page. | 82 // Let's build the html error page. |
| 81 DictionaryValue strings; | 83 DictionaryValue strings; |
| 82 SSLErrorInfo error_info = SSLErrorInfo::CreateError( | 84 SSLErrorInfo error_info = SSLErrorInfo::CreateError( |
| 83 SSLErrorInfo::NetErrorToErrorType(cert_error_), ssl_info_.cert, | 85 SSLErrorInfo::NetErrorToErrorType(cert_error_), ssl_info_.cert, |
| 84 request_url_); | 86 request_url_); |
| 85 | 87 |
| 86 strings.SetString("headLine", error_info.title()); | 88 strings.SetString("headLine", error_info.title()); |
| 87 strings.SetString("description", error_info.details()); | 89 strings.SetString("description", error_info.details()); |
| 88 | 90 |
| 89 strings.SetString("moreInfoTitle", | 91 strings.SetString("moreInfoTitle", |
| 90 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); | 92 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXTRA_INFO_TITLE)); |
| 91 SetExtraInfo(&strings, error_info.extra_information()); | 93 SetExtraInfo(&strings, error_info.extra_information()); |
| 92 | 94 |
| 93 int resource_id; | 95 int resource_id; |
| 94 if (overridable_) { | 96 if (overridable_ && !strict_enforcement_) { |
| 95 resource_id = IDR_SSL_ROAD_BLOCK_HTML; | 97 resource_id = IDR_SSL_ROAD_BLOCK_HTML; |
| 96 strings.SetString("title", | 98 strings.SetString("title", |
| 97 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); | 99 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_TITLE)); |
| 98 strings.SetString("proceed", | 100 strings.SetString("proceed", |
| 99 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_PROCEED)); | 101 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_PROCEED)); |
| 100 strings.SetString("exit", | 102 strings.SetString("exit", |
| 101 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_EXIT)); | 103 l10n_util::GetStringUTF16(IDS_SSL_BLOCKING_PAGE_EXIT)); |
| 102 strings.SetString("shouldNotProceed", | 104 strings.SetString("shouldNotProceed", |
| 103 l10n_util::GetStringUTF16( | 105 l10n_util::GetStringUTF16( |
| 104 IDS_SSL_BLOCKING_PAGE_SHOULD_NOT_PROCEED)); | 106 IDS_SSL_BLOCKING_PAGE_SHOULD_NOT_PROCEED)); |
| 105 } else { | 107 } else { |
| 106 resource_id = IDR_SSL_ERROR_HTML; | 108 resource_id = IDR_SSL_ERROR_HTML; |
| 107 strings.SetString("title", | 109 strings.SetString("title", |
| 108 l10n_util::GetStringUTF16(IDS_SSL_ERROR_PAGE_TITLE)); | 110 l10n_util::GetStringUTF16(IDS_SSL_ERROR_PAGE_TITLE)); |
| 109 strings.SetString("back", | 111 strings.SetString("back", |
| 110 l10n_util::GetStringUTF16(IDS_SSL_ERROR_PAGE_BACK)); | 112 l10n_util::GetStringUTF16(IDS_SSL_ERROR_PAGE_BACK)); |
| 111 strings.SetString("cannotProceed", | 113 if (strict_enforcement_) { |
| 112 l10n_util::GetStringUTF16( | 114 strings.SetString("cannotProceed", |
| 113 IDS_SSL_ERROR_PAGE_CANNOT_PROCEED)); | 115 l10n_util::GetStringUTF16( |
| 116 IDS_SSL_ERROR_PAGE_CANNOT_PROCEED)); |
| 117 } |
| 114 } | 118 } |
| 115 | 119 |
| 116 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); | 120 strings.SetString("textdirection", base::i18n::IsRTL() ? "rtl" : "ltr"); |
| 117 | 121 |
| 118 base::StringPiece html( | 122 base::StringPiece html( |
| 119 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); | 123 ResourceBundle::GetSharedInstance().GetRawDataResource(resource_id)); |
| 120 | 124 |
| 121 return jstemplate_builder::GetI18nTemplateHtml(html, &strings); | 125 return jstemplate_builder::GetI18nTemplateHtml(html, &strings); |
| 122 } | 126 } |
| 123 | 127 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 142 } else { | 146 } else { |
| 143 interstitial_page_->DontProceed(); | 147 interstitial_page_->DontProceed(); |
| 144 } | 148 } |
| 145 } | 149 } |
| 146 | 150 |
| 147 void SSLBlockingPage::OverrideRendererPrefs( | 151 void SSLBlockingPage::OverrideRendererPrefs( |
| 148 content::RendererPreferences* prefs) { | 152 content::RendererPreferences* prefs) { |
| 149 Profile* profile = Profile::FromBrowserContext( | 153 Profile* profile = Profile::FromBrowserContext( |
| 150 web_contents_->GetBrowserContext()); | 154 web_contents_->GetBrowserContext()); |
| 151 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); | 155 renderer_preferences_util::UpdateFromSystemSettings(prefs, profile); |
| 152 } | 156 } |
| 153 | 157 |
| 154 void SSLBlockingPage::OnProceed() { | 158 void SSLBlockingPage::OnProceed() { |
| 155 RecordSSLBlockingPageStats(PROCEED); | 159 RecordSSLBlockingPageStats(PROCEED); |
| 156 | 160 |
| 157 // Accepting the certificate resumes the loading of the page. | 161 // Accepting the certificate resumes the loading of the page. |
| 158 NotifyAllowCertificate(); | 162 NotifyAllowCertificate(); |
| 159 } | 163 } |
| 160 | 164 |
| 161 void SSLBlockingPage::OnDontProceed() { | 165 void SSLBlockingPage::OnDontProceed() { |
| 162 RecordSSLBlockingPageStats(DONT_PROCEED); | 166 RecordSSLBlockingPageStats(DONT_PROCEED); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 191 "moreInfo1", "moreInfo2", "moreInfo3", "moreInfo4", "moreInfo5" | 195 "moreInfo1", "moreInfo2", "moreInfo3", "moreInfo4", "moreInfo5" |
| 192 }; | 196 }; |
| 193 int i; | 197 int i; |
| 194 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { | 198 for (i = 0; i < static_cast<int>(extra_info.size()); i++) { |
| 195 strings->SetString(keys[i], extra_info[i]); | 199 strings->SetString(keys[i], extra_info[i]); |
| 196 } | 200 } |
| 197 for (; i < 5; i++) { | 201 for (; i < 5; i++) { |
| 198 strings->SetString(keys[i], ""); | 202 strings->SetString(keys[i], ""); |
| 199 } | 203 } |
| 200 } | 204 } |
| OLD | NEW |