Chromium Code Reviews| 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 // When editing, assume no security style. | 114 content::WebContents* web_contents = delegate_->GetActiveWebContents(); |
| 115 return (input_in_progress() && !ignore_editing) | 115 SecurityStateModel* model = |
| 116 ? connection_security::NONE | 116 web_contents ? SecurityStateModel::FromWebContents(web_contents) |
| 117 : connection_security::GetSecurityLevelForWebContents( | 117 : nullptr; |
| 118 delegate_->GetActiveWebContents()); | 118 |
| 119 // When editing, or if there is no available security model (for | |
| 120 // example, during startup when Browser::VisibleSSLStateChanged() has | |
| 121 // not yet been called), assume no security style. | |
|
Avi (use Gerrit)
2015/09/03 22:57:36
If you add the SSM to the tab helper set, then we
estark
2015/09/03 23:16:40
Done. (Though we still need to account for a null
Avi (use Gerrit)
2015/09/03 23:21:11
Re a null WC, yep.
| |
| 122 return ((input_in_progress() && !ignore_editing) || !model) | |
| 123 ? SecurityStateModel::NONE | |
| 124 : model->security_info().security_level; | |
| 119 } | 125 } |
| 120 | 126 |
| 121 int ToolbarModelImpl::GetIcon() const { | 127 int ToolbarModelImpl::GetIcon() const { |
| 122 if (WouldPerformSearchTermReplacement(false)) | 128 if (WouldPerformSearchTermReplacement(false)) |
| 123 return IDR_OMNIBOX_SEARCH_SECURED; | 129 return IDR_OMNIBOX_SEARCH_SECURED; |
| 124 | 130 |
| 125 return GetIconForSecurityLevel(GetSecurityLevel(false)); | 131 return GetIconForSecurityLevel(GetSecurityLevel(false)); |
| 126 } | 132 } |
| 127 | 133 |
| 128 int ToolbarModelImpl::GetIconForSecurityLevel( | 134 int ToolbarModelImpl::GetIconForSecurityLevel( |
| 129 connection_security::SecurityLevel level) const { | 135 SecurityStateModel::SecurityLevel level) const { |
| 130 switch (level) { | 136 switch (level) { |
| 131 case connection_security::NONE: | 137 case SecurityStateModel::NONE: |
| 132 return IDR_LOCATION_BAR_HTTP; | 138 return IDR_LOCATION_BAR_HTTP; |
| 133 case connection_security::EV_SECURE: | 139 case SecurityStateModel::EV_SECURE: |
| 134 case connection_security::SECURE: | 140 case SecurityStateModel::SECURE: |
| 135 return IDR_OMNIBOX_HTTPS_VALID; | 141 return IDR_OMNIBOX_HTTPS_VALID; |
| 136 case connection_security::SECURITY_WARNING: | 142 case SecurityStateModel::SECURITY_WARNING: |
| 137 // Surface Dubious as Neutral. | 143 // Surface Dubious as Neutral. |
| 138 return IDR_LOCATION_BAR_HTTP; | 144 return IDR_LOCATION_BAR_HTTP; |
| 139 case connection_security::SECURITY_POLICY_WARNING: | 145 case SecurityStateModel::SECURITY_POLICY_WARNING: |
| 140 return IDR_OMNIBOX_HTTPS_POLICY_WARNING; | 146 return IDR_OMNIBOX_HTTPS_POLICY_WARNING; |
| 141 case connection_security::SECURITY_ERROR: | 147 case SecurityStateModel::SECURITY_ERROR: |
| 142 return IDR_OMNIBOX_HTTPS_INVALID; | 148 return IDR_OMNIBOX_HTTPS_INVALID; |
| 143 } | 149 } |
| 144 | 150 |
| 145 NOTREACHED(); | 151 NOTREACHED(); |
| 146 return IDR_LOCATION_BAR_HTTP; | 152 return IDR_LOCATION_BAR_HTTP; |
| 147 } | 153 } |
| 148 | 154 |
| 149 base::string16 ToolbarModelImpl::GetEVCertName() const { | 155 base::string16 ToolbarModelImpl::GetEVCertName() const { |
| 150 if (GetSecurityLevel(false) != connection_security::EV_SECURE) | 156 if (GetSecurityLevel(false) != SecurityStateModel::EV_SECURE) |
| 151 return base::string16(); | 157 return base::string16(); |
| 152 | 158 |
| 153 // Note: Navigation controller and active entry are guaranteed non-NULL or | 159 // Note: Navigation controller and active entry are guaranteed non-NULL or |
| 154 // the security level would be NONE. | 160 // the security level would be NONE. |
| 155 scoped_refptr<net::X509Certificate> cert; | 161 scoped_refptr<net::X509Certificate> cert; |
| 156 content::CertStore::GetInstance()->RetrieveCert( | 162 content::CertStore::GetInstance()->RetrieveCert( |
| 157 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); | 163 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); |
| 158 | 164 |
| 159 // EV are required to have an organization name and country. | 165 // EV are required to have an organization name and country. |
| 160 DCHECK(!cert->subject().organization_names.empty()); | 166 DCHECK(!cert->subject().organization_names.empty()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 return search_terms; | 239 return search_terms; |
| 234 | 240 |
| 235 // If the URL is using a Google base URL specified via the command line, we | 241 // If the URL is using a Google base URL specified via the command line, we |
| 236 // bypass the security check below. | 242 // bypass the security check below. |
| 237 if (entry && | 243 if (entry && |
| 238 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) | 244 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) |
| 239 return search_terms; | 245 return search_terms; |
| 240 | 246 |
| 241 // Otherwise, extract search terms for HTTPS pages that do not have a security | 247 // Otherwise, extract search terms for HTTPS pages that do not have a security |
| 242 // error. | 248 // error. |
| 243 connection_security::SecurityLevel security_level = | 249 SecurityStateModel::SecurityLevel security_level = |
| 244 GetSecurityLevel(ignore_editing); | 250 GetSecurityLevel(ignore_editing); |
| 245 return ((security_level == connection_security::NONE) || | 251 return ((security_level == SecurityStateModel::NONE) || |
| 246 (security_level == connection_security::SECURITY_ERROR)) | 252 (security_level == SecurityStateModel::SECURITY_ERROR)) |
| 247 ? base::string16() | 253 ? base::string16() |
| 248 : search_terms; | 254 : search_terms; |
| 249 } | 255 } |
| OLD | NEW |