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

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

Issue 2939423003: URL Formatter: Add StripSubdomain method that preserves eTLD + 1. (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 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 // url_formatter contains routines for formatting URLs in a way that can be 5 // url_formatter contains routines for formatting URLs in a way that can be
6 // safely and securely displayed to users. For example, it is responsible 6 // safely and securely displayed to users. For example, it is responsible
7 // for determining when to convert an IDN A-Label (e.g. "xn--[something]") 7 // for determining when to convert an IDN A-Label (e.g. "xn--[something]")
8 // into the IDN U-Label. 8 // into the IDN U-Label.
9 // 9 //
10 // Note that this formatting is only intended for display purposes; it would 10 // Note that this formatting is only intended for display purposes; it would
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 // Converts the given host name to unicode characters. This can be called for 131 // Converts the given host name to unicode characters. This can be called for
132 // any host name, if the input is not IDN or is invalid in some way, we'll just 132 // any host name, if the input is not IDN or is invalid in some way, we'll just
133 // return the ASCII source so it is still usable. 133 // return the ASCII source so it is still usable.
134 // 134 //
135 // The input should be the canonicalized ASCII host name from GURL. This 135 // The input should be the canonicalized ASCII host name from GURL. This
136 // function does NOT accept UTF-8! 136 // function does NOT accept UTF-8!
137 base::string16 IDNToUnicode(base::StringPiece host); 137 base::string16 IDNToUnicode(base::StringPiece host);
138 138
139 // If |text| starts with "www." it is removed, otherwise |text| is returned 139 // If |text| starts with "www." it is removed, otherwise |text| is returned
140 // unmodified. 140 // unmodified. |text| is an arbitrary string and not necessarily a valid host.
141 // Even if |text| is a valid host, this method may return an invalid host.
Peter Kasting 2017/06/17 02:46:55 I think these two sentences use "valid" in a way t
tommycli 2017/06/19 23:03:08 Done.
142 // This is useful for finding search engine keywords inside user input.
141 base::string16 StripWWW(const base::string16& text); 143 base::string16 StripWWW(const base::string16& text);
142 144
143 // Runs |url|'s host through StripWWW(). |url| must be valid. 145 // Returns the host of |url| with subdomains specified by |subdomains|
144 base::string16 StripWWWFromHost(const GURL& url); 146 // removed. |url| must be valid. If the |url| host is already an eTLD+1,
147 // the host is returned unmodified.
148 typedef uint32_t StripSubdomainType;
149 typedef uint32_t StripSubdomainTypes;
150 constexpr StripSubdomainType kStripWWW = 1 << 0;
151 constexpr StripSubdomainType kStripM = 1 << 1;
152 base::StringPiece StripSubdomains(const GURL& url,
153 StripSubdomainTypes subdomains);
145 154
146 } // namespace url_formatter 155 } // namespace url_formatter
147 156
148 #endif // COMPONENTS_URL_FORMATTER_URL_FORMATTER_H_ 157 #endif // COMPONENTS_URL_FORMATTER_URL_FORMATTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698