blob: f5b5327526dadbfb10bd40c561962c1366c0643f [file] [log] [blame]
[email protected]89f550b2011-06-08 18:34:031// Copyright (c) 2011 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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
initial.commit09911bf2008-07-26 23:55:298
9#include <string>
10
[email protected]a2fedb1e2011-01-25 15:23:3611#include "base/string16.h"
[email protected]76e7da22010-06-18 22:44:4912#include "googleurl/src/gurl.h"
13
[email protected]71be2a62009-03-12 00:23:0714namespace url_parse {
[email protected]d1e83b32010-12-22 00:34:3515 struct Component;
[email protected]71be2a62009-03-12 00:23:0716 struct Parsed;
17}
initial.commit09911bf2008-07-26 23:55:2918
[email protected]b1c33f82009-01-23 01:51:2319class FilePath;
20
initial.commit09911bf2008-07-26 23:55:2921// 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.
25namespace 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]76e7da22010-06-18 22:44:4930 // Returns the canonicalized scheme, or the empty string when |text| is only
31 // whitespace.
[email protected]b1c33f82009-01-23 01:51:2332 std::string SegmentURL(const std::string& text, url_parse::Parsed* parts);
[email protected]a2fedb1e2011-01-25 15:23:3633 string16 SegmentURL(const string16& text, url_parse::Parsed* parts);
initial.commit09911bf2008-07-26 23:55:2934
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]76e7da22010-06-18 22:44:4941 // be valid, so check the return value's validity or use
42 // possibly_invalid_spec().
initial.commit09911bf2008-07-26 23:55:2943 //
[email protected]89f550b2011-06-08 18:34:0344 // 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.commit09911bf2008-07-26 23:55:2949 // 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]76e7da22010-06-18 22:44:4955 GURL FixupURL(const std::string& text, const std::string& desired_tld);
initial.commit09911bf2008-07-26 23:55:2956
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]76e7da22010-06-18 22:44:4966 GURL FixupRelativeFile(const FilePath& base_dir, const FilePath& text);
[email protected]b1c33f82009-01-23 01:51:2367
[email protected]d1e83b32010-12-22 00:34:3568 // 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]762c5542009-10-21 16:45:3876 // 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.commit09911bf2008-07-26 23:55:2980};
81
[email protected]11f4857282009-11-13 19:56:1782#endif // CHROME_BROWSER_NET_URL_FIXER_UPPER_H_