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

Side by Side Diff: components/omnibox/browser/search_suggestion_parser.cc

Issue 1855423003: Interpret '?' and Ctrl-K or Ctrl-E as putting omnibox in keyword search mode for Default Search Pro… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed forced queries using '?'. Removed Ctrl-K preserving the user's keyword if they're already … Created 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/omnibox/browser/search_suggestion_parser.h" 5 #include "components/omnibox/browser/search_suggestion_parser.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 } 450 }
451 451
452 // Clear the previous results now that new results are available. 452 // Clear the previous results now that new results are available.
453 results->suggest_results.clear(); 453 results->suggest_results.clear();
454 results->navigation_results.clear(); 454 results->navigation_results.clear();
455 results->answers_image_urls.clear(); 455 results->answers_image_urls.clear();
456 456
457 base::string16 suggestion; 457 base::string16 suggestion;
458 std::string type; 458 std::string type;
459 int relevance = default_result_relevance; 459 int relevance = default_result_relevance;
460 // Prohibit navsuggest in FORCED_QUERY mode. Users wants queries, not URLs.
461 const bool allow_navsuggest =
462 input.type() != metrics::OmniboxInputType::FORCED_QUERY;
463 const base::string16& trimmed_input = 460 const base::string16& trimmed_input =
464 base::CollapseWhitespace(input.text(), false); 461 base::CollapseWhitespace(input.text(), false);
465 for (size_t index = 0; results_list->GetString(index, &suggestion); ++index) { 462 for (size_t index = 0; results_list->GetString(index, &suggestion); ++index) {
466 // Google search may return empty suggestions for weird input characters, 463 // Google search may return empty suggestions for weird input characters,
467 // they make no sense at all and can cause problems in our code. 464 // they make no sense at all and can cause problems in our code.
468 if (suggestion.empty()) 465 if (suggestion.empty())
469 continue; 466 continue;
470 467
471 // Apply valid suggested relevance scores; discard invalid lists. 468 // Apply valid suggested relevance scores; discard invalid lists.
472 if (relevances != NULL && !relevances->GetInteger(index, &relevance)) 469 if (relevances != NULL && !relevances->GetInteger(index, &relevance))
473 relevances = NULL; 470 relevances = NULL;
474 AutocompleteMatchType::Type match_type = 471 AutocompleteMatchType::Type match_type =
475 AutocompleteMatchType::SEARCH_SUGGEST; 472 AutocompleteMatchType::SEARCH_SUGGEST;
476 if (types && types->GetString(index, &type)) 473 if (types && types->GetString(index, &type))
477 match_type = GetAutocompleteMatchType(type); 474 match_type = GetAutocompleteMatchType(type);
478 const base::DictionaryValue* suggestion_detail = NULL; 475 const base::DictionaryValue* suggestion_detail = NULL;
479 std::string deletion_url; 476 std::string deletion_url;
480 477
481 if (suggestion_details && 478 if (suggestion_details &&
482 suggestion_details->GetDictionary(index, &suggestion_detail)) 479 suggestion_details->GetDictionary(index, &suggestion_detail))
483 suggestion_detail->GetString("du", &deletion_url); 480 suggestion_detail->GetString("du", &deletion_url);
484 481
485 if ((match_type == AutocompleteMatchType::NAVSUGGEST) || 482 if ((match_type == AutocompleteMatchType::NAVSUGGEST) ||
486 (match_type == AutocompleteMatchType::NAVSUGGEST_PERSONALIZED)) { 483 (match_type == AutocompleteMatchType::NAVSUGGEST_PERSONALIZED)) {
487 // Do not blindly trust the URL coming from the server to be valid. 484 // Do not blindly trust the URL coming from the server to be valid.
488 GURL url(url_formatter::FixupURL(base::UTF16ToUTF8(suggestion), 485 GURL url(url_formatter::FixupURL(base::UTF16ToUTF8(suggestion),
489 std::string())); 486 std::string()));
490 if (url.is_valid() && allow_navsuggest) { 487 if (url.is_valid()) {
491 base::string16 title; 488 base::string16 title;
492 if (descriptions != NULL) 489 if (descriptions != NULL)
493 descriptions->GetString(index, &title); 490 descriptions->GetString(index, &title);
494 results->navigation_results.push_back(NavigationResult( 491 results->navigation_results.push_back(NavigationResult(
495 scheme_classifier, url, match_type, title, deletion_url, 492 scheme_classifier, url, match_type, title, deletion_url,
496 is_keyword_result, relevance, relevances != NULL, input.text(), 493 is_keyword_result, relevance, relevances != NULL, input.text(),
497 languages)); 494 languages));
498 } 495 }
499 } else { 496 } else {
500 // TODO(dschuyler) If the "= " is no longer sent from the back-end 497 // TODO(dschuyler) If the "= " is no longer sent from the back-end
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 base::CollapseWhitespace(match_contents, false), 550 base::CollapseWhitespace(match_contents, false),
554 match_contents_prefix, annotation, answer_contents, answer_type_str, 551 match_contents_prefix, annotation, answer_contents, answer_type_str,
555 std::move(answer), suggest_query_params, deletion_url, 552 std::move(answer), suggest_query_params, deletion_url,
556 is_keyword_result, relevance, relevances != NULL, should_prefetch, 553 is_keyword_result, relevance, relevances != NULL, should_prefetch,
557 trimmed_input)); 554 trimmed_input));
558 } 555 }
559 } 556 }
560 results->relevances_from_server = relevances != NULL; 557 results->relevances_from_server = relevances != NULL;
561 return true; 558 return true;
562 } 559 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698