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/feature_list.h" |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 base::LimitOffset<std::string>(format_url_return_value.length())); | 519 base::LimitOffset<std::string>(format_url_return_value.length())); |
| 520 } | 520 } |
| 521 return format_url_return_value; | 521 return format_url_return_value; |
| 522 } | 522 } |
| 523 | 523 |
| 524 // static | 524 // static |
| 525 base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplayWithAdjustments( | 525 base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplayWithAdjustments( |
| 526 const GURL& url, | 526 const GURL& url, |
| 527 bool trim_scheme, | 527 bool trim_scheme, |
| 528 base::OffsetAdjuster::Adjustments* adjustments) { | 528 base::OffsetAdjuster::Adjustments* adjustments) { |
| 529 GURL trimmed_url = url; | |
| 530 | |
| 531 // Trim off trivial subdomains if experiment is enabled. | |
| 532 if (base::FeatureList::IsEnabled( | |
| 533 omnibox::kUIExperimentHideSuggestionUrlTrivialSubdomains)) { | |
| 534 GURL::Replacements replacements; | |
| 535 replacements.SetHostStr(url_formatter::StripSubdomains( | |
| 536 url, url_formatter::kStripWWW | url_formatter::kStripM)); | |
| 537 trimmed_url = url.ReplaceComponents(replacements); | |
| 538 } | |
|
tommycli
2017/06/23 00:10:54
This pattern now makes me feel that the smart thin
Justin Donnelly
2017/06/23 15:12:25
That's both an elegant solution to the code duplic
tommycli
2017/06/23 18:23:05
Gotcha, alright good to hear my first instinct was
| |
| 539 | |
| 529 const url_formatter::FormatUrlTypes format_types = | 540 const url_formatter::FormatUrlTypes format_types = |
| 530 url_formatter::kFormatUrlOmitAll & | 541 url_formatter::kFormatUrlOmitAll & |
| 531 ~(trim_scheme ? 0 : url_formatter::kFormatUrlOmitHTTP); | 542 ~(trim_scheme ? 0 : url_formatter::kFormatUrlOmitHTTP); |
| 532 base::string16 result = url_formatter::FormatUrlWithAdjustments( | 543 base::string16 result = url_formatter::FormatUrlWithAdjustments( |
| 533 url, format_types, net::UnescapeRule::SPACES, nullptr, nullptr, | 544 trimmed_url, format_types, net::UnescapeRule::SPACES, nullptr, nullptr, |
| 534 adjustments); | 545 adjustments); |
| 535 | 546 |
| 536 // Also trim HTTPS if experiment is enabled. Note this intentionally has | 547 // Also trim HTTPS if experiment is enabled. Note this intentionally has |
| 537 // no effect on view-source URLs. | 548 // no effect on view-source URLs. |
| 538 if (trim_scheme && base::FeatureList::IsEnabled( | 549 if (trim_scheme && base::FeatureList::IsEnabled( |
| 539 omnibox::kUIExperimentHideSuggestionUrlScheme)) { | 550 omnibox::kUIExperimentHideSuggestionUrlScheme)) { |
| 540 // TODO(tommycli): If this becomes enabled by default, investigate | 551 // TODO(tommycli): If this becomes enabled by default, investigate |
| 541 // folding this logic into url_formatter::FormatUrlWithAdjustments. | 552 // folding this logic into url_formatter::FormatUrlWithAdjustments. |
| 542 if (url.SchemeIs(url::kHttpsScheme)) { | 553 if (url.SchemeIs(url::kHttpsScheme)) { |
| 543 const size_t kHTTPSSize = | 554 const size_t kHTTPSSize = |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 689 << " is unsorted in relation to last offset of " << last_offset | 700 << " is unsorted in relation to last offset of " << last_offset |
| 690 << ". Provider: " << provider_name << "."; | 701 << ". Provider: " << provider_name << "."; |
| 691 DCHECK_LT(i->offset, text.length()) | 702 DCHECK_LT(i->offset, text.length()) |
| 692 << " Classification of [" << i->offset << "," << text.length() | 703 << " Classification of [" << i->offset << "," << text.length() |
| 693 << "] is out of bounds for \"" << text << "\". Provider: " | 704 << "] is out of bounds for \"" << text << "\". Provider: " |
| 694 << provider_name << "."; | 705 << provider_name << "."; |
| 695 last_offset = i->offset; | 706 last_offset = i->offset; |
| 696 } | 707 } |
| 697 } | 708 } |
| 698 #endif | 709 #endif |
| OLD | NEW |