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