mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-01-24 00:12:14 +01:00
dbe8de277f
- Replace CefHandler with a new CefClient interface and separate handler interfaces. - Add support for virtual inheritance to allow multiple CefBase parented interfaces to be implemented in the same class. - Replace CefThreadSafeBase with IMPLEMENT_* macros to support virtual inheritance and to only provide locking implementations when needed. - Move the CefBrowserSettings parameter from CefInitialize to CreateBrowser. - Add a new cef_build.h header that provides platform-specific and OS_* defines. - Introduce the use of OVERRIDE to generate compiler errors on Windows if a child virtual method declaration doesn't match the parent declaration. - Use NDEBUG instead of _DEBUG because _DEBUG is not defined on Mac. (issue #240). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@235 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
165 lines
3.8 KiB
C++
165 lines
3.8 KiB
C++
// 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.
|
|
class CefFileReader : public CefStreamReader
|
|
{
|
|
public:
|
|
CefFileReader(FILE* file, bool close);
|
|
virtual ~CefFileReader();
|
|
|
|
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;
|
|
|
|
protected:
|
|
bool close_;
|
|
FILE *file_;
|
|
|
|
IMPLEMENT_REFCOUNTING(CefFileReader);
|
|
IMPLEMENT_LOCKING(CefFileReader);
|
|
};
|
|
|
|
// Implementation of CefStreamWriter for files.
|
|
class CefFileWriter : public CefStreamWriter
|
|
{
|
|
public:
|
|
CefFileWriter(FILE* file, bool close);
|
|
virtual ~CefFileWriter();
|
|
|
|
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;
|
|
|
|
protected:
|
|
FILE *file_;
|
|
bool close_;
|
|
|
|
IMPLEMENT_REFCOUNTING(CefFileWriter);
|
|
IMPLEMENT_LOCKING(CefFileWriter);
|
|
};
|
|
|
|
// Implementation of CefStreamReader for byte buffers.
|
|
class CefBytesReader : public CefStreamReader
|
|
{
|
|
public:
|
|
CefBytesReader(void* data, long datasize, bool copy);
|
|
virtual ~CefBytesReader();
|
|
|
|
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;
|
|
|
|
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_;
|
|
|
|
IMPLEMENT_REFCOUNTING(CefBytesReader);
|
|
IMPLEMENT_LOCKING(CefBytesReader);
|
|
};
|
|
|
|
// Implementation of CefStreamWriter for byte buffers.
|
|
class CefBytesWriter : public CefStreamWriter
|
|
{
|
|
public:
|
|
CefBytesWriter(size_t grow);
|
|
virtual ~CefBytesWriter();
|
|
|
|
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;
|
|
|
|
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_;
|
|
|
|
IMPLEMENT_REFCOUNTING(CefBytesWriter);
|
|
IMPLEMENT_LOCKING(CefBytesWriter);
|
|
};
|
|
|
|
// Implementation of CefStreamReader for handlers.
|
|
class CefHandlerReader : public CefStreamReader
|
|
{
|
|
public:
|
|
CefHandlerReader(CefRefPtr<CefReadHandler> handler) : handler_(handler) {}
|
|
|
|
virtual size_t Read(void* ptr, size_t size, size_t n) OVERRIDE
|
|
{
|
|
return handler_->Read(ptr, size, n);
|
|
}
|
|
virtual int Seek(long offset, int whence) OVERRIDE
|
|
{
|
|
return handler_->Seek(offset, whence);
|
|
}
|
|
virtual long Tell() OVERRIDE
|
|
{
|
|
return handler_->Tell();
|
|
}
|
|
virtual int Eof() OVERRIDE
|
|
{
|
|
return handler_->Eof();
|
|
}
|
|
|
|
protected:
|
|
CefRefPtr<CefReadHandler> handler_;
|
|
|
|
IMPLEMENT_REFCOUNTING(CefHandlerReader);
|
|
};
|
|
|
|
// Implementation of CefStreamWriter for handlers.
|
|
class CefHandlerWriter : public CefStreamWriter
|
|
{
|
|
public:
|
|
CefHandlerWriter(CefRefPtr<CefWriteHandler> handler) : handler_(handler) {}
|
|
|
|
virtual size_t Write(const void* ptr, size_t size, size_t n) OVERRIDE
|
|
{
|
|
return handler_->Write(ptr, size, n);
|
|
}
|
|
virtual int Seek(long offset, int whence) OVERRIDE
|
|
{
|
|
return handler_->Seek(offset, whence);
|
|
}
|
|
virtual long Tell() OVERRIDE
|
|
{
|
|
return handler_->Tell();
|
|
}
|
|
virtual int Flush() OVERRIDE
|
|
{
|
|
return handler_->Flush();
|
|
}
|
|
|
|
protected:
|
|
CefRefPtr<CefWriteHandler> handler_;
|
|
|
|
IMPLEMENT_REFCOUNTING(CefHandlerWriter);
|
|
};
|
|
|
|
#endif // _STREAM_IMPL_H
|