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