Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_model_impl.cc

Issue 1124383007: Revert of Revert of Move SecurityLevel into a class of its own (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/connection_security_helper.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
85 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevelForWebContents(
86 content::WebContents* web_contents) {
87 if (!web_contents)
88 return NONE;
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 }
155
156 // ToolbarModelImpl Implementation. 49 // ToolbarModelImpl Implementation.
157 base::string16 ToolbarModelImpl::GetText() const { 50 base::string16 ToolbarModelImpl::GetText() const {
158 base::string16 search_terms(GetSearchTerms(false)); 51 base::string16 search_terms(GetSearchTerms(false));
159 if (!search_terms.empty()) 52 if (!search_terms.empty())
160 return search_terms; 53 return search_terms;
161 54
162 return GetFormattedURL(NULL); 55 return GetFormattedURL(NULL);
163 } 56 }
164 57
165 base::string16 ToolbarModelImpl::GetFormattedURL(size_t* prefix_end) const { 58 base::string16 ToolbarModelImpl::GetFormattedURL(size_t* prefix_end) const {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 102 }
210 103
211 return GURL(url::kAboutBlankURL); 104 return GURL(url::kAboutBlankURL);
212 } 105 }
213 106
214 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( 107 bool ToolbarModelImpl::WouldPerformSearchTermReplacement(
215 bool ignore_editing) const { 108 bool ignore_editing) const {
216 return !GetSearchTerms(ignore_editing).empty(); 109 return !GetSearchTerms(ignore_editing).empty();
217 } 110 }
218 111
219 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( 112 ConnectionSecurityHelper::SecurityLevel ToolbarModelImpl::GetSecurityLevel(
220 bool ignore_editing) const { 113 bool ignore_editing) const {
221 // When editing, assume no security style. 114 // When editing, assume no security style.
222 return (input_in_progress() && !ignore_editing) ? 115 return (input_in_progress() && !ignore_editing)
223 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents()); 116 ? ConnectionSecurityHelper::NONE
117 : ConnectionSecurityHelper::GetSecurityLevelForWebContents(
118 delegate_->GetActiveWebContents());
224 } 119 }
225 120
226 int ToolbarModelImpl::GetIcon() const { 121 int ToolbarModelImpl::GetIcon() const {
227 if (WouldPerformSearchTermReplacement(false)) 122 if (WouldPerformSearchTermReplacement(false))
228 return IDR_OMNIBOX_SEARCH_SECURED; 123 return IDR_OMNIBOX_SEARCH_SECURED;
229 124
230 return GetIconForSecurityLevel(GetSecurityLevel(false)); 125 return GetIconForSecurityLevel(GetSecurityLevel(false));
231 } 126 }
232 127
233 int ToolbarModelImpl::GetIconForSecurityLevel(SecurityLevel level) const { 128 int ToolbarModelImpl::GetIconForSecurityLevel(
234 static int icon_ids[NUM_SECURITY_LEVELS] = { 129 ConnectionSecurityHelper::SecurityLevel level) const {
235 IDR_LOCATION_BAR_HTTP, 130 switch (level) {
236 IDR_OMNIBOX_HTTPS_VALID, 131 case ConnectionSecurityHelper::NONE:
237 IDR_OMNIBOX_HTTPS_VALID, 132 return IDR_LOCATION_BAR_HTTP;
238 IDR_OMNIBOX_HTTPS_WARNING, 133 case ConnectionSecurityHelper::EV_SECURE:
239 IDR_OMNIBOX_HTTPS_POLICY_WARNING, 134 case ConnectionSecurityHelper::SECURE:
240 IDR_OMNIBOX_HTTPS_INVALID, 135 return IDR_OMNIBOX_HTTPS_VALID;
241 }; 136 case ConnectionSecurityHelper::SECURITY_WARNING:
242 DCHECK(arraysize(icon_ids) == NUM_SECURITY_LEVELS); 137 return IDR_OMNIBOX_HTTPS_WARNING;
243 return icon_ids[level]; 138 case ConnectionSecurityHelper::SECURITY_POLICY_WARNING:
139 return IDR_OMNIBOX_HTTPS_POLICY_WARNING;
140 case ConnectionSecurityHelper::SECURITY_ERROR:
141 return IDR_OMNIBOX_HTTPS_INVALID;
142 }
143
144 NOTREACHED();
145 return IDR_LOCATION_BAR_HTTP;
244 } 146 }
245 147
246 base::string16 ToolbarModelImpl::GetEVCertName() const { 148 base::string16 ToolbarModelImpl::GetEVCertName() const {
247 if (GetSecurityLevel(false) != EV_SECURE) 149 if (GetSecurityLevel(false) != ConnectionSecurityHelper::EV_SECURE)
248 return base::string16(); 150 return base::string16();
249 151
250 // Note: Navigation controller and active entry are guaranteed non-NULL or 152 // Note: Navigation controller and active entry are guaranteed non-NULL or
251 // the security level would be NONE. 153 // the security level would be NONE.
252 scoped_refptr<net::X509Certificate> cert; 154 scoped_refptr<net::X509Certificate> cert;
253 content::CertStore::GetInstance()->RetrieveCert( 155 content::CertStore::GetInstance()->RetrieveCert(
254 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); 156 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert);
255 157
256 // EV are required to have an organization name and country. 158 // EV are required to have an organization name and country.
257 DCHECK(!cert->subject().organization_names.empty()); 159 DCHECK(!cert->subject().organization_names.empty());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 return search_terms; 232 return search_terms;
331 233
332 // If the URL is using a Google base URL specified via the command line, we 234 // If the URL is using a Google base URL specified via the command line, we
333 // bypass the security check below. 235 // bypass the security check below.
334 if (entry && 236 if (entry &&
335 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) 237 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL()))
336 return search_terms; 238 return search_terms;
337 239
338 // Otherwise, extract search terms for HTTPS pages that do not have a security 240 // Otherwise, extract search terms for HTTPS pages that do not have a security
339 // error. 241 // error.
340 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); 242 ConnectionSecurityHelper::SecurityLevel security_level =
341 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? 243 GetSecurityLevel(ignore_editing);
342 base::string16() : search_terms; 244 return ((security_level == ConnectionSecurityHelper::NONE) ||
245 (security_level == ConnectionSecurityHelper::SECURITY_ERROR))
246 ? base::string16()
247 : search_terms;
343 } 248 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_model_impl.h ('k') | chrome/browser/ui/views/location_bar/location_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698