• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
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
12 // distribution.
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.
17 //
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.
29 //
30 // ---------------------------------------------------------------------------
31 //
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.
35 //
36 
37 #ifndef CEF_INCLUDE_CEF_PARSER_H_
38 #define CEF_INCLUDE_CEF_PARSER_H_
39 #pragma once
40 
41 #include <vector>
42 
43 #include "include/cef_base.h"
44 #include "include/cef_values.h"
45 
46 ///
47 // Parse the specified |url| into its component parts.
48 // Returns false if the URL is empty or invalid.
49 ///
50 /*--cef()--*/
51 bool CefParseURL(const CefString& url, CefURLParts& parts);
52 
53 ///
54 // Creates a URL from the specified |parts|, which must contain a non-empty
55 // spec or a non-empty host and path (at a minimum), but not both.
56 // Returns false if |parts| isn't initialized as described.
57 ///
58 /*--cef()--*/
59 bool CefCreateURL(const CefURLParts& parts, CefString& url);
60 
61 ///
62 // This is a convenience function for formatting a URL in a concise and human-
63 // friendly way to help users make security-related decisions (or in other
64 // circumstances when people need to distinguish sites, origins, or otherwise-
65 // simplified URLs from each other). Internationalized domain names (IDN) may be
66 // presented in Unicode if the conversion is considered safe. The returned value
67 // will (a) omit the path for standard schemes, excepting file and filesystem,
68 // and (b) omit the port if it is the default for the scheme. Do not use this
69 // for URLs which will be parsed or sent to other applications.
70 ///
71 /*--cef(optional_param=languages)--*/
72 CefString CefFormatUrlForSecurityDisplay(const CefString& origin_url);
73 
74 ///
75 // Returns the mime type for the specified file extension or an empty string if
76 // unknown.
77 ///
78 /*--cef()--*/
79 CefString CefGetMimeType(const CefString& extension);
80 
81 ///
82 // Get the extensions associated with the given mime type. This should be passed
83 // in lower case. There could be multiple extensions for a given mime type, like
84 // "html,htm" for "text/html", or "txt,text,html,..." for "text/*". Any existing
85 // elements in the provided vector will not be erased.
86 ///
87 /*--cef()--*/
88 void CefGetExtensionsForMimeType(const CefString& mime_type,
89                                  std::vector<CefString>& extensions);
90 
91 ///
92 // Encodes |data| as a base64 string.
93 ///
94 /*--cef()--*/
95 CefString CefBase64Encode(const void* data, size_t data_size);
96 
97 ///
98 // Decodes the base64 encoded string |data|. The returned value will be NULL if
99 // the decoding fails.
100 ///
101 /*--cef()--*/
102 CefRefPtr<CefBinaryValue> CefBase64Decode(const CefString& data);
103 
104 ///
105 // Escapes characters in |text| which are unsuitable for use as a query
106 // parameter value. Everything except alphanumerics and -_.!~*'() will be
107 // converted to "%XX". If |use_plus| is true spaces will change to "+". The
108 // result is basically the same as encodeURIComponent in Javacript.
109 ///
110 /*--cef()--*/
111 CefString CefURIEncode(const CefString& text, bool use_plus);
112 
113 ///
114 // Unescapes |text| and returns the result. Unescaping consists of looking for
115 // the exact pattern "%XX" where each X is a hex digit and converting to the
116 // character with the numerical value of those digits (e.g. "i%20=%203%3b"
117 // unescapes to "i = 3;"). If |convert_to_utf8| is true this function will
118 // attempt to interpret the initial decoded result as UTF-8. If the result is
119 // convertable into UTF-8 it will be returned as converted. Otherwise the
120 // initial decoded result will be returned.  The |unescape_rule| parameter
121 // supports further customization the decoding process.
122 ///
123 /*--cef()--*/
124 CefString CefURIDecode(const CefString& text,
125                        bool convert_to_utf8,
126                        cef_uri_unescape_rule_t unescape_rule);
127 
128 ///
129 // Parses the specified |json_string| and returns a dictionary or list
130 // representation. If JSON parsing fails this method returns NULL.
131 ///
132 /*--cef()--*/
133 CefRefPtr<CefValue> CefParseJSON(const CefString& json_string,
134                                  cef_json_parser_options_t options);
135 
136 ///
137 // Parses the specified UTF8-encoded |json| buffer of size |json_size| and
138 // returns a dictionary or list representation. If JSON parsing fails this
139 // method returns NULL.
140 ///
141 /*--cef(capi_name=cef_parse_json_buffer)--*/
142 CefRefPtr<CefValue> CefParseJSON(const void* json,
143                                  size_t json_size,
144                                  cef_json_parser_options_t options);
145 
146 ///
147 // Parses the specified |json_string| and returns a dictionary or list
148 // representation. If JSON parsing fails this method returns NULL and populates
149 // |error_msg_out| with a formatted error message.
150 ///
151 /*--cef()--*/
152 CefRefPtr<CefValue> CefParseJSONAndReturnError(
153     const CefString& json_string,
154     cef_json_parser_options_t options,
155     CefString& error_msg_out);
156 
157 ///
158 // Generates a JSON string from the specified root |node| which should be a
159 // dictionary or list value. Returns an empty string on failure. This method
160 // requires exclusive access to |node| including any underlying data.
161 ///
162 /*--cef()--*/
163 CefString CefWriteJSON(CefRefPtr<CefValue> node,
164                        cef_json_writer_options_t options);
165 
166 #endif  // CEF_INCLUDE_CEF_PARSER_H_
167