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_STREAM_H_
38 #define CEF_INCLUDE_CEF_STREAM_H_
40 #include "include/cef_base.h"
43 // Interface the client can implement to provide a custom stream reader. The
44 // methods of this class may be called on any thread.
46 /*--cef(source=client)--*/
47 class CefReadHandler : public virtual CefBase {
50 // Read raw binary data.
53 virtual size_t Read(void* ptr, size_t size, size_t n) =0;
56 // Seek to the specified offset position. |whence| may be any one of
57 // SEEK_CUR, SEEK_END or SEEK_SET. Return zero on success and non-zero on
61 virtual int Seek(int64 offset, int whence) =0;
64 // Return the current offset position.
67 virtual int64 Tell() =0;
70 // Return non-zero if at end of file.
76 // Return true if this handler performs work like accessing the file system
77 // which may block. Used as a hint for determining the thread to access the
81 virtual bool MayBlock() =0;
86 // Class used to read data from a stream. The methods of this class may be
87 // called on any thread.
89 /*--cef(source=library)--*/
90 class CefStreamReader : public virtual CefBase {
93 // Create a new CefStreamReader object from a file.
96 static CefRefPtr<CefStreamReader> CreateForFile(const CefString& fileName);
98 // Create a new CefStreamReader object from data.
101 static CefRefPtr<CefStreamReader> CreateForData(void* data, size_t size);
103 // Create a new CefStreamReader object from a custom handler.
106 static CefRefPtr<CefStreamReader> CreateForHandler(
107 CefRefPtr<CefReadHandler> handler);
110 // Read raw binary data.
113 virtual size_t Read(void* ptr, size_t size, size_t n) =0;
116 // Seek to the specified offset position. |whence| may be any one of
117 // SEEK_CUR, SEEK_END or SEEK_SET. Returns zero on success and non-zero on
121 virtual int Seek(int64 offset, int whence) =0;
124 // Return the current offset position.
127 virtual int64 Tell() =0;
130 // Return non-zero if at end of file.
133 virtual int Eof() =0;
136 // Returns true if this reader performs work like accessing the file system
137 // which may block. Used as a hint for determining the thread to access the
141 virtual bool MayBlock() =0;
146 // Interface the client can implement to provide a custom stream writer. The
147 // methods of this class may be called on any thread.
149 /*--cef(source=client)--*/
150 class CefWriteHandler : public virtual CefBase {
153 // Write raw binary data.
156 virtual size_t Write(const void* ptr, size_t size, size_t n) =0;
159 // Seek to the specified offset position. |whence| may be any one of
160 // SEEK_CUR, SEEK_END or SEEK_SET. Return zero on success and non-zero on
164 virtual int Seek(int64 offset, int whence) =0;
167 // Return the current offset position.
170 virtual int64 Tell() =0;
176 virtual int Flush() =0;
179 // Return true if this handler performs work like accessing the file system
180 // which may block. Used as a hint for determining the thread to access the
184 virtual bool MayBlock() =0;
189 // Class used to write data to a stream. The methods of this class may be called
192 /*--cef(source=library)--*/
193 class CefStreamWriter : public virtual CefBase {
196 // Create a new CefStreamWriter object for a file.
199 static CefRefPtr<CefStreamWriter> CreateForFile(const CefString& fileName);
201 // Create a new CefStreamWriter object for a custom handler.
204 static CefRefPtr<CefStreamWriter> CreateForHandler(
205 CefRefPtr<CefWriteHandler> handler);
208 // Write raw binary data.
211 virtual size_t Write(const void* ptr, size_t size, size_t n) =0;
214 // Seek to the specified offset position. |whence| may be any one of
215 // SEEK_CUR, SEEK_END or SEEK_SET. Returns zero on success and non-zero on
219 virtual int Seek(int64 offset, int whence) =0;
222 // Return the current offset position.
225 virtual int64 Tell() =0;
231 virtual int Flush() =0;
234 // Returns true if this writer performs work like accessing the file system
235 // which may block. Used as a hint for determining the thread to access the
239 virtual bool MayBlock() =0;
242 #endif // CEF_INCLUDE_CEF_STREAM_H_