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

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

Issue 2940973002: Omnibox UI Experiments: Implement scheme-trimming for suggested URLs. (Closed)
Patch Set: fix Created 3 years, 6 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/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
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 base::OffsetAdjuster::Adjustments adjustments;
497 const base::string16& format_url_return_value =
498 FormatUrlForSuggestionDisplayWithAdjustments(url, trim_scheme,
499 &adjustments);
500 if (offset_for_adjustment)
501 base::OffsetAdjuster::AdjustOffset(adjustments, offset_for_adjustment);
502 return format_url_return_value;
503 }
504
505 // static
506 base::string16 AutocompleteMatch::FormatUrlForSuggestionDisplayWithAdjustments(
507 const GURL& url,
508 bool trim_scheme,
509 base::OffsetAdjuster::Adjustments* adjustments) {
510 const url_formatter::FormatUrlTypes format_types =
511 url_formatter::kFormatUrlOmitAll &
512 ~(trim_scheme ? 0 : url_formatter::kFormatUrlOmitHTTP);
513 base::string16 result = url_formatter::FormatUrlWithAdjustments(
514 url, format_types, net::UnescapeRule::SPACES, nullptr, nullptr,
515 adjustments);
516
517 // Also trim HTTPS if this experiment is enabled.
Justin Donnelly 2017/06/20 17:31:01 Can you add a note that it's intentional that this
tommycli 2017/06/20 22:51:21 Done.
518 if (trim_scheme && base::FeatureList::IsEnabled(
519 omnibox::kUIExperimentHideSuggestionUrlScheme)) {
520 constexpr char kHTTPS[] = "https://";
Justin Donnelly 2017/06/20 17:31:01 std::string(url::kHttpsScheme) + url::kStandardSch
tommycli 2017/06/20 22:51:21 Done.
521 if (base::StartsWith(result, base::ASCIIToUTF16(kHTTPS),
522 base::CompareCase::SENSITIVE)) {
523 const size_t kHTTPSSize = arraysize(kHTTPS) - 1;
524 result = result.substr(kHTTPSSize);
525 adjustments->insert(adjustments->begin(),
Justin Donnelly 2017/06/20 17:31:01 Is this right? Inserting at the beginning instead
tommycli 2017/06/20 22:51:21 Acknowledged.
526 base::OffsetAdjuster::Adjustment(0, kHTTPSSize, 0));
527 }
528 }
529
530 return result;
531 }
532
488 void AutocompleteMatch::ComputeStrippedDestinationURL( 533 void AutocompleteMatch::ComputeStrippedDestinationURL(
489 const AutocompleteInput& input, 534 const AutocompleteInput& input,
490 TemplateURLService* template_url_service) { 535 TemplateURLService* template_url_service) {
491 stripped_destination_url = GURLToStrippedGURL( 536 stripped_destination_url = GURLToStrippedGURL(
492 destination_url, input, template_url_service, keyword); 537 destination_url, input, template_url_service, keyword);
493 } 538 }
494 539
495 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( 540 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault(
496 const AutocompleteInput& input, 541 const AutocompleteInput& input,
497 TemplateURLService* template_url_service) { 542 TemplateURLService* template_url_service) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 << " is unsorted in relation to last offset of " << last_offset 668 << " is unsorted in relation to last offset of " << last_offset
624 << ". Provider: " << provider_name << "."; 669 << ". Provider: " << provider_name << ".";
625 DCHECK_LT(i->offset, text.length()) 670 DCHECK_LT(i->offset, text.length())
626 << " Classification of [" << i->offset << "," << text.length() 671 << " Classification of [" << i->offset << "," << text.length()
627 << "] is out of bounds for \"" << text << "\". Provider: " 672 << "] is out of bounds for \"" << text << "\". Provider: "
628 << provider_name << "."; 673 << provider_name << ".";
629 last_offset = i->offset; 674 last_offset = i->offset;
630 } 675 }
631 } 676 }
632 #endif 677 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698