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