Chromium Code Reviews| 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) { | |
|
tommycli
2017/06/21 18:53:44
These three methods duplicate a lot of offset adju
Peter Kasting
2017/06/21 23:17:27
I'm a little leery of adding a new flag type and t
tommycli
2017/06/22 19:18:43
Okay cool -- In that case, it seems like the best
tommycli
2017/06/22 19:22:51
FWIW, Justin actually liked that these convenience
| |
| 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 const std::string kHTTPS = | |
| 543 std::string(url::kHttpsScheme) + url::kStandardSchemeSeparator; | |
| 544 if (base::StartsWith(result, base::ASCIIToUTF16(kHTTPS), | |
| 545 base::CompareCase::SENSITIVE)) { | |
|
Peter Kasting
2017/06/21 23:17:27
Can we just check if url.SchemeIs(url::kHttpsSchem
tommycli
2017/06/22 19:18:43
Done.
| |
| 546 const size_t kHTTPSSize = kHTTPS.size(); | |
| 547 result = result.substr(kHTTPSSize); | |
| 548 adjustments->insert(adjustments->begin(), | |
| 549 base::OffsetAdjuster::Adjustment(0, kHTTPSSize, 0)); | |
| 550 } | |
| 551 } | |
| 552 | |
| 553 return result; | |
| 554 } | |
| 555 | |
| 488 void AutocompleteMatch::ComputeStrippedDestinationURL( | 556 void AutocompleteMatch::ComputeStrippedDestinationURL( |
| 489 const AutocompleteInput& input, | 557 const AutocompleteInput& input, |
| 490 TemplateURLService* template_url_service) { | 558 TemplateURLService* template_url_service) { |
| 491 stripped_destination_url = GURLToStrippedGURL( | 559 stripped_destination_url = GURLToStrippedGURL( |
| 492 destination_url, input, template_url_service, keyword); | 560 destination_url, input, template_url_service, keyword); |
| 493 } | 561 } |
| 494 | 562 |
| 495 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( | 563 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( |
| 496 const AutocompleteInput& input, | 564 const AutocompleteInput& input, |
| 497 TemplateURLService* template_url_service) { | 565 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 | 691 << " is unsorted in relation to last offset of " << last_offset |
| 624 << ". Provider: " << provider_name << "."; | 692 << ". Provider: " << provider_name << "."; |
| 625 DCHECK_LT(i->offset, text.length()) | 693 DCHECK_LT(i->offset, text.length()) |
| 626 << " Classification of [" << i->offset << "," << text.length() | 694 << " Classification of [" << i->offset << "," << text.length() |
| 627 << "] is out of bounds for \"" << text << "\". Provider: " | 695 << "] is out of bounds for \"" << text << "\". Provider: " |
| 628 << provider_name << "."; | 696 << provider_name << "."; |
| 629 last_offset = i->offset; | 697 last_offset = i->offset; |
| 630 } | 698 } |
| 631 } | 699 } |
| 632 #endif | 700 #endif |
| OLD | NEW |