OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_BASE_DATA_URL_H_ | 5 #ifndef NET_BASE_DATA_URL_H_ |
6 #define NET_BASE_DATA_URL_H_ | 6 #define NET_BASE_DATA_URL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "net/base/net_api.h" | 11 #include "net/base/net_export.h" |
12 | 12 |
13 class GURL; | 13 class GURL; |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 // See RFC 2397 for a complete description of the 'data' URL scheme. | 17 // See RFC 2397 for a complete description of the 'data' URL scheme. |
18 // | 18 // |
19 // Briefly, a 'data' URL has the form: | 19 // Briefly, a 'data' URL has the form: |
20 // | 20 // |
21 // data:[<mediatype>][;base64],<data> | 21 // data:[<mediatype>][;base64],<data> |
22 // | 22 // |
23 // The <mediatype> is an Internet media type specification (with optional | 23 // The <mediatype> is an Internet media type specification (with optional |
24 // parameters.) The appearance of ";base64" means that the data is encoded as | 24 // parameters.) The appearance of ";base64" means that the data is encoded as |
25 // base64. Without ";base64", the data (as a sequence of octets) is represented | 25 // base64. Without ";base64", the data (as a sequence of octets) is represented |
26 // using ASCII encoding for octets inside the range of safe URL characters and | 26 // using ASCII encoding for octets inside the range of safe URL characters and |
27 // using the standard %xx hex encoding of URLs for octets outside that range. | 27 // using the standard %xx hex encoding of URLs for octets outside that range. |
28 // If <mediatype> is omitted, it defaults to text/plain;charset=US-ASCII. As a | 28 // If <mediatype> is omitted, it defaults to text/plain;charset=US-ASCII. As a |
29 // shorthand, "text/plain" can be omitted but the charset parameter supplied. | 29 // shorthand, "text/plain" can be omitted but the charset parameter supplied. |
30 // | 30 // |
31 class NET_API DataURL { | 31 class NET_EXPORT DataURL { |
32 public: | 32 public: |
33 // This method can be used to parse a 'data' URL into its component pieces. | 33 // This method can be used to parse a 'data' URL into its component pieces. |
34 // | 34 // |
35 // The resulting mime_type is normalized to lowercase. The data is the | 35 // The resulting mime_type is normalized to lowercase. The data is the |
36 // decoded data (e.g.., if the data URL specifies base64 encoding, then the | 36 // decoded data (e.g.., if the data URL specifies base64 encoding, then the |
37 // returned data is base64 decoded, and any %-escaped bytes are unescaped). | 37 // returned data is base64 decoded, and any %-escaped bytes are unescaped). |
38 // | 38 // |
39 // If the URL is malformed, then this method will return false, and its | 39 // If the URL is malformed, then this method will return false, and its |
40 // output variables will remain unchanged. On success, true is returned. | 40 // output variables will remain unchanged. On success, true is returned. |
41 // | 41 // |
42 // OPTIONAL: If |data| is NULL, then the <data> section will not be parsed | 42 // OPTIONAL: If |data| is NULL, then the <data> section will not be parsed |
43 // or validated. | 43 // or validated. |
44 // | 44 // |
45 static bool Parse(const GURL& url, | 45 static bool Parse(const GURL& url, |
46 std::string* mime_type, | 46 std::string* mime_type, |
47 std::string* charset, | 47 std::string* charset, |
48 std::string* data); | 48 std::string* data); |
49 }; | 49 }; |
50 | 50 |
51 } // namespace net | 51 } // namespace net |
52 | 52 |
53 #endif // NET_BASE_DATA_URL_H_ | 53 #endif // NET_BASE_DATA_URL_H_ |
OLD | NEW |