| 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/core/security_state.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_icon_types.h" |
| 23 |
| 24 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 25 #include "components/toolbar/vector_icons.h" // nogncheck |
| 26 #endif |
| 23 | 27 |
| 24 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate, | 28 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate, |
| 25 size_t max_url_display_chars) | 29 size_t max_url_display_chars) |
| 26 : delegate_(delegate), max_url_display_chars_(max_url_display_chars) { | 30 : delegate_(delegate), max_url_display_chars_(max_url_display_chars) { |
| 27 DCHECK(delegate_); | 31 DCHECK(delegate_); |
| 28 } | 32 } |
| 29 | 33 |
| 30 ToolbarModelImpl::~ToolbarModelImpl() { | 34 ToolbarModelImpl::~ToolbarModelImpl() { |
| 31 } | 35 } |
| 32 | 36 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 60 } | 64 } |
| 61 | 65 |
| 62 security_state::SecurityLevel ToolbarModelImpl::GetSecurityLevel( | 66 security_state::SecurityLevel ToolbarModelImpl::GetSecurityLevel( |
| 63 bool ignore_editing) const { | 67 bool ignore_editing) const { |
| 64 // When editing or empty, assume no security style. | 68 // When editing or empty, assume no security style. |
| 65 return ((input_in_progress() && !ignore_editing) || !ShouldDisplayURL()) | 69 return ((input_in_progress() && !ignore_editing) || !ShouldDisplayURL()) |
| 66 ? security_state::NONE | 70 ? security_state::NONE |
| 67 : delegate_->GetSecurityLevel(); | 71 : delegate_->GetSecurityLevel(); |
| 68 } | 72 } |
| 69 | 73 |
| 70 gfx::VectorIconId ToolbarModelImpl::GetVectorIcon() const { | 74 const gfx::VectorIcon& ToolbarModelImpl::GetVectorIcon() const { |
| 71 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 75 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 72 const auto icon_override = delegate_->GetVectorIconOverride(); | 76 const auto icon_override = delegate_->GetVectorIconOverride(); |
| 73 if (icon_override != gfx::VectorIconId::VECTOR_ICON_NONE) | 77 if (icon_override) |
| 74 return icon_override; | 78 return *icon_override; |
| 75 | 79 |
| 76 switch (GetSecurityLevel(false)) { | 80 switch (GetSecurityLevel(false)) { |
| 77 case security_state::NONE: | 81 case security_state::NONE: |
| 78 case security_state::HTTP_SHOW_WARNING: | 82 case security_state::HTTP_SHOW_WARNING: |
| 79 return gfx::VectorIconId::LOCATION_BAR_HTTP; | 83 return toolbar::kHttpIcon; |
| 80 case security_state::EV_SECURE: | 84 case security_state::EV_SECURE: |
| 81 case security_state::SECURE: | 85 case security_state::SECURE: |
| 82 return gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID; | 86 return toolbar::kHttpsValidIcon; |
| 83 case security_state::SECURITY_WARNING: | 87 case security_state::SECURITY_WARNING: |
| 84 // Surface Dubious as Neutral. | 88 // Surface Dubious as Neutral. |
| 85 return gfx::VectorIconId::LOCATION_BAR_HTTP; | 89 return toolbar::kHttpIcon; |
| 86 case security_state::SECURE_WITH_POLICY_INSTALLED_CERT: | 90 case security_state::SECURE_WITH_POLICY_INSTALLED_CERT: |
| 87 return gfx::VectorIconId::BUSINESS; | 91 return toolbar::kBusinessIcon; |
| 88 case security_state::DANGEROUS: | 92 case security_state::DANGEROUS: |
| 89 return gfx::VectorIconId::LOCATION_BAR_HTTPS_INVALID; | 93 return toolbar::kHttpsInvalidIcon; |
| 90 } | 94 } |
| 95 NOTREACHED(); |
| 96 return toolbar::kHttpIcon; |
| 97 #else |
| 98 NOTREACHED(); |
| 99 static const gfx::VectorIcon dummy = {}; |
| 100 return dummy; |
| 91 #endif | 101 #endif |
| 92 NOTREACHED(); | |
| 93 return gfx::VectorIconId::VECTOR_ICON_NONE; | |
| 94 } | 102 } |
| 95 | 103 |
| 96 base::string16 ToolbarModelImpl::GetEVCertName() const { | 104 base::string16 ToolbarModelImpl::GetEVCertName() const { |
| 97 if (GetSecurityLevel(false) != security_state::EV_SECURE) | 105 if (GetSecurityLevel(false) != security_state::EV_SECURE) |
| 98 return base::string16(); | 106 return base::string16(); |
| 99 | 107 |
| 100 // Note: cert is guaranteed non-NULL or the security level would be NONE. | 108 // Note: cert is guaranteed non-NULL or the security level would be NONE. |
| 101 scoped_refptr<net::X509Certificate> cert = delegate_->GetCertificate(); | 109 scoped_refptr<net::X509Certificate> cert = delegate_->GetCertificate(); |
| 102 DCHECK(cert.get()); | 110 DCHECK(cert.get()); |
| 103 | 111 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 121 ? IDS_DANGEROUS_VERBOSE_STATE | 129 ? IDS_DANGEROUS_VERBOSE_STATE |
| 122 : IDS_NOT_SECURE_VERBOSE_STATE); | 130 : IDS_NOT_SECURE_VERBOSE_STATE); |
| 123 default: | 131 default: |
| 124 return base::string16(); | 132 return base::string16(); |
| 125 } | 133 } |
| 126 } | 134 } |
| 127 | 135 |
| 128 bool ToolbarModelImpl::ShouldDisplayURL() const { | 136 bool ToolbarModelImpl::ShouldDisplayURL() const { |
| 129 return delegate_->ShouldDisplayURL(); | 137 return delegate_->ShouldDisplayURL(); |
| 130 } | 138 } |
| OLD | NEW |