| 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 "components/toolbar/toolbar_model_impl.h" | 5 #include "components/toolbar/toolbar_model_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.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 "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "components/prefs/pref_service.h" | 11 #include "components/prefs/pref_service.h" |
| 12 #include "components/security_state/security_state_model.h" | 12 #include "components/security_state/core/security_state.h" |
| 13 #include "components/strings/grit/components_strings.h" | 13 #include "components/strings/grit/components_strings.h" |
| 14 #include "components/toolbar/toolbar_model_delegate.h" | 14 #include "components/toolbar/toolbar_model_delegate.h" |
| 15 #include "components/url_formatter/elide_url.h" | 15 #include "components/url_formatter/elide_url.h" |
| 16 #include "components/url_formatter/url_formatter.h" | 16 #include "components/url_formatter/url_formatter.h" |
| 17 #include "net/cert/cert_status_flags.h" | 17 #include "net/cert/cert_status_flags.h" |
| 18 #include "net/cert/x509_certificate.h" | 18 #include "net/cert/x509_certificate.h" |
| 19 #include "net/ssl/ssl_connection_status_flags.h" | 19 #include "net/ssl/ssl_connection_status_flags.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/gfx/text_elider.h" | 21 #include "ui/gfx/text_elider.h" |
| 22 #include "ui/gfx/vector_icons_public.h" | 22 #include "ui/gfx/vector_icons_public.h" |
| 23 | 23 |
| 24 using security_state::SecurityStateModel; | |
| 25 | |
| 26 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate, | 24 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate, |
| 27 size_t max_url_display_chars) | 25 size_t max_url_display_chars) |
| 28 : delegate_(delegate), max_url_display_chars_(max_url_display_chars) { | 26 : delegate_(delegate), max_url_display_chars_(max_url_display_chars) { |
| 29 DCHECK(delegate_); | 27 DCHECK(delegate_); |
| 30 } | 28 } |
| 31 | 29 |
| 32 ToolbarModelImpl::~ToolbarModelImpl() { | 30 ToolbarModelImpl::~ToolbarModelImpl() { |
| 33 } | 31 } |
| 34 | 32 |
| 35 // ToolbarModelImpl Implementation. | 33 // ToolbarModelImpl Implementation. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 54 return gfx::TruncateString(formatted_text, max_url_display_chars_ - 1, | 52 return gfx::TruncateString(formatted_text, max_url_display_chars_ - 1, |
| 55 gfx::CHARACTER_BREAK) + | 53 gfx::CHARACTER_BREAK) + |
| 56 gfx::kEllipsisUTF16; | 54 gfx::kEllipsisUTF16; |
| 57 } | 55 } |
| 58 | 56 |
| 59 GURL ToolbarModelImpl::GetURL() const { | 57 GURL ToolbarModelImpl::GetURL() const { |
| 60 GURL url; | 58 GURL url; |
| 61 return delegate_->GetURL(&url) ? url : GURL(url::kAboutBlankURL); | 59 return delegate_->GetURL(&url) ? url : GURL(url::kAboutBlankURL); |
| 62 } | 60 } |
| 63 | 61 |
| 64 SecurityStateModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( | 62 security_state::SecurityLevel ToolbarModelImpl::GetSecurityLevel( |
| 65 bool ignore_editing) const { | 63 bool ignore_editing) const { |
| 66 // When editing or empty, assume no security style. | 64 // When editing or empty, assume no security style. |
| 67 return ((input_in_progress() && !ignore_editing) || !ShouldDisplayURL()) | 65 return ((input_in_progress() && !ignore_editing) || !ShouldDisplayURL()) |
| 68 ? SecurityStateModel::NONE | 66 ? security_state::NONE |
| 69 : delegate_->GetSecurityLevel(); | 67 : delegate_->GetSecurityLevel(); |
| 70 } | 68 } |
| 71 | 69 |
| 72 gfx::VectorIconId ToolbarModelImpl::GetVectorIcon() const { | 70 gfx::VectorIconId ToolbarModelImpl::GetVectorIcon() const { |
| 73 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 71 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 74 switch (GetSecurityLevel(false)) { | 72 switch (GetSecurityLevel(false)) { |
| 75 case SecurityStateModel::NONE: | 73 case security_state::NONE: |
| 76 case SecurityStateModel::HTTP_SHOW_WARNING: | 74 case security_state::HTTP_SHOW_WARNING: |
| 77 return gfx::VectorIconId::LOCATION_BAR_HTTP; | 75 return gfx::VectorIconId::LOCATION_BAR_HTTP; |
| 78 case SecurityStateModel::EV_SECURE: | 76 case security_state::EV_SECURE: |
| 79 case SecurityStateModel::SECURE: | 77 case security_state::SECURE: |
| 80 return gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID; | 78 return gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID; |
| 81 case SecurityStateModel::SECURITY_WARNING: | 79 case security_state::SECURITY_WARNING: |
| 82 // Surface Dubious as Neutral. | 80 // Surface Dubious as Neutral. |
| 83 return gfx::VectorIconId::LOCATION_BAR_HTTP; | 81 return gfx::VectorIconId::LOCATION_BAR_HTTP; |
| 84 case SecurityStateModel::SECURE_WITH_POLICY_INSTALLED_CERT: | 82 case security_state::SECURE_WITH_POLICY_INSTALLED_CERT: |
| 85 return gfx::VectorIconId::BUSINESS; | 83 return gfx::VectorIconId::BUSINESS; |
| 86 case SecurityStateModel::DANGEROUS: | 84 case security_state::DANGEROUS: |
| 87 return gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID; | 85 return gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID; |
| 88 } | 86 } |
| 89 #endif | 87 #endif |
| 90 NOTREACHED(); | 88 NOTREACHED(); |
| 91 return gfx::VectorIconId::VECTOR_ICON_NONE; | 89 return gfx::VectorIconId::VECTOR_ICON_NONE; |
| 92 } | 90 } |
| 93 | 91 |
| 94 base::string16 ToolbarModelImpl::GetEVCertName() const { | 92 base::string16 ToolbarModelImpl::GetEVCertName() const { |
| 95 if (GetSecurityLevel(false) != SecurityStateModel::EV_SECURE) | 93 if (GetSecurityLevel(false) != security_state::EV_SECURE) |
| 96 return base::string16(); | 94 return base::string16(); |
| 97 | 95 |
| 98 // Note: cert is guaranteed non-NULL or the security level would be NONE. | 96 // Note: cert is guaranteed non-NULL or the security level would be NONE. |
| 99 scoped_refptr<net::X509Certificate> cert = delegate_->GetCertificate(); | 97 scoped_refptr<net::X509Certificate> cert = delegate_->GetCertificate(); |
| 100 DCHECK(cert.get()); | 98 DCHECK(cert.get()); |
| 101 | 99 |
| 102 // EV are required to have an organization name and country. | 100 // EV are required to have an organization name and country. |
| 103 DCHECK(!cert->subject().organization_names.empty()); | 101 DCHECK(!cert->subject().organization_names.empty()); |
| 104 DCHECK(!cert->subject().country_name.empty()); | 102 DCHECK(!cert->subject().country_name.empty()); |
| 105 return l10n_util::GetStringFUTF16( | 103 return l10n_util::GetStringFUTF16( |
| 106 IDS_SECURE_CONNECTION_EV, | 104 IDS_SECURE_CONNECTION_EV, |
| 107 base::UTF8ToUTF16(cert->subject().organization_names[0]), | 105 base::UTF8ToUTF16(cert->subject().organization_names[0]), |
| 108 base::UTF8ToUTF16(cert->subject().country_name)); | 106 base::UTF8ToUTF16(cert->subject().country_name)); |
| 109 } | 107 } |
| 110 | 108 |
| 111 base::string16 ToolbarModelImpl::GetSecureVerboseText() const { | 109 base::string16 ToolbarModelImpl::GetSecureVerboseText() const { |
| 112 switch (GetSecurityLevel(false)) { | 110 switch (GetSecurityLevel(false)) { |
| 113 case SecurityStateModel::HTTP_SHOW_WARNING: | 111 case security_state::HTTP_SHOW_WARNING: |
| 114 return l10n_util::GetStringUTF16(IDS_NOT_SECURE_VERBOSE_STATE); | 112 return l10n_util::GetStringUTF16(IDS_NOT_SECURE_VERBOSE_STATE); |
| 115 case SecurityStateModel::SECURE: | 113 case security_state::SECURE: |
| 116 return l10n_util::GetStringUTF16(IDS_SECURE_VERBOSE_STATE); | 114 return l10n_util::GetStringUTF16(IDS_SECURE_VERBOSE_STATE); |
| 117 case SecurityStateModel::DANGEROUS: | 115 case security_state::DANGEROUS: |
| 118 return l10n_util::GetStringUTF16(delegate_->FailsMalwareCheck() | 116 return l10n_util::GetStringUTF16(delegate_->FailsMalwareCheck() |
| 119 ? IDS_DANGEROUS_VERBOSE_STATE | 117 ? IDS_DANGEROUS_VERBOSE_STATE |
| 120 : IDS_NOT_SECURE_VERBOSE_STATE); | 118 : IDS_NOT_SECURE_VERBOSE_STATE); |
| 121 default: | 119 default: |
| 122 return base::string16(); | 120 return base::string16(); |
| 123 } | 121 } |
| 124 } | 122 } |
| 125 | 123 |
| 126 bool ToolbarModelImpl::ShouldDisplayURL() const { | 124 bool ToolbarModelImpl::ShouldDisplayURL() const { |
| 127 return delegate_->ShouldDisplayURL(); | 125 return delegate_->ShouldDisplayURL(); |
| 128 } | 126 } |
| OLD | NEW |