Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: components/toolbar/toolbar_model_impl.cc

Issue 2232863002: Remove search::GetSearchTerms since it always returns empty string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_query_extract
Patch Set: Android Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/toolbar/toolbar_model_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 16 matching lines...) Expand all
27 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate, 27 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate,
28 size_t max_url_display_chars) 28 size_t max_url_display_chars)
29 : delegate_(delegate), max_url_display_chars_(max_url_display_chars) { 29 : delegate_(delegate), max_url_display_chars_(max_url_display_chars) {
30 DCHECK(delegate_); 30 DCHECK(delegate_);
31 } 31 }
32 32
33 ToolbarModelImpl::~ToolbarModelImpl() { 33 ToolbarModelImpl::~ToolbarModelImpl() {
34 } 34 }
35 35
36 // ToolbarModelImpl Implementation. 36 // ToolbarModelImpl Implementation.
37 base::string16 ToolbarModelImpl::GetText() const {
38 base::string16 search_terms(GetSearchTerms(false));
39 if (!search_terms.empty())
40 return search_terms;
41
42 return GetFormattedURL(NULL);
43 }
44
45 base::string16 ToolbarModelImpl::GetFormattedURL(size_t* prefix_end) const { 37 base::string16 ToolbarModelImpl::GetFormattedURL(size_t* prefix_end) const {
46 GURL url(GetURL()); 38 GURL url(GetURL());
47 // Note that we can't unescape spaces here, because if the user copies this 39 // Note that we can't unescape spaces here, because if the user copies this
48 // and pastes it into another program, that program may think the URL ends at 40 // and pastes it into another program, that program may think the URL ends at
49 // the space. 41 // the space.
50 const base::string16 formatted_text = 42 const base::string16 formatted_text =
51 delegate_->FormattedStringWithEquivalentMeaning( 43 delegate_->FormattedStringWithEquivalentMeaning(
52 url, url_formatter::FormatUrl( 44 url, url_formatter::FormatUrl(
53 url, url_formatter::kFormatUrlOmitAll, 45 url, url_formatter::kFormatUrlOmitAll,
54 net::UnescapeRule::NORMAL, nullptr, prefix_end, nullptr)); 46 net::UnescapeRule::NORMAL, nullptr, prefix_end, nullptr));
55 if (formatted_text.length() <= max_url_display_chars_) 47 if (formatted_text.length() <= max_url_display_chars_)
56 return formatted_text; 48 return formatted_text;
57 49
58 // Truncating the URL breaks editing and then pressing enter, but hopefully 50 // Truncating the URL breaks editing and then pressing enter, but hopefully
59 // people won't try to do much with such enormous URLs anyway. If this becomes 51 // people won't try to do much with such enormous URLs anyway. If this becomes
60 // a real problem, we could perhaps try to keep some sort of different "elided 52 // a real problem, we could perhaps try to keep some sort of different "elided
61 // visible URL" where editing affects and reloads the "real underlying URL", 53 // visible URL" where editing affects and reloads the "real underlying URL",
62 // but this seems very tricky for little gain. 54 // but this seems very tricky for little gain.
63 return gfx::TruncateString(formatted_text, max_url_display_chars_ - 1, 55 return gfx::TruncateString(formatted_text, max_url_display_chars_ - 1,
64 gfx::CHARACTER_BREAK) + 56 gfx::CHARACTER_BREAK) +
65 gfx::kEllipsisUTF16; 57 gfx::kEllipsisUTF16;
66 } 58 }
67 59
68 GURL ToolbarModelImpl::GetURL() const { 60 GURL ToolbarModelImpl::GetURL() const {
69 GURL url; 61 GURL url;
70 return delegate_->GetURL(&url) ? url : GURL(url::kAboutBlankURL); 62 return delegate_->GetURL(&url) ? url : GURL(url::kAboutBlankURL);
71 } 63 }
72 64
73 bool ToolbarModelImpl::WouldPerformSearchTermReplacement(
74 bool ignore_editing) const {
75 return !GetSearchTerms(ignore_editing).empty();
76 }
77
78 SecurityStateModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel( 65 SecurityStateModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel(
79 bool ignore_editing) const { 66 bool ignore_editing) const {
80 // When editing or empty, assume no security style. 67 // When editing or empty, assume no security style.
81 return ((input_in_progress() && !ignore_editing) || !ShouldDisplayURL()) 68 return ((input_in_progress() && !ignore_editing) || !ShouldDisplayURL())
82 ? SecurityStateModel::NONE 69 ? SecurityStateModel::NONE
83 : delegate_->GetSecurityLevel(); 70 : delegate_->GetSecurityLevel();
84 } 71 }
85 72
86 int ToolbarModelImpl::GetIcon() const { 73 int ToolbarModelImpl::GetIcon() const {
87 switch (GetSecurityLevel(false)) { 74 switch (GetSecurityLevel(false)) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 DCHECK(!cert->subject().country_name.empty()); 125 DCHECK(!cert->subject().country_name.empty());
139 return l10n_util::GetStringFUTF16( 126 return l10n_util::GetStringFUTF16(
140 IDS_SECURE_CONNECTION_EV, 127 IDS_SECURE_CONNECTION_EV,
141 base::UTF8ToUTF16(cert->subject().organization_names[0]), 128 base::UTF8ToUTF16(cert->subject().organization_names[0]),
142 base::UTF8ToUTF16(cert->subject().country_name)); 129 base::UTF8ToUTF16(cert->subject().country_name));
143 } 130 }
144 131
145 bool ToolbarModelImpl::ShouldDisplayURL() const { 132 bool ToolbarModelImpl::ShouldDisplayURL() const {
146 return delegate_->ShouldDisplayURL(); 133 return delegate_->ShouldDisplayURL();
147 } 134 }
148
149 base::string16 ToolbarModelImpl::GetSearchTerms(bool ignore_editing) const {
150 if (!url_replacement_enabled() || (input_in_progress() && !ignore_editing))
151 return base::string16();
152
153 return delegate_->GetSearchTerms(GetSecurityLevel(ignore_editing));
154 }
OLDNEW
« no previous file with comments | « components/toolbar/toolbar_model_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698