1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_HISTORY_URL_UTILS_H_ 6 #define CHROME_BROWSER_HISTORY_URL_UTILS_H_ 7 8 #include <string> 9 10 class GURL; 11 12 namespace history { 13 14 // CanonicalURLStringCompare performs lexicographical comparison of two strings 15 // that represent valid URLs, so that if the pre-path (scheme, host, and port) 16 // parts are equal, then the path parts are compared by treating path components 17 // (delimited by "/") as separate tokens that form units of comparison. 18 // For example, let us compare |s1| and |s2|, with 19 // |s1| = "http://www.google.com:80/base/test/ab/cd?query/stuff" 20 // |s2| = "http://www.google.com:80/base/test-case/yz#ref/stuff" 21 // The pre-path parts "http://www.google.com:80/" match. We treat the paths as 22 // |s1| => ["base", "test", "ab", "cd"] 23 // |s2| => ["base", "test-case", "yz"] 24 // Components 1 "base" are identical. Components 2 yield "test" < "test-case", 25 // so we consider |s1| < |s2|, and return true. Note that naive string 26 // comparison would yield the opposite (|s1| > |s2|), since '/' > '-' in ASCII. 27 // Note that path can be terminated by "?query" or "#ref". The post-path parts 28 // are compared in an arbitrary (but consistent) way. 29 bool CanonicalURLStringCompare(const std::string& s1, const std::string& s2); 30 31 // Returns whether |url1| and |url2| have the same scheme, host, and port. 32 bool HaveSameSchemeHostAndPort(const GURL&url1, const GURL& url2); 33 34 // Treats |path1| and |path2| as lists of path components (e.g., ["a", "bb"] 35 // for "/a/bb"). Returns whether |path1|'s list is a prefix of |path2|'s list. 36 // This is used to define "URL prefix". Note that "test" does not count as a 37 // prefix of "testing", even though "test" is a (string) prefix of "testing". 38 bool IsPathPrefix(const std::string& p1, const std::string& p2); 39 40 // Converts |url| from HTTP to HTTPS, and vice versa, then returns the result. 41 // If |url| is neither HTTP nor HTTPS, returns an empty URL. 42 GURL ToggleHTTPAndHTTPS(const GURL& url); 43 44 } // namespace history 45 46 #endif // CHROME_BROWSER_HISTORY_URL_UTILS_H_ 47