[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame^] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 0bfc29a | 2009-04-27 16:15:44 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_NET_URL_FIXER_UPPER_H_ |
| 6 | #define CHROME_BROWSER_NET_URL_FIXER_UPPER_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame^] | 10 | #include "googleurl/src/gurl.h" |
| 11 | |
[email protected] | 71be2a6 | 2009-03-12 00:23:07 | [diff] [blame] | 12 | namespace url_parse { |
| 13 | struct Parsed; |
| 14 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 16 | class FilePath; |
| 17 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | // This object is designed to convert various types of input into URLs that we |
| 19 | // know are valid. For example, user typing in the URL bar or command line |
| 20 | // options. This is NOT the place for converting between different types of |
| 21 | // URLs or parsing them, see net_util.h for that. |
| 22 | namespace URLFixerUpper { |
| 23 | |
| 24 | // Segments the given text string into parts of a URL. This is most useful |
| 25 | // for schemes such as http, https, and ftp where |SegmentURL| will find many |
| 26 | // segments. Currently does not segment "file" schemes. |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame^] | 27 | // Returns the canonicalized scheme, or the empty string when |text| is only |
| 28 | // whitespace. |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 29 | std::string SegmentURL(const std::string& text, url_parse::Parsed* parts); |
| 30 | // Deprecated temporary compatibility function. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 31 | std::wstring SegmentURL(const std::wstring& text, url_parse::Parsed* parts); |
| 32 | |
| 33 | // Converts |text| to a fixed-up URL and returns it. Attempts to make |
| 34 | // some "smart" adjustments to obviously-invalid input where possible. |
| 35 | // |text| may be an absolute path to a file, which will get converted to a |
| 36 | // "file:" URL. |
| 37 | // |
| 38 | // The result will be a "more" valid URL than the input. It may still not |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame^] | 39 | // be valid, so check the return value's validity or use |
| 40 | // possibly_invalid_spec(). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | // |
| 42 | // If |desired_tld| is non-empty, it represents the TLD the user wishes to |
| 43 | // append in the case of an incomplete domain. We check that this is not a |
| 44 | // file path and there does not appear to be a valid TLD already, then append |
| 45 | // |desired_tld| to the domain and prepend "www." (unless it, or a scheme, |
| 46 | // are already present.) This TLD should not have a leading '.' (use "com" |
| 47 | // instead of ".com"). |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame^] | 48 | GURL FixupURL(const std::string& text, const std::string& desired_tld); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 49 | |
| 50 | // Converts |text| to a fixed-up URL, allowing it to be a relative path on |
| 51 | // the local filesystem. Begin searching in |base_dir|; if empty, use the |
| 52 | // current working directory. If this resolves to a file on disk, convert it |
| 53 | // to a "file:" URL in |fixed_up_url|; otherwise, fall back to the behavior |
| 54 | // of FixupURL(). |
| 55 | // |
| 56 | // For "regular" input, even if it is possibly a file with a full path, you |
| 57 | // should use FixupURL() directly. This function should only be used when |
| 58 | // relative path handling is desired, as for command line processing. |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame^] | 59 | GURL FixupRelativeFile(const FilePath& base_dir, const FilePath& text); |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 60 | // Deprecated temporary compatibility function. |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame^] | 61 | GURL FixupRelativeFile(const std::wstring& base_dir, |
| 62 | const std::wstring& text); |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 63 | |
[email protected] | 762c554 | 2009-10-21 16:45:38 | [diff] [blame] | 64 | // For paths like ~, we use $HOME for the current user's home |
| 65 | // directory. For tests, we allow our idea of $HOME to be overriden |
| 66 | // by this variable. |
| 67 | extern const char* home_directory_override; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 68 | }; |
| 69 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 70 | #endif // CHROME_BROWSER_NET_URL_FIXER_UPPER_H_ |