2010-10-03 23:04:50 +02:00
|
|
|
// Copyright (c) 2008 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.
|
|
|
|
|
|
|
|
#ifndef _STREAM_IMPL_H
|
|
|
|
#define _STREAM_IMPL_H
|
|
|
|
|
|
|
|
#include "../include/cef.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
// Implementation of CefStreamReader for files.
|
2011-05-20 16:42:25 +02:00
|
|
|
class CefFileReader : public CefStreamReader
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefFileReader(FILE* file, bool close);
|
|
|
|
virtual ~CefFileReader();
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual size_t Read(void* ptr, size_t size, size_t n) OVERRIDE;
|
|
|
|
virtual int Seek(long offset, int whence) OVERRIDE;
|
|
|
|
virtual long Tell() OVERRIDE;
|
|
|
|
virtual int Eof() OVERRIDE;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool close_;
|
|
|
|
FILE *file_;
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefFileReader);
|
|
|
|
IMPLEMENT_LOCKING(CefFileReader);
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of CefStreamWriter for files.
|
2011-05-20 16:42:25 +02:00
|
|
|
class CefFileWriter : public CefStreamWriter
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefFileWriter(FILE* file, bool close);
|
|
|
|
virtual ~CefFileWriter();
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual size_t Write(const void* ptr, size_t size, size_t n) OVERRIDE;
|
|
|
|
virtual int Seek(long offset, int whence) OVERRIDE;
|
|
|
|
virtual long Tell() OVERRIDE;
|
|
|
|
virtual int Flush() OVERRIDE;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
FILE *file_;
|
|
|
|
bool close_;
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefFileWriter);
|
|
|
|
IMPLEMENT_LOCKING(CefFileWriter);
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of CefStreamReader for byte buffers.
|
2011-05-20 16:42:25 +02:00
|
|
|
class CefBytesReader : public CefStreamReader
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefBytesReader(void* data, long datasize, bool copy);
|
|
|
|
virtual ~CefBytesReader();
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual size_t Read(void* ptr, size_t size, size_t n) OVERRIDE;
|
|
|
|
virtual int Seek(long offset, int whence) OVERRIDE;
|
|
|
|
virtual long Tell() OVERRIDE;
|
|
|
|
virtual int Eof() OVERRIDE;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
void SetData(void* data, long datasize, bool copy);
|
|
|
|
|
|
|
|
void* GetData() { return data_; }
|
|
|
|
size_t GetDataSize() { return offset_; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void* data_;
|
|
|
|
size_t datasize_;
|
|
|
|
bool copy_;
|
|
|
|
size_t offset_;
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefBytesReader);
|
|
|
|
IMPLEMENT_LOCKING(CefBytesReader);
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of CefStreamWriter for byte buffers.
|
2011-05-20 16:42:25 +02:00
|
|
|
class CefBytesWriter : public CefStreamWriter
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefBytesWriter(size_t grow);
|
|
|
|
virtual ~CefBytesWriter();
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual size_t Write(const void* ptr, size_t size, size_t n) OVERRIDE;
|
|
|
|
virtual int Seek(long offset, int whence) OVERRIDE;
|
|
|
|
virtual long Tell() OVERRIDE;
|
|
|
|
virtual int Flush() OVERRIDE;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
void* GetData() { return data_; }
|
|
|
|
size_t GetDataSize() { return offset_; }
|
|
|
|
std::string GetDataString();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
size_t Grow(size_t size);
|
|
|
|
|
|
|
|
size_t grow_;
|
|
|
|
void* data_;
|
|
|
|
size_t datasize_;
|
|
|
|
size_t offset_;
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefBytesWriter);
|
|
|
|
IMPLEMENT_LOCKING(CefBytesWriter);
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of CefStreamReader for handlers.
|
2011-05-20 16:42:25 +02:00
|
|
|
class CefHandlerReader : public CefStreamReader
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefHandlerReader(CefRefPtr<CefReadHandler> handler) : handler_(handler) {}
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual size_t Read(void* ptr, size_t size, size_t n) OVERRIDE
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
return handler_->Read(ptr, size, n);
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual int Seek(long offset, int whence) OVERRIDE
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
return handler_->Seek(offset, whence);
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual long Tell() OVERRIDE
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
return handler_->Tell();
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual int Eof() OVERRIDE
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
return handler_->Eof();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
CefRefPtr<CefReadHandler> handler_;
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefHandlerReader);
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Implementation of CefStreamWriter for handlers.
|
2011-05-20 16:42:25 +02:00
|
|
|
class CefHandlerWriter : public CefStreamWriter
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CefHandlerWriter(CefRefPtr<CefWriteHandler> handler) : handler_(handler) {}
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual size_t Write(const void* ptr, size_t size, size_t n) OVERRIDE
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
return handler_->Write(ptr, size, n);
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual int Seek(long offset, int whence) OVERRIDE
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
return handler_->Seek(offset, whence);
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual long Tell() OVERRIDE
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
return handler_->Tell();
|
|
|
|
}
|
2011-05-20 16:42:25 +02:00
|
|
|
virtual int Flush() OVERRIDE
|
2010-10-03 23:04:50 +02:00
|
|
|
{
|
|
|
|
return handler_->Flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
CefRefPtr<CefWriteHandler> handler_;
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefHandlerWriter);
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _STREAM_IMPL_H
|