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

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

Issue 1138473003: 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"
7 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
9 #include "base/time/time.h" 11 #include "base/time/time.h"
10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 12 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 13 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
12 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" 14 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
13 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/search/search.h" 16 #include "chrome/browser/search/search.h"
15 #include "chrome/browser/ssl/connection_security_helper.h" 17 #include "chrome/browser/ssl/ssl_error_info.h"
16 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" 18 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h"
19 #include "chrome/common/chrome_constants.h"
20 #include "chrome/common/chrome_switches.h"
17 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
18 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
19 #include "chrome/grit/generated_resources.h" 23 #include "chrome/grit/generated_resources.h"
20 #include "components/google/core/browser/google_util.h" 24 #include "components/google/core/browser/google_util.h"
21 #include "components/omnibox/autocomplete_input.h" 25 #include "components/omnibox/autocomplete_input.h"
22 #include "components/omnibox/autocomplete_match.h" 26 #include "components/omnibox/autocomplete_match.h"
23 #include "content/public/browser/cert_store.h" 27 #include "content/public/browser/cert_store.h"
24 #include "content/public/browser/navigation_controller.h" 28 #include "content/public/browser/navigation_controller.h"
25 #include "content/public/browser/navigation_entry.h" 29 #include "content/public/browser/navigation_entry.h"
26 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
27 #include "content/public/browser/web_ui.h" 31 #include "content/public/browser/web_ui.h"
28 #include "content/public/common/content_constants.h" 32 #include "content/public/common/content_constants.h"
29 #include "content/public/common/ssl_status.h" 33 #include "content/public/common/ssl_status.h"
30 #include "grit/components_scaled_resources.h" 34 #include "grit/components_scaled_resources.h"
31 #include "grit/theme_resources.h" 35 #include "grit/theme_resources.h"
32 #include "net/base/net_util.h" 36 #include "net/base/net_util.h"
33 #include "net/cert/cert_status_flags.h" 37 #include "net/cert/cert_status_flags.h"
34 #include "net/cert/x509_certificate.h" 38 #include "net/cert/x509_certificate.h"
35 #include "net/ssl/ssl_connection_status_flags.h" 39 #include "net/ssl/ssl_connection_status_flags.h"
36 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
37 41
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
38 using content::NavigationController; 47 using content::NavigationController;
39 using content::NavigationEntry; 48 using content::NavigationEntry;
49 using content::SSLStatus;
40 using content::WebContents; 50 using content::WebContents;
41 51
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
42 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate) 77 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate)
43 : delegate_(delegate) { 78 : delegate_(delegate) {
44 } 79 }
45 80
46 ToolbarModelImpl::~ToolbarModelImpl() { 81 ToolbarModelImpl::~ToolbarModelImpl() {
47 } 82 }
48 83
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
49 // ToolbarModelImpl Implementation. 156 // ToolbarModelImpl Implementation.
50 base::string16 ToolbarModelImpl::GetText() const { 157 base::string16 ToolbarModelImpl::GetText() const {
51 base::string16 search_terms(GetSearchTerms(false)); 158 base::string16 search_terms(GetSearchTerms(false));
52 if (!search_terms.empty()) 159 if (!search_terms.empty())
53 return search_terms; 160 return search_terms;
54 161
55 return GetFormattedURL(NULL); 162 return GetFormattedURL(NULL);
56 } 163 }
57 164
58 base::string16 ToolbarModelImpl::GetFormattedURL(size_t* prefix_end) const { 165 base::string16 ToolbarModelImpl::GetFormattedURL(size_t* prefix_end) const {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 209 }
103 210
104 return GURL(url::kAboutBlankURL); 211 return GURL(url::kAboutBlankURL);
105 } 212 }
106 213
107 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( 214 bool ToolbarModelImpl::WouldPerformSearchTermReplacement(
108 bool ignore_editing) const { 215 bool ignore_editing) const {
109 return !GetSearchTerms(ignore_editing).empty(); 216 return !GetSearchTerms(ignore_editing).empty();
110 } 217 }
111 218
112 ConnectionSecurityHelper::SecurityLevel ToolbarModelImpl::GetSecurityLevel( 219 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel(
113 bool ignore_editing) const { 220 bool ignore_editing) const {
114 // When editing, assume no security style. 221 // When editing, assume no security style.
115 return (input_in_progress() && !ignore_editing) 222 return (input_in_progress() && !ignore_editing) ?
116 ? ConnectionSecurityHelper::NONE 223 NONE : GetSecurityLevelForWebContents(delegate_->GetActiveWebContents());
117 : ConnectionSecurityHelper::GetSecurityLevelForWebContents(
118 delegate_->GetActiveWebContents());
119 } 224 }
120 225
121 int ToolbarModelImpl::GetIcon() const { 226 int ToolbarModelImpl::GetIcon() const {
122 if (WouldPerformSearchTermReplacement(false)) 227 if (WouldPerformSearchTermReplacement(false))
123 return IDR_OMNIBOX_SEARCH_SECURED; 228 return IDR_OMNIBOX_SEARCH_SECURED;
124 229
125 return GetIconForSecurityLevel(GetSecurityLevel(false)); 230 return GetIconForSecurityLevel(GetSecurityLevel(false));
126 } 231 }
127 232
128 int ToolbarModelImpl::GetIconForSecurityLevel( 233 int ToolbarModelImpl::GetIconForSecurityLevel(SecurityLevel level) const {
129 ConnectionSecurityHelper::SecurityLevel level) const { 234 static int icon_ids[NUM_SECURITY_LEVELS] = {
130 switch (level) { 235 IDR_LOCATION_BAR_HTTP,
131 case ConnectionSecurityHelper::NONE: 236 IDR_OMNIBOX_HTTPS_VALID,
132 return IDR_LOCATION_BAR_HTTP; 237 IDR_OMNIBOX_HTTPS_VALID,
133 case ConnectionSecurityHelper::EV_SECURE: 238 IDR_OMNIBOX_HTTPS_WARNING,
134 case ConnectionSecurityHelper::SECURE: 239 IDR_OMNIBOX_HTTPS_POLICY_WARNING,
135 return IDR_OMNIBOX_HTTPS_VALID; 240 IDR_OMNIBOX_HTTPS_INVALID,
136 case ConnectionSecurityHelper::SECURITY_WARNING: 241 };
137 return IDR_OMNIBOX_HTTPS_WARNING; 242 DCHECK(arraysize(icon_ids) == NUM_SECURITY_LEVELS);
138 case ConnectionSecurityHelper::SECURITY_POLICY_WARNING: 243 return icon_ids[level];
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;
146 } 244 }
147 245
148 base::string16 ToolbarModelImpl::GetEVCertName() const { 246 base::string16 ToolbarModelImpl::GetEVCertName() const {
149 if (GetSecurityLevel(false) != ConnectionSecurityHelper::EV_SECURE) 247 if (GetSecurityLevel(false) != EV_SECURE)
150 return base::string16(); 248 return base::string16();
151 249
152 // Note: Navigation controller and active entry are guaranteed non-NULL or 250 // Note: Navigation controller and active entry are guaranteed non-NULL or
153 // the security level would be NONE. 251 // the security level would be NONE.
154 scoped_refptr<net::X509Certificate> cert; 252 scoped_refptr<net::X509Certificate> cert;
155 content::CertStore::GetInstance()->RetrieveCert( 253 content::CertStore::GetInstance()->RetrieveCert(
156 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); 254 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert);
157 255
158 // EV are required to have an organization name and country. 256 // EV are required to have an organization name and country.
159 DCHECK(!cert->subject().organization_names.empty()); 257 DCHECK(!cert->subject().organization_names.empty());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 return search_terms; 330 return search_terms;
233 331
234 // If the URL is using a Google base URL specified via the command line, we 332 // If the URL is using a Google base URL specified via the command line, we
235 // bypass the security check below. 333 // bypass the security check below.
236 if (entry && 334 if (entry &&
237 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) 335 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL()))
238 return search_terms; 336 return search_terms;
239 337
240 // Otherwise, extract search terms for HTTPS pages that do not have a security 338 // Otherwise, extract search terms for HTTPS pages that do not have a security
241 // error. 339 // error.
242 ConnectionSecurityHelper::SecurityLevel security_level = 340 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing);
243 GetSecurityLevel(ignore_editing); 341 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ?
244 return ((security_level == ConnectionSecurityHelper::NONE) || 342 base::string16() : search_terms;
245 (security_level == ConnectionSecurityHelper::SECURITY_ERROR))
246 ? base::string16()
247 : search_terms;
248 } 343 }
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