| 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_error_info.h" | 5 #include "chrome/browser/ssl/ssl_error_info.h" |
| 6 | 6 |
| 7 #include "base/i18n/time_formatting.h" | 7 #include "base/i18n/message_formatter.h" |
| 8 #include "base/strings/string_number_conversions.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/grit/chromium_strings.h" | 9 #include "chrome/grit/chromium_strings.h" |
| 11 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| 12 #include "content/public/browser/cert_store.h" | 11 #include "content/public/browser/cert_store.h" |
| 13 #include "net/base/escape.h" | 12 #include "net/base/escape.h" |
| 14 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 15 #include "net/cert/cert_status_flags.h" | 14 #include "net/cert/cert_status_flags.h" |
| 16 #include "net/ssl/ssl_info.h" | 15 #include "net/ssl/ssl_info.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 short_description = l10n_util::GetStringUTF16( | 55 short_description = l10n_util::GetStringUTF16( |
| 57 IDS_CERT_ERROR_COMMON_NAME_INVALID_DESCRIPTION); | 56 IDS_CERT_ERROR_COMMON_NAME_INVALID_DESCRIPTION); |
| 58 break; | 57 break; |
| 59 } | 58 } |
| 60 case CERT_DATE_INVALID: | 59 case CERT_DATE_INVALID: |
| 61 if (cert->HasExpired()) { | 60 if (cert->HasExpired()) { |
| 62 // Make sure to round up to the smallest integer value not less than | 61 // Make sure to round up to the smallest integer value not less than |
| 63 // the expiration value (https://crbug.com/476758). | 62 // the expiration value (https://crbug.com/476758). |
| 64 int expiration_value = | 63 int expiration_value = |
| 65 (base::Time::Now() - cert->valid_expiry()).InDays() + 1; | 64 (base::Time::Now() - cert->valid_expiry()).InDays() + 1; |
| 66 details = l10n_util::GetStringFUTF16( | 65 details = base::i18n::MessageFormatter::FormatWithNumberedArgs( |
| 67 IDS_CERT_ERROR_EXPIRED_DETAILS, UTF8ToUTF16(request_url.host()), | 66 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXPIRED_DETAILS), |
| 68 base::IntToString16(expiration_value), | 67 request_url.host(), expiration_value, base::Time::Now()); |
| 69 base::TimeFormatFriendlyDate(base::Time::Now())); | |
| 70 short_description = | 68 short_description = |
| 71 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXPIRED_DESCRIPTION); | 69 l10n_util::GetStringUTF16(IDS_CERT_ERROR_EXPIRED_DESCRIPTION); |
| 72 } else if (base::Time::Now() < cert->valid_start()) { | 70 } else if (base::Time::Now() < cert->valid_start()) { |
| 73 details = l10n_util::GetStringFUTF16( | 71 details = base::i18n::MessageFormatter::FormatWithNumberedArgs( |
| 74 IDS_CERT_ERROR_NOT_YET_VALID_DETAILS, | 72 l10n_util::GetStringUTF16(IDS_CERT_ERROR_NOT_YET_VALID_DETAILS), |
| 75 UTF8ToUTF16(request_url.host()), | 73 request_url.host(), |
| 76 base::IntToString16( | 74 (cert->valid_start() - base::Time::Now()).InDays()); |
| 77 (cert->valid_start() - base::Time::Now()).InDays())); | |
| 78 short_description = | 75 short_description = |
| 79 l10n_util::GetStringUTF16(IDS_CERT_ERROR_NOT_YET_VALID_DESCRIPTION); | 76 l10n_util::GetStringUTF16(IDS_CERT_ERROR_NOT_YET_VALID_DESCRIPTION); |
| 80 } else { | 77 } else { |
| 81 // Two possibilities: (1) an intermediate or root certificate has | 78 // Two possibilities: (1) an intermediate or root certificate has |
| 82 // expired, or (2) the certificate has become valid since the error | 79 // expired, or (2) the certificate has become valid since the error |
| 83 // occurred. Both are probably rare cases. To avoid giving the wrong | 80 // occurred. Both are probably rare cases. To avoid giving the wrong |
| 84 // date, remove the information. | 81 // date, remove the information. |
| 85 details = l10n_util::GetStringFUTF16( | 82 details = l10n_util::GetStringFUTF16( |
| 86 IDS_CERT_ERROR_NOT_VALID_AT_THIS_TIME_DETAILS, | 83 IDS_CERT_ERROR_NOT_VALID_AT_THIS_TIME_DETAILS, |
| 87 UTF8ToUTF16(request_url.host())); | 84 UTF8ToUTF16(request_url.host())); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 cert_id, &cert); | 251 cert_id, &cert); |
| 255 DCHECK(r); | 252 DCHECK(r); |
| 256 } | 253 } |
| 257 if (errors) { | 254 if (errors) { |
| 258 errors->push_back( | 255 errors->push_back( |
| 259 SSLErrorInfo::CreateError(kErrorTypes[i], cert.get(), url)); | 256 SSLErrorInfo::CreateError(kErrorTypes[i], cert.get(), url)); |
| 260 } | 257 } |
| 261 } | 258 } |
| 262 } | 259 } |
| 263 } | 260 } |
| OLD | NEW |