1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
13 // * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // ---------------------------------------------------------------------------
32 // The contents of this file must follow a specific format in order to
33 // support the CEF translator tool. See the translator.README.txt file in the
34 // tools directory for more information.
37 #ifndef CEF_INCLUDE_CEF_PARSER_H_
38 #define CEF_INCLUDE_CEF_PARSER_H_
43 #include "include/cef_base.h"
44 #include "include/cef_values.h"
47 // Parse the specified |url| into its component parts.
48 // Returns false if the URL is empty or invalid.
51 bool CefParseURL(const CefString& url,
55 // Creates a URL from the specified |parts|, which must contain a non-empty
56 // spec or a non-empty host and path (at a minimum), but not both.
57 // Returns false if |parts| isn't initialized as described.
60 bool CefCreateURL(const CefURLParts& parts,
64 // This is a convenience function for formatting a URL in a concise and human-
65 // friendly way to help users make security-related decisions (or in other
66 // circumstances when people need to distinguish sites, origins, or otherwise-
67 // simplified URLs from each other). Internationalized domain names (IDN) may be
68 // presented in Unicode if the conversion is considered safe. The returned value
69 // will (a) omit the path for standard schemes, excepting file and filesystem,
70 // and (b) omit the port if it is the default for the scheme. Do not use this
71 // for URLs which will be parsed or sent to other applications.
73 /*--cef(optional_param=languages)--*/
74 CefString CefFormatUrlForSecurityDisplay(const CefString& origin_url);
77 // Returns the mime type for the specified file extension or an empty string if
81 CefString CefGetMimeType(const CefString& extension);
84 // Get the extensions associated with the given mime type. This should be passed
85 // in lower case. There could be multiple extensions for a given mime type, like
86 // "html,htm" for "text/html", or "txt,text,html,..." for "text/*". Any existing
87 // elements in the provided vector will not be erased.
90 void CefGetExtensionsForMimeType(const CefString& mime_type,
91 std::vector<CefString>& extensions);
94 // Encodes |data| as a base64 string.
97 CefString CefBase64Encode(const void* data, size_t data_size);
100 // Decodes the base64 encoded string |data|. The returned value will be NULL if
101 // the decoding fails.
104 CefRefPtr<CefBinaryValue> CefBase64Decode(const CefString& data);
107 // Escapes characters in |text| which are unsuitable for use as a query
108 // parameter value. Everything except alphanumerics and -_.!~*'() will be
109 // converted to "%XX". If |use_plus| is true spaces will change to "+". The
110 // result is basically the same as encodeURIComponent in Javacript.
113 CefString CefURIEncode(const CefString& text, bool use_plus);
116 // Unescapes |text| and returns the result. Unescaping consists of looking for
117 // the exact pattern "%XX" where each X is a hex digit and converting to the
118 // character with the numerical value of those digits (e.g. "i%20=%203%3b"
119 // unescapes to "i = 3;"). If |convert_to_utf8| is true this function will
120 // attempt to interpret the initial decoded result as UTF-8. If the result is
121 // convertable into UTF-8 it will be returned as converted. Otherwise the
122 // initial decoded result will be returned. The |unescape_rule| parameter
123 // supports further customization the decoding process.
126 CefString CefURIDecode(const CefString& text,
127 bool convert_to_utf8,
128 cef_uri_unescape_rule_t unescape_rule);
131 // Parses the specified |json_string| and returns a dictionary or list
132 // representation. If JSON parsing fails this method returns NULL.
135 CefRefPtr<CefValue> CefParseJSON(const CefString& json_string,
136 cef_json_parser_options_t options);
139 // Parses the specified |json_string| and returns a dictionary or list
140 // representation. If JSON parsing fails this method returns NULL and populates
141 // |error_code_out| and |error_msg_out| with an error code and a formatted error
142 // message respectively.
145 CefRefPtr<CefValue> CefParseJSONAndReturnError(
146 const CefString& json_string,
147 cef_json_parser_options_t options,
148 cef_json_parser_error_t& error_code_out,
149 CefString& error_msg_out);
152 // Generates a JSON string from the specified root |node| which should be a
153 // dictionary or list value. Returns an empty string on failure. This method
154 // requires exclusive access to |node| including any underlying data.
157 CefString CefWriteJSON(CefRefPtr<CefValue> node,
158 cef_json_writer_options_t options);
160 #endif // CEF_INCLUDE_CEF_PARSER_H_