OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/page_info_model.h" | 5 #include "chrome/browser/page_info_model.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 24 matching lines...) Expand all Loading... | |
35 scoped_refptr<net::X509Certificate> cert; | 35 scoped_refptr<net::X509Certificate> cert; |
36 | 36 |
37 // Identity section. | 37 // Identity section. |
38 string16 subject_name(UTF8ToUTF16(url.host())); | 38 string16 subject_name(UTF8ToUTF16(url.host())); |
39 bool empty_subject_name = false; | 39 bool empty_subject_name = false; |
40 if (subject_name.empty()) { | 40 if (subject_name.empty()) { |
41 subject_name.assign( | 41 subject_name.assign( |
42 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); | 42 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); |
43 empty_subject_name = true; | 43 empty_subject_name = true; |
44 } | 44 } |
45 | |
46 // Some of what IsCertStatusError classifies as errors we want to show as | |
47 // warnings instead. | |
48 static const int cert_warnings = | |
49 net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION | | |
50 net::CERT_STATUS_NO_REVOCATION_MECHANISM; | |
51 int status_with_warnings_removed = ssl.cert_status() & ~cert_warnings; | |
52 | |
45 if (ssl.cert_id() && | 53 if (ssl.cert_id() && |
46 CertStore::GetSharedInstance()->RetrieveCert(ssl.cert_id(), &cert) && | 54 CertStore::GetSharedInstance()->RetrieveCert(ssl.cert_id(), &cert) && |
47 !net::IsCertStatusError(ssl.cert_status())) { | 55 !net::IsCertStatusError(status_with_warnings_removed)) { |
48 // OK HTTPS page. | 56 // No error found so far, check cert_status warnings. |
49 if ((ssl.cert_status() & net::CERT_STATUS_IS_EV) != 0) { | 57 int cert_status = ssl.cert_status(); |
58 if (cert_status & cert_warnings) { | |
59 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName())); | |
60 if (issuer_name.empty()) { | |
61 issuer_name.assign(l10n_util::GetStringUTF16( | |
62 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); | |
63 } | |
64 description.assign(l10n_util::GetStringFUTF16( | |
65 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name)); | |
66 | |
67 description += ASCIIToUTF16("\n\n"); | |
68 if (cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) { | |
69 description += l10n_util::GetStringUTF16( | |
70 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION); | |
71 } else if (cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) { | |
wtc
2010/09/14 22:31:56
Strictly speaking, we should not use "else if" her
| |
72 description += l10n_util::GetStringUTF16( | |
73 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM); | |
74 } else { | |
75 NOTREACHED() << "Need to specify string for this warning"; | |
76 } | |
77 state = SECTION_STATE_WARNING_MINOR; | |
78 } else if ((ssl.cert_status() & net::CERT_STATUS_IS_EV) != 0) { | |
79 // EV HTTPS page. | |
50 DCHECK(!cert->subject().organization_names.empty()); | 80 DCHECK(!cert->subject().organization_names.empty()); |
51 headline = | 81 headline = |
52 l10n_util::GetStringFUTF16(IDS_PAGE_INFO_EV_IDENTITY_TITLE, | 82 l10n_util::GetStringFUTF16(IDS_PAGE_INFO_EV_IDENTITY_TITLE, |
53 UTF8ToUTF16(cert->subject().organization_names[0]), | 83 UTF8ToUTF16(cert->subject().organization_names[0]), |
54 UTF8ToUTF16(url.host())); | 84 UTF8ToUTF16(url.host())); |
55 // An EV Cert is required to have a city (localityName) and country but | 85 // An EV Cert is required to have a city (localityName) and country but |
56 // state is "if any". | 86 // state is "if any". |
57 DCHECK(!cert->subject().locality_name.empty()); | 87 DCHECK(!cert->subject().locality_name.empty()); |
58 DCHECK(!cert->subject().country_name.empty()); | 88 DCHECK(!cert->subject().country_name.empty()); |
59 string16 locality; | 89 string16 locality; |
60 if (!cert->subject().state_or_province_name.empty()) { | 90 if (!cert->subject().state_or_province_name.empty()) { |
61 locality = l10n_util::GetStringFUTF16( | 91 locality = l10n_util::GetStringFUTF16( |
62 IDS_PAGEINFO_ADDRESS, | 92 IDS_PAGEINFO_ADDRESS, |
63 UTF8ToUTF16(cert->subject().locality_name), | 93 UTF8ToUTF16(cert->subject().locality_name), |
64 UTF8ToUTF16(cert->subject().state_or_province_name), | 94 UTF8ToUTF16(cert->subject().state_or_province_name), |
65 UTF8ToUTF16(cert->subject().country_name)); | 95 UTF8ToUTF16(cert->subject().country_name)); |
66 } else { | 96 } else { |
67 locality = l10n_util::GetStringFUTF16( | 97 locality = l10n_util::GetStringFUTF16( |
68 IDS_PAGEINFO_PARTIAL_ADDRESS, | 98 IDS_PAGEINFO_PARTIAL_ADDRESS, |
69 UTF8ToUTF16(cert->subject().locality_name), | 99 UTF8ToUTF16(cert->subject().locality_name), |
70 UTF8ToUTF16(cert->subject().country_name)); | 100 UTF8ToUTF16(cert->subject().country_name)); |
71 } | 101 } |
72 DCHECK(!cert->subject().organization_names.empty()); | 102 DCHECK(!cert->subject().organization_names.empty()); |
73 description.assign(l10n_util::GetStringFUTF16( | 103 description.assign(l10n_util::GetStringFUTF16( |
74 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV, | 104 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV, |
75 UTF8ToUTF16(cert->subject().organization_names[0]), | 105 UTF8ToUTF16(cert->subject().organization_names[0]), |
76 locality, | 106 locality, |
77 UTF8ToUTF16(cert->issuer().GetDisplayName()))); | 107 UTF8ToUTF16(cert->issuer().GetDisplayName()))); |
78 } else { | 108 } else { |
79 // Non EV OK HTTPS. | 109 // Non-EV OK HTTPS page. |
80 if (empty_subject_name) | 110 if (empty_subject_name) |
81 headline.clear(); // Don't display any title. | 111 headline.clear(); // Don't display any title. |
82 else | 112 else |
83 headline.assign(subject_name); | 113 headline.assign(subject_name); |
84 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName())); | 114 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName())); |
85 if (issuer_name.empty()) { | 115 if (issuer_name.empty()) { |
86 issuer_name.assign(l10n_util::GetStringUTF16( | 116 issuer_name.assign(l10n_util::GetStringUTF16( |
87 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); | 117 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); |
88 } else { | |
89 description.assign(l10n_util::GetStringFUTF16( | |
90 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name)); | |
91 } | 118 } |
119 description.assign(l10n_util::GetStringFUTF16( | |
120 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name)); | |
92 } | 121 } |
93 } else { | 122 } else { |
94 // HTTP or bad HTTPS. | 123 // HTTP or HTTPS with errors (not warnings). |
95 description.assign(l10n_util::GetStringUTF16( | 124 description.assign(l10n_util::GetStringUTF16( |
96 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY)); | 125 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY)); |
97 state = ssl.security_style() == SECURITY_STYLE_UNAUTHENTICATED ? | 126 state = ssl.security_style() == SECURITY_STYLE_UNAUTHENTICATED ? |
98 SECTION_STATE_WARNING_MAJOR : SECTION_STATE_ERROR; | 127 SECTION_STATE_WARNING_MAJOR : SECTION_STATE_ERROR; |
99 } | 128 } |
100 sections_.push_back(SectionInfo( | 129 sections_.push_back(SectionInfo( |
101 state, | 130 state, |
102 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), | 131 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_IDENTITY_TITLE), |
103 headline, | 132 headline, |
104 description, | 133 description, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 observer_->ModelChanged(); | 302 observer_->ModelChanged(); |
274 } | 303 } |
275 | 304 |
276 // static | 305 // static |
277 void PageInfoModel::RegisterPrefs(PrefService* prefs) { | 306 void PageInfoModel::RegisterPrefs(PrefService* prefs) { |
278 prefs->RegisterDictionaryPref(prefs::kPageInfoWindowPlacement); | 307 prefs->RegisterDictionaryPref(prefs::kPageInfoWindowPlacement); |
279 } | 308 } |
280 | 309 |
281 PageInfoModel::PageInfoModel() { | 310 PageInfoModel::PageInfoModel() { |
282 } | 311 } |
OLD | NEW |