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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 10 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/search/search.h" | 12 #include "chrome/browser/search/search.h" |
13 #include "chrome/browser/ssl/connection_security.h" | 13 #include "chrome/browser/ssl/security_state_model.h" |
14 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" | 14 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
17 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
18 #include "components/google/core/browser/google_util.h" | 18 #include "components/google/core/browser/google_util.h" |
19 #include "components/omnibox/browser/autocomplete_classifier.h" | 19 #include "components/omnibox/browser/autocomplete_classifier.h" |
20 #include "components/omnibox/browser/autocomplete_input.h" | 20 #include "components/omnibox/browser/autocomplete_input.h" |
21 #include "components/omnibox/browser/autocomplete_match.h" | 21 #include "components/omnibox/browser/autocomplete_match.h" |
22 #include "components/url_formatter/url_formatter.h" | 22 #include "components/url_formatter/url_formatter.h" |
23 #include "content/public/browser/cert_store.h" | 23 #include "content/public/browser/cert_store.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 102 } |
103 | 103 |
104 return GURL(url::kAboutBlankURL); | 104 return GURL(url::kAboutBlankURL); |
105 } | 105 } |
106 | 106 |
107 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( | 107 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( |
108 bool ignore_editing) const { | 108 bool ignore_editing) const { |
109 return !GetSearchTerms(ignore_editing).empty(); | 109 return !GetSearchTerms(ignore_editing).empty(); |
110 } | 110 } |
111 | 111 |
112 connection_security::SecurityLevel ToolbarModelImpl::GetSecurityLevel( | 112 SecurityStateModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( |
113 bool ignore_editing) const { | 113 bool ignore_editing) const { |
| 114 SecurityStateModel* model(nullptr); |
| 115 if (delegate_->GetActiveWebContents()) { |
| 116 model = |
| 117 SecurityStateModel::FromWebContents(delegate_->GetActiveWebContents()); |
| 118 } |
| 119 |
114 // When editing, assume no security style. | 120 // When editing, assume no security style. |
115 return (input_in_progress() && !ignore_editing) | 121 return ((input_in_progress() && !ignore_editing) || !model) |
116 ? connection_security::NONE | 122 ? SecurityStateModel::NONE |
117 : connection_security::GetSecurityLevelForWebContents( | 123 : model->security_info().security_level; |
118 delegate_->GetActiveWebContents()); | |
119 } | 124 } |
120 | 125 |
121 int ToolbarModelImpl::GetIcon() const { | 126 int ToolbarModelImpl::GetIcon() const { |
122 if (WouldPerformSearchTermReplacement(false)) | 127 if (WouldPerformSearchTermReplacement(false)) |
123 return IDR_OMNIBOX_SEARCH_SECURED; | 128 return IDR_OMNIBOX_SEARCH_SECURED; |
124 | 129 |
125 return GetIconForSecurityLevel(GetSecurityLevel(false)); | 130 return GetIconForSecurityLevel(GetSecurityLevel(false)); |
126 } | 131 } |
127 | 132 |
128 int ToolbarModelImpl::GetIconForSecurityLevel( | 133 int ToolbarModelImpl::GetIconForSecurityLevel( |
129 connection_security::SecurityLevel level) const { | 134 SecurityStateModel::SecurityLevel level) const { |
130 switch (level) { | 135 switch (level) { |
131 case connection_security::NONE: | 136 case SecurityStateModel::NONE: |
132 return IDR_LOCATION_BAR_HTTP; | 137 return IDR_LOCATION_BAR_HTTP; |
133 case connection_security::EV_SECURE: | 138 case SecurityStateModel::EV_SECURE: |
134 case connection_security::SECURE: | 139 case SecurityStateModel::SECURE: |
135 return IDR_OMNIBOX_HTTPS_VALID; | 140 return IDR_OMNIBOX_HTTPS_VALID; |
136 case connection_security::SECURITY_WARNING: | 141 case SecurityStateModel::SECURITY_WARNING: |
137 // Surface Dubious as Neutral. | 142 // Surface Dubious as Neutral. |
138 return IDR_LOCATION_BAR_HTTP; | 143 return IDR_LOCATION_BAR_HTTP; |
139 case connection_security::SECURITY_POLICY_WARNING: | 144 case SecurityStateModel::SECURITY_POLICY_WARNING: |
140 return IDR_OMNIBOX_HTTPS_POLICY_WARNING; | 145 return IDR_OMNIBOX_HTTPS_POLICY_WARNING; |
141 case connection_security::SECURITY_ERROR: | 146 case SecurityStateModel::SECURITY_ERROR: |
142 return IDR_OMNIBOX_HTTPS_INVALID; | 147 return IDR_OMNIBOX_HTTPS_INVALID; |
143 } | 148 } |
144 | 149 |
145 NOTREACHED(); | 150 NOTREACHED(); |
146 return IDR_LOCATION_BAR_HTTP; | 151 return IDR_LOCATION_BAR_HTTP; |
147 } | 152 } |
148 | 153 |
149 base::string16 ToolbarModelImpl::GetEVCertName() const { | 154 base::string16 ToolbarModelImpl::GetEVCertName() const { |
150 if (GetSecurityLevel(false) != connection_security::EV_SECURE) | 155 if (GetSecurityLevel(false) != SecurityStateModel::EV_SECURE) |
151 return base::string16(); | 156 return base::string16(); |
152 | 157 |
153 // Note: Navigation controller and active entry are guaranteed non-NULL or | 158 // Note: Navigation controller and active entry are guaranteed non-NULL or |
154 // the security level would be NONE. | 159 // the security level would be NONE. |
155 scoped_refptr<net::X509Certificate> cert; | 160 scoped_refptr<net::X509Certificate> cert; |
156 content::CertStore::GetInstance()->RetrieveCert( | 161 content::CertStore::GetInstance()->RetrieveCert( |
157 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); | 162 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); |
158 | 163 |
159 // EV are required to have an organization name and country. | 164 // EV are required to have an organization name and country. |
160 DCHECK(!cert->subject().organization_names.empty()); | 165 DCHECK(!cert->subject().organization_names.empty()); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 return search_terms; | 238 return search_terms; |
234 | 239 |
235 // If the URL is using a Google base URL specified via the command line, we | 240 // If the URL is using a Google base URL specified via the command line, we |
236 // bypass the security check below. | 241 // bypass the security check below. |
237 if (entry && | 242 if (entry && |
238 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) | 243 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) |
239 return search_terms; | 244 return search_terms; |
240 | 245 |
241 // Otherwise, extract search terms for HTTPS pages that do not have a security | 246 // Otherwise, extract search terms for HTTPS pages that do not have a security |
242 // error. | 247 // error. |
243 connection_security::SecurityLevel security_level = | 248 SecurityStateModel::SecurityLevel security_level = |
244 GetSecurityLevel(ignore_editing); | 249 GetSecurityLevel(ignore_editing); |
245 return ((security_level == connection_security::NONE) || | 250 return ((security_level == SecurityStateModel::NONE) || |
246 (security_level == connection_security::SECURITY_ERROR)) | 251 (security_level == SecurityStateModel::SECURITY_ERROR)) |
247 ? base::string16() | 252 ? base::string16() |
248 : search_terms; | 253 : search_terms; |
249 } | 254 } |
OLD | NEW |