OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/toolbar/toolbar_model_impl.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_model_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | |
8 #include "base/metrics/field_trial.h" | |
9 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
10 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
11 #include "base/time/time.h" | 9 #include "base/time/time.h" |
12 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
13 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
14 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 12 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
15 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/search/search.h" | 14 #include "chrome/browser/search/search.h" |
17 #include "chrome/browser/ssl/ssl_error_info.h" | 15 #include "chrome/browser/ssl/security_level_policy.h" |
18 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" | 16 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" |
19 #include "chrome/common/chrome_constants.h" | |
20 #include "chrome/common/chrome_switches.h" | |
21 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
23 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
24 #include "components/google/core/browser/google_util.h" | 20 #include "components/google/core/browser/google_util.h" |
25 #include "components/omnibox/autocomplete_input.h" | 21 #include "components/omnibox/autocomplete_input.h" |
26 #include "components/omnibox/autocomplete_match.h" | 22 #include "components/omnibox/autocomplete_match.h" |
27 #include "content/public/browser/cert_store.h" | 23 #include "content/public/browser/cert_store.h" |
28 #include "content/public/browser/navigation_controller.h" | 24 #include "content/public/browser/navigation_controller.h" |
29 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
30 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
31 #include "content/public/browser/web_ui.h" | 27 #include "content/public/browser/web_ui.h" |
32 #include "content/public/common/content_constants.h" | 28 #include "content/public/common/content_constants.h" |
33 #include "content/public/common/ssl_status.h" | 29 #include "content/public/common/ssl_status.h" |
34 #include "grit/components_scaled_resources.h" | 30 #include "grit/components_scaled_resources.h" |
35 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
36 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
37 #include "net/cert/cert_status_flags.h" | 33 #include "net/cert/cert_status_flags.h" |
38 #include "net/cert/x509_certificate.h" | 34 #include "net/cert/x509_certificate.h" |
39 #include "net/ssl/ssl_connection_status_flags.h" | 35 #include "net/ssl/ssl_connection_status_flags.h" |
40 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
41 | 37 |
42 #if defined(OS_CHROMEOS) | |
43 #include "chrome/browser/chromeos/policy/policy_cert_service.h" | |
44 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" | |
45 #endif | |
46 | |
47 using content::NavigationController; | 38 using content::NavigationController; |
48 using content::NavigationEntry; | 39 using content::NavigationEntry; |
49 using content::SSLStatus; | |
50 using content::WebContents; | 40 using content::WebContents; |
51 | 41 |
52 namespace { | |
53 | |
54 ToolbarModel::SecurityLevel GetSecurityLevelForNonSecureFieldTrial() { | |
55 std::string choice = base::CommandLine::ForCurrentProcess()-> | |
56 GetSwitchValueASCII(switches::kMarkNonSecureAs); | |
57 if (choice == switches::kMarkNonSecureAsNeutral) | |
58 return ToolbarModel::NONE; | |
59 if (choice == switches::kMarkNonSecureAsDubious) | |
60 return ToolbarModel::SECURITY_WARNING; | |
61 if (choice == switches::kMarkNonSecureAsNonSecure) | |
62 return ToolbarModel::SECURITY_ERROR; | |
63 | |
64 std::string group = base::FieldTrialList::FindFullName("MarkNonSecureAs"); | |
65 if (group == switches::kMarkNonSecureAsNeutral) | |
66 return ToolbarModel::NONE; | |
67 if (group == switches::kMarkNonSecureAsDubious) | |
68 return ToolbarModel::SECURITY_WARNING; | |
69 if (group == switches::kMarkNonSecureAsNonSecure) | |
70 return ToolbarModel::SECURITY_ERROR; | |
71 | |
72 return ToolbarModel::NONE; | |
73 } | |
74 | |
75 } // namespace | |
76 | |
77 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate) | 42 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate) |
78 : delegate_(delegate) { | 43 : delegate_(delegate) { |
79 } | 44 } |
80 | 45 |
81 ToolbarModelImpl::~ToolbarModelImpl() { | 46 ToolbarModelImpl::~ToolbarModelImpl() { |
82 } | 47 } |
83 | 48 |
84 // static | 49 // static |
85 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevelForWebContents( | 50 SecurityLevelPolicy::SecurityLevel |
86 content::WebContents* web_contents) { | 51 ToolbarModelImpl::GetSecurityLevelForWebContents( |
87 if (!web_contents) | 52 content::WebContents* web_contents) { |
88 return NONE; | 53 return SecurityLevelPolicy::GetSecurityLevelForWebContents(web_contents); |
89 | |
90 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); | |
91 if (!entry) | |
92 return NONE; | |
93 | |
94 const SSLStatus& ssl = entry->GetSSL(); | |
95 switch (ssl.security_style) { | |
96 case content::SECURITY_STYLE_UNKNOWN: | |
97 return NONE; | |
98 | |
99 case content::SECURITY_STYLE_UNAUTHENTICATED: { | |
100 const GURL& url = entry->GetURL(); | |
101 if (url.SchemeIs("http") || url.SchemeIs("ftp")) | |
102 return GetSecurityLevelForNonSecureFieldTrial(); | |
103 return NONE; | |
104 } | |
105 | |
106 case content::SECURITY_STYLE_AUTHENTICATION_BROKEN: | |
107 return SECURITY_ERROR; | |
108 | |
109 case content::SECURITY_STYLE_AUTHENTICATED: { | |
110 #if defined(OS_CHROMEOS) | |
111 policy::PolicyCertService* service = | |
112 policy::PolicyCertServiceFactory::GetForProfile( | |
113 Profile::FromBrowserContext(web_contents->GetBrowserContext())); | |
114 if (service && service->UsedPolicyCertificates()) | |
115 return SECURITY_POLICY_WARNING; | |
116 #endif | |
117 if (!!(ssl.content_status & SSLStatus::DISPLAYED_INSECURE_CONTENT)) | |
118 return SECURITY_WARNING; | |
119 scoped_refptr<net::X509Certificate> cert; | |
120 if (content::CertStore::GetInstance()->RetrieveCert(ssl.cert_id, &cert) && | |
121 (ssl.cert_status & net::CERT_STATUS_SHA1_SIGNATURE_PRESENT)) { | |
122 // The internal representation of the dates for UI treatment of SHA-1. | |
123 // See http://crbug.com/401365 for details | |
124 static const int64_t kJanuary2017 = INT64_C(13127702400000000); | |
125 // kJanuary2016 needs to be kept in sync with | |
126 // ToolbarModelAndroid::IsDeprecatedSHA1Present(). | |
127 static const int64_t kJanuary2016 = INT64_C(13096080000000000); | |
128 if (cert->valid_expiry() >= | |
129 base::Time::FromInternalValue(kJanuary2017)) { | |
130 return SECURITY_ERROR; | |
131 } | |
132 if (cert->valid_expiry() >= | |
133 base::Time::FromInternalValue(kJanuary2016)) { | |
134 return SECURITY_WARNING; | |
135 } | |
136 } | |
137 if (net::IsCertStatusError(ssl.cert_status)) { | |
138 DCHECK(net::IsCertStatusMinorError(ssl.cert_status)); | |
139 return SECURITY_WARNING; | |
140 } | |
141 if (net::SSLConnectionStatusToVersion(ssl.connection_status) == | |
142 net::SSL_CONNECTION_VERSION_SSL3) { | |
143 // SSLv3 will be removed in the future. | |
144 return SECURITY_WARNING; | |
145 } | |
146 if ((ssl.cert_status & net::CERT_STATUS_IS_EV) && cert.get()) | |
147 return EV_SECURE; | |
148 return SECURE; | |
149 } | |
150 default: | |
151 NOTREACHED(); | |
152 return NONE; | |
153 } | |
154 } | 54 } |
155 | 55 |
156 // ToolbarModelImpl Implementation. | 56 // ToolbarModelImpl Implementation. |
157 base::string16 ToolbarModelImpl::GetText() const { | 57 base::string16 ToolbarModelImpl::GetText() const { |
158 base::string16 search_terms(GetSearchTerms(false)); | 58 base::string16 search_terms(GetSearchTerms(false)); |
159 if (!search_terms.empty()) | 59 if (!search_terms.empty()) |
160 return search_terms; | 60 return search_terms; |
161 | 61 |
162 return GetFormattedURL(NULL); | 62 return GetFormattedURL(NULL); |
163 } | 63 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 } | 109 } |
210 | 110 |
211 return GURL(url::kAboutBlankURL); | 111 return GURL(url::kAboutBlankURL); |
212 } | 112 } |
213 | 113 |
214 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( | 114 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( |
215 bool ignore_editing) const { | 115 bool ignore_editing) const { |
216 return !GetSearchTerms(ignore_editing).empty(); | 116 return !GetSearchTerms(ignore_editing).empty(); |
217 } | 117 } |
218 | 118 |
219 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( | 119 SecurityLevelPolicy::SecurityLevel ToolbarModelImpl::GetSecurityLevel( |
220 bool ignore_editing) const { | 120 bool ignore_editing) const { |
221 // When editing, assume no security style. | 121 // When editing, assume no security style. |
222 return (input_in_progress() && !ignore_editing) ? | 122 return (input_in_progress() && !ignore_editing) |
223 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents()); | 123 ? SecurityLevelPolicy::NONE |
| 124 : GetSecurityLevelForWebContents( |
| 125 delegate_->GetActiveWebContents()); |
224 } | 126 } |
225 | 127 |
226 int ToolbarModelImpl::GetIcon() const { | 128 int ToolbarModelImpl::GetIcon() const { |
227 if (WouldPerformSearchTermReplacement(false)) | 129 if (WouldPerformSearchTermReplacement(false)) |
228 return IDR_OMNIBOX_SEARCH_SECURED; | 130 return IDR_OMNIBOX_SEARCH_SECURED; |
229 | 131 |
230 return GetIconForSecurityLevel(GetSecurityLevel(false)); | 132 return GetIconForSecurityLevel(GetSecurityLevel(false)); |
231 } | 133 } |
232 | 134 |
233 int ToolbarModelImpl::GetIconForSecurityLevel(SecurityLevel level) const { | 135 int ToolbarModelImpl::GetIconForSecurityLevel( |
234 static int icon_ids[NUM_SECURITY_LEVELS] = { | 136 SecurityLevelPolicy::SecurityLevel level) const { |
235 IDR_LOCATION_BAR_HTTP, | 137 static int icon_ids[SecurityLevelPolicy::NUM_SECURITY_LEVELS] = { |
236 IDR_OMNIBOX_HTTPS_VALID, | 138 IDR_LOCATION_BAR_HTTP, |
237 IDR_OMNIBOX_HTTPS_VALID, | 139 IDR_OMNIBOX_HTTPS_VALID, |
238 IDR_OMNIBOX_HTTPS_WARNING, | 140 IDR_OMNIBOX_HTTPS_VALID, |
239 IDR_OMNIBOX_HTTPS_POLICY_WARNING, | 141 IDR_OMNIBOX_HTTPS_WARNING, |
240 IDR_OMNIBOX_HTTPS_INVALID, | 142 IDR_OMNIBOX_HTTPS_POLICY_WARNING, |
| 143 IDR_OMNIBOX_HTTPS_INVALID, |
241 }; | 144 }; |
242 DCHECK(arraysize(icon_ids) == NUM_SECURITY_LEVELS); | 145 DCHECK(arraysize(icon_ids) == SecurityLevelPolicy::NUM_SECURITY_LEVELS); |
243 return icon_ids[level]; | 146 return icon_ids[level]; |
244 } | 147 } |
245 | 148 |
246 base::string16 ToolbarModelImpl::GetEVCertName() const { | 149 base::string16 ToolbarModelImpl::GetEVCertName() const { |
247 if (GetSecurityLevel(false) != EV_SECURE) | 150 if (GetSecurityLevel(false) != SecurityLevelPolicy::EV_SECURE) |
248 return base::string16(); | 151 return base::string16(); |
249 | 152 |
250 // Note: Navigation controller and active entry are guaranteed non-NULL or | 153 // Note: Navigation controller and active entry are guaranteed non-NULL or |
251 // the security level would be NONE. | 154 // the security level would be NONE. |
252 scoped_refptr<net::X509Certificate> cert; | 155 scoped_refptr<net::X509Certificate> cert; |
253 content::CertStore::GetInstance()->RetrieveCert( | 156 content::CertStore::GetInstance()->RetrieveCert( |
254 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); | 157 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); |
255 | 158 |
256 // EV are required to have an organization name and country. | 159 // EV are required to have an organization name and country. |
257 DCHECK(!cert->subject().organization_names.empty()); | 160 DCHECK(!cert->subject().organization_names.empty()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 return search_terms; | 233 return search_terms; |
331 | 234 |
332 // If the URL is using a Google base URL specified via the command line, we | 235 // If the URL is using a Google base URL specified via the command line, we |
333 // bypass the security check below. | 236 // bypass the security check below. |
334 if (entry && | 237 if (entry && |
335 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) | 238 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) |
336 return search_terms; | 239 return search_terms; |
337 | 240 |
338 // Otherwise, extract search terms for HTTPS pages that do not have a security | 241 // Otherwise, extract search terms for HTTPS pages that do not have a security |
339 // error. | 242 // error. |
340 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); | 243 SecurityLevelPolicy::SecurityLevel security_level = |
341 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? | 244 GetSecurityLevel(ignore_editing); |
342 base::string16() : search_terms; | 245 return ((security_level == SecurityLevelPolicy::NONE) || |
| 246 (security_level == SecurityLevelPolicy::SECURITY_ERROR)) |
| 247 ? base::string16() |
| 248 : search_terms; |
343 } | 249 } |
OLD | NEW |