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

Side by Side Diff: components/url_formatter/url_formatter.cc

Issue 1841653003: Drop |languages| from {Format,Elide}Url* and IDNToUnicode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in elide_url.cc Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/url_formatter/url_formatter.h" 5 #include "components/url_formatter/url_formatter.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 DCHECK(new_parsed); 159 DCHECK(new_parsed);
160 const char kViewSource[] = "view-source:"; 160 const char kViewSource[] = "view-source:";
161 const size_t kViewSourceLength = arraysize(kViewSource) - 1; 161 const size_t kViewSourceLength = arraysize(kViewSource) - 1;
162 162
163 // Format the underlying URL and record adjustments. 163 // Format the underlying URL and record adjustments.
164 const std::string& url_str(url.possibly_invalid_spec()); 164 const std::string& url_str(url.possibly_invalid_spec());
165 adjustments->clear(); 165 adjustments->clear();
166 base::string16 result( 166 base::string16 result(
167 base::ASCIIToUTF16(kViewSource) + 167 base::ASCIIToUTF16(kViewSource) +
168 FormatUrlWithAdjustments(GURL(url_str.substr(kViewSourceLength)), 168 FormatUrlWithAdjustments(GURL(url_str.substr(kViewSourceLength)),
169 std::string(), format_types, unescape_rules, 169 format_types, unescape_rules, new_parsed,
170 new_parsed, prefix_end, adjustments)); 170 prefix_end, adjustments));
171 // Revise |adjustments| by shifting to the offsets to prefix that the above 171 // Revise |adjustments| by shifting to the offsets to prefix that the above
172 // call to FormatUrl didn't get to see. 172 // call to FormatUrl didn't get to see.
173 for (base::OffsetAdjuster::Adjustments::iterator it = adjustments->begin(); 173 for (base::OffsetAdjuster::Adjustments::iterator it = adjustments->begin();
174 it != adjustments->end(); ++it) 174 it != adjustments->end(); ++it)
175 it->original_offset += kViewSourceLength; 175 it->original_offset += kViewSourceLength;
176 176
177 // Adjust positions of the parsed components. 177 // Adjust positions of the parsed components.
178 if (new_parsed->scheme.is_nonempty()) { 178 if (new_parsed->scheme.is_nonempty()) {
179 // Assume "view-source:real-scheme" as a scheme. 179 // Assume "view-source:real-scheme" as a scheme.
180 new_parsed->scheme.len += kViewSourceLength; 180 new_parsed->scheme.len += kViewSourceLength;
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 570
571 const FormatUrlType kFormatUrlOmitNothing = 0; 571 const FormatUrlType kFormatUrlOmitNothing = 0;
572 const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0; 572 const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0;
573 const FormatUrlType kFormatUrlOmitHTTP = 1 << 1; 573 const FormatUrlType kFormatUrlOmitHTTP = 1 << 1;
574 const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2; 574 const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2;
575 const FormatUrlType kFormatUrlOmitAll = 575 const FormatUrlType kFormatUrlOmitAll =
576 kFormatUrlOmitUsernamePassword | kFormatUrlOmitHTTP | 576 kFormatUrlOmitUsernamePassword | kFormatUrlOmitHTTP |
577 kFormatUrlOmitTrailingSlashOnBareHostname; 577 kFormatUrlOmitTrailingSlashOnBareHostname;
578 578
579 base::string16 FormatUrl(const GURL& url, 579 base::string16 FormatUrl(const GURL& url,
580 const std::string& languages,
581 FormatUrlTypes format_types, 580 FormatUrlTypes format_types,
582 net::UnescapeRule::Type unescape_rules, 581 net::UnescapeRule::Type unescape_rules,
583 url::Parsed* new_parsed, 582 url::Parsed* new_parsed,
584 size_t* prefix_end, 583 size_t* prefix_end,
585 size_t* offset_for_adjustment) { 584 size_t* offset_for_adjustment) {
586 std::vector<size_t> offsets; 585 std::vector<size_t> offsets;
587 if (offset_for_adjustment) 586 if (offset_for_adjustment)
588 offsets.push_back(*offset_for_adjustment); 587 offsets.push_back(*offset_for_adjustment);
589 base::string16 result = 588 base::string16 result =
590 FormatUrlWithOffsets(url, std::string(), format_types, unescape_rules, 589 FormatUrlWithOffsets(url, format_types, unescape_rules, new_parsed,
591 new_parsed, prefix_end, &offsets); 590 prefix_end, &offsets);
592 if (offset_for_adjustment) 591 if (offset_for_adjustment)
593 *offset_for_adjustment = offsets[0]; 592 *offset_for_adjustment = offsets[0];
594 return result; 593 return result;
595 } 594 }
596 595
597 base::string16 FormatUrlWithOffsets( 596 base::string16 FormatUrlWithOffsets(
598 const GURL& url, 597 const GURL& url,
599 const std::string& languages,
600 FormatUrlTypes format_types, 598 FormatUrlTypes format_types,
601 net::UnescapeRule::Type unescape_rules, 599 net::UnescapeRule::Type unescape_rules,
602 url::Parsed* new_parsed, 600 url::Parsed* new_parsed,
603 size_t* prefix_end, 601 size_t* prefix_end,
604 std::vector<size_t>* offsets_for_adjustment) { 602 std::vector<size_t>* offsets_for_adjustment) {
605 base::OffsetAdjuster::Adjustments adjustments; 603 base::OffsetAdjuster::Adjustments adjustments;
606 const base::string16& format_url_return_value = 604 const base::string16& format_url_return_value =
607 FormatUrlWithAdjustments(url, std::string(), format_types, unescape_rules, 605 FormatUrlWithAdjustments(url, format_types, unescape_rules, new_parsed,
608 new_parsed, prefix_end, &adjustments); 606 prefix_end, &adjustments);
609 base::OffsetAdjuster::AdjustOffsets(adjustments, offsets_for_adjustment); 607 base::OffsetAdjuster::AdjustOffsets(adjustments, offsets_for_adjustment);
610 if (offsets_for_adjustment) { 608 if (offsets_for_adjustment) {
611 std::for_each( 609 std::for_each(
612 offsets_for_adjustment->begin(), offsets_for_adjustment->end(), 610 offsets_for_adjustment->begin(), offsets_for_adjustment->end(),
613 base::LimitOffset<std::string>(format_url_return_value.length())); 611 base::LimitOffset<std::string>(format_url_return_value.length()));
614 } 612 }
615 return format_url_return_value; 613 return format_url_return_value;
616 } 614 }
617 615
618 base::string16 FormatUrlWithAdjustments( 616 base::string16 FormatUrlWithAdjustments(
619 const GURL& url, 617 const GURL& url,
620 const std::string& languages,
621 FormatUrlTypes format_types, 618 FormatUrlTypes format_types,
622 net::UnescapeRule::Type unescape_rules, 619 net::UnescapeRule::Type unescape_rules,
623 url::Parsed* new_parsed, 620 url::Parsed* new_parsed,
624 size_t* prefix_end, 621 size_t* prefix_end,
625 base::OffsetAdjuster::Adjustments* adjustments) { 622 base::OffsetAdjuster::Adjustments* adjustments) {
626 DCHECK(adjustments != NULL); 623 DCHECK(adjustments != NULL);
627 adjustments->clear(); 624 adjustments->clear();
628 url::Parsed parsed_temp; 625 url::Parsed parsed_temp;
629 if (!new_parsed) 626 if (!new_parsed)
630 new_parsed = &parsed_temp; 627 new_parsed = &parsed_temp;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 return url_string; 770 return url_string;
774 } 771 }
775 772
776 bool CanStripTrailingSlash(const GURL& url) { 773 bool CanStripTrailingSlash(const GURL& url) {
777 // Omit the path only for standard, non-file URLs with nothing but "/" after 774 // Omit the path only for standard, non-file URLs with nothing but "/" after
778 // the hostname. 775 // the hostname.
779 return url.IsStandard() && !url.SchemeIsFile() && !url.SchemeIsFileSystem() && 776 return url.IsStandard() && !url.SchemeIsFile() && !url.SchemeIsFileSystem() &&
780 !url.has_query() && !url.has_ref() && url.path() == "/"; 777 !url.has_query() && !url.has_ref() && url.path() == "/";
781 } 778 }
782 779
783 void AppendFormattedHost(const GURL& url, 780 void AppendFormattedHost(const GURL& url, base::string16* output) {
784 const std::string& languages,
785 base::string16* output) {
786 AppendFormattedComponent( 781 AppendFormattedComponent(
787 url.possibly_invalid_spec(), url.parsed_for_possibly_invalid_spec().host, 782 url.possibly_invalid_spec(), url.parsed_for_possibly_invalid_spec().host,
788 HostComponentTransform(), output, NULL, NULL); 783 HostComponentTransform(), output, NULL, NULL);
789 } 784 }
790 785
791 base::string16 IDNToUnicode(const std::string& host, 786 base::string16 IDNToUnicode(const std::string& host) {
792 const std::string& languages) { 787 return IDNToUnicodeWithAdjustments(host, nullptr);
793 return IDNToUnicodeWithAdjustments(host, NULL);
794 } 788 }
795 789
796 base::string16 StripWWW(const base::string16& text) { 790 base::string16 StripWWW(const base::string16& text) {
797 const base::string16 www(base::ASCIIToUTF16("www.")); 791 const base::string16 www(base::ASCIIToUTF16("www."));
798 return base::StartsWith(text, www, base::CompareCase::SENSITIVE) 792 return base::StartsWith(text, www, base::CompareCase::SENSITIVE)
799 ? text.substr(www.length()) : text; 793 ? text.substr(www.length()) : text;
800 } 794 }
801 795
802 base::string16 StripWWWFromHost(const GURL& url) { 796 base::string16 StripWWWFromHost(const GURL& url) {
803 DCHECK(url.is_valid()); 797 DCHECK(url.is_valid());
804 return StripWWW(base::ASCIIToUTF16(url.host_piece())); 798 return StripWWW(base::ASCIIToUTF16(url.host_piece()));
805 } 799 }
806 800
807 } // namespace url_formatter 801 } // namespace url_formatter
OLDNEW
« no previous file with comments | « components/url_formatter/url_formatter.h ('k') | components/url_formatter/url_formatter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698