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" |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 stripped_destination_url = stripped_destination_url.ReplaceComponents( | 486 stripped_destination_url = stripped_destination_url.ReplaceComponents( |
487 replacements); | 487 replacements); |
488 return stripped_destination_url; | 488 return stripped_destination_url; |
489 } | 489 } |
490 | 490 |
491 // static | 491 // static |
492 base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplay( | 492 base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplay( |
493 const GURL& url, | 493 const GURL& url, |
494 bool trim_scheme, | 494 bool trim_scheme, |
495 size_t* offset_for_adjustment) { | 495 size_t* offset_for_adjustment) { |
496 std::vector<size_t> offsets; | 496 base::OffsetAdjuster::Adjustments adjustments; |
497 if (offset_for_adjustment) | 497 base::string16 result = FormatUrlForSuggestionDisplayWithAdjustments( |
498 offsets.push_back(*offset_for_adjustment); | 498 url, trim_scheme, &adjustments); |
499 base::string16 result = | 499 if (offset_for_adjustment) { |
500 FormatUrlForSuggestionDisplayWithOffsets(url, trim_scheme, &offsets); | 500 base::OffsetAdjuster::AdjustOffset(adjustments, offset_for_adjustment, |
501 if (offset_for_adjustment) | 501 result.length()); |
502 *offset_for_adjustment = offsets[0]; | 502 } |
503 return result; | 503 return result; |
504 } | 504 } |
505 | 505 |
506 // static | 506 // static |
507 base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplayWithOffsets( | |
Justin Donnelly
2017/06/27 15:28:45
I think we should keep this function. If it makes
tommycli
2017/07/07 19:27:10
Acknowledged.
| |
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( | 507 base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplayWithAdjustments( |
526 const GURL& url, | 508 const GURL& url, |
527 bool trim_scheme, | 509 bool trim_scheme, |
528 base::OffsetAdjuster::Adjustments* adjustments) { | 510 base::OffsetAdjuster::Adjustments* adjustments) { |
529 const url_formatter::FormatUrlTypes format_types = | 511 const url_formatter::FormatUrlTypes format_types = |
530 url_formatter::kFormatUrlOmitAll & | 512 url_formatter::kFormatUrlOmitAll & |
531 ~(trim_scheme ? 0 : url_formatter::kFormatUrlOmitHTTP); | 513 ~(trim_scheme ? 0 : url_formatter::kFormatUrlOmitHTTP); |
532 base::string16 result = url_formatter::FormatUrlWithAdjustments( | 514 base::string16 result = url_formatter::FormatUrlWithAdjustments( |
533 url, format_types, net::UnescapeRule::SPACES, nullptr, nullptr, | 515 url, format_types, net::UnescapeRule::SPACES, nullptr, nullptr, |
534 adjustments); | 516 adjustments); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 << " is unsorted in relation to last offset of " << last_offset | 671 << " is unsorted in relation to last offset of " << last_offset |
690 << ". Provider: " << provider_name << "."; | 672 << ". Provider: " << provider_name << "."; |
691 DCHECK_LT(i->offset, text.length()) | 673 DCHECK_LT(i->offset, text.length()) |
692 << " Classification of [" << i->offset << "," << text.length() | 674 << " Classification of [" << i->offset << "," << text.length() |
693 << "] is out of bounds for \"" << text << "\". Provider: " | 675 << "] is out of bounds for \"" << text << "\". Provider: " |
694 << provider_name << "."; | 676 << provider_name << "."; |
695 last_offset = i->offset; | 677 last_offset = i->offset; |
696 } | 678 } |
697 } | 679 } |
698 #endif | 680 #endif |
OLD | NEW |