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/browser/search_provider.h" | 5 #include "components/omnibox/browser/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/browser/autocomplete_provider_client.h" | 24 #include "components/omnibox/browser/autocomplete_provider_client.h" |
25 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 25 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
26 #include "components/omnibox/browser/autocomplete_result.h" | 26 #include "components/omnibox/browser/autocomplete_result.h" |
27 #include "components/omnibox/browser/keyword_provider.h" | 27 #include "components/omnibox/browser/keyword_provider.h" |
28 #include "components/omnibox/browser/omnibox_field_trial.h" | 28 #include "components/omnibox/browser/omnibox_field_trial.h" |
29 #include "components/omnibox/browser/suggestion_answer.h" | 29 #include "components/omnibox/browser/suggestion_answer.h" |
30 #include "components/omnibox/browser/url_prefix.h" | 30 #include "components/omnibox/browser/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 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1372 BaseSearchProvider::SetDeletionURL(navigation.deletion_url(), &match); | 1372 BaseSearchProvider::SetDeletionURL(navigation.deletion_url(), &match); |
1373 // First look for the user's input inside the formatted url as it would be | 1373 // First look for the user's input inside the formatted url as it would be |
1374 // without trimming the scheme, so we can find matches at the beginning of the | 1374 // without trimming the scheme, so we can find matches at the beginning of the |
1375 // scheme. | 1375 // scheme. |
1376 const URLPrefix* prefix = | 1376 const URLPrefix* prefix = |
1377 URLPrefix::BestURLPrefix(navigation.formatted_url(), input); | 1377 URLPrefix::BestURLPrefix(navigation.formatted_url(), input); |
1378 size_t match_start = (prefix == NULL) ? | 1378 size_t match_start = (prefix == NULL) ? |
1379 navigation.formatted_url().find(input) : prefix->prefix.length(); | 1379 navigation.formatted_url().find(input) : prefix->prefix.length(); |
1380 bool trim_http = !AutocompleteInput::HasHTTPScheme(input) && | 1380 bool trim_http = !AutocompleteInput::HasHTTPScheme(input) && |
1381 (!prefix || (match_start != 0)); | 1381 (!prefix || (match_start != 0)); |
1382 const net::FormatUrlTypes format_types = | 1382 const url_formatter::FormatUrlTypes format_types = |
1383 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP); | 1383 url_formatter::kFormatUrlOmitAll & |
| 1384 ~(trim_http ? 0 : url_formatter::kFormatUrlOmitHTTP); |
1384 | 1385 |
1385 const std::string languages(client()->GetAcceptLanguages()); | 1386 const std::string languages(client()->GetAcceptLanguages()); |
1386 size_t inline_autocomplete_offset = (prefix == NULL) ? | 1387 size_t inline_autocomplete_offset = (prefix == NULL) ? |
1387 base::string16::npos : (match_start + input.length()); | 1388 base::string16::npos : (match_start + input.length()); |
1388 match.fill_into_edit += | 1389 match.fill_into_edit += |
1389 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 1390 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
1390 navigation.url(), | 1391 navigation.url(), |
1391 net::FormatUrl(navigation.url(), languages, format_types, | 1392 url_formatter::FormatUrl(navigation.url(), languages, format_types, |
1392 net::UnescapeRule::SPACES, NULL, NULL, | 1393 net::UnescapeRule::SPACES, nullptr, nullptr, |
1393 &inline_autocomplete_offset), | 1394 &inline_autocomplete_offset), |
1394 client()->GetSchemeClassifier()); | 1395 client()->GetSchemeClassifier()); |
1395 // Preserve the forced query '?' prefix in |match.fill_into_edit|. | 1396 // Preserve the forced query '?' prefix in |match.fill_into_edit|. |
1396 // Otherwise, user edits to a suggestion would show non-Search results. | 1397 // Otherwise, user edits to a suggestion would show non-Search results. |
1397 if (input_.type() == metrics::OmniboxInputType::FORCED_QUERY) { | 1398 if (input_.type() == metrics::OmniboxInputType::FORCED_QUERY) { |
1398 match.fill_into_edit.insert(0, base::ASCIIToUTF16("?")); | 1399 match.fill_into_edit.insert(0, base::ASCIIToUTF16("?")); |
1399 if (inline_autocomplete_offset != base::string16::npos) | 1400 if (inline_autocomplete_offset != base::string16::npos) |
1400 ++inline_autocomplete_offset; | 1401 ++inline_autocomplete_offset; |
1401 } | 1402 } |
1402 if (inline_autocomplete_offset != base::string16::npos) { | 1403 if (inline_autocomplete_offset != base::string16::npos) { |
1403 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); | 1404 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1497 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
1497 matches.push_back(i->second); | 1498 matches.push_back(i->second); |
1498 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1499 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
1499 | 1500 |
1500 // If there is a top scoring entry, find the corresponding answer. | 1501 // If there is a top scoring entry, find the corresponding answer. |
1501 if (!matches.empty()) | 1502 if (!matches.empty()) |
1502 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1503 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
1503 | 1504 |
1504 return AnswersQueryData(); | 1505 return AnswersQueryData(); |
1505 } | 1506 } |
OLD | NEW |