mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
libcef:
- Add CefReadHandler and CefWriteHandler classes for creating streams handled by the client. cefclient: - Add a CefReadHandler test. - Move tests out of cefclient.cpp and into separate implementation files. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@39 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
91
tests/cefclient/resource_util.cpp
Normal file
91
tests/cefclient/resource_util.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "resource_util.h"
|
||||
|
||||
|
||||
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes)
|
||||
{
|
||||
extern HINSTANCE hInst;
|
||||
HRSRC hRes = FindResource(hInst, MAKEINTRESOURCE(binaryId),
|
||||
MAKEINTRESOURCE(256));
|
||||
if(hRes)
|
||||
{
|
||||
HGLOBAL hGlob = LoadResource(hInst, hRes);
|
||||
if(hGlob)
|
||||
{
|
||||
dwSize = SizeofResource(hInst, hRes);
|
||||
pBytes = (LPBYTE)LockResource(hGlob);
|
||||
if(dwSize > 0 && pBytes)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user