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:
Marshall Greenblatt
2010-10-24 16:41:21 +00:00
parent 1911b23bf5
commit 5a4c8f5a13
20 changed files with 1492 additions and 99 deletions

View File

@@ -3,6 +3,7 @@
// can be found in the LICENSE file.
#include "include/cef.h"
#include "include/cef_wrapper.h"
#include "cefclient.h"
#include "binding_test.h"
#include "download_handler.h"
@@ -408,21 +409,21 @@ public:
// Show the uiapp contents
if(LoadBinaryResource(IDS_UIPLUGIN, dwSize, pBytes)) {
resourceStream = CefStreamReader::CreateForHandler(
new ClientReadHandler(pBytes, dwSize));
new CefByteReadHandler(pBytes, dwSize, NULL));
mimeType = L"text/html";
}
} else if(wcsstr(url.c_str(), L"/ps_logo2.png") != NULL) {
// Any time we find "ps_logo2.png" in the URL substitute in our own image
if(LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) {
resourceStream = CefStreamReader::CreateForHandler(
new ClientReadHandler(pBytes, dwSize));
new CefByteReadHandler(pBytes, dwSize, NULL));
mimeType = L"image/png";
}
} else if(wcsstr(url.c_str(), L"/logoball.png") != NULL) {
// Load the "logoball.png" image resource.
if(LoadBinaryResource(IDS_LOGOBALL, dwSize, pBytes)) {
resourceStream = CefStreamReader::CreateForHandler(
new ClientReadHandler(pBytes, dwSize));
new CefByteReadHandler(pBytes, dwSize, NULL));
mimeType = L"image/png";
}
}

View File

@@ -4,7 +4,6 @@
#include "resource_util.h"
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes)
{
extern HINSTANCE hInst;
@@ -24,67 +23,3 @@ bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes)
return false;
}
// ClientReadHandler implementation
ClientReadHandler::ClientReadHandler(LPBYTE pBytes, DWORD dwSize)
: bytes_(pBytes), size_(dwSize), offset_(0) {}
size_t ClientReadHandler::Read(void* ptr, size_t size, size_t n)
{
Lock();
size_t s = (size_ - offset_) / size;
size_t ret = min(n, s);
memcpy(ptr, bytes_ + offset_, ret * size);
offset_ += ret * size;
Unlock();
return ret;
}
int ClientReadHandler::Seek(long offset, int whence)
{
int rv = -1L;
Lock();
switch(whence) {
case SEEK_CUR:
if(offset_ + offset > size_) {
break;
}
offset_ += offset;
rv = offset_;
break;
case SEEK_END:
if(offset > (int)size_) {
break;
}
offset_ = size_ - offset;
rv = offset_;
case SEEK_SET:
if(offset > (int)size_) {
break;
}
offset_ = offset;
rv = offset_;
break;
}
Unlock();
return rv;
}
long ClientReadHandler::Tell()
{
Lock();
long rv = offset_;
Unlock();
return rv;
}
int ClientReadHandler::Eof()
{
Lock();
int rv = (offset_ >= size_);
Unlock();
return rv;
}

View File

@@ -6,34 +6,5 @@
#include "include/cef.h"
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
// Load a resource of type BINARY
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes);
// Implementation of the stream read handler for reading in-memory data.
class ClientReadHandler : public CefThreadSafeBase<CefReadHandler>
{
public:
ClientReadHandler(LPBYTE pBytes, DWORD dwSize);
// 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:
LPBYTE bytes_;
DWORD size_, offset_;
};

View File

@@ -2,6 +2,7 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef_wrapper.h"
#include "scheme_test.h"
#include "string_util.h"
#include "resource_util.h"