[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame^] | 1 | // Copyright (c) 2011 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_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | |
| 9 | #include <string> |
| 10 | |
[email protected] | a2fedb1e | 2011-01-25 15:23:36 | [diff] [blame] | 11 | #include "base/string16.h" |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 12 | #include "googleurl/src/gurl.h" |
| 13 | |
[email protected] | 71be2a6 | 2009-03-12 00:23:07 | [diff] [blame] | 14 | namespace url_parse { |
[email protected] | d1e83b3 | 2010-12-22 00:34:35 | [diff] [blame] | 15 | struct Component; |
[email protected] | 71be2a6 | 2009-03-12 00:23:07 | [diff] [blame] | 16 | struct Parsed; |
| 17 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 19 | class FilePath; |
| 20 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | // This object is designed to convert various types of input into URLs that we |
| 22 | // know are valid. For example, user typing in the URL bar or command line |
| 23 | // options. This is NOT the place for converting between different types of |
| 24 | // URLs or parsing them, see net_util.h for that. |
| 25 | namespace URLFixerUpper { |
| 26 | |
| 27 | // Segments the given text string into parts of a URL. This is most useful |
| 28 | // for schemes such as http, https, and ftp where |SegmentURL| will find many |
| 29 | // segments. Currently does not segment "file" schemes. |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 30 | // Returns the canonicalized scheme, or the empty string when |text| is only |
| 31 | // whitespace. |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 32 | std::string SegmentURL(const std::string& text, url_parse::Parsed* parts); |
[email protected] | a2fedb1e | 2011-01-25 15:23:36 | [diff] [blame] | 33 | string16 SegmentURL(const string16& text, url_parse::Parsed* parts); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 34 | |
| 35 | // Converts |text| to a fixed-up URL and returns it. Attempts to make |
| 36 | // some "smart" adjustments to obviously-invalid input where possible. |
| 37 | // |text| may be an absolute path to a file, which will get converted to a |
| 38 | // "file:" URL. |
| 39 | // |
| 40 | // 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] | 41 | // be valid, so check the return value's validity or use |
| 42 | // possibly_invalid_spec(). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 43 | // |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame^] | 44 | // Schemes "about" and "chrome" are normalized to "chrome://", with slashes. |
| 45 | // "about:blank" is unaltered, as Webkit allows frames to access about:blank. |
| 46 | // Additionally, if a chrome URL does not have a valid host, as in "about:", |
| 47 | // the returned URL will have the host "version", as in "chrome://version". |
| 48 | // |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 49 | // If |desired_tld| is non-empty, it represents the TLD the user wishes to |
| 50 | // append in the case of an incomplete domain. We check that this is not a |
| 51 | // file path and there does not appear to be a valid TLD already, then append |
| 52 | // |desired_tld| to the domain and prepend "www." (unless it, or a scheme, |
| 53 | // are already present.) This TLD should not have a leading '.' (use "com" |
| 54 | // instead of ".com"). |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 55 | GURL FixupURL(const std::string& text, const std::string& desired_tld); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 56 | |
| 57 | // Converts |text| to a fixed-up URL, allowing it to be a relative path on |
| 58 | // the local filesystem. Begin searching in |base_dir|; if empty, use the |
| 59 | // current working directory. If this resolves to a file on disk, convert it |
| 60 | // to a "file:" URL in |fixed_up_url|; otherwise, fall back to the behavior |
| 61 | // of FixupURL(). |
| 62 | // |
| 63 | // For "regular" input, even if it is possibly a file with a full path, you |
| 64 | // should use FixupURL() directly. This function should only be used when |
| 65 | // relative path handling is desired, as for command line processing. |
[email protected] | 76e7da2 | 2010-06-18 22:44:49 | [diff] [blame] | 66 | GURL FixupRelativeFile(const FilePath& base_dir, const FilePath& text); |
[email protected] | b1c33f8 | 2009-01-23 01:51:23 | [diff] [blame] | 67 | |
[email protected] | d1e83b3 | 2010-12-22 00:34:35 | [diff] [blame] | 68 | // Offsets the beginning index of |part| by |offset|, which is allowed to be |
| 69 | // negative. In some cases, the desired component does not exist at the given |
| 70 | // offset. For example, when converting from "http://foo" to "foo", the |
| 71 | // scheme component no longer exists. In such a case, the beginning index is |
| 72 | // set to 0. |
| 73 | // Does nothing if |part| is invalid. |
| 74 | void OffsetComponent(int offset, url_parse::Component* part); |
| 75 | |
[email protected] | 762c554 | 2009-10-21 16:45:38 | [diff] [blame] | 76 | // For paths like ~, we use $HOME for the current user's home |
| 77 | // directory. For tests, we allow our idea of $HOME to be overriden |
| 78 | // by this variable. |
| 79 | extern const char* home_directory_override; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 80 | }; |
| 81 | |
[email protected] | 11f485728 | 2009-11-13 19:56:17 | [diff] [blame] | 82 | #endif // CHROME_BROWSER_NET_URL_FIXER_UPPER_H_ |