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

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

Issue 171753002: Omnibox: SearchProvider: Fix Navsuggestions in Prevent-Inlining Mode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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/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 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 int base_score; 1502 int base_score;
1503 if (is_primary_provider) 1503 if (is_primary_provider)
1504 base_score = (input_.type() == AutocompleteInput::URL) ? 750 : 1050; 1504 base_score = (input_.type() == AutocompleteInput::URL) ? 750 : 1050;
1505 else 1505 else
1506 base_score = 200; 1506 base_score = 200;
1507 return std::max(0, base_score - score_discount); 1507 return std::max(0, base_score - score_discount);
1508 } 1508 }
1509 1509
1510 AutocompleteMatch SearchProvider::NavigationToMatch( 1510 AutocompleteMatch SearchProvider::NavigationToMatch(
1511 const NavigationResult& navigation) { 1511 const NavigationResult& navigation) {
1512 const base::string16& input = navigation.from_keyword_provider() ? 1512 const base::string16& full_input = navigation.from_keyword_provider() ?
1513 keyword_input_.text() : input_.text(); 1513 keyword_input_.text() : input_.text();
1514 // Actual input to use when matching, discarding trailing slash if any.
Mark P 2014/02/19 00:26:19 This helps handle cases like input doodle.com/ wit
Peter Kasting 2014/02/19 20:39:32 What about e.g. matches where the "www." is only p
Mark P 2014/02/19 23:23:01 The code (below) uses BestUrlPrefix, exactly like
1515 const base::string16 input = (*(full_input.rbegin()) == '/') ?
1516 full_input.substr(0, full_input.length() - 1) : full_input;
1514 AutocompleteMatch match(this, navigation.relevance(), false, 1517 AutocompleteMatch match(this, navigation.relevance(), false,
1515 AutocompleteMatchType::NAVSUGGEST); 1518 AutocompleteMatchType::NAVSUGGEST);
1516 match.destination_url = navigation.url(); 1519 match.destination_url = navigation.url();
1517 1520
1518 // First look for the user's input inside the formatted url as it would be 1521 // First look for the user's input inside the formatted url as it would be
1519 // without trimming the scheme, so we can find matches at the beginning of the 1522 // without trimming the scheme, so we can find matches at the beginning of the
1520 // scheme. 1523 // scheme.
1521 const URLPrefix* prefix = 1524 const URLPrefix* prefix =
1522 URLPrefix::BestURLPrefix(navigation.formatted_url(), input); 1525 URLPrefix::BestURLPrefix(navigation.formatted_url(), input);
1523 size_t match_start = (prefix == NULL) ? 1526 size_t match_start = (prefix == NULL) ?
(...skipping 12 matching lines...) Expand all
1536 net::FormatUrl(navigation.url(), languages, format_types, 1539 net::FormatUrl(navigation.url(), languages, format_types,
1537 net::UnescapeRule::SPACES, NULL, NULL, 1540 net::UnescapeRule::SPACES, NULL, NULL,
1538 &inline_autocomplete_offset)); 1541 &inline_autocomplete_offset));
1539 // Preserve the forced query '?' prefix in |match.fill_into_edit|. 1542 // Preserve the forced query '?' prefix in |match.fill_into_edit|.
1540 // Otherwise, user edits to a suggestion would show non-Search results. 1543 // Otherwise, user edits to a suggestion would show non-Search results.
1541 if (input_.type() == AutocompleteInput::FORCED_QUERY) { 1544 if (input_.type() == AutocompleteInput::FORCED_QUERY) {
1542 match.fill_into_edit.insert(0, base::ASCIIToUTF16("?")); 1545 match.fill_into_edit.insert(0, base::ASCIIToUTF16("?"));
1543 if (inline_autocomplete_offset != base::string16::npos) 1546 if (inline_autocomplete_offset != base::string16::npos)
1544 ++inline_autocomplete_offset; 1547 ++inline_autocomplete_offset;
1545 } 1548 }
1546 if (!input_.prevent_inline_autocomplete() && 1549 if (inline_autocomplete_offset != base::string16::npos) {
Mark P 2014/02/19 00:26:19 The restructuring in this block allows handling si
1547 (inline_autocomplete_offset != base::string16::npos)) {
1548 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); 1550 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length());
1551 match.inline_autocompletion =
1552 match.fill_into_edit.substr(inline_autocomplete_offset);
1549 // A navsuggestion can only be the default match when there is no 1553 // A navsuggestion can only be the default match when there is no
1550 // keyword provider active, lest it appear first and break the user 1554 // keyword provider active, lest it appear first and break the user
1551 // out of keyword mode. 1555 // out of keyword mode. It can also only be default when we're not
1556 // preventing inline autocompletion (unless the inline autocompletion
1557 // would be empty).
1552 match.allowed_to_be_default_match = 1558 match.allowed_to_be_default_match =
1553 (providers_.GetKeywordProviderURL() == NULL); 1559 (providers_.GetKeywordProviderURL() == NULL) &&
1554 match.inline_autocompletion = 1560 (!input_.prevent_inline_autocomplete() ||
1555 match.fill_into_edit.substr(inline_autocomplete_offset); 1561 match.inline_autocompletion.empty());
Peter Kasting 2014/02/19 20:39:32 Does this mean that an input of "doodle.com" won't
Mark P 2014/02/19 23:23:01 There's some subtlety here. Technically, you're ri
1556 } 1562 }
1557 1563
1558 match.contents = navigation.match_contents(); 1564 match.contents = navigation.match_contents();
1559 match.contents_class = navigation.match_contents_class(); 1565 match.contents_class = navigation.match_contents_class();
1560 match.description = navigation.description(); 1566 match.description = navigation.description();
1561 AutocompleteMatch::ClassifyMatchInString(input, match.description, 1567 AutocompleteMatch::ClassifyMatchInString(input, match.description,
1562 ACMatchClassification::NONE, &match.description_class); 1568 ACMatchClassification::NONE, &match.description_class);
1563 1569
1564 match.RecordAdditionalInfo( 1570 match.RecordAdditionalInfo(
1565 kRelevanceFromServerKey, 1571 kRelevanceFromServerKey,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 it->set_relevance(max_query_relevance); 1614 it->set_relevance(max_query_relevance);
1609 it->set_relevance_from_server(relevance_from_server); 1615 it->set_relevance_from_server(relevance_from_server);
1610 } 1616 }
1611 } 1617 }
1612 1618
1613 void SearchProvider::UpdateDone() { 1619 void SearchProvider::UpdateDone() {
1614 // We're done when the timer isn't running, there are no suggest queries 1620 // We're done when the timer isn't running, there are no suggest queries
1615 // pending, and we're not waiting on Instant. 1621 // pending, and we're not waiting on Instant.
1616 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); 1622 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0);
1617 } 1623 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698