| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 content::CertStore::GetInstance()->RetrieveCert(ssl.cert_id, NULL)) | 88 content::CertStore::GetInstance()->RetrieveCert(ssl.cert_id, NULL)) |
| 89 return EV_SECURE; | 89 return EV_SECURE; |
| 90 return SECURE; | 90 return SECURE; |
| 91 } | 91 } |
| 92 default: | 92 default: |
| 93 NOTREACHED(); | 93 NOTREACHED(); |
| 94 return NONE; | 94 return NONE; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 // static | |
| 99 base::string16 ToolbarModelImpl::GetEVCertName( | |
| 100 const net::X509Certificate& cert) { | |
| 101 // EV are required to have an organization name and country. | |
| 102 DCHECK(!cert.subject().organization_names.empty()); | |
| 103 DCHECK(!cert.subject().country_name.empty()); | |
| 104 | |
| 105 return l10n_util::GetStringFUTF16( | |
| 106 IDS_SECURE_CONNECTION_EV, | |
| 107 base::UTF8ToUTF16(cert.subject().organization_names[0]), | |
| 108 base::UTF8ToUTF16(cert.subject().country_name)); | |
| 109 } | |
| 110 | |
| 111 // ToolbarModelImpl Implementation. | 98 // ToolbarModelImpl Implementation. |
| 112 base::string16 ToolbarModelImpl::GetText() const { | 99 base::string16 ToolbarModelImpl::GetText() const { |
| 113 base::string16 search_terms(GetSearchTerms(false)); | 100 base::string16 search_terms(GetSearchTerms(false)); |
| 114 if (!search_terms.empty()) | 101 if (!search_terms.empty()) |
| 115 return search_terms; | 102 return search_terms; |
| 116 | 103 |
| 117 if (WouldOmitURLDueToOriginChip()) | 104 if (WouldOmitURLDueToOriginChip()) |
| 118 return base::string16(); | 105 return base::string16(); |
| 119 | 106 |
| 120 return GetFormattedURL(); | 107 return GetFormattedURL(NULL); |
| 121 } | 108 } |
| 122 | 109 |
| 123 base::string16 ToolbarModelImpl::GetFormattedURL() const { | 110 base::string16 ToolbarModelImpl::GetFormattedURL(size_t* prefix_end) const { |
| 124 std::string languages; // Empty if we don't have a |navigation_controller|. | 111 std::string languages; // Empty if we don't have a |navigation_controller|. |
| 125 Profile* profile = GetProfile(); | 112 Profile* profile = GetProfile(); |
| 126 if (profile) | 113 if (profile) |
| 127 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); | 114 languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 128 | 115 |
| 129 GURL url(GetURL()); | 116 GURL url(GetURL()); |
| 130 if (url.spec().length() > content::kMaxURLDisplayChars) | 117 if (url.spec().length() > content::kMaxURLDisplayChars) |
| 131 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); | 118 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); |
| 132 // Note that we can't unescape spaces here, because if the user copies this | 119 // Note that we can't unescape spaces here, because if the user copies this |
| 133 // and pastes it into another program, that program may think the URL ends at | 120 // and pastes it into another program, that program may think the URL ends at |
| 134 // the space. | 121 // the space. |
| 135 return AutocompleteInput::FormattedStringWithEquivalentMeaning( | 122 return AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 136 url, net::FormatUrl(url, languages, net::kFormatUrlOmitAll, | 123 url, net::FormatUrl(url, languages, net::kFormatUrlOmitAll, |
| 137 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); | 124 net::UnescapeRule::NORMAL, NULL, prefix_end, NULL)); |
| 138 } | 125 } |
| 139 | 126 |
| 140 base::string16 ToolbarModelImpl::GetCorpusNameForMobile() const { | 127 base::string16 ToolbarModelImpl::GetCorpusNameForMobile() const { |
| 141 if (!WouldPerformSearchTermReplacement(false)) | 128 if (!WouldPerformSearchTermReplacement(false)) |
| 142 return base::string16(); | 129 return base::string16(); |
| 143 GURL url(GetURL()); | 130 GURL url(GetURL()); |
| 144 // If there is a query in the url fragment look for the corpus name there, | 131 // If there is a query in the url fragment look for the corpus name there, |
| 145 // otherwise look for the corpus name in the query parameters. | 132 // otherwise look for the corpus name in the query parameters. |
| 146 const std::string& query_str(google_util::HasGoogleSearchQueryParam( | 133 const std::string& query_str(google_util::HasGoogleSearchQueryParam( |
| 147 url.ref()) ? url.ref() : url.query()); | 134 url.ref()) ? url.ref() : url.query()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 IDR_OMNIBOX_HTTPS_VALID, | 187 IDR_OMNIBOX_HTTPS_VALID, |
| 201 IDR_OMNIBOX_HTTPS_WARNING, | 188 IDR_OMNIBOX_HTTPS_WARNING, |
| 202 IDR_OMNIBOX_HTTPS_POLICY_WARNING, | 189 IDR_OMNIBOX_HTTPS_POLICY_WARNING, |
| 203 IDR_OMNIBOX_HTTPS_INVALID, | 190 IDR_OMNIBOX_HTTPS_INVALID, |
| 204 }; | 191 }; |
| 205 DCHECK(arraysize(icon_ids) == NUM_SECURITY_LEVELS); | 192 DCHECK(arraysize(icon_ids) == NUM_SECURITY_LEVELS); |
| 206 return icon_ids[level]; | 193 return icon_ids[level]; |
| 207 } | 194 } |
| 208 | 195 |
| 209 base::string16 ToolbarModelImpl::GetEVCertName() const { | 196 base::string16 ToolbarModelImpl::GetEVCertName() const { |
| 210 DCHECK_EQ(EV_SECURE, GetSecurityLevel(false)); | 197 if (GetSecurityLevel(false) != EV_SECURE) |
| 211 scoped_refptr<net::X509Certificate> cert; | 198 return base::string16(); |
| 199 |
| 212 // Note: Navigation controller and active entry are guaranteed non-NULL or | 200 // Note: Navigation controller and active entry are guaranteed non-NULL or |
| 213 // the security level would be NONE. | 201 // the security level would be NONE. |
| 202 scoped_refptr<net::X509Certificate> cert; |
| 214 content::CertStore::GetInstance()->RetrieveCert( | 203 content::CertStore::GetInstance()->RetrieveCert( |
| 215 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); | 204 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); |
| 216 return GetEVCertName(*cert.get()); | 205 |
| 206 // EV are required to have an organization name and country. |
| 207 DCHECK(!cert->subject().organization_names.empty()); |
| 208 DCHECK(!cert->subject().country_name.empty()); |
| 209 return l10n_util::GetStringFUTF16( |
| 210 IDS_SECURE_CONNECTION_EV, |
| 211 base::UTF8ToUTF16(cert->subject().organization_names[0]), |
| 212 base::UTF8ToUTF16(cert->subject().country_name)); |
| 217 } | 213 } |
| 218 | 214 |
| 219 bool ToolbarModelImpl::ShouldDisplayURL() const { | 215 bool ToolbarModelImpl::ShouldDisplayURL() const { |
| 220 // Note: The order here is important. | 216 // Note: The order here is important. |
| 221 // - The WebUI test must come before the extension scheme test because there | 217 // - The WebUI test must come before the extension scheme test because there |
| 222 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In | 218 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In |
| 223 // that case, we should prefer what the WebUI instance says. | 219 // that case, we should prefer what the WebUI instance says. |
| 224 // - The view-source test must come before the NTP test because of the case | 220 // - The view-source test must come before the NTP test because of the case |
| 225 // of view-source:chrome://newtab, which should display its URL despite what | 221 // of view-source:chrome://newtab, which should display its URL despite what |
| 226 // chrome://newtab says. | 222 // chrome://newtab says. |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 if (entry && | 326 if (entry && |
| 331 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) | 327 google_util::StartsWithCommandLineGoogleBaseURL(entry->GetVirtualURL())) |
| 332 return search_terms; | 328 return search_terms; |
| 333 | 329 |
| 334 // Otherwise, extract search terms for HTTPS pages that do not have a security | 330 // Otherwise, extract search terms for HTTPS pages that do not have a security |
| 335 // error. | 331 // error. |
| 336 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); | 332 ToolbarModel::SecurityLevel security_level = GetSecurityLevel(ignore_editing); |
| 337 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? | 333 return ((security_level == NONE) || (security_level == SECURITY_ERROR)) ? |
| 338 base::string16() : search_terms; | 334 base::string16() : search_terms; |
| 339 } | 335 } |
| OLD | NEW |