OLD | NEW |
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 "components/omnibox/search_provider.h" | 5 #include "components/omnibox/search_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "components/omnibox/autocomplete_provider_client.h" | 24 #include "components/omnibox/autocomplete_provider_client.h" |
25 #include "components/omnibox/autocomplete_provider_listener.h" | 25 #include "components/omnibox/autocomplete_provider_listener.h" |
26 #include "components/omnibox/autocomplete_result.h" | 26 #include "components/omnibox/autocomplete_result.h" |
27 #include "components/omnibox/keyword_provider.h" | 27 #include "components/omnibox/keyword_provider.h" |
28 #include "components/omnibox/omnibox_field_trial.h" | 28 #include "components/omnibox/omnibox_field_trial.h" |
29 #include "components/omnibox/suggestion_answer.h" | 29 #include "components/omnibox/suggestion_answer.h" |
30 #include "components/omnibox/url_prefix.h" | 30 #include "components/omnibox/url_prefix.h" |
31 #include "components/search/search.h" | 31 #include "components/search/search.h" |
32 #include "components/search_engines/template_url_prepopulate_data.h" | 32 #include "components/search_engines/template_url_prepopulate_data.h" |
33 #include "components/search_engines/template_url_service.h" | 33 #include "components/search_engines/template_url_service.h" |
| 34 #include "components/url_formatter/url_formatter.h" |
34 #include "components/variations/net/variations_http_header_provider.h" | 35 #include "components/variations/net/variations_http_header_provider.h" |
35 #include "grit/components_strings.h" | 36 #include "grit/components_strings.h" |
36 #include "net/base/escape.h" | 37 #include "net/base/escape.h" |
37 #include "net/base/load_flags.h" | 38 #include "net/base/load_flags.h" |
38 #include "net/base/net_util.h" | |
39 #include "net/http/http_request_headers.h" | 39 #include "net/http/http_request_headers.h" |
40 #include "net/url_request/url_fetcher.h" | 40 #include "net/url_request/url_fetcher.h" |
41 #include "net/url_request/url_request_status.h" | 41 #include "net/url_request/url_request_status.h" |
42 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
43 #include "url/url_constants.h" | 43 #include "url/url_constants.h" |
44 #include "url/url_util.h" | 44 #include "url/url_util.h" |
45 | 45 |
46 // Helpers -------------------------------------------------------------------- | 46 // Helpers -------------------------------------------------------------------- |
47 | 47 |
48 namespace { | 48 namespace { |
(...skipping 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 BaseSearchProvider::SetDeletionURL(navigation.deletion_url(), &match); | 1388 BaseSearchProvider::SetDeletionURL(navigation.deletion_url(), &match); |
1389 // First look for the user's input inside the formatted url as it would be | 1389 // First look for the user's input inside the formatted url as it would be |
1390 // without trimming the scheme, so we can find matches at the beginning of the | 1390 // without trimming the scheme, so we can find matches at the beginning of the |
1391 // scheme. | 1391 // scheme. |
1392 const URLPrefix* prefix = | 1392 const URLPrefix* prefix = |
1393 URLPrefix::BestURLPrefix(navigation.formatted_url(), input); | 1393 URLPrefix::BestURLPrefix(navigation.formatted_url(), input); |
1394 size_t match_start = (prefix == NULL) ? | 1394 size_t match_start = (prefix == NULL) ? |
1395 navigation.formatted_url().find(input) : prefix->prefix.length(); | 1395 navigation.formatted_url().find(input) : prefix->prefix.length(); |
1396 bool trim_http = !AutocompleteInput::HasHTTPScheme(input) && | 1396 bool trim_http = !AutocompleteInput::HasHTTPScheme(input) && |
1397 (!prefix || (match_start != 0)); | 1397 (!prefix || (match_start != 0)); |
1398 const net::FormatUrlTypes format_types = | 1398 const url_formatter::FormatUrlTypes format_types = |
1399 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP); | 1399 url_formatter::kFormatUrlOmitAll & |
| 1400 ~(trim_http ? 0 : url_formatter::kFormatUrlOmitHTTP); |
1400 | 1401 |
1401 const std::string languages(client_->AcceptLanguages()); | 1402 const std::string languages(client_->AcceptLanguages()); |
1402 size_t inline_autocomplete_offset = (prefix == NULL) ? | 1403 size_t inline_autocomplete_offset = (prefix == NULL) ? |
1403 base::string16::npos : (match_start + input.length()); | 1404 base::string16::npos : (match_start + input.length()); |
1404 match.fill_into_edit += | 1405 match.fill_into_edit += |
1405 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 1406 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
1406 navigation.url(), | 1407 navigation.url(), |
1407 net::FormatUrl(navigation.url(), languages, format_types, | 1408 url_formatter::FormatUrl(navigation.url(), languages, format_types, |
1408 net::UnescapeRule::SPACES, NULL, NULL, | 1409 net::UnescapeRule::SPACES, NULL, NULL, |
1409 &inline_autocomplete_offset), | 1410 &inline_autocomplete_offset), |
1410 client_->SchemeClassifier()); | 1411 client_->SchemeClassifier()); |
1411 // Preserve the forced query '?' prefix in |match.fill_into_edit|. | 1412 // Preserve the forced query '?' prefix in |match.fill_into_edit|. |
1412 // Otherwise, user edits to a suggestion would show non-Search results. | 1413 // Otherwise, user edits to a suggestion would show non-Search results. |
1413 if (input_.type() == metrics::OmniboxInputType::FORCED_QUERY) { | 1414 if (input_.type() == metrics::OmniboxInputType::FORCED_QUERY) { |
1414 match.fill_into_edit.insert(0, base::ASCIIToUTF16("?")); | 1415 match.fill_into_edit.insert(0, base::ASCIIToUTF16("?")); |
1415 if (inline_autocomplete_offset != base::string16::npos) | 1416 if (inline_autocomplete_offset != base::string16::npos) |
1416 ++inline_autocomplete_offset; | 1417 ++inline_autocomplete_offset; |
1417 } | 1418 } |
1418 if (inline_autocomplete_offset != base::string16::npos) { | 1419 if (inline_autocomplete_offset != base::string16::npos) { |
1419 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); | 1420 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1513 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
1513 matches.push_back(i->second); | 1514 matches.push_back(i->second); |
1514 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1515 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
1515 | 1516 |
1516 // If there is a top scoring entry, find the corresponding answer. | 1517 // If there is a top scoring entry, find the corresponding answer. |
1517 if (!matches.empty()) | 1518 if (!matches.empty()) |
1518 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1519 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
1519 | 1520 |
1520 return AnswersQueryData(); | 1521 return AnswersQueryData(); |
1521 } | 1522 } |
OLD | NEW |