OLD | NEW |
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 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 } | 447 } |
448 | 448 |
449 // Clear the previous results now that new results are available. | 449 // Clear the previous results now that new results are available. |
450 results->suggest_results.clear(); | 450 results->suggest_results.clear(); |
451 results->navigation_results.clear(); | 451 results->navigation_results.clear(); |
452 results->answers_image_urls.clear(); | 452 results->answers_image_urls.clear(); |
453 | 453 |
454 base::string16 suggestion; | 454 base::string16 suggestion; |
455 std::string type; | 455 std::string type; |
456 int relevance = default_result_relevance; | 456 int relevance = default_result_relevance; |
457 // Prohibit navsuggest in FORCED_QUERY mode. Users wants queries, not URLs. | |
458 const bool allow_navsuggest = | |
459 input.type() != metrics::OmniboxInputType::FORCED_QUERY; | |
460 const base::string16& trimmed_input = | 457 const base::string16& trimmed_input = |
461 base::CollapseWhitespace(input.text(), false); | 458 base::CollapseWhitespace(input.text(), false); |
462 for (size_t index = 0; results_list->GetString(index, &suggestion); ++index) { | 459 for (size_t index = 0; results_list->GetString(index, &suggestion); ++index) { |
463 // Google search may return empty suggestions for weird input characters, | 460 // Google search may return empty suggestions for weird input characters, |
464 // they make no sense at all and can cause problems in our code. | 461 // they make no sense at all and can cause problems in our code. |
465 if (suggestion.empty()) | 462 if (suggestion.empty()) |
466 continue; | 463 continue; |
467 | 464 |
468 // Apply valid suggested relevance scores; discard invalid lists. | 465 // Apply valid suggested relevance scores; discard invalid lists. |
469 if (relevances != NULL && !relevances->GetInteger(index, &relevance)) | 466 if (relevances != NULL && !relevances->GetInteger(index, &relevance)) |
470 relevances = NULL; | 467 relevances = NULL; |
471 AutocompleteMatchType::Type match_type = | 468 AutocompleteMatchType::Type match_type = |
472 AutocompleteMatchType::SEARCH_SUGGEST; | 469 AutocompleteMatchType::SEARCH_SUGGEST; |
473 if (types && types->GetString(index, &type)) | 470 if (types && types->GetString(index, &type)) |
474 match_type = GetAutocompleteMatchType(type); | 471 match_type = GetAutocompleteMatchType(type); |
475 const base::DictionaryValue* suggestion_detail = NULL; | 472 const base::DictionaryValue* suggestion_detail = NULL; |
476 std::string deletion_url; | 473 std::string deletion_url; |
477 | 474 |
478 if (suggestion_details && | 475 if (suggestion_details && |
479 suggestion_details->GetDictionary(index, &suggestion_detail)) | 476 suggestion_details->GetDictionary(index, &suggestion_detail)) |
480 suggestion_detail->GetString("du", &deletion_url); | 477 suggestion_detail->GetString("du", &deletion_url); |
481 | 478 |
482 if ((match_type == AutocompleteMatchType::NAVSUGGEST) || | 479 if ((match_type == AutocompleteMatchType::NAVSUGGEST) || |
483 (match_type == AutocompleteMatchType::NAVSUGGEST_PERSONALIZED)) { | 480 (match_type == AutocompleteMatchType::NAVSUGGEST_PERSONALIZED)) { |
484 // Do not blindly trust the URL coming from the server to be valid. | 481 // Do not blindly trust the URL coming from the server to be valid. |
485 GURL url(url_formatter::FixupURL(base::UTF16ToUTF8(suggestion), | 482 GURL url(url_formatter::FixupURL(base::UTF16ToUTF8(suggestion), |
486 std::string())); | 483 std::string())); |
487 if (url.is_valid() && allow_navsuggest) { | 484 if (url.is_valid()) { |
488 base::string16 title; | 485 base::string16 title; |
489 if (descriptions != NULL) | 486 if (descriptions != NULL) |
490 descriptions->GetString(index, &title); | 487 descriptions->GetString(index, &title); |
491 results->navigation_results.push_back(NavigationResult( | 488 results->navigation_results.push_back(NavigationResult( |
492 scheme_classifier, url, match_type, title, deletion_url, | 489 scheme_classifier, url, match_type, title, deletion_url, |
493 is_keyword_result, relevance, relevances != NULL, input.text())); | 490 is_keyword_result, relevance, relevances != NULL, input.text())); |
494 } | 491 } |
495 } else { | 492 } else { |
496 // TODO(dschuyler) If the "= " is no longer sent from the back-end | 493 // TODO(dschuyler) If the "= " is no longer sent from the back-end |
497 // then this may be removed. | 494 // then this may be removed. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 base::CollapseWhitespace(match_contents, false), | 546 base::CollapseWhitespace(match_contents, false), |
550 match_contents_prefix, annotation, answer_contents, answer_type_str, | 547 match_contents_prefix, annotation, answer_contents, answer_type_str, |
551 std::move(answer), suggest_query_params, deletion_url, | 548 std::move(answer), suggest_query_params, deletion_url, |
552 is_keyword_result, relevance, relevances != NULL, should_prefetch, | 549 is_keyword_result, relevance, relevances != NULL, should_prefetch, |
553 trimmed_input)); | 550 trimmed_input)); |
554 } | 551 } |
555 } | 552 } |
556 results->relevances_from_server = relevances != NULL; | 553 results->relevances_from_server = relevances != NULL; |
557 return true; | 554 return true; |
558 } | 555 } |
OLD | NEW |