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

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 67693004: Omnibox: Don't Let Users Escape Keyword Mode Accidentally (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 std::string(), 1201 std::string(),
1202 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, 1202 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED,
1203 false, 1203 false,
1204 input_.text(), 1204 input_.text(),
1205 string16(), 1205 string16(),
1206 input_.text(), 1206 input_.text(),
1207 did_not_accept_default_suggestion, 1207 did_not_accept_default_suggestion,
1208 std::string(), 1208 std::string(),
1209 &map); 1209 &map);
1210 } 1210 }
1211 const TemplateURL* keyword_url = NULL;
1211 if (!keyword_input_.text().empty()) { 1212 if (!keyword_input_.text().empty()) {
1212 const TemplateURL* keyword_url = providers_.GetKeywordProviderURL(); 1213 keyword_url = providers_.GetKeywordProviderURL();
1213 // We only create the verbatim search query match for a keyword 1214 // We only create the verbatim search query match for a keyword
1214 // if it's not an extension keyword. Extension keywords are handled 1215 // if it's not an extension keyword. Extension keywords are handled
1215 // in KeywordProvider::Start(). (Extensions are complicated...) 1216 // in KeywordProvider::Start(). (Extensions are complicated...)
1216 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond 1217 // Note: in this provider, SEARCH_OTHER_ENGINE must correspond
1217 // to the keyword verbatim search query. Do not create other matches 1218 // to the keyword verbatim search query. Do not create other matches
1218 // of type SEARCH_OTHER_ENGINE. 1219 // of type SEARCH_OTHER_ENGINE.
1219 if (keyword_url && 1220 if (keyword_url &&
1220 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) { 1221 (keyword_url->GetType() != TemplateURL::OMNIBOX_API_EXTENSION)) {
1221 bool keyword_relevance_from_server; 1222 bool keyword_relevance_from_server;
1222 const int keyword_verbatim_relevance = 1223 const int keyword_verbatim_relevance =
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 (!chrome::IsInstantExtendedAPIEnabled() || 1287 (!chrome::IsInstantExtendedAPIEnabled() ||
1287 (i->GetAdditionalInfo(kRelevanceFromServerKey) != kTrue))) { 1288 (i->GetAdditionalInfo(kRelevanceFromServerKey) != kTrue))) {
1288 continue; 1289 continue;
1289 } 1290 }
1290 1291
1291 ++num_suggestions; 1292 ++num_suggestions;
1292 } 1293 }
1293 1294
1294 matches_.push_back(*i); 1295 matches_.push_back(*i);
1295 } 1296 }
1297 if (keyword_url != NULL) {
1298 // When in keyword mode, make sure all matches are not associated with the
Peter Kasting 2013/11/15 03:03:34 Nit: are -> that are
Mark P 2013/11/15 17:36:33 Done.
1299 // keyword are not allowed to be the default match lest they cause the user
1300 // to break out of keyword mode. For reference, non-keyword matches are
1301 // queries to the default search engine and navsuggestions from any source.
1302 for (ACMatches::iterator it = matches_.begin(); it != matches_.end();
Peter Kasting 2013/11/15 03:03:34 Is this truly the best place for this code? Perha
Mark P 2013/11/15 17:36:33 Yes, I think this is the right place. As you say,
1303 ++it) {
1304 if (it->keyword != keyword_url->keyword())
1305 it->allowed_to_be_default_match = false;
Peter Kasting 2013/11/15 03:03:34 Thought experiment. Let's say the user types an e
Mark P 2013/11/15 17:36:33 What a dang tricky thought experiment. I'm going
1306 }
1307 }
1296 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.ConvertResultsTime", 1308 UMA_HISTOGRAM_TIMES("Omnibox.SearchProvider.ConvertResultsTime",
1297 base::TimeTicks::Now() - start_time); 1309 base::TimeTicks::Now() - start_time);
1298 } 1310 }
1299 1311
1300 ACMatches::const_iterator SearchProvider::FindTopMatch( 1312 ACMatches::const_iterator SearchProvider::FindTopMatch(
1301 bool autocomplete_result_will_reorder_for_default_match) const { 1313 bool autocomplete_result_will_reorder_for_default_match) const {
1302 if (!autocomplete_result_will_reorder_for_default_match) 1314 if (!autocomplete_result_will_reorder_for_default_match)
1303 return matches_.begin(); 1315 return matches_.begin();
1304 ACMatches::const_iterator it = matches_.begin(); 1316 ACMatches::const_iterator it = matches_.begin();
1305 while ((it != matches_.end()) && !it->allowed_to_be_default_match) 1317 while ((it != matches_.end()) && !it->allowed_to_be_default_match)
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1907 it->set_relevance(max_query_relevance); 1919 it->set_relevance(max_query_relevance);
1908 it->set_relevance_from_server(relevance_from_server); 1920 it->set_relevance_from_server(relevance_from_server);
1909 } 1921 }
1910 } 1922 }
1911 1923
1912 void SearchProvider::UpdateDone() { 1924 void SearchProvider::UpdateDone() {
1913 // We're done when the timer isn't running, there are no suggest queries 1925 // We're done when the timer isn't running, there are no suggest queries
1914 // pending, and we're not waiting on Instant. 1926 // pending, and we're not waiting on Instant.
1915 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); 1927 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0);
1916 } 1928 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698