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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_model_impl.cc

Issue 14259008: Instant Extended: Add prominent search term support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
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 "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/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
(...skipping 23 matching lines...) Expand all
34 #include "net/cert/x509_certificate.h" 34 #include "net/cert/x509_certificate.h"
35 #include "ui/base/l10n/l10n_util.h" 35 #include "ui/base/l10n/l10n_util.h"
36 36
37 using content::NavigationController; 37 using content::NavigationController;
38 using content::NavigationEntry; 38 using content::NavigationEntry;
39 using content::SSLStatus; 39 using content::SSLStatus;
40 using content::WebContents; 40 using content::WebContents;
41 41
42 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate) 42 ToolbarModelImpl::ToolbarModelImpl(ToolbarModelDelegate* delegate)
43 : delegate_(delegate), 43 : delegate_(delegate),
44 input_in_progress_(false) { 44 input_in_progress_(false),
45 is_prominent_search_term_ui_supported_(false) {
45 } 46 }
46 47
47 ToolbarModelImpl::~ToolbarModelImpl() { 48 ToolbarModelImpl::~ToolbarModelImpl() {
48 } 49 }
49 50
50 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevelForWebContents( 51 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevelForWebContents(
51 content::WebContents* web_contents) { 52 content::WebContents* web_contents) {
52 if (!web_contents) 53 if (!web_contents)
53 return NONE; 54 return NONE;
54 55
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":"); 102 url = url.IsStandard() ? url.GetOrigin() : GURL(url.scheme() + ":");
102 // Note that we can't unescape spaces here, because if the user copies this 103 // Note that we can't unescape spaces here, because if the user copies this
103 // and pastes it into another program, that program may think the URL ends at 104 // and pastes it into another program, that program may think the URL ends at
104 // the space. 105 // the space.
105 return AutocompleteInput::FormattedStringWithEquivalentMeaning( 106 return AutocompleteInput::FormattedStringWithEquivalentMeaning(
106 url, net::FormatUrl(url, languages, net::kFormatUrlOmitAll, 107 url, net::FormatUrl(url, languages, net::kFormatUrlOmitAll,
107 net::UnescapeRule::NORMAL, NULL, NULL, NULL)); 108 net::UnescapeRule::NORMAL, NULL, NULL, NULL));
108 } 109 }
109 110
110 string16 ToolbarModelImpl::GetCorpusNameForMobile() const { 111 string16 ToolbarModelImpl::GetCorpusNameForMobile() const {
111 if (!WouldReplaceSearchURLWithSearchTerms()) 112 if (GetSearchTermType() == SEARCH_TERM_NONE)
112 return string16(); 113 return string16();
113 GURL url(GetURL()); 114 GURL url(GetURL());
114 // If there is a query in the url fragment look for the corpus name there, 115 // If there is a query in the url fragment look for the corpus name there,
115 // otherwise look for the corpus name in the query parameters. 116 // otherwise look for the corpus name in the query parameters.
116 const std::string& query_str(google_util::HasGoogleSearchQueryParam( 117 const std::string& query_str(google_util::HasGoogleSearchQueryParam(
117 url.ref()) ? url.ref() : url.query()); 118 url.ref()) ? url.ref() : url.query());
118 url_parse::Component query(0, query_str.length()), key, value; 119 url_parse::Component query(0, query_str.length()), key, value;
119 const char kChipKey[] = "sboxchip"; 120 const char kChipKey[] = "sboxchip";
120 while (url_parse::ExtractQueryKeyValue(query_str.c_str(), &query, &key, 121 while (url_parse::ExtractQueryKeyValue(query_str.c_str(), &query, &key,
121 &value)) { 122 &value)) {
(...skipping 10 matching lines...) Expand all
132 const NavigationController* navigation_controller = GetNavigationController(); 133 const NavigationController* navigation_controller = GetNavigationController();
133 if (navigation_controller) { 134 if (navigation_controller) {
134 const NavigationEntry* entry = navigation_controller->GetVisibleEntry(); 135 const NavigationEntry* entry = navigation_controller->GetVisibleEntry();
135 if (entry) 136 if (entry)
136 return ShouldDisplayURL() ? entry->GetVirtualURL() : GURL(); 137 return ShouldDisplayURL() ? entry->GetVirtualURL() : GURL();
137 } 138 }
138 139
139 return GURL(chrome::kAboutBlankURL); 140 return GURL(chrome::kAboutBlankURL);
140 } 141 }
141 142
142 bool ToolbarModelImpl::WouldReplaceSearchURLWithSearchTerms() const { 143 ToolbarModel::SearchTermType ToolbarModelImpl::GetSearchTermType() const {
143 return !GetSearchTerms().empty(); 144 string16 search_terms = GetSearchTerms();
145 if (search_terms.empty())
146 return SEARCH_TERM_NONE;
147 if (AreProminentSearchTerms(search_terms))
sreeram 2013/04/23 22:56:45 This now runs the classifier for the second time (
sail 2013/04/24 00:22:23 Changing the API won't reduce the number of times
sail 2013/04/25 02:08:16 Done. Gah, I obviously didn't understand this at a
148 return SEARCH_TERM_PROMINENT;
149 return SEARCH_TERM_NORMAL;
150 }
151
152 void ToolbarModelImpl::SetIsProminentSearchTermUISupported(bool value) {
153 is_prominent_search_term_ui_supported_ = value;
144 } 154 }
145 155
146 bool ToolbarModelImpl::ShouldDisplayURL() const { 156 bool ToolbarModelImpl::ShouldDisplayURL() const {
147 // Note: The order here is important. 157 // Note: The order here is important.
148 // - The WebUI test must come before the extension scheme test because there 158 // - The WebUI test must come before the extension scheme test because there
149 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In 159 // can be WebUIs that have extension schemes (e.g. the bookmark manager). In
150 // that case, we should prefer what the WebUI instance says. 160 // that case, we should prefer what the WebUI instance says.
151 // - The view-source test must come before the NTP test because of the case 161 // - The view-source test must come before the NTP test because of the case
152 // of view-source:chrome://newtab, which should display its URL despite what 162 // of view-source:chrome://newtab, which should display its URL despite what
153 // chrome://newtab says. 163 // chrome://newtab says.
(...skipping 22 matching lines...) Expand all
176 } 186 }
177 187
178 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel() const { 188 ToolbarModel::SecurityLevel ToolbarModelImpl::GetSecurityLevel() const {
179 if (input_in_progress_) // When editing, assume no security style. 189 if (input_in_progress_) // When editing, assume no security style.
180 return NONE; 190 return NONE;
181 191
182 return GetSecurityLevelForWebContents(delegate_->GetActiveWebContents()); 192 return GetSecurityLevelForWebContents(delegate_->GetActiveWebContents());
183 } 193 }
184 194
185 int ToolbarModelImpl::GetIcon() const { 195 int ToolbarModelImpl::GetIcon() const {
186 if (WouldReplaceSearchURLWithSearchTerms()) 196 SecurityLevel security_level = GetSecurityLevel();
197 SearchTermType search_term_type = GetSearchTermType();
198 if (search_term_type == SEARCH_TERM_NORMAL ||
199 (search_term_type == SEARCH_TERM_PROMINENT &&
200 security_level != SECURITY_WARNING)) {
sreeram 2013/04/23 22:56:45 Do we need the security_level check? AreProminentS
sail 2013/04/24 00:22:23 This check is needed when the search term is URL s
187 return IDR_OMNIBOX_SEARCH; 201 return IDR_OMNIBOX_SEARCH;
202 }
188 static int icon_ids[NUM_SECURITY_LEVELS] = { 203 static int icon_ids[NUM_SECURITY_LEVELS] = {
189 IDR_LOCATION_BAR_HTTP, 204 IDR_LOCATION_BAR_HTTP,
190 IDR_OMNIBOX_HTTPS_VALID, 205 IDR_OMNIBOX_HTTPS_VALID,
191 IDR_OMNIBOX_HTTPS_VALID, 206 IDR_OMNIBOX_HTTPS_VALID,
192 IDR_OMNIBOX_HTTPS_WARNING, 207 IDR_OMNIBOX_HTTPS_WARNING,
193 IDR_OMNIBOX_HTTPS_INVALID, 208 IDR_OMNIBOX_HTTPS_INVALID,
194 }; 209 };
195 DCHECK(arraysize(icon_ids) == NUM_SECURITY_LEVELS); 210 DCHECK(arraysize(icon_ids) == NUM_SECURITY_LEVELS);
196 return icon_ids[GetSecurityLevel()]; 211 return icon_ids[security_level];
197 } 212 }
198 213
199 string16 ToolbarModelImpl::GetEVCertName() const { 214 string16 ToolbarModelImpl::GetEVCertName() const {
200 DCHECK_EQ(GetSecurityLevel(), EV_SECURE); 215 DCHECK_EQ(GetSecurityLevel(), EV_SECURE);
201 scoped_refptr<net::X509Certificate> cert; 216 scoped_refptr<net::X509Certificate> cert;
202 // Note: Navigation controller and active entry are guaranteed non-NULL or 217 // Note: Navigation controller and active entry are guaranteed non-NULL or
203 // the security level would be NONE. 218 // the security level would be NONE.
204 content::CertStore::GetInstance()->RetrieveCert( 219 content::CertStore::GetInstance()->RetrieveCert(
205 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert); 220 GetNavigationController()->GetVisibleEntry()->GetSSL().cert_id, &cert);
206 return GetEVCertName(*cert); 221 return GetEVCertName(*cert);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 253 }
239 254
240 Profile* ToolbarModelImpl::GetProfile() const { 255 Profile* ToolbarModelImpl::GetProfile() const {
241 NavigationController* navigation_controller = GetNavigationController(); 256 NavigationController* navigation_controller = GetNavigationController();
242 return navigation_controller ? 257 return navigation_controller ?
243 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) : 258 Profile::FromBrowserContext(navigation_controller->GetBrowserContext()) :
244 NULL; 259 NULL;
245 } 260 }
246 261
247 string16 ToolbarModelImpl::GetSearchTerms() const { 262 string16 ToolbarModelImpl::GetSearchTerms() const {
248 const WebContents* contents = delegate_->GetActiveWebContents(); 263 string16 search_terms =
249 string16 search_terms = chrome::GetSearchTerms(contents); 264 chrome::GetSearchTerms(delegate_->GetActiveWebContents());
250 265
251 // Don't extract search terms that the omnibox would treat as a navigation. 266 if (!is_prominent_search_term_ui_supported_ &&
252 // This might confuse users into believing that the search terms were the 267 AreProminentSearchTerms(search_terms)) {
253 // URL of the current page, and could cause problems if users hit enter in 268 return string16();
254 // the omnibox expecting to reload the page.
255 if (!search_terms.empty()) {
256 AutocompleteMatch match;
257 Profile* profile =
258 Profile::FromBrowserContext(contents->GetBrowserContext());
259 AutocompleteClassifierFactory::GetForProfile(profile)->Classify(
260 search_terms, false, false, &match, NULL);
261 if (!AutocompleteMatch::IsSearchType(match.type))
262 search_terms.clear();
263 } 269 }
264 270
265 return search_terms; 271 return search_terms;
266 } 272 }
273
274 bool ToolbarModelImpl::AreProminentSearchTerms(
275 const string16& search_terms) const {
276 if (search_terms.empty())
277 return false;
278 if (GetSecurityLevel() == SECURITY_WARNING)
279 return true;
sreeram 2013/04/23 22:56:45 Shouldn't this be "security_level != EV_SECURE &&
sail 2013/04/24 00:22:23 Done.
280
281 AutocompleteMatch match;
282 Profile* profile = Profile::FromBrowserContext(
283 delegate_->GetActiveWebContents()->GetBrowserContext());
284 AutocompleteClassifierFactory::GetForProfile(profile)->Classify(
285 search_terms, false, false, &match, NULL);
286 if (!AutocompleteMatch::IsSearchType(match.type))
287 return true;
288
289 return false;
290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698