2010-10-24 18:41:21 +02:00
|
|
|
// Copyright (c) 2010 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 "include/cef_wrapper.h"
|
|
|
|
#include "base/logging.h"
|
|
|
|
|
|
|
|
CefByteReadHandler::CefByteReadHandler(const unsigned char* bytes, size_t size,
|
|
|
|
CefRefPtr<CefBase> source)
|
|
|
|
: bytes_(bytes), size_(size), offset_(0), source_(source)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CefByteReadHandler::Read(void* ptr, size_t size, size_t n)
|
|
|
|
{
|
2011-05-20 16:42:25 +02:00
|
|
|
AutoLock lock_scope(this);
|
2010-10-24 18:41:21 +02:00
|
|
|
size_t s = (size_ - offset_) / size;
|
2010-11-15 16:39:56 +01:00
|
|
|
size_t ret = std::min(n, s);
|
2010-10-24 18:41:21 +02:00
|
|
|
memcpy(ptr, bytes_ + offset_, ret * size);
|
|
|
|
offset_ += ret * size;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefByteReadHandler::Seek(long offset, int whence)
|
|
|
|
{
|
|
|
|
int rv = -1L;
|
2011-05-20 16:42:25 +02:00
|
|
|
AutoLock lock_scope(this);
|
2010-10-24 18:41:21 +02:00
|
|
|
switch(whence) {
|
|
|
|
case SEEK_CUR:
|
|
|
|
if(offset_ + offset > size_)
|
|
|
|
break;
|
|
|
|
offset_ += offset;
|
2010-11-17 23:59:46 +01:00
|
|
|
rv = 0;
|
2010-10-24 18:41:21 +02:00
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
if(offset > static_cast<long>(size_))
|
|
|
|
break;
|
|
|
|
offset_ = size_ - offset;
|
2010-11-17 23:59:46 +01:00
|
|
|
rv = 0;
|
|
|
|
break;
|
2010-10-24 18:41:21 +02:00
|
|
|
case SEEK_SET:
|
|
|
|
if(offset > static_cast<long>(size_))
|
|
|
|
break;
|
|
|
|
offset_ = offset;
|
2010-11-17 23:59:46 +01:00
|
|
|
rv = 0;
|
2010-10-24 18:41:21 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
long CefByteReadHandler::Tell()
|
|
|
|
{
|
2011-05-20 16:42:25 +02:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return offset_;
|
2010-10-24 18:41:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int CefByteReadHandler::Eof()
|
|
|
|
{
|
2011-05-20 16:42:25 +02:00
|
|
|
AutoLock lock_scope(this);
|
|
|
|
return (offset_ >= size_);
|
2010-10-24 18:41:21 +02:00
|
|
|
}
|