blob: 97bc6c0cdd7189c985cb8514d0adde85723b3860 [file] [log] [blame]
[email protected]76e7da22010-06-18 22:44:491// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]0bfc29a2009-04-27 16:15:445#ifndef CHROME_BROWSER_NET_URL_FIXER_UPPER_H_
6#define CHROME_BROWSER_NET_URL_FIXER_UPPER_H_
initial.commit09911bf2008-07-26 23:55:297
8#include <string>
9
[email protected]76e7da22010-06-18 22:44:4910#include "googleurl/src/gurl.h"
11
[email protected]71be2a62009-03-12 00:23:0712namespace url_parse {
13 struct Parsed;
14}
initial.commit09911bf2008-07-26 23:55:2915
[email protected]b1c33f82009-01-23 01:51:2316class FilePath;
17
initial.commit09911bf2008-07-26 23:55:2918// 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.
22namespace 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]76e7da22010-06-18 22:44:4927 // Returns the canonicalized scheme, or the empty string when |text| is only
28 // whitespace.
[email protected]b1c33f82009-01-23 01:51:2329 std::string SegmentURL(const std::string& text, url_parse::Parsed* parts);
30 // Deprecated temporary compatibility function.
initial.commit09911bf2008-07-26 23:55:2931 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]76e7da22010-06-18 22:44:4939 // be valid, so check the return value's validity or use
40 // possibly_invalid_spec().
initial.commit09911bf2008-07-26 23:55:2941 //
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]76e7da22010-06-18 22:44:4948 GURL FixupURL(const std::string& text, const std::string& desired_tld);
initial.commit09911bf2008-07-26 23:55:2949
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]76e7da22010-06-18 22:44:4959 GURL FixupRelativeFile(const FilePath& base_dir, const FilePath& text);
[email protected]b1c33f82009-01-23 01:51:2360 // Deprecated temporary compatibility function.
[email protected]76e7da22010-06-18 22:44:4961 GURL FixupRelativeFile(const std::wstring& base_dir,
62 const std::wstring& text);
[email protected]b1c33f82009-01-23 01:51:2363
[email protected]762c5542009-10-21 16:45:3864 // 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.commit09911bf2008-07-26 23:55:2968};
69
[email protected]11f4857282009-11-13 19:56:1770#endif // CHROME_BROWSER_NET_URL_FIXER_UPPER_H_