| 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/chrome_security_state_model_client.h" | 13 #include "chrome/browser/ssl/chrome_security_state_model_client.h" |
| 14 #include "chrome/browser/ssl/security_state_model.h" | |
| 15 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" | 14 #include "chrome/browser/ui/toolbar/toolbar_model_delegate.h" |
| 16 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 18 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
| 19 #include "components/google/core/browser/google_util.h" | 18 #include "components/google/core/browser/google_util.h" |
| 20 #include "components/omnibox/browser/autocomplete_classifier.h" | 19 #include "components/omnibox/browser/autocomplete_classifier.h" |
| 21 #include "components/omnibox/browser/autocomplete_input.h" | 20 #include "components/omnibox/browser/autocomplete_input.h" |
| 22 #include "components/omnibox/browser/autocomplete_match.h" | 21 #include "components/omnibox/browser/autocomplete_match.h" |
| 22 #include "components/security_state/security_state_model.h" |
| 23 #include "components/url_formatter/elide_url.h" | 23 #include "components/url_formatter/elide_url.h" |
| 24 #include "components/url_formatter/url_formatter.h" | 24 #include "components/url_formatter/url_formatter.h" |
| 25 #include "content/public/browser/cert_store.h" | 25 #include "content/public/browser/cert_store.h" |
| 26 #include "content/public/browser/navigation_controller.h" | 26 #include "content/public/browser/navigation_controller.h" |
| 27 #include "content/public/browser/navigation_entry.h" | 27 #include "content/public/browser/navigation_entry.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
| 30 #include "content/public/common/content_constants.h" | 30 #include "content/public/common/content_constants.h" |
| 31 #include "content/public/common/ssl_status.h" | 31 #include "content/public/common/ssl_status.h" |
| 32 #include "grit/components_scaled_resources.h" | 32 #include "grit/components_scaled_resources.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 return GURL(url::kAboutBlankURL); | 118 return GURL(url::kAboutBlankURL); |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( | 121 bool ToolbarModelImpl::WouldPerformSearchTermReplacement( |
| 122 bool ignore_editing) const { | 122 bool ignore_editing) const { |
| 123 return !GetSearchTerms(ignore_editing).empty(); | 123 return !GetSearchTerms(ignore_editing).empty(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 SecurityStateModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( | 126 security_state::SecurityStateModel::SecurityLevel |
| 127 bool ignore_editing) const { | 127 ToolbarModelImpl::GetSecurityLevel(bool ignore_editing) const { |
| 128 const content::WebContents* web_contents = delegate_->GetActiveWebContents(); | 128 const content::WebContents* web_contents = delegate_->GetActiveWebContents(); |
| 129 // If there is no active WebContents (which can happen during toolbar | 129 // If there is no active WebContents (which can happen during toolbar |
| 130 // initialization), assume no security style. | 130 // initialization), assume no security style. |
| 131 if (!web_contents) | 131 if (!web_contents) |
| 132 return SecurityStateModel::NONE; | 132 return security_state::SecurityStateModel::NONE; |
| 133 const ChromeSecurityStateModelClient* model_client = | 133 const ChromeSecurityStateModelClient* model_client = |
| 134 ChromeSecurityStateModelClient::FromWebContents(web_contents); | 134 ChromeSecurityStateModelClient::FromWebContents(web_contents); |
| 135 | 135 |
| 136 // When editing, assume no security style. | 136 // When editing, assume no security style. |
| 137 return (input_in_progress() && !ignore_editing) | 137 return (input_in_progress() && !ignore_editing) |
| 138 ? SecurityStateModel::NONE | 138 ? security_state::SecurityStateModel::NONE |
| 139 : model_client->GetSecurityInfo().security_level; | 139 : model_client->GetSecurityInfo().security_level; |
| 140 } | 140 } |
| 141 | 141 |
| 142 int ToolbarModelImpl::GetIcon() const { | 142 int ToolbarModelImpl::GetIcon() const { |
| 143 switch (GetSecurityLevel(false)) { | 143 switch (GetSecurityLevel(false)) { |
| 144 case SecurityStateModel::NONE: | 144 case security_state::SecurityStateModel::NONE: |
| 145 return IDR_LOCATION_BAR_HTTP; | 145 return IDR_LOCATION_BAR_HTTP; |
| 146 case SecurityStateModel::EV_SECURE: | 146 case security_state::SecurityStateModel::EV_SECURE: |
| 147 case SecurityStateModel::SECURE: | 147 case security_state::SecurityStateModel::SECURE: |
| 148 return IDR_OMNIBOX_HTTPS_VALID; | 148 return IDR_OMNIBOX_HTTPS_VALID; |
| 149 case SecurityStateModel::SECURITY_WARNING: | 149 case security_state::SecurityStateModel::SECURITY_WARNING: |
| 150 // Surface Dubious as Neutral. | 150 // Surface Dubious as Neutral. |
| 151 return IDR_LOCATION_BAR_HTTP; | 151 return IDR_LOCATION_BAR_HTTP; |
| 152 case SecurityStateModel::SECURITY_POLICY_WARNING: | 152 case security_state::SecurityStateModel::SECURITY_POLICY_WARNING: |
| 153 return IDR_OMNIBOX_HTTPS_POLICY_WARNING; | 153 return IDR_OMNIBOX_HTTPS_POLICY_WARNING; |
| 154 case SecurityStateModel::SECURITY_ERROR: | 154 case security_state::SecurityStateModel::SECURITY_ERROR: |
| 155 return IDR_OMNIBOX_HTTPS_INVALID; | 155 return IDR_OMNIBOX_HTTPS_INVALID; |
| 156 } | 156 } |
| 157 | 157 |
| 158 NOTREACHED(); | 158 NOTREACHED(); |
| 159 return IDR_LOCATION_BAR_HTTP; | 159 return IDR_LOCATION_BAR_HTTP; |
| 160 } | 160 } |
| 161 | 161 |
| 162 gfx::VectorIconId ToolbarModelImpl::GetVectorIcon() const { | 162 gfx::VectorIconId ToolbarModelImpl::GetVectorIcon() const { |
| 163 #if !defined(OS_ANDROID) && !defined(OS_MACOSX) && !defined(OS_IOS) | 163 #if !defined(OS_ANDROID) && !defined(OS_MACOSX) && !defined(OS_IOS) |
| 164 switch (GetSecurityLevel(false)) { | 164 switch (GetSecurityLevel(false)) { |
| 165 case SecurityStateModel::NONE: | 165 case security_state::SecurityStateModel::NONE: |
| 166 return gfx::VectorIconId::LOCATION_BAR_HTTP; | 166 return gfx::VectorIconId::LOCATION_BAR_HTTP; |
| 167 case SecurityStateModel::EV_SECURE: | 167 case security_state::SecurityStateModel::EV_SECURE: |
| 168 case SecurityStateModel::SECURE: | 168 case security_state::SecurityStateModel::SECURE: |
| 169 return gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID; | 169 return gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID; |
| 170 case SecurityStateModel::SECURITY_WARNING: | 170 case security_state::SecurityStateModel::SECURITY_WARNING: |
| 171 // Surface Dubious as Neutral. | 171 // Surface Dubious as Neutral. |
| 172 return gfx::VectorIconId::LOCATION_BAR_HTTP; | 172 return gfx::VectorIconId::LOCATION_BAR_HTTP; |
| 173 case SecurityStateModel::SECURITY_POLICY_WARNING: | 173 case security_state::SecurityStateModel::SECURITY_POLICY_WARNING: |
| 174 return gfx::VectorIconId::BUSINESS; | 174 return gfx::VectorIconId::BUSINESS; |
| 175 case SecurityStateModel::SECURITY_ERROR: | 175 case security_state::SecurityStateModel::SECURITY_ERROR: |
| 176 return gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID; | 176 return gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID; |
| 177 } | 177 } |
| 178 #endif | 178 #endif |
| 179 | 179 |
| 180 NOTREACHED(); | 180 NOTREACHED(); |
| 181 return gfx::VectorIconId::VECTOR_ICON_NONE; | 181 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| 182 } | 182 } |
| 183 | 183 |
| 184 base::string16 ToolbarModelImpl::GetEVCertName() const { | 184 base::string16 ToolbarModelImpl::GetEVCertName() const { |
| 185 if (GetSecurityLevel(false) != SecurityStateModel::EV_SECURE) | 185 if (GetSecurityLevel(false) != security_state::SecurityStateModel::EV_SECURE) |
| 186 return base::string16(); | 186 return base::string16(); |
| 187 | 187 |
| 188 // Note: Navigation controller and active entry are guaranteed non-NULL or | 188 // Note: Navigation controller and active entry are guaranteed non-NULL or |
| 189 // the security level would be NONE. | 189 // the security level would be NONE. |
| 190 scoped_refptr<net::X509Certificate> cert; | 190 scoped_refptr<net::X509Certificate> cert; |
| 191 content::CertStore::GetInstance()->RetrieveCert( | 191 content::CertStore::GetInstance()->RetrieveCert( |
| 192 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); | 192 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); |
| 193 | 193 |
| 194 // EV are required to have an organization name and country. | 194 // EV are required to have an organization name and country. |
| 195 DCHECK(!cert->subject().organization_names.empty()); | 195 DCHECK(!cert->subject().organization_names.empty()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 return search_terms; | 268 return search_terms; |
| 269 | 269 |
| 270 // If the URL is using a Google base URL specified via the command line, we | 270 // If the URL is using a Google base URL specified via the command line, we |
| 271 // bypass the security check below. | 271 // bypass the security check below. |
| 272 if (entry && | 272 if (entry && |
| 273 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) | 273 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) |
| 274 return search_terms; | 274 return search_terms; |
| 275 | 275 |
| 276 // Otherwise, extract search terms for HTTPS pages that do not have a security | 276 // Otherwise, extract search terms for HTTPS pages that do not have a security |
| 277 // error. | 277 // error. |
| 278 SecurityStateModel::SecurityLevel security_level = | 278 security_state::SecurityStateModel::SecurityLevel security_level = |
| 279 GetSecurityLevel(ignore_editing); | 279 GetSecurityLevel(ignore_editing); |
| 280 return ((security_level == SecurityStateModel::NONE) || | 280 return ((security_level == security_state::SecurityStateModel::NONE) || |
| 281 (security_level == SecurityStateModel::SECURITY_ERROR)) | 281 (security_level == |
| 282 security_state::SecurityStateModel::SECURITY_ERROR)) |
| 282 ? base::string16() | 283 ? base::string16() |
| 283 : search_terms; | 284 : search_terms; |
| 284 } | 285 } |
| OLD | NEW |