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/autocomplete_match.h" | 5 #include "components/omnibox/browser/autocomplete_match.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
| 10 #include "base/feature_list.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
15 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" |
18 #include "base/time/time.h" | 20 #include "base/time/time.h" |
19 #include "build/build_config.h" | 21 #include "build/build_config.h" |
20 #include "components/omnibox/browser/autocomplete_provider.h" | 22 #include "components/omnibox/browser/autocomplete_provider.h" |
| 23 #include "components/omnibox/browser/omnibox_field_trial.h" |
21 #include "components/omnibox/browser/suggestion_answer.h" | 24 #include "components/omnibox/browser/suggestion_answer.h" |
22 #include "components/search_engines/template_url.h" | 25 #include "components/search_engines/template_url.h" |
23 #include "components/search_engines/template_url_service.h" | 26 #include "components/search_engines/template_url_service.h" |
24 #include "components/url_formatter/url_formatter.h" | 27 #include "components/url_formatter/url_formatter.h" |
25 #include "ui/gfx/vector_icon_types.h" | 28 #include "ui/gfx/vector_icon_types.h" |
26 | 29 |
27 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 30 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
28 #include "components/omnibox/browser/vector_icons.h" // nogncheck | 31 #include "components/omnibox/browser/vector_icons.h" // nogncheck |
29 #include "ui/vector_icons/vector_icons.h" // nogncheck | 32 #include "ui/vector_icons/vector_icons.h" // nogncheck |
30 #endif | 33 #endif |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 url::Component(0, strlen(url::kHttpScheme))); | 481 url::Component(0, strlen(url::kHttpScheme))); |
479 needs_replacement = true; | 482 needs_replacement = true; |
480 } | 483 } |
481 | 484 |
482 if (needs_replacement) | 485 if (needs_replacement) |
483 stripped_destination_url = stripped_destination_url.ReplaceComponents( | 486 stripped_destination_url = stripped_destination_url.ReplaceComponents( |
484 replacements); | 487 replacements); |
485 return stripped_destination_url; | 488 return stripped_destination_url; |
486 } | 489 } |
487 | 490 |
| 491 // static |
| 492 base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplay( |
| 493 const GURL& url, |
| 494 bool trim_scheme, |
| 495 size_t* offset_for_adjustment) { |
| 496 std::vector<size_t> offsets; |
| 497 if (offset_for_adjustment) |
| 498 offsets.push_back(*offset_for_adjustment); |
| 499 base::string16 result = |
| 500 FormatUrlForSuggestionDisplayWithOffsets(url, trim_scheme, &offsets); |
| 501 if (offset_for_adjustment) |
| 502 *offset_for_adjustment = offsets[0]; |
| 503 return result; |
| 504 } |
| 505 |
| 506 // static |
| 507 base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplayWithOffsets( |
| 508 const GURL& url, |
| 509 bool trim_scheme, |
| 510 std::vector<size_t>* offsets_for_adjustment) { |
| 511 base::OffsetAdjuster::Adjustments adjustments; |
| 512 const base::string16& format_url_return_value = |
| 513 FormatUrlForSuggestionDisplayWithAdjustments(url, trim_scheme, |
| 514 &adjustments); |
| 515 base::OffsetAdjuster::AdjustOffsets(adjustments, offsets_for_adjustment); |
| 516 if (offsets_for_adjustment) { |
| 517 std::for_each( |
| 518 offsets_for_adjustment->begin(), offsets_for_adjustment->end(), |
| 519 base::LimitOffset<std::string>(format_url_return_value.length())); |
| 520 } |
| 521 return format_url_return_value; |
| 522 } |
| 523 |
| 524 // static |
| 525 base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplayWithAdjustments( |
| 526 const GURL& url, |
| 527 bool trim_scheme, |
| 528 base::OffsetAdjuster::Adjustments* adjustments) { |
| 529 const url_formatter::FormatUrlTypes format_types = |
| 530 url_formatter::kFormatUrlOmitAll & |
| 531 ~(trim_scheme ? 0 : url_formatter::kFormatUrlOmitHTTP); |
| 532 base::string16 result = url_formatter::FormatUrlWithAdjustments( |
| 533 url, format_types, net::UnescapeRule::SPACES, nullptr, nullptr, |
| 534 adjustments); |
| 535 |
| 536 // Also trim HTTPS if experiment is enabled. Note this intentionally has |
| 537 // no effect on view-source URLs. |
| 538 if (trim_scheme && base::FeatureList::IsEnabled( |
| 539 omnibox::kUIExperimentHideSuggestionUrlScheme)) { |
| 540 // TODO(tommycli): If this becomes enabled by default, investigate |
| 541 // folding this logic into url_formatter::FormatUrlWithAdjustments. |
| 542 if (url.SchemeIs(url::kHttpsScheme)) { |
| 543 const size_t kHTTPSSize = |
| 544 strlen(url::kHttpsScheme) + strlen(url::kStandardSchemeSeparator); |
| 545 result = result.substr(kHTTPSSize); |
| 546 adjustments->insert(adjustments->begin(), |
| 547 base::OffsetAdjuster::Adjustment(0, kHTTPSSize, 0)); |
| 548 } |
| 549 } |
| 550 |
| 551 return result; |
| 552 } |
| 553 |
488 void AutocompleteMatch::ComputeStrippedDestinationURL( | 554 void AutocompleteMatch::ComputeStrippedDestinationURL( |
489 const AutocompleteInput& input, | 555 const AutocompleteInput& input, |
490 TemplateURLService* template_url_service) { | 556 TemplateURLService* template_url_service) { |
491 stripped_destination_url = GURLToStrippedGURL( | 557 stripped_destination_url = GURLToStrippedGURL( |
492 destination_url, input, template_url_service, keyword); | 558 destination_url, input, template_url_service, keyword); |
493 } | 559 } |
494 | 560 |
495 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( | 561 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( |
496 const AutocompleteInput& input, | 562 const AutocompleteInput& input, |
497 TemplateURLService* template_url_service) { | 563 TemplateURLService* template_url_service) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 << " is unsorted in relation to last offset of " << last_offset | 689 << " is unsorted in relation to last offset of " << last_offset |
624 << ". Provider: " << provider_name << "."; | 690 << ". Provider: " << provider_name << "."; |
625 DCHECK_LT(i->offset, text.length()) | 691 DCHECK_LT(i->offset, text.length()) |
626 << " Classification of [" << i->offset << "," << text.length() | 692 << " Classification of [" << i->offset << "," << text.length() |
627 << "] is out of bounds for \"" << text << "\". Provider: " | 693 << "] is out of bounds for \"" << text << "\". Provider: " |
628 << provider_name << "."; | 694 << provider_name << "."; |
629 last_offset = i->offset; | 695 last_offset = i->offset; |
630 } | 696 } |
631 } | 697 } |
632 #endif | 698 #endif |
OLD | NEW |