blob: c7f3f005070973410ae362a4f058b4914b4289c3 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 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.
initial.commit09911bf2008-07-26 23:55:294
5#ifndef CHROME_BROWSER_URL_FIXER_UPPER_H__
6#define CHROME_BROWSER_URL_FIXER_UPPER_H__
7
8#include <string>
9
10#include "googleurl/src/url_parse.h"
11
12// This object is designed to convert various types of input into URLs that we
13// know are valid. For example, user typing in the URL bar or command line
14// options. This is NOT the place for converting between different types of
15// URLs or parsing them, see net_util.h for that.
16namespace URLFixerUpper {
17
18 // Segments the given text string into parts of a URL. This is most useful
19 // for schemes such as http, https, and ftp where |SegmentURL| will find many
20 // segments. Currently does not segment "file" schemes.
21 std::wstring SegmentURL(const std::wstring& text, url_parse::Parsed* parts);
22
23 // Converts |text| to a fixed-up URL and returns it. Attempts to make
24 // some "smart" adjustments to obviously-invalid input where possible.
25 // |text| may be an absolute path to a file, which will get converted to a
26 // "file:" URL.
27 //
28 // The result will be a "more" valid URL than the input. It may still not
29 // be valid, convert to a GURL for that.
30 //
31 // If |desired_tld| is non-empty, it represents the TLD the user wishes to
32 // append in the case of an incomplete domain. We check that this is not a
33 // file path and there does not appear to be a valid TLD already, then append
34 // |desired_tld| to the domain and prepend "www." (unless it, or a scheme,
35 // are already present.) This TLD should not have a leading '.' (use "com"
36 // instead of ".com").
37 std::wstring FixupURL(const std::wstring& text,
38 const std::wstring& desired_tld);
39
40 // Converts |text| to a fixed-up URL, allowing it to be a relative path on
41 // the local filesystem. Begin searching in |base_dir|; if empty, use the
42 // current working directory. If this resolves to a file on disk, convert it
43 // to a "file:" URL in |fixed_up_url|; otherwise, fall back to the behavior
44 // of FixupURL().
45 //
46 // For "regular" input, even if it is possibly a file with a full path, you
47 // should use FixupURL() directly. This function should only be used when
48 // relative path handling is desired, as for command line processing.
49 std::wstring FixupRelativeFile(const std::wstring& base_dir,
50 const std::wstring& text);
51};
52
53#endif // #ifndef CHROME_BROWSER_URL_FIXER_UPPER_H__
license.botbf09a502008-08-24 00:55:5554