Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: components/omnibox/browser/autocomplete_match.cc

Issue 2963883002: Omnibox UI Experiments: Refactor HTTPS trimming into UrlFormatter. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 needs_replacement = true; 482 needs_replacement = true;
483 } 483 }
484 484
485 if (needs_replacement) 485 if (needs_replacement)
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(
Peter Kasting 2017/06/28 23:09:59 I think we should nuke all these functions now. I
tommycli 2017/06/29 00:19:43 Done.
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 std::vector<size_t> offsets;
497 if (offset_for_adjustment) 497 if (offset_for_adjustment)
498 offsets.push_back(*offset_for_adjustment); 498 offsets.push_back(*offset_for_adjustment);
499 base::string16 result = 499 base::string16 result =
500 FormatUrlForSuggestionDisplayWithOffsets(url, trim_scheme, &offsets); 500 FormatUrlForSuggestionDisplayWithOffsets(url, trim_scheme, &offsets);
501 if (offset_for_adjustment) 501 if (offset_for_adjustment)
502 *offset_for_adjustment = offsets[0]; 502 *offset_for_adjustment = offsets[0];
(...skipping 16 matching lines...) Expand all
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 const url_formatter::FormatUrlTypes format_types = 529 auto format_types = url_formatter::kFormatUrlOmitAll;
530 url_formatter::kFormatUrlOmitAll & 530 if (!trim_scheme) {
531 ~(trim_scheme ? 0 : url_formatter::kFormatUrlOmitHTTP); 531 format_types &= ~url_formatter::kFormatUrlOmitHTTP;
532 base::string16 result = url_formatter::FormatUrlWithAdjustments( 532 } else if (base::FeatureList::IsEnabled(
533 url, format_types, net::UnescapeRule::SPACES, nullptr, nullptr, 533 omnibox::kUIExperimentHideSuggestionUrlScheme)) {
534 adjustments); 534 format_types |= url_formatter::kFormatUrlExperimentalOmitHTTPS;
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 } 535 }
550 536
551 return result; 537 return url_formatter::FormatUrlWithAdjustments(url, format_types,
538 net::UnescapeRule::SPACES,
539 nullptr, nullptr, adjustments);
552 } 540 }
553 541
554 void AutocompleteMatch::ComputeStrippedDestinationURL( 542 void AutocompleteMatch::ComputeStrippedDestinationURL(
555 const AutocompleteInput& input, 543 const AutocompleteInput& input,
556 TemplateURLService* template_url_service) { 544 TemplateURLService* template_url_service) {
557 stripped_destination_url = GURLToStrippedGURL( 545 stripped_destination_url = GURLToStrippedGURL(
558 destination_url, input, template_url_service, keyword); 546 destination_url, input, template_url_service, keyword);
559 } 547 }
560 548
561 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( 549 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault(
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 << " is unsorted in relation to last offset of " << last_offset 677 << " is unsorted in relation to last offset of " << last_offset
690 << ". Provider: " << provider_name << "."; 678 << ". Provider: " << provider_name << ".";
691 DCHECK_LT(i->offset, text.length()) 679 DCHECK_LT(i->offset, text.length())
692 << " Classification of [" << i->offset << "," << text.length() 680 << " Classification of [" << i->offset << "," << text.length()
693 << "] is out of bounds for \"" << text << "\". Provider: " 681 << "] is out of bounds for \"" << text << "\". Provider: "
694 << provider_name << "."; 682 << provider_name << ".";
695 last_offset = i->offset; 683 last_offset = i->offset;
696 } 684 }
697 } 685 }
698 #endif 686 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698