| 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/feature_list.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 #include "components/omnibox/browser/autocomplete_provider.h" | 22 #include "components/omnibox/browser/autocomplete_provider.h" |
| 23 #include "components/omnibox/browser/omnibox_field_trial.h" | 23 #include "components/omnibox/browser/omnibox_field_trial.h" |
| 24 #include "components/omnibox/browser/suggestion_answer.h" | 24 #include "components/omnibox/browser/suggestion_answer.h" |
| 25 #include "components/search_engines/template_url.h" | 25 #include "components/search_engines/template_url.h" |
| 26 #include "components/search_engines/template_url_service.h" | 26 #include "components/search_engines/template_url_service.h" |
| 27 #include "components/url_formatter/url_formatter.h" | |
| 28 #include "ui/gfx/vector_icon_types.h" | 27 #include "ui/gfx/vector_icon_types.h" |
| 29 | 28 |
| 30 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 29 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 31 #include "components/omnibox/browser/vector_icons.h" // nogncheck | 30 #include "components/omnibox/browser/vector_icons.h" // nogncheck |
| 32 #include "ui/vector_icons/vector_icons.h" // nogncheck | 31 #include "ui/vector_icons/vector_icons.h" // nogncheck |
| 33 #endif | 32 #endif |
| 34 | 33 |
| 35 namespace { | 34 namespace { |
| 36 | 35 |
| 37 bool IsTrivialClassification(const ACMatchClassifications& classifications) { | 36 bool IsTrivialClassification(const ACMatchClassifications& classifications) { |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 needs_replacement = true; | 481 needs_replacement = true; |
| 483 } | 482 } |
| 484 | 483 |
| 485 if (needs_replacement) | 484 if (needs_replacement) |
| 486 stripped_destination_url = stripped_destination_url.ReplaceComponents( | 485 stripped_destination_url = stripped_destination_url.ReplaceComponents( |
| 487 replacements); | 486 replacements); |
| 488 return stripped_destination_url; | 487 return stripped_destination_url; |
| 489 } | 488 } |
| 490 | 489 |
| 491 // static | 490 // static |
| 492 base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplay( | 491 url_formatter::FormatUrlTypes AutocompleteMatch::GetFormatTypes( |
| 493 const GURL& url, | 492 bool trim_scheme) { |
| 494 bool trim_scheme, | 493 auto format_types = url_formatter::kFormatUrlOmitAll; |
| 495 size_t* offset_for_adjustment) { | 494 if (!trim_scheme) { |
| 496 std::vector<size_t> offsets; | 495 format_types &= ~url_formatter::kFormatUrlOmitHTTP; |
| 497 if (offset_for_adjustment) | 496 } else if (base::FeatureList::IsEnabled( |
| 498 offsets.push_back(*offset_for_adjustment); | 497 omnibox::kUIExperimentHideSuggestionUrlScheme)) { |
| 499 base::string16 result = | 498 format_types |= url_formatter::kFormatUrlExperimentalOmitHTTPS; |
| 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 } | 499 } |
| 521 return format_url_return_value; | 500 return format_types; |
| 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 } | 501 } |
| 553 | 502 |
| 554 void AutocompleteMatch::ComputeStrippedDestinationURL( | 503 void AutocompleteMatch::ComputeStrippedDestinationURL( |
| 555 const AutocompleteInput& input, | 504 const AutocompleteInput& input, |
| 556 TemplateURLService* template_url_service) { | 505 TemplateURLService* template_url_service) { |
| 557 stripped_destination_url = GURLToStrippedGURL( | 506 stripped_destination_url = GURLToStrippedGURL( |
| 558 destination_url, input, template_url_service, keyword); | 507 destination_url, input, template_url_service, keyword); |
| 559 } | 508 } |
| 560 | 509 |
| 561 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( | 510 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 << " is unsorted in relation to last offset of " << last_offset | 638 << " is unsorted in relation to last offset of " << last_offset |
| 690 << ". Provider: " << provider_name << "."; | 639 << ". Provider: " << provider_name << "."; |
| 691 DCHECK_LT(i->offset, text.length()) | 640 DCHECK_LT(i->offset, text.length()) |
| 692 << " Classification of [" << i->offset << "," << text.length() | 641 << " Classification of [" << i->offset << "," << text.length() |
| 693 << "] is out of bounds for \"" << text << "\". Provider: " | 642 << "] is out of bounds for \"" << text << "\". Provider: " |
| 694 << provider_name << "."; | 643 << provider_name << "."; |
| 695 last_offset = i->offset; | 644 last_offset = i->offset; |
| 696 } | 645 } |
| 697 } | 646 } |
| 698 #endif | 647 #endif |
| OLD | NEW |