Files.app: Show surprise-unplug warning on kDiskRemoved event rather than kDeviceRemoved.
[chromium-blink-merge.git] / components / url_fixer / url_fixer.h
blobfa682d74a58981e468fd38a73e19e62767583694
1 // Copyright (c) 2011 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.
5 #ifndef COMPONENTS_URL_FIXER_URL_FIXER_H_
6 #define COMPONENTS_URL_FIXER_URL_FIXER_H_
8 #include <string>
10 #include "base/strings/string16.h"
11 #include "url/gurl.h"
13 namespace base {
14 class FilePath;
17 namespace url {
18 struct Component;
19 struct Parsed;
22 // This object is designed to convert various types of input into URLs that we
23 // know are valid. For example, user typing in the URL bar or command line
24 // options. This is NOT the place for converting between different types of
25 // URLs or parsing them, see net_util.h for that.
26 namespace url_fixer {
28 // Segments the given text string into parts of a URL. This is most useful
29 // for schemes such as http, https, and ftp where |SegmentURL| will find many
30 // segments. Currently does not segment "file" schemes.
31 // Returns the canonicalized scheme, or the empty string when |text| is only
32 // whitespace.
33 std::string SegmentURL(const std::string& text, url::Parsed* parts);
34 base::string16 SegmentURL(const base::string16& text, url::Parsed* parts);
36 // Converts |text| to a fixed-up URL and returns it. Attempts to make
37 // some "smart" adjustments to obviously-invalid input where possible.
38 // |text| may be an absolute path to a file, which will get converted to a
39 // "file:" URL.
41 // The result will be a "more" valid URL than the input. It may still not
42 // be valid, so check the return value's validity or use
43 // possibly_invalid_spec().
45 // Schemes "about" and "chrome" are normalized to "chrome://", with slashes.
46 // "about:blank" is unaltered, as Webkit allows frames to access about:blank.
47 // Additionally, if a chrome URL does not have a valid host, as in "about:",
48 // the returned URL will have the host "version", as in "chrome://version".
50 // If |desired_tld| is non-empty, it represents the TLD the user wishes to
51 // append in the case of an incomplete domain. We check that this is not a
52 // file path and there does not appear to be a valid TLD already, then append
53 // |desired_tld| to the domain and prepend "www." (unless it, or a scheme,
54 // are already present.) This TLD should not have a leading '.' (use "com"
55 // instead of ".com").
56 GURL FixupURL(const std::string& text, const std::string& desired_tld);
58 // Converts |text| to a fixed-up URL, allowing it to be a relative path on
59 // the local filesystem. Begin searching in |base_dir|; if empty, use the
60 // current working directory. If this resolves to a file on disk, convert it
61 // to a "file:" URL in |fixed_up_url|; otherwise, fall back to the behavior
62 // of FixupURL().
64 // For "regular" input, even if it is possibly a file with a full path, you
65 // should use FixupURL() directly. This function should only be used when
66 // relative path handling is desired, as for command line processing.
67 GURL FixupRelativeFile(const base::FilePath& base_dir,
68 const base::FilePath& text);
70 // Offsets the beginning index of |part| by |offset|, which is allowed to be
71 // negative. In some cases, the desired component does not exist at the given
72 // offset. For example, when converting from "http://foo" to "foo", the
73 // scheme component no longer exists. In such a case, the beginning index is
74 // set to 0.
75 // Does nothing if |part| is invalid.
76 void OffsetComponent(int offset, url::Component* part);
78 // For paths like ~, we use $HOME for the current user's home
79 // directory. For tests, we allow our idea of $HOME to be overriden
80 // by this variable.
81 extern const char* home_directory_override;
83 } // namespace url_fixer
85 #endif // COMPONENTS_URL_FIXER_URL_FIXER_H_