mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Expose zip archive reading support (issue #30).
Move ClientReadHandler to CefByteReadHandler in cef_wrapper.h. Add support for the time_t data type to cef_parser.py. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@125 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -1272,7 +1272,7 @@ public:
|
||||
/*--cef()--*/
|
||||
virtual bool MoveToNextNode() =0;
|
||||
|
||||
// Close the document. This must be called directly to ensure that cleanup
|
||||
// Close the document. This should be called directly to ensure that cleanup
|
||||
// occurs on the correct thread.
|
||||
/*--cef()--*/
|
||||
virtual bool Close() =0;
|
||||
@@ -1412,4 +1412,74 @@ public:
|
||||
virtual bool MoveToCarryingElement() =0;
|
||||
};
|
||||
|
||||
|
||||
// Class that supports the reading of zip archives via the zlib unzip API.
|
||||
/*--cef(source=library)--*/
|
||||
class CefZipReader : public CefBase
|
||||
{
|
||||
public:
|
||||
// Create a new CefZipReader object. The returned object's methods can only
|
||||
// be called from the thread that created the object.
|
||||
/*--cef()--*/
|
||||
static CefRefPtr<CefZipReader> Create(CefRefPtr<CefStreamReader> stream);
|
||||
|
||||
// Moves the cursor to the first file in the archive. Returns true if the
|
||||
// cursor position was set successfully.
|
||||
/*--cef()--*/
|
||||
virtual bool MoveToFirstFile() =0;
|
||||
|
||||
// Moves the cursor to the next file in the archive. Returns true if the
|
||||
// cursor position was set successfully.
|
||||
/*--cef()--*/
|
||||
virtual bool MoveToNextFile() =0;
|
||||
|
||||
// Moves the cursor to the specified file in the archive. If |caseSensitive|
|
||||
// is true then the search will be case sensitive. Returns true if the cursor
|
||||
// position was set successfully.
|
||||
/*--cef()--*/
|
||||
virtual bool MoveToFile(const std::wstring& fileName, bool caseSensitive) =0;
|
||||
|
||||
// Closes the archive. This should be called directly to ensure that cleanup
|
||||
// occurs on the correct thread.
|
||||
/*--cef()--*/
|
||||
virtual bool Close() =0;
|
||||
|
||||
|
||||
// The below methods act on the file at the current cursor position.
|
||||
|
||||
// Returns the name of the file.
|
||||
/*--cef()--*/
|
||||
virtual std::wstring GetFileName() =0;
|
||||
|
||||
// Returns the uncompressed size of the file.
|
||||
/*--cef()--*/
|
||||
virtual long GetFileSize() =0;
|
||||
|
||||
// Returns the last modified timestamp for the file.
|
||||
/*--cef()--*/
|
||||
virtual time_t GetFileLastModified() =0;
|
||||
|
||||
// Opens the file for reading of uncompressed data. A read password may
|
||||
// optionally be specified.
|
||||
/*--cef()--*/
|
||||
virtual bool OpenFile(const std::wstring& password) =0;
|
||||
|
||||
// Closes the file.
|
||||
/*--cef()--*/
|
||||
virtual bool CloseFile() =0;
|
||||
|
||||
// Read uncompressed file contents into the specified buffer. Returns < 0 if
|
||||
// an error occurred, 0 if at the end of file, or the number of bytes read.
|
||||
/*--cef()--*/
|
||||
virtual int ReadFile(void* buffer, size_t bufferSize) =0;
|
||||
|
||||
// Returns the current offset in the uncompressed file contents.
|
||||
/*--cef()--*/
|
||||
virtual long Tell() =0;
|
||||
|
||||
// Returns true if at end of the file contents.
|
||||
/*--cef()--*/
|
||||
virtual bool Eof() =0;
|
||||
};
|
||||
|
||||
#endif // _CEF_H
|
||||
|
@@ -1015,7 +1015,7 @@ typedef struct _cef_xml_reader_t
|
||||
// if the cursor position was set successfully.
|
||||
int (CEF_CALLBACK *move_to_next_node)(struct _cef_xml_reader_t* self);
|
||||
|
||||
// Close the document. This must be called directly to ensure that cleanup
|
||||
// Close the document. This should be called directly to ensure that cleanup
|
||||
// occurs on the correct thread.
|
||||
int (CEF_CALLBACK *close)(struct _cef_xml_reader_t* self);
|
||||
|
||||
@@ -1157,6 +1157,70 @@ CEF_EXPORT cef_xml_reader_t* cef_xml_reader_create(cef_stream_reader_t* stream,
|
||||
enum cef_xml_encoding_type_t encodingType, const wchar_t* URI);
|
||||
|
||||
|
||||
// Structure that supports the reading of zip archives via the zlib unzip API.
|
||||
typedef struct _cef_zip_reader_t
|
||||
{
|
||||
// Base structure.
|
||||
cef_base_t base;
|
||||
|
||||
// Moves the cursor to the first file in the archive. Returns true (1) if the
|
||||
// cursor position was set successfully.
|
||||
int (CEF_CALLBACK *move_to_first_file)(struct _cef_zip_reader_t* self);
|
||||
|
||||
// Moves the cursor to the next file in the archive. Returns true (1) if the
|
||||
// cursor position was set successfully.
|
||||
int (CEF_CALLBACK *move_to_next_file)(struct _cef_zip_reader_t* self);
|
||||
|
||||
// Moves the cursor to the specified file in the archive. If |caseSensitive|
|
||||
// is true (1) then the search will be case sensitive. Returns true (1) if the
|
||||
// cursor position was set successfully.
|
||||
int (CEF_CALLBACK *move_to_file)(struct _cef_zip_reader_t* self,
|
||||
const wchar_t* fileName, int caseSensitive);
|
||||
|
||||
// Closes the archive. This should be called directly to ensure that cleanup
|
||||
// occurs on the correct thread.
|
||||
int (CEF_CALLBACK *close)(struct _cef_zip_reader_t* self);
|
||||
|
||||
|
||||
// The below functions act on the file at the current cursor position.
|
||||
|
||||
// Returns the name of the file.
|
||||
// The resulting string must be freed by calling cef_string_free().
|
||||
cef_string_t (CEF_CALLBACK *get_file_name)(struct _cef_zip_reader_t* self);
|
||||
|
||||
// Returns the uncompressed size of the file.
|
||||
long (CEF_CALLBACK *get_file_size)(struct _cef_zip_reader_t* self);
|
||||
|
||||
// Returns the last modified timestamp for the file.
|
||||
time_t (CEF_CALLBACK *get_file_last_modified)(struct _cef_zip_reader_t* self);
|
||||
|
||||
// Opens the file for reading of uncompressed data. A read password may
|
||||
// optionally be specified.
|
||||
int (CEF_CALLBACK *open_file)(struct _cef_zip_reader_t* self,
|
||||
const wchar_t* password);
|
||||
|
||||
// Closes the file.
|
||||
int (CEF_CALLBACK *close_file)(struct _cef_zip_reader_t* self);
|
||||
|
||||
// Read uncompressed file contents into the specified buffer. Returns < 0 if
|
||||
// an error occurred, 0 if at the end of file, or the number of bytes read.
|
||||
int (CEF_CALLBACK *read_file)(struct _cef_zip_reader_t* self, void* buffer,
|
||||
size_t bufferSize);
|
||||
|
||||
// Returns the current offset in the uncompressed file contents.
|
||||
long (CEF_CALLBACK *tell)(struct _cef_zip_reader_t* self);
|
||||
|
||||
// Returns true (1) if at end of the file contents.
|
||||
int (CEF_CALLBACK *eof)(struct _cef_zip_reader_t* self);
|
||||
|
||||
} cef_zip_reader_t;
|
||||
|
||||
|
||||
// Create a new cef_zip_reader_t object. The returned object's functions can
|
||||
// only be called from the thread that created the object.
|
||||
CEF_EXPORT cef_zip_reader_t* cef_zip_reader_create(cef_stream_reader_t* stream);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -40,6 +40,11 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#ifndef min
|
||||
#define min(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
|
||||
// Thread safe class for representing XML data as a structured object. This
|
||||
// class should not be used with large XML documents because all data will be
|
||||
// resident in memory at the same time. This implementation supports a
|
||||
@@ -149,4 +154,97 @@ private:
|
||||
ObjectVector children_;
|
||||
};
|
||||
|
||||
|
||||
// Thread safe implementation of the CefReadHandler class for reading an
|
||||
// in-memory array of bytes.
|
||||
class CefByteReadHandler : public CefThreadSafeBase<CefReadHandler>
|
||||
{
|
||||
public:
|
||||
// Create a new object for reading an array of bytes. An optional |source|
|
||||
// reference can be kept to keep the underlying data source from being
|
||||
// released while the reader exists.
|
||||
CefByteReadHandler(const unsigned char* bytes, size_t size,
|
||||
CefRefPtr<CefBase> source);
|
||||
|
||||
// Read raw binary data.
|
||||
virtual size_t Read(void* ptr, size_t size, size_t n);
|
||||
|
||||
// Seek to the specified offset position. |whence| may be any one of
|
||||
// SEEK_CUR, SEEK_END or SEEK_SET.
|
||||
virtual int Seek(long offset, int whence);
|
||||
|
||||
// Return the current offset position.
|
||||
virtual long Tell();
|
||||
|
||||
// Return non-zero if at end of file.
|
||||
virtual int Eof();
|
||||
|
||||
private:
|
||||
const unsigned char* bytes_;
|
||||
size_t size_;
|
||||
size_t offset_;
|
||||
CefRefPtr<CefBase> source_;
|
||||
};
|
||||
|
||||
|
||||
// Thread-safe class for accessing zip archive file contents. This class should
|
||||
// not be used with large archive files because all data will be resident in
|
||||
// memory at the same time. This implementation supports a restricted set of zip
|
||||
// archive features:
|
||||
// (1) Password-protected files are not supported.
|
||||
// (2) All file names are stored and compared in lower case.
|
||||
// (3) File ordering from the original zip archive is not maintained. This
|
||||
// means that files from the same folder may not be located together in the
|
||||
// file content map.
|
||||
class CefZipArchive : public CefThreadSafeBase<CefBase>
|
||||
{
|
||||
public:
|
||||
// Class representing a file in the archive. Accessing the file data from
|
||||
// multiple threads is safe provided a reference to the File object is kept.
|
||||
class File : public CefBase
|
||||
{
|
||||
public:
|
||||
// Returns the read-only data contained in the file.
|
||||
virtual const unsigned char* GetData() =0;
|
||||
|
||||
// Returns the size of the data in the file.
|
||||
virtual size_t GetDataSize() =0;
|
||||
|
||||
// Returns a CefStreamReader object for streaming the contents of the file.
|
||||
virtual CefRefPtr<CefStreamReader> GetStreamReader() =0;
|
||||
};
|
||||
typedef std::map<std::wstring, CefRefPtr<File> > FileMap;
|
||||
|
||||
// Create a new object.
|
||||
CefZipArchive();
|
||||
virtual ~CefZipArchive();
|
||||
|
||||
// Load the contents of the specified zip archive stream into this object.
|
||||
// If |overwriteExisting| is true then any files in this object that also
|
||||
// exist in the specified archive will be replaced with the new files.
|
||||
// Returns the number of files successfully loaded.
|
||||
size_t Load(CefRefPtr<CefStreamReader> stream, bool overwriteExisting);
|
||||
|
||||
// Clears the contents of this object.
|
||||
void Clear();
|
||||
|
||||
// Returns the number of files in the archive.
|
||||
size_t GetFileCount();
|
||||
|
||||
// Returns true if the specified file exists and has contents.
|
||||
bool HasFile(const std::wstring& fileName);
|
||||
|
||||
// Returns the specified file.
|
||||
CefRefPtr<File> GetFile(const std::wstring& fileName);
|
||||
|
||||
// Removes the specified file.
|
||||
bool RemoveFile(const std::wstring& fileName);
|
||||
|
||||
// Returns the map of all files.
|
||||
size_t GetFiles(FileMap& map);
|
||||
|
||||
private:
|
||||
FileMap contents_;
|
||||
};
|
||||
|
||||
#endif // _CEF_WRAPPER_H
|
||||
|
Reference in New Issue
Block a user