- 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:
Marshall Greenblatt 2009-08-21 17:41:09 +00:00
parent b821811c08
commit 2b7e69d200
34 changed files with 1592 additions and 516 deletions

View File

@ -745,6 +745,30 @@ public:
};
// Interface the client can implement to provide a custom stream reader.
/*--cef(source=client)--*/
class CefReadHandler : public CefBase
{
public:
// Read raw binary data.
/*--cef()--*/
virtual size_t Read(void* ptr, size_t size, size_t n) =0;
// Seek to the specified offset position. |whence| may be any one of
// SEEK_CUR, SEEK_END or SEEK_SET.
/*--cef()--*/
virtual int Seek(long offset, int whence) =0;
// Return the current offset position.
/*--cef()--*/
virtual long Tell() =0;
// Return non-zero if at end of file.
/*--cef()--*/
virtual int Eof() =0;
};
// Class used to read data from a stream.
/*--cef(source=library)--*/
class CefStreamReader : public CefBase
@ -755,6 +779,8 @@ public:
static CefRefPtr<CefStreamReader> CreateForFile(const std::wstring& fileName);
/*--cef()--*/
static CefRefPtr<CefStreamReader> CreateForData(void* data, size_t size);
/*--cef()--*/
static CefRefPtr<CefStreamReader> CreateForHandler(CefRefPtr<CefReadHandler> handler);
// Read raw binary data.
/*--cef()--*/
@ -775,11 +801,41 @@ public:
};
// Interface the client can implement to provide a custom stream writer.
/*--cef(source=client)--*/
class CefWriteHandler : public CefBase
{
public:
// Write raw binary data.
/*--cef()--*/
virtual size_t Write(const void* ptr, size_t size, size_t n) =0;
// Seek to the specified offset position. |whence| may be any one of
// SEEK_CUR, SEEK_END or SEEK_SET.
/*--cef()--*/
virtual int Seek(long offset, int whence) =0;
// Return the current offset position.
/*--cef()--*/
virtual long Tell() =0;
// Flush the stream.
/*--cef()--*/
virtual int Flush() =0;
};
// Class used to write data to a stream.
/*--cef(source=library)--*/
class CefStreamWriter : public CefBase
{
public:
// Create a new CefStreamWriter object.
/*--cef()--*/
static CefRefPtr<CefStreamWriter> CreateForFile(const std::wstring& fileName);
/*--cef()--*/
static CefRefPtr<CefStreamWriter> CreateForHandler(CefRefPtr<CefWriteHandler> handler);
// Write raw binary data.
/*--cef()--*/
virtual size_t Write(const void* ptr, size_t size, size_t n) =0;

View File

@ -600,6 +600,30 @@ typedef struct _cef_post_data_element_t
CEF_EXPORT cef_post_data_element_t* cef_post_data_element_create();
// Structure the client can implement to provide a custom stream reader.
typedef struct _cef_read_handler_t
{
// Base structure.
cef_base_t base;
// Read raw binary data.
size_t (CEF_CALLBACK *read)(struct _cef_read_handler_t* self, 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.
int (CEF_CALLBACK *seek)(struct _cef_read_handler_t* self, long offset,
int whence);
// Return the current offset position.
long (CEF_CALLBACK *tell)(struct _cef_read_handler_t* self);
// Return non-zero if at end of file.
int (CEF_CALLBACK *eof)(struct _cef_read_handler_t* self);
} cef_read_handler_t;
// Structure used to read data from a stream.
typedef struct _cef_stream_reader_t
{
@ -629,6 +653,32 @@ CEF_EXPORT cef_stream_reader_t* cef_stream_reader_create_for_file(
const wchar_t* fileName);
CEF_EXPORT cef_stream_reader_t* cef_stream_reader_create_for_data(void* data,
size_t size);
CEF_EXPORT cef_stream_reader_t* cef_stream_reader_create_for_handler(
cef_read_handler_t* handler);
// Structure the client can implement to provide a custom stream writer.
typedef struct _cef_write_handler_t
{
// Base structure.
cef_base_t base;
// Write raw binary data.
size_t (CEF_CALLBACK *write)(struct _cef_write_handler_t* self,
const 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.
int (CEF_CALLBACK *seek)(struct _cef_write_handler_t* self, long offset,
int whence);
// Return the current offset position.
long (CEF_CALLBACK *tell)(struct _cef_write_handler_t* self);
// Flush the stream.
int (CEF_CALLBACK *flush)(struct _cef_write_handler_t* self);
} cef_write_handler_t;
// Structure used to write data to a stream.
@ -655,6 +705,13 @@ typedef struct _cef_stream_writer_t
} cef_stream_writer_t;
// Create a new cef_stream_writer_t object.
CEF_EXPORT cef_stream_writer_t* cef_stream_writer_create_for_file(
const wchar_t* fileName);
CEF_EXPORT cef_stream_writer_t* cef_stream_writer_create_for_handler(
cef_write_handler_t* handler);
// Structure that should be implemented to handle V8 function calls.
typedef struct _cef_v8handler_t
{

View File

@ -10,7 +10,8 @@
// Static functions
CefRefPtr<CefStreamReader> CefStreamReader::CreateForFile(const std::wstring& fileName)
CefRefPtr<CefStreamReader> CefStreamReader::CreateForFile(
const std::wstring& fileName)
{
CefRefPtr<CefStreamReader> reader;
FILE *f = _wfopen(fileName.c_str(), L"rb");
@ -19,7 +20,8 @@ CefRefPtr<CefStreamReader> CefStreamReader::CreateForFile(const std::wstring& fi
return reader;
}
CefRefPtr<CefStreamReader> CefStreamReader::CreateForData(void* data, size_t size)
CefRefPtr<CefStreamReader> CefStreamReader::CreateForData(void* data,
size_t size)
{
DCHECK(data != NULL);
DCHECK(size > 0);
@ -29,6 +31,37 @@ CefRefPtr<CefStreamReader> CefStreamReader::CreateForData(void* data, size_t siz
return reader;
}
CefRefPtr<CefStreamReader> CefStreamReader::CreateForHandler(
CefRefPtr<CefReadHandler> handler)
{
DCHECK(handler.get());
CefRefPtr<CefStreamReader> reader;
if(handler.get())
reader = new CefHandlerReader(handler);
return reader;
}
CefRefPtr<CefStreamWriter> CefStreamWriter::CreateForFile(
const std::wstring& fileName)
{
DCHECK(!fileName.empty());
CefRefPtr<CefStreamWriter> writer;
FILE* file = _wfopen(fileName.c_str(), L"wb");
if(file)
writer = new CefFileWriter(file, true);
return writer;
}
CefRefPtr<CefStreamWriter> CefStreamWriter::CreateForHandler(
CefRefPtr<CefWriteHandler> handler)
{
DCHECK(handler.get());
CefRefPtr<CefStreamWriter> writer;
if(handler.get())
writer = new CefHandlerWriter(handler);
return writer;
}
// CefFileReader

View File

@ -13,7 +13,7 @@ class CefFileReader : public CefThreadSafeBase<CefStreamReader>
{
public:
CefFileReader(FILE* file, bool close);
~CefFileReader();
virtual ~CefFileReader();
virtual size_t Read(void* ptr, size_t size, size_t n);
virtual int Seek(long offset, int whence);
@ -30,7 +30,7 @@ class CefFileWriter : public CefThreadSafeBase<CefStreamWriter>
{
public:
CefFileWriter(FILE* file, bool close);
~CefFileWriter();
virtual ~CefFileWriter();
virtual size_t Write(const void* ptr, size_t size, size_t n);
virtual int Seek(long offset, int whence);
@ -47,7 +47,7 @@ class CefBytesReader : public CefThreadSafeBase<CefStreamReader>
{
public:
CefBytesReader(void* data, long datasize, bool copy);
~CefBytesReader();
virtual ~CefBytesReader();
virtual size_t Read(void* ptr, size_t size, size_t n);
virtual int Seek(long offset, int whence);
@ -71,7 +71,7 @@ class CefBytesWriter : public CefThreadSafeBase<CefStreamWriter>
{
public:
CefBytesWriter(size_t grow);
~CefBytesWriter();
virtual ~CefBytesWriter();
virtual size_t Write(const void* ptr, size_t size, size_t n);
virtual int Seek(long offset, int whence);
@ -92,4 +92,58 @@ protected:
size_t offset_;
};
// Implementation of CefStreamReader for handlers.
class CefHandlerReader : public CefThreadSafeBase<CefStreamReader>
{
public:
CefHandlerReader(CefRefPtr<CefReadHandler> handler) : handler_(handler) {}
virtual size_t Read(void* ptr, size_t size, size_t n)
{
return handler_->Read(ptr, size, n);
}
virtual int Seek(long offset, int whence)
{
return handler_->Seek(offset, whence);
}
virtual long Tell()
{
return handler_->Tell();
}
virtual int Eof()
{
return handler_->Eof();
}
protected:
CefRefPtr<CefReadHandler> handler_;
};
// Implementation of CefStreamWriter for handlers.
class CefHandlerWriter : public CefThreadSafeBase<CefStreamWriter>
{
public:
CefHandlerWriter(CefRefPtr<CefWriteHandler> handler) : handler_(handler) {}
virtual size_t Write(const void* ptr, size_t size, size_t n)
{
return handler_->Write(ptr, size, n);
}
virtual int Seek(long offset, int whence)
{
return handler_->Seek(offset, whence);
}
virtual long Tell()
{
return handler_->Tell();
}
virtual int Flush()
{
return handler_->Flush();
}
protected:
CefRefPtr<CefWriteHandler> handler_;
};
#endif // _STREAM_IMPL_H

View File

@ -0,0 +1,73 @@
// Copyright (c) 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.
//
// ---------------------------------------------------------------------------
//
// A portion of this file was generated by the CEF translator tool. When
// making changes by hand only do so within the body of existing function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "../precompiled_libcef.h"
#include "cpptoc/read_handler_cpptoc.h"
// MEMBER FUNCTIONS - Body may be edited by hand.
size_t CEF_CALLBACK read_handler_read(struct _cef_read_handler_t* self,
void* ptr, size_t size, size_t n)
{
DCHECK(self);
if(!self)
return 0;
return CefReadHandlerCppToC::Get(self)->Read(ptr, size, n);
}
int CEF_CALLBACK read_handler_seek(struct _cef_read_handler_t* self,
long offset, int whence)
{
DCHECK(self);
if(!self)
return 0;
return CefReadHandlerCppToC::Get(self)->Seek(offset, whence);
}
long CEF_CALLBACK read_handler_tell(struct _cef_read_handler_t* self)
{
DCHECK(self);
if(!self)
return 0;
return CefReadHandlerCppToC::Get(self)->Tell();
}
int CEF_CALLBACK read_handler_eof(struct _cef_read_handler_t* self)
{
DCHECK(self);
if(!self)
return 0;
return CefReadHandlerCppToC::Get(self)->Eof();
}
// CONSTRUCTOR - Do not edit by hand.
CefReadHandlerCppToC::CefReadHandlerCppToC(CefReadHandler* cls)
: CefCppToC<CefReadHandlerCppToC, CefReadHandler, cef_read_handler_t>(cls)
{
struct_.struct_.read = read_handler_read;
struct_.struct_.seek = read_handler_seek;
struct_.struct_.tell = read_handler_tell;
struct_.struct_.eof = read_handler_eof;
}
#ifdef _DEBUG
long CefCppToC<CefReadHandlerCppToC, CefReadHandler,
cef_read_handler_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,34 @@
// Copyright (c) 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.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool and should not edited
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
#ifndef _READHANDLER_CPPTOC_H
#define _READHANDLER_CPPTOC_H
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "cpptoc.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed wrapper-side only.
class CefReadHandlerCppToC
: public CefCppToC<CefReadHandlerCppToC, CefReadHandler, cef_read_handler_t>
{
public:
CefReadHandlerCppToC(CefReadHandler* cls);
virtual ~CefReadHandlerCppToC() {}
};
#endif // USING_CEF_SHARED
#endif // _READHANDLER_CPPTOC_H

View File

@ -12,6 +12,7 @@
#include "../precompiled_libcef.h"
#include "cpptoc/stream_reader_cpptoc.h"
#include "ctocpp/read_handler_ctocpp.h"
// GLOBAL FUNCTIONS - Body may be edited by hand.
@ -37,6 +38,16 @@ CEF_EXPORT cef_stream_reader_t* cef_stream_reader_create_for_data(void* data,
return NULL;
}
CEF_EXPORT cef_stream_reader_t* cef_stream_reader_create_for_handler(
cef_read_handler_t* handler)
{
CefRefPtr<CefStreamReader> impl =
CefStreamReader::CreateForHandler(CefReadHandlerCToCpp::Wrap(handler));
if(impl.get())
return CefStreamReaderCppToC::Wrap(impl);
return NULL;
}
// MEMBER FUNCTIONS - Body may be edited by hand.

View File

@ -12,6 +12,38 @@
#include "../precompiled_libcef.h"
#include "cpptoc/stream_writer_cpptoc.h"
#include "ctocpp/write_handler_ctocpp.h"
// GLOBAL FUNCTIONS - Body may be edited by hand.
CEF_EXPORT cef_stream_writer_t* cef_stream_writer_create_for_file(
const wchar_t* fileName)
{
DCHECK(fileName);
if(!fileName)
return NULL;
std::wstring fileNameStr = fileName;
CefRefPtr<CefStreamWriter> impl = CefStreamWriter::CreateForFile(fileName);
if(impl.get())
return CefStreamWriterCppToC::Wrap(impl);
return NULL;
}
CEF_EXPORT cef_stream_writer_t* cef_stream_writer_create_for_handler(
cef_write_handler_t* handler)
{
DCHECK(handler);
if(!handler)
return NULL;
CefRefPtr<CefStreamWriter> impl =
CefStreamWriter::CreateForHandler(CefWriteHandlerCToCpp::Wrap(handler));
if(impl.get())
return CefStreamWriterCppToC::Wrap(impl);
return NULL;
}
// MEMBER FUNCTIONS - Body may be edited by hand.

View File

@ -0,0 +1,74 @@
// Copyright (c) 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.
//
// ---------------------------------------------------------------------------
//
// A portion of this file was generated by the CEF translator tool. When
// making changes by hand only do so within the body of existing function
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
#include "../precompiled_libcef.h"
#include "cpptoc/write_handler_cpptoc.h"
// MEMBER FUNCTIONS - Body may be edited by hand.
size_t CEF_CALLBACK write_handler_write(struct _cef_write_handler_t* self,
const void* ptr, size_t size, size_t n)
{
DCHECK(self);
if(!self)
return 0;
return CefWriteHandlerCppToC::Get(self)->Write(ptr, size, n);
}
int CEF_CALLBACK write_handler_seek(struct _cef_write_handler_t* self,
long offset, int whence)
{
DCHECK(self);
if(!self)
return 0;
return CefWriteHandlerCppToC::Get(self)->Seek(offset, whence);
}
long CEF_CALLBACK write_handler_tell(struct _cef_write_handler_t* self)
{
DCHECK(self);
if(!self)
return 0;
return CefWriteHandlerCppToC::Get(self)->Tell();
}
int CEF_CALLBACK write_handler_flush(struct _cef_write_handler_t* self)
{
DCHECK(self);
if(!self)
return 0;
return CefWriteHandlerCppToC::Get(self)->Flush();
}
// CONSTRUCTOR - Do not edit by hand.
CefWriteHandlerCppToC::CefWriteHandlerCppToC(CefWriteHandler* cls)
: CefCppToC<CefWriteHandlerCppToC, CefWriteHandler, cef_write_handler_t>(
cls)
{
struct_.struct_.write = write_handler_write;
struct_.struct_.seek = write_handler_seek;
struct_.struct_.tell = write_handler_tell;
struct_.struct_.flush = write_handler_flush;
}
#ifdef _DEBUG
long CefCppToC<CefWriteHandlerCppToC, CefWriteHandler,
cef_write_handler_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,35 @@
// Copyright (c) 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.
//
// ---------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool and should not edited
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
#ifndef _WRITEHANDLER_CPPTOC_H
#define _WRITEHANDLER_CPPTOC_H
#ifndef USING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
#else // USING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "cpptoc.h"
// Wrap a C++ class with a C structure.
// This class may be instantiated and accessed wrapper-side only.
class CefWriteHandlerCppToC
: public CefCppToC<CefWriteHandlerCppToC, CefWriteHandler,
cef_write_handler_t>
{
public:
CefWriteHandlerCppToC(CefWriteHandler* cls);
virtual ~CefWriteHandlerCppToC() {}
};
#endif // USING_CEF_SHARED
#endif // _WRITEHANDLER_CPPTOC_H

View File

@ -0,0 +1,56 @@
// Copyright (c) 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.
//
// ---------------------------------------------------------------------------
//
// A portion of this file was generated by the CEF translator tool. When
// making changes by hand only do so within the body of existing static and
// virtual method implementations. See the translator.README.txt file in the
// tools directory for more information.
//
#include "../precompiled_libcef.h"
#include "ctocpp/read_handler_ctocpp.h"
// VIRTUAL METHODS - Body may be edited by hand.
size_t CefReadHandlerCToCpp::Read(void* ptr, size_t size, size_t n)
{
if(CEF_MEMBER_MISSING(struct_, read))
return 0;
return struct_->read(struct_, ptr, size, n);
}
int CefReadHandlerCToCpp::Seek(long offset, int whence)
{
if(CEF_MEMBER_MISSING(struct_, seek))
return 0;
return struct_->seek(struct_, offset, whence);
}
long CefReadHandlerCToCpp::Tell()
{
if(CEF_MEMBER_MISSING(struct_, tell))
return 0;
return struct_->tell(struct_);
}
int CefReadHandlerCToCpp::Eof()
{
if(CEF_MEMBER_MISSING(struct_, eof))
return 0;
return struct_->eof(struct_);
}
#ifdef _DEBUG
long CefCToCpp<CefReadHandlerCToCpp, CefReadHandler,
cef_read_handler_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,43 @@
// Copyright (c) 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.
//
// -------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool and should not edited
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
#ifndef _READHANDLER_CTOCPP_H
#define _READHANDLER_CTOCPP_H
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C structure with a C++ class.
// This class may be instantiated and accessed DLL-side only.
class CefReadHandlerCToCpp
: public CefCToCpp<CefReadHandlerCToCpp, CefReadHandler, cef_read_handler_t>
{
public:
CefReadHandlerCToCpp(cef_read_handler_t* str)
: CefCToCpp<CefReadHandlerCToCpp, CefReadHandler, cef_read_handler_t>(
str) {}
virtual ~CefReadHandlerCToCpp() {}
// CefReadHandler methods
virtual size_t Read(void* ptr, size_t size, size_t n);
virtual int Seek(long offset, int whence);
virtual long Tell();
virtual int Eof();
};
#endif // BUILDING_CEF_SHARED
#endif // _READHANDLER_CTOCPP_H

View File

@ -11,6 +11,7 @@
//
#include "../precompiled_libcef.h"
#include "cpptoc/read_handler_cpptoc.h"
#include "ctocpp/stream_reader_ctocpp.h"
@ -35,6 +36,16 @@ CefRefPtr<CefStreamReader> CefStreamReader::CreateForData(void* data,
return NULL;
}
CefRefPtr<CefStreamReader> CefStreamReader::CreateForHandler(
CefRefPtr<CefReadHandler> handler)
{
cef_stream_reader_t* impl =
cef_stream_reader_create_for_handler(CefReadHandlerCppToC::Wrap(handler));
if(impl)
return CefStreamReaderCToCpp::Wrap(impl);
return NULL;
}
// VIRTUAL METHODS - Body may be edited by hand.

View File

@ -11,9 +11,42 @@
//
#include "../precompiled_libcef.h"
#include "cpptoc/write_handler_cpptoc.h"
#include "ctocpp/stream_writer_ctocpp.h"
// STATIC METHODS - Body may be edited by hand.
CefRefPtr<CefStreamWriter> CefStreamWriter::CreateForFile(
const std::wstring& fileName)
{
DCHECK(!fileName.empty());
if(fileName.empty())
return NULL;
cef_stream_writer_t* impl =
cef_stream_writer_create_for_file(fileName.c_str());
if(impl)
return CefStreamWriterCToCpp::Wrap(impl);
return NULL;
}
CefRefPtr<CefStreamWriter> CefStreamWriter::CreateForHandler(
CefRefPtr<CefWriteHandler> handler)
{
DCHECK(handler.get());
if(!handler.get())
return NULL;
cef_stream_writer_t* impl =
cef_stream_writer_create_for_handler(
CefWriteHandlerCppToC::Wrap(handler));
if(impl)
return CefStreamWriterCToCpp::Wrap(impl);
return NULL;
}
// VIRTUAL METHODS - Body may be edited by hand.
size_t CefStreamWriterCToCpp::Write(const void* ptr, size_t size, size_t n)

View File

@ -0,0 +1,56 @@
// Copyright (c) 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.
//
// ---------------------------------------------------------------------------
//
// A portion of this file was generated by the CEF translator tool. When
// making changes by hand only do so within the body of existing static and
// virtual method implementations. See the translator.README.txt file in the
// tools directory for more information.
//
#include "../precompiled_libcef.h"
#include "ctocpp/write_handler_ctocpp.h"
// VIRTUAL METHODS - Body may be edited by hand.
size_t CefWriteHandlerCToCpp::Write(const void* ptr, size_t size, size_t n)
{
if(CEF_MEMBER_MISSING(struct_, write))
return 0;
return struct_->write(struct_, ptr, size, n);
}
int CefWriteHandlerCToCpp::Seek(long offset, int whence)
{
if(CEF_MEMBER_MISSING(struct_, seek))
return 0;
return struct_->seek(struct_, offset, whence);
}
long CefWriteHandlerCToCpp::Tell()
{
if(CEF_MEMBER_MISSING(struct_, tell))
return 0;
return struct_->tell(struct_);
}
int CefWriteHandlerCToCpp::Flush()
{
if(CEF_MEMBER_MISSING(struct_, flush))
return 0;
return struct_->flush(struct_);
}
#ifdef _DEBUG
long CefCToCpp<CefWriteHandlerCToCpp, CefWriteHandler,
cef_write_handler_t>::DebugObjCt = 0;
#endif

View File

@ -0,0 +1,44 @@
// Copyright (c) 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.
//
// -------------------------------------------------------------------------
//
// This file was generated by the CEF translator tool and should not edited
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
#ifndef _WRITEHANDLER_CTOCPP_H
#define _WRITEHANDLER_CTOCPP_H
#ifndef BUILDING_CEF_SHARED
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
#else // BUILDING_CEF_SHARED
#include "cef.h"
#include "cef_capi.h"
#include "ctocpp.h"
// Wrap a C structure with a C++ class.
// This class may be instantiated and accessed DLL-side only.
class CefWriteHandlerCToCpp
: public CefCToCpp<CefWriteHandlerCToCpp, CefWriteHandler,
cef_write_handler_t>
{
public:
CefWriteHandlerCToCpp(cef_write_handler_t* str)
: CefCToCpp<CefWriteHandlerCToCpp, CefWriteHandler, cef_write_handler_t>(
str) {}
virtual ~CefWriteHandlerCToCpp() {}
// CefWriteHandler methods
virtual size_t Write(const void* ptr, size_t size, size_t n);
virtual int Seek(long offset, int whence);
virtual long Tell();
virtual int Flush();
};
#endif // BUILDING_CEF_SHARED
#endif // _WRITEHANDLER_CTOCPP_H

View File

@ -16,9 +16,11 @@
#include "cpptoc/stream_writer_cpptoc.h"
#include "cpptoc/v8value_cpptoc.h"
#include "ctocpp/handler_ctocpp.h"
#include "ctocpp/read_handler_ctocpp.h"
#include "ctocpp/scheme_handler_ctocpp.h"
#include "ctocpp/scheme_handler_factory_ctocpp.h"
#include "ctocpp/v8handler_ctocpp.h"
#include "ctocpp/write_handler_ctocpp.h"
#include "base/string_util.h"
@ -45,9 +47,11 @@ CEF_EXPORT void cef_shutdown()
DCHECK(CefStreamWriterCppToC::DebugObjCt == 0);
DCHECK(CefV8ValueCppToC::DebugObjCt == 0);
DCHECK(CefHandlerCToCpp::DebugObjCt == 0);
DCHECK(CefReadHandlerCToCpp::DebugObjCt == 0);
DCHECK(CefSchemeHandlerCToCpp::DebugObjCt == 0);
DCHECK(CefSchemeHandlerFactoryCToCpp::DebugObjCt == 0);
DCHECK(CefV8HandlerCToCpp::DebugObjCt == 0);
DCHECK(CefWriteHandlerCToCpp::DebugObjCt == 0);
#endif // _DEBUG
}

View File

@ -430,6 +430,30 @@
RelativePath=".\ctocpp\handler_ctocpp.h"
>
</File>
<File
RelativePath=".\ctocpp\read_handler_ctocpp.cc"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PrecompiledHeaderThrough="../precompiled_libcef.h"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PrecompiledHeaderThrough="../precompiled_libcef.h"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\ctocpp\read_handler_ctocpp.h"
>
</File>
<File
RelativePath=".\ctocpp\scheme_handler_ctocpp.cc"
>
@ -502,6 +526,30 @@
RelativePath=".\ctocpp\v8handler_ctocpp.h"
>
</File>
<File
RelativePath=".\ctocpp\write_handler_ctocpp.cc"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PrecompiledHeaderThrough="../precompiled_libcef.h"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PrecompiledHeaderThrough="../precompiled_libcef.h"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\ctocpp\write_handler_ctocpp.h"
>
</File>
</Filter>
<Filter
Name="resources"

View File

@ -8,9 +8,11 @@
#include "cef_nplugin.h"
#include "cef_nplugin_capi.h"
#include "../cpptoc/handler_cpptoc.h"
#include "../cpptoc/read_handler_cpptoc.h"
#include "../cpptoc/scheme_handler_cpptoc.h"
#include "../cpptoc/scheme_handler_factory_cpptoc.h"
#include "../cpptoc/v8handler_cpptoc.h"
#include "../cpptoc/write_handler_cpptoc.h"
#include "../ctocpp/browser_ctocpp.h"
#include "../ctocpp/post_data_ctocpp.h"
#include "../ctocpp/post_data_element_ctocpp.h"
@ -33,9 +35,11 @@ void CefShutdown()
#ifdef _DEBUG
// Check that all wrapper objects have been destroyed
DCHECK(CefHandlerCppToC::DebugObjCt == 0);
DCHECK(CefReadHandlerCppToC::DebugObjCt == 0);
DCHECK(CefSchemeHandlerCppToC::DebugObjCt == 0);
DCHECK(CefSchemeHandlerFactoryCppToC::DebugObjCt == 0);
DCHECK(CefV8HandlerCppToC::DebugObjCt == 0);
DCHECK(CefWriteHandlerCppToC::DebugObjCt == 0);
DCHECK(CefBrowserCToCpp::DebugObjCt == 0);
DCHECK(CefRequestCToCpp::DebugObjCt == 0);
DCHECK(CefPostDataCToCpp::DebugObjCt == 0);

View File

@ -141,6 +141,14 @@
RelativePath="..\cpptoc\handler_cpptoc.h"
>
</File>
<File
RelativePath="..\cpptoc\read_handler_cpptoc.cc"
>
</File>
<File
RelativePath="..\cpptoc\read_handler_cpptoc.h"
>
</File>
<File
RelativePath="..\cpptoc\scheme_handler_cpptoc.cc"
>
@ -165,6 +173,14 @@
RelativePath="..\cpptoc\v8handler_cpptoc.h"
>
</File>
<File
RelativePath="..\cpptoc\write_handler_cpptoc.cc"
>
</File>
<File
RelativePath="..\cpptoc\write_handler_cpptoc.h"
>
</File>
</Filter>
<Filter
Name="ctocpp"

View File

@ -0,0 +1,174 @@
// 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 "binding_test.h"
#include <sstream>
// Implementation of the V8 handler class for the "window.cef_test.Dump"
// function.
class ClientV8FunctionHandler : public CefThreadSafeBase<CefV8Handler>
{
public:
ClientV8FunctionHandler() {}
virtual ~ClientV8FunctionHandler() {}
// Execute with the specified argument list and return value. Return true if
// the method was handled.
virtual bool Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
if(name == L"Dump")
{
// The "Dump" function will return a human-readable dump of the input
// arguments.
std::wstringstream stream;
size_t i;
for(i = 0; i < arguments.size(); ++i)
{
stream << L"arg[" << i << L"] = ";
PrintValue(arguments[i], stream, 0);
stream << L"\n";
}
retval = CefV8Value::CreateString(stream.str());
return true;
}
else if(name == L"Call")
{
// The "Call" function will execute a function to get an object and then
// return the result of calling a function belonging to that object. The
// first arument is the function that will return an object and the second
// argument is the function that will be called on that returned object.
int argSize = arguments.size();
if(argSize < 2 || !arguments[0]->IsFunction()
|| !arguments[1]->IsString())
return false;
CefV8ValueList argList;
// Execute the function stored in the first argument to retrieve an
// object.
CefRefPtr<CefV8Value> objectPtr;
if(!arguments[0]->ExecuteFunction(object, argList, objectPtr, exception))
return false;
// Verify that the returned value is an object.
if(!objectPtr.get() || !objectPtr->IsObject())
return false;
// Retrieve the member function specified by name in the second argument
// from the object.
CefRefPtr<CefV8Value> funcPtr =
objectPtr->GetValue(arguments[1]->GetStringValue());
// Verify that the returned value is a function.
if(!funcPtr.get() || !funcPtr->IsFunction())
return false;
// Pass any additional arguments on to the member function.
for(int i = 2; i < argSize; ++i)
argList.push_back(arguments[i]);
// Execute the member function.
return funcPtr->ExecuteFunction(arguments[0], argList, retval, exception);
}
return false;
}
// Simple function for formatted output of a V8 value.
void PrintValue(CefRefPtr<CefV8Value> value, std::wstringstream &stream,
int indent)
{
std::wstringstream indent_stream;
for(int i = 0; i < indent; ++i)
indent_stream << L" ";
std::wstring indent_str = indent_stream.str();
if(value->IsUndefined())
stream << L"(undefined)";
else if(value->IsNull())
stream << L"(null)";
else if(value->IsBool())
stream << L"(bool) " << (value->GetBoolValue() ? L"true" : L"false");
else if(value->IsInt())
stream << L"(int) " << value->GetIntValue();
else if(value->IsDouble())
stream << L"(double) " << value->GetDoubleValue();
else if(value->IsString())
stream << L"(string) " << value->GetStringValue().c_str();
else if(value->IsFunction())
stream << L"(function) " << value->GetFunctionName().c_str();
else if(value->IsArray()) {
stream << L"(array) [";
int len = value->GetArrayLength();
for(int i = 0; i < len; ++i) {
stream << L"\n " << indent_str.c_str() << i << L" = ";
PrintValue(value->GetValue(i), stream, indent+1);
}
stream << L"\n" << indent_str.c_str() << L"]";
} else if(value->IsObject()) {
stream << L"(object) [";
std::vector<std::wstring> keys;
if(value->GetKeys(keys)) {
for(size_t i = 0; i < keys.size(); ++i) {
stream << L"\n " << indent_str.c_str() << keys[i].c_str() << L" = ";
PrintValue(value->GetValue(keys[i]), stream, indent+1);
}
}
stream << L"\n" << indent_str.c_str() << L"]";
}
}
};
void InitBindingTest(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object)
{
// Create the new V8 object.
CefRefPtr<CefV8Value> testObjPtr = CefV8Value::CreateObject(NULL);
// Add the new V8 object to the global window object with the name
// "cef_test".
object->SetValue(L"cef_test", testObjPtr);
// Create an instance of ClientV8FunctionHandler as the V8 handler.
CefRefPtr<CefV8Handler> handlerPtr = new ClientV8FunctionHandler();
// Add a new V8 function to the cef_test object with the name "Dump".
testObjPtr->SetValue(L"Dump",
CefV8Value::CreateFunction(L"Dump", handlerPtr));
// Add a new V8 function to the cef_test object with the name "Call".
testObjPtr->SetValue(L"Call",
CefV8Value::CreateFunction(L"Call", handlerPtr));
}
void RunBindingTest(CefRefPtr<CefBrowser> browser)
{
std::wstring html =
L"<html><body>ClientV8FunctionHandler says:<br><pre>"
L"<script language=\"JavaScript\">"
L"document.writeln(window.cef_test.Dump(false, 1, 7.6654,'bar',"
L" [false,true],[5, 7.654, 1, 'foo', [true, 'bar'], 8]));"
L"document.writeln(window.cef_test.Dump(cef));"
L"document.writeln("
L" window.cef_test.Call(cef.test.test_object, 'GetMessage'));"
L"function my_object() {"
L" var obj = {};"
L" (function() {"
L" obj.GetMessage = function(a) {"
L" return 'Calling a function with value '+a+' on a user object succeeded.';"
L" };"
L" })();"
L" return obj;"
L"};"
L"document.writeln("
L" window.cef_test.Call(my_object, 'GetMessage', 'foobar'));"
L"</script>"
L"</pre></body></html>";
browser->GetMainFrame()->LoadString(html, L"about:blank");
}

View File

@ -0,0 +1,14 @@
// Copyright (c) 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.
#pragma once
#include "cef.h"
// Add the V8 bindings.
void InitBindingTest(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object);
// Run the test.
void RunBindingTest(CefRefPtr<CefBrowser> browser);

View File

@ -2,11 +2,15 @@
// 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 "cefclient.h"
#include "clientplugin.h"
#include "cef.h"
#include "cefclient.h"
#include "binding_test.h"
#include "extension_test.h"
#include "plugin_test.h"
#include "resource_util.h"
#include "scheme_test.h"
#include "string_util.h"
#include <sstream>
@ -30,284 +34,6 @@ BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
// Convert a std::string to a std::wstring
std::wstring StringToWString(const std::string& s)
{
wchar_t* wch;
UINT bytes = MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size()+1, NULL, 0);
wch = new wchar_t[bytes];
if(wch)
bytes = MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size()+1, wch, bytes);
std::wstring str = wch;
delete [] wch;
return str;
}
// Convert a std::wstring to a std::string
std::string WStringToString(const std::wstring& s)
{
char* ch;
UINT bytes = WideCharToMultiByte(CP_ACP, 0, s.c_str(), s.size()+1, NULL, 0,
NULL, NULL);
ch = new char[bytes];
if(ch)
bytes = WideCharToMultiByte(CP_ACP, 0, s.c_str(), s.size()+1, ch, bytes,
NULL, NULL);
std::string str = ch;
delete [] ch;
return str;
}
// Load a resource of type BINARY
bool LoadBinaryResource(int binaryId, DWORD &dwSize, LPBYTE &pBytes)
{
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;
}
// Dump the contents of the request into a string.
void DumpRequestContents(CefRefPtr<CefRequest> request, std::wstring& str)
{
std::wstringstream ss;
ss << L"URL: " << request->GetURL();
ss << L"\nMethod: " << request->GetMethod();
CefRequest::HeaderMap headerMap;
request->GetHeaderMap(headerMap);
if(headerMap.size() > 0) {
ss << L"\nHeaders:";
CefRequest::HeaderMap::const_iterator it = headerMap.begin();
for(; it != headerMap.end(); ++it) {
ss << L"\n\t" << (*it).first << L": " << (*it).second;
}
}
CefRefPtr<CefPostData> postData = request->GetPostData();
if(postData.get()) {
CefPostData::ElementVector elements;
postData->GetElements(elements);
if(elements.size() > 0) {
ss << L"\nPost Data:";
CefRefPtr<CefPostDataElement> element;
CefPostData::ElementVector::const_iterator it = elements.begin();
for(; it != elements.end(); ++it) {
element = (*it);
if(element->GetType() == PDE_TYPE_BYTES) {
// the element is composed of bytes
ss << L"\n\tBytes: ";
if(element->GetBytesCount() == 0)
ss << L"(empty)";
else {
// retrieve the data.
size_t size = element->GetBytesCount();
char* bytes = new char[size];
element->GetBytes(size, bytes);
ss << StringToWString(std::string(bytes, size));
delete [] bytes;
}
} else if(element->GetType() == PDE_TYPE_FILE) {
ss << L"\n\tFile: " << element->GetFile();
}
}
}
}
str = ss.str();
}
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
// Implementation of the V8 handler class for the "cef.test" extension.
class ClientV8ExtensionHandler : public CefThreadSafeBase<CefV8Handler>
{
public:
ClientV8ExtensionHandler() : test_param_(L"An initial string value.") {}
virtual ~ClientV8ExtensionHandler() {}
// Execute with the specified argument list and return value. Return true if
// the method was handled.
virtual bool Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
if(name == L"SetTestParam")
{
// Handle the SetTestParam native function by saving the string argument
// into the local member.
if(arguments.size() != 1 || !arguments[0]->IsString())
return false;
test_param_ = arguments[0]->GetStringValue();
return true;
}
else if(name == L"GetTestParam")
{
// Handle the GetTestParam native function by returning the local member
// value.
retval = CefV8Value::CreateString(test_param_);
return true;
}
else if(name == L"GetTestObject")
{
// Handle the GetTestObject native function by creating and returning a
// new V8 object.
retval = CefV8Value::CreateObject(NULL);
// Add a string parameter to the new V8 object.
retval->SetValue(L"param", CefV8Value::CreateString(
L"Retrieving a parameter on a native object succeeded."));
// Add a function to the new V8 object.
retval->SetValue(L"GetMessage",
CefV8Value::CreateFunction(L"GetMessage", this));
return true;
}
else if(name == L"GetMessage")
{
// Handle the GetMessage object function by returning a string.
retval = CefV8Value::CreateString(
L"Calling a function on a native object succeeded.");
return true;
}
return false;
}
private:
std::wstring test_param_;
};
// Implementation of the schema handler for client:// requests.
class ClientSchemeHandler : public CefThreadSafeBase<CefSchemeHandler>
{
public:
ClientSchemeHandler() : size_(0), offset_(0), bytes_(NULL) {}
// Process the request. All response generation should take place in this
// method. If there is no response set |response_length| to zero and
// ReadResponse() will not be called. If the response length is not known then
// set |response_length| to -1 and ReadResponse() will be called until it
// returns false or until the value of |bytes_read| is set to 0. Otherwise,
// set |response_length| to a positive value and ReadResponse() will be called
// until it returns false, the value of |bytes_read| is set to 0 or the
// specified number of bytes have been read. If there is a response set
// |mime_type| to the mime type for the response.
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
std::wstring& mime_type, int* response_length)
{
bool handled = false;
Lock();
std::wstring url = request->GetURL();
if(wcsstr(url.c_str(), L"handler.html") != NULL) {
// Build the response html
html_ = "<html><head><title>Client Scheme Handler</title></head><body>"
"This contents of this page page are served by the "
"ClientSchemeHandler class handling the client:// protocol."
"<br>You should see an image:"
"<br/><img src=\"client://tests/client.gif\"><pre>";
// Output a string representation of the request
std::wstring dump;
DumpRequestContents(request, dump);
html_.append(WStringToString(dump));
html_.append("</pre><br>Try the test form:"
"<form method=\"POST\" action=\"handler.html\">"
"<input type=\"text\" name=\"field1\">"
"<input type=\"text\" name=\"field2\">"
"<input type=\"submit\">"
"</form></body></html>");
handled = true;
size_ = html_.size();
bytes_ = (LPBYTE)html_.c_str();
// Set the resulting mime type
mime_type = L"text/html";
}
else if(wcsstr(url.c_str(), L"client.gif") != NULL) {
// Load the response image
if(LoadBinaryResource(IDS_LOGO, size_, bytes_)) {
handled = true;
// Set the resulting mime type
mime_type = L"image/jpg";
}
}
// Set the resulting response length
*response_length = size_;
Unlock();
return handled;
}
// Cancel processing of the request.
virtual void Cancel()
{
}
// Copy up to |bytes_to_read| bytes into |data_out|. If the copy succeeds
// set |bytes_read| to the number of bytes copied and return true. If the
// copy fails return false and ReadResponse() will not be called again.
virtual bool ReadResponse(void* data_out, int bytes_to_read,
int* bytes_read)
{
bool has_data = false;
*bytes_read = 0;
Lock();
if(offset_ < size_) {
// Copy the next block of data into the buffer.
int transfer_size = min(bytes_to_read, static_cast<int>(size_ - offset_));
memcpy(data_out, bytes_ + offset_, transfer_size);
offset_ += transfer_size;
*bytes_read = transfer_size;
has_data = true;
}
Unlock();
return has_data;
}
private:
DWORD size_, offset_;
LPBYTE bytes_;
std::string html_;
};
// Implementation of the factory for for creating schema handlers.
class ClientSchemeHandlerFactory :
public CefThreadSafeBase<CefSchemeHandlerFactory>
{
public:
// Return a new scheme handler instance to handle the request.
virtual CefRefPtr<CefSchemeHandler> Create()
{
return new ClientSchemeHandler();
}
};
// Program entry point function.
int APIENTRY _tWinMain(HINSTANCE hInstance,
@ -327,51 +53,14 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
CefInitialize(true, std::wstring());
#endif
// Structure providing information about the client plugin.
CefPluginInfo plugin_info;
plugin_info.display_name = L"Client Plugin";
plugin_info.unique_name = L"client_plugin";
plugin_info.version = L"1, 0, 0, 1";
plugin_info.description = L"My Example Client Plugin";
// Register the internal client plugin.
InitPluginTest();
CefPluginMimeType mime_type;
mime_type.mime_type = L"application/x-client-plugin";
mime_type.file_extensions.push_back(L"*");
plugin_info.mime_types.push_back(mime_type);
// Register the V8 extension handler.
InitExtensionTest();
plugin_info.np_getentrypoints = NP_GetEntryPoints;
plugin_info.np_initialize = NP_Initialize;
plugin_info.np_shutdown = NP_Shutdown;
// Register the internal client plugin
CefRegisterPlugin(plugin_info);
// Register a V8 extension with the below JavaScript code that calls native
// methods implemented in ClientV8ExtensionHandler.
std::wstring code = L"var cef;"
L"if (!cef)"
L" cef = {};"
L"if (!cef.test)"
L" cef.test = {};"
L"(function() {"
L" cef.test.__defineGetter__('test_param', function() {"
L" native function GetTestParam();"
L" return GetTestParam();"
L" });"
L" cef.test.__defineSetter__('test_param', function(b) {"
L" native function SetTestParam();"
L" if(b) SetTestParam(b);"
L" });"
L" cef.test.test_object = function() {"
L" native function GetTestObject();"
L" return GetTestObject();"
L" };"
L"})();";
CefRegisterExtension(L"v8/test", code, new ClientV8ExtensionHandler());
// Register the scheme handler factory for requests using the client://
// protocol in the tests domain.
CefRegisterScheme(L"client", L"tests", new ClientSchemeHandlerFactory());
// Register the scheme handler.
InitSchemeTest();
MSG msg;
HACCEL hAccelTable;
@ -410,8 +99,6 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
@ -477,123 +164,6 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
return TRUE;
}
// Implementation of the V8 handler class for the "window.cef_test.Dump"
// function.
class ClientV8FunctionHandler : public CefThreadSafeBase<CefV8Handler>
{
public:
ClientV8FunctionHandler() {}
virtual ~ClientV8FunctionHandler() {}
// Execute with the specified argument list and return value. Return true if
// the method was handled.
virtual bool Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
if(name == L"Dump")
{
// The "Dump" function will return a human-readable dump of the input
// arguments.
std::wstringstream stream;
size_t i;
for(i = 0; i < arguments.size(); ++i)
{
stream << L"arg[" << i << L"] = ";
PrintValue(arguments[i], stream, 0);
stream << L"\n";
}
retval = CefV8Value::CreateString(stream.str());
return true;
}
else if(name == L"Call")
{
// The "Call" function will execute a function to get an object and then
// return the result of calling a function belonging to that object. The
// first arument is the function that will return an object and the second
// argument is the function that will be called on that returned object.
int argSize = arguments.size();
if(argSize < 2 || !arguments[0]->IsFunction()
|| !arguments[1]->IsString())
return false;
CefV8ValueList argList;
// Execute the function stored in the first argument to retrieve an
// object.
CefRefPtr<CefV8Value> objectPtr;
if(!arguments[0]->ExecuteFunction(object, argList, objectPtr, exception))
return false;
// Verify that the returned value is an object.
if(!objectPtr.get() || !objectPtr->IsObject())
return false;
// Retrieve the member function specified by name in the second argument
// from the object.
CefRefPtr<CefV8Value> funcPtr =
objectPtr->GetValue(arguments[1]->GetStringValue());
// Verify that the returned value is a function.
if(!funcPtr.get() || !funcPtr->IsFunction())
return false;
// Pass any additional arguments on to the member function.
for(int i = 2; i < argSize; ++i)
argList.push_back(arguments[i]);
// Execute the member function.
return funcPtr->ExecuteFunction(arguments[0], argList, retval, exception);
}
return false;
}
// Simple function for formatted output of a V8 value.
void PrintValue(CefRefPtr<CefV8Value> value, std::wstringstream &stream,
int indent)
{
std::wstringstream indent_stream;
for(int i = 0; i < indent; ++i)
indent_stream << L" ";
std::wstring indent_str = indent_stream.str();
if(value->IsUndefined())
stream << L"(undefined)";
else if(value->IsNull())
stream << L"(null)";
else if(value->IsBool())
stream << L"(bool) " << (value->GetBoolValue() ? L"true" : L"false");
else if(value->IsInt())
stream << L"(int) " << value->GetIntValue();
else if(value->IsDouble())
stream << L"(double) " << value->GetDoubleValue();
else if(value->IsString())
stream << L"(string) " << value->GetStringValue().c_str();
else if(value->IsFunction())
stream << L"(function) " << value->GetFunctionName().c_str();
else if(value->IsArray()) {
stream << L"(array) [";
int len = value->GetArrayLength();
for(int i = 0; i < len; ++i) {
stream << L"\n " << indent_str.c_str() << i << L" = ";
PrintValue(value->GetValue(i), stream, indent+1);
}
stream << L"\n" << indent_str.c_str() << L"]";
} else if(value->IsObject()) {
stream << L"(object) [";
std::vector<std::wstring> keys;
if(value->GetKeys(keys)) {
for(size_t i = 0; i < keys.size(); ++i) {
stream << L"\n " << indent_str.c_str() << keys[i].c_str() << L" = ";
PrintValue(value->GetValue(keys[i]), stream, indent+1);
}
}
stream << L"\n" << indent_str.c_str() << L"]";
}
}
};
// Client implementation of the browser handler class
class ClientHandler : public CefThreadSafeBase<CefHandler>
@ -784,7 +354,8 @@ public:
DWORD dwSize;
LPBYTE pBytes;
if(LoadBinaryResource(IDS_LOGO, dwSize, pBytes)) {
resourceStream = CefStreamReader::CreateForData(pBytes, dwSize);
resourceStream = CefStreamReader::CreateForHandler(
new ClientReadHandler(pBytes, dwSize));
mimeType = L"image/jpg";
}
}
@ -912,21 +483,8 @@ public:
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Value> object)
{
// Create the new V8 object.
CefRefPtr<CefV8Value> testObjPtr = CefV8Value::CreateObject(NULL);
// Add the new V8 object to the global window object with the name
// "cef_test".
object->SetValue(L"cef_test", testObjPtr);
// Create an instance of ClientV8FunctionHandler as the V8 handler.
CefRefPtr<CefV8Handler> handlerPtr = new ClientV8FunctionHandler();
// Add a new V8 function to the cef_test object with the name "Dump".
testObjPtr->SetValue(L"Dump",
CefV8Value::CreateFunction(L"Dump", handlerPtr));
// Add a new V8 function to the cef_test object with the name "Call".
testObjPtr->SetValue(L"Call",
CefV8Value::CreateFunction(L"Call", handlerPtr));
// Add the V8 bindings.
InitBindingTest(browser, frame, object);
return RV_HANDLED;
}
@ -1162,50 +720,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
case ID_TESTS_JAVASCRIPT_HANDLER: // Test the V8 function handler
if(browser.get())
{
std::wstring html =
L"<html><body>ClientV8FunctionHandler says:<br><pre>"
L"<script language=\"JavaScript\">"
L"document.writeln(window.cef_test.Dump(false, 1, 7.6654,'bar',"
L" [false,true],[5, 7.654, 1, 'foo', [true, 'bar'], 8]));"
L"document.writeln(window.cef_test.Dump(cef));"
L"document.writeln("
L" window.cef_test.Call(cef.test.test_object, 'GetMessage'));"
L"function my_object() {"
L" var obj = {};"
L" (function() {"
L" obj.GetMessage = function(a) {"
L" return 'Calling a function with value '+a+' on a user object succeeded.';"
L" };"
L" })();"
L" return obj;"
L"};"
L"document.writeln("
L" window.cef_test.Call(my_object, 'GetMessage', 'foobar'));"
L"</script>"
L"</pre></body></html>";
browser->GetMainFrame()->LoadString(html, L"about:blank");
}
RunBindingTest(browser);
return 0;
case ID_TESTS_JAVASCRIPT_HANDLER2: // Test the V8 extension handler
if(browser.get())
{
std::wstring html =
L"<html><body>ClientV8ExtensionHandler says:<br><pre>"
L"<script language=\"JavaScript\">"
L"cef.test.test_param ="
L" 'Assign and retrieve a value succeeded the first time.';"
L"document.writeln(cef.test.test_param);"
L"cef.test.test_param ="
L" 'Assign and retrieve a value succeeded the second time.';"
L"document.writeln(cef.test.test_param);"
L"var obj = cef.test.test_object();"
L"document.writeln(obj.param);"
L"document.writeln(obj.GetMessage());"
L"</script>"
L"</pre></body></html>";
browser->GetMainFrame()->LoadString(html, L"about:blank");
}
RunExtensionTest(browser);
return 0;
case ID_TESTS_JAVASCRIPT_EXECUTE: // Test execution of javascript
if(browser.get())
@ -1217,14 +736,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
case ID_TESTS_PLUGIN: // Test the custom plugin
if(browser.get())
{
std::wstring html =
L"<html><body>Client Plugin:<br>"
L"<embed type=\"application/x-client-plugin\""
L"width=600 height=40>"
L"</body></html>";
browser->GetMainFrame()->LoadString(html, L"about:blank");
}
RunPluginTest(browser);
return 0;
case ID_TESTS_POPUP: // Test a popup window
if(browser.get())
@ -1265,7 +777,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
case ID_TESTS_SCHEME_HANDLER: // Test the scheme handler
if(browser.get())
browser->GetMainFrame()->LoadURL(L"client://tests/handler.html");
RunSchemeTest(browser);
return 0;
}
}

View File

@ -169,6 +169,14 @@
>
</File>
</Filter>
<File
RelativePath=".\binding_test.cpp"
>
</File>
<File
RelativePath=".\binding_test.h"
>
</File>
<File
RelativePath=".\cefclient.cpp"
>
@ -189,10 +197,42 @@
RelativePath=".\clientplugin.h"
>
</File>
<File
RelativePath=".\extension_test.cpp"
>
</File>
<File
RelativePath=".\extension_test.h"
>
</File>
<File
RelativePath=".\plugin_test.cpp"
>
</File>
<File
RelativePath=".\plugin_test.h"
>
</File>
<File
RelativePath=".\Resource.h"
>
</File>
<File
RelativePath=".\resource_util.cpp"
>
</File>
<File
RelativePath=".\resource_util.h"
>
</File>
<File
RelativePath=".\scheme_test.cpp"
>
</File>
<File
RelativePath=".\scheme_test.h"
>
</File>
<File
RelativePath=".\stdafx.cpp"
>
@ -217,6 +257,14 @@
RelativePath=".\stdafx.h"
>
</File>
<File
RelativePath=".\string_util.cpp"
>
</File>
<File
RelativePath=".\string_util.h"
>
</File>
</Files>
<Globals>
</Globals>

View File

@ -0,0 +1,112 @@
// 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 "extension_test.h"
// Implementation of the V8 handler class for the "cef.test" extension.
class ClientV8ExtensionHandler : public CefThreadSafeBase<CefV8Handler>
{
public:
ClientV8ExtensionHandler() : test_param_(L"An initial string value.") {}
virtual ~ClientV8ExtensionHandler() {}
// Execute with the specified argument list and return value. Return true if
// the method was handled.
virtual bool Execute(const std::wstring& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
std::wstring& exception)
{
if(name == L"SetTestParam")
{
// Handle the SetTestParam native function by saving the string argument
// into the local member.
if(arguments.size() != 1 || !arguments[0]->IsString())
return false;
test_param_ = arguments[0]->GetStringValue();
return true;
}
else if(name == L"GetTestParam")
{
// Handle the GetTestParam native function by returning the local member
// value.
retval = CefV8Value::CreateString(test_param_);
return true;
}
else if(name == L"GetTestObject")
{
// Handle the GetTestObject native function by creating and returning a
// new V8 object.
retval = CefV8Value::CreateObject(NULL);
// Add a string parameter to the new V8 object.
retval->SetValue(L"param", CefV8Value::CreateString(
L"Retrieving a parameter on a native object succeeded."));
// Add a function to the new V8 object.
retval->SetValue(L"GetMessage",
CefV8Value::CreateFunction(L"GetMessage", this));
return true;
}
else if(name == L"GetMessage")
{
// Handle the GetMessage object function by returning a string.
retval = CefV8Value::CreateString(
L"Calling a function on a native object succeeded.");
return true;
}
return false;
}
private:
std::wstring test_param_;
};
void InitExtensionTest()
{
// Register a V8 extension with the below JavaScript code that calls native
// methods implemented in ClientV8ExtensionHandler.
std::wstring code = L"var cef;"
L"if (!cef)"
L" cef = {};"
L"if (!cef.test)"
L" cef.test = {};"
L"(function() {"
L" cef.test.__defineGetter__('test_param', function() {"
L" native function GetTestParam();"
L" return GetTestParam();"
L" });"
L" cef.test.__defineSetter__('test_param', function(b) {"
L" native function SetTestParam();"
L" if(b) SetTestParam(b);"
L" });"
L" cef.test.test_object = function() {"
L" native function GetTestObject();"
L" return GetTestObject();"
L" };"
L"})();";
CefRegisterExtension(L"v8/test", code, new ClientV8ExtensionHandler());
}
void RunExtensionTest(CefRefPtr<CefBrowser> browser)
{
std::wstring html =
L"<html><body>ClientV8ExtensionHandler says:<br><pre>"
L"<script language=\"JavaScript\">"
L"cef.test.test_param ="
L" 'Assign and retrieve a value succeeded the first time.';"
L"document.writeln(cef.test.test_param);"
L"cef.test.test_param ="
L" 'Assign and retrieve a value succeeded the second time.';"
L"document.writeln(cef.test.test_param);"
L"var obj = cef.test.test_object();"
L"document.writeln(obj.param);"
L"document.writeln(obj.GetMessage());"
L"</script>"
L"</pre></body></html>";
browser->GetMainFrame()->LoadString(html, L"about:blank");
}

View File

@ -0,0 +1,12 @@
// Copyright (c) 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.
#pragma once
#include "cef.h"
// Register the V8 extension handler.
void InitExtensionTest();
// Run the test.
void RunExtensionTest(CefRefPtr<CefBrowser> browser);

View File

@ -0,0 +1,40 @@
// 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 "plugin_test.h"
#include "clientplugin.h"
void InitPluginTest()
{
// Structure providing information about the client plugin.
CefPluginInfo plugin_info;
plugin_info.display_name = L"Client Plugin";
plugin_info.unique_name = L"client_plugin";
plugin_info.version = L"1, 0, 0, 1";
plugin_info.description = L"My Example Client Plugin";
CefPluginMimeType mime_type;
mime_type.mime_type = L"application/x-client-plugin";
mime_type.file_extensions.push_back(L"*");
plugin_info.mime_types.push_back(mime_type);
plugin_info.np_getentrypoints = NP_GetEntryPoints;
plugin_info.np_initialize = NP_Initialize;
plugin_info.np_shutdown = NP_Shutdown;
// Register the internal client plugin
CefRegisterPlugin(plugin_info);
}
void RunPluginTest(CefRefPtr<CefBrowser> browser)
{
std::wstring html =
L"<html><body>Client Plugin:<br>"
L"<embed type=\"application/x-client-plugin\""
L"width=600 height=40>"
L"</body></html>";
browser->GetMainFrame()->LoadString(html, L"about:blank");
}

View File

@ -0,0 +1,12 @@
// Copyright (c) 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.
#pragma once
#include "cef.h"
// Register the internal client plugin.
void InitPluginTest();
// Run the test.
void RunPluginTest(CefRefPtr<CefBrowser> browser);

View 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;
}

View File

@ -0,0 +1,39 @@
// Copyright (c) 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.
#pragma once
#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

@ -0,0 +1,134 @@
// Copyright (c) 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 "scheme_test.h"
#include "string_util.h"
#include "resource_util.h"
#include "resource.h"
// Implementation of the schema handler for client:// requests.
class ClientSchemeHandler : public CefThreadSafeBase<CefSchemeHandler>
{
public:
ClientSchemeHandler() : size_(0), offset_(0), bytes_(NULL) {}
// Process the request. All response generation should take place in this
// method. If there is no response set |response_length| to zero and
// ReadResponse() will not be called. If the response length is not known then
// set |response_length| to -1 and ReadResponse() will be called until it
// returns false or until the value of |bytes_read| is set to 0. Otherwise,
// set |response_length| to a positive value and ReadResponse() will be called
// until it returns false, the value of |bytes_read| is set to 0 or the
// specified number of bytes have been read. If there is a response set
// |mime_type| to the mime type for the response.
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
std::wstring& mime_type, int* response_length)
{
bool handled = false;
Lock();
std::wstring url = request->GetURL();
if(wcsstr(url.c_str(), L"handler.html") != NULL) {
// Build the response html
html_ = "<html><head><title>Client Scheme Handler</title></head><body>"
"This contents of this page page are served by the "
"ClientSchemeHandler class handling the client:// protocol."
"<br>You should see an image:"
"<br/><img src=\"client://tests/client.gif\"><pre>";
// Output a string representation of the request
std::wstring dump;
DumpRequestContents(request, dump);
html_.append(WStringToString(dump));
html_.append("</pre><br>Try the test form:"
"<form method=\"POST\" action=\"handler.html\">"
"<input type=\"text\" name=\"field1\">"
"<input type=\"text\" name=\"field2\">"
"<input type=\"submit\">"
"</form></body></html>");
handled = true;
size_ = html_.size();
bytes_ = (LPBYTE)html_.c_str();
// Set the resulting mime type
mime_type = L"text/html";
}
else if(wcsstr(url.c_str(), L"client.gif") != NULL) {
// Load the response image
if(LoadBinaryResource(IDS_LOGO, size_, bytes_)) {
handled = true;
// Set the resulting mime type
mime_type = L"image/jpg";
}
}
// Set the resulting response length
*response_length = size_;
Unlock();
return handled;
}
// Cancel processing of the request.
virtual void Cancel()
{
}
// Copy up to |bytes_to_read| bytes into |data_out|. If the copy succeeds
// set |bytes_read| to the number of bytes copied and return true. If the
// copy fails return false and ReadResponse() will not be called again.
virtual bool ReadResponse(void* data_out, int bytes_to_read,
int* bytes_read)
{
bool has_data = false;
*bytes_read = 0;
Lock();
if(offset_ < size_) {
// Copy the next block of data into the buffer.
int transfer_size = min(bytes_to_read, static_cast<int>(size_ - offset_));
memcpy(data_out, bytes_ + offset_, transfer_size);
offset_ += transfer_size;
*bytes_read = transfer_size;
has_data = true;
}
Unlock();
return has_data;
}
private:
DWORD size_, offset_;
LPBYTE bytes_;
std::string html_;
};
// Implementation of the factory for for creating schema handlers.
class ClientSchemeHandlerFactory :
public CefThreadSafeBase<CefSchemeHandlerFactory>
{
public:
// Return a new scheme handler instance to handle the request.
virtual CefRefPtr<CefSchemeHandler> Create()
{
return new ClientSchemeHandler();
}
};
void InitSchemeTest()
{
CefRegisterScheme(L"client", L"tests", new ClientSchemeHandlerFactory());
}
void RunSchemeTest(CefRefPtr<CefBrowser> browser)
{
browser->GetMainFrame()->LoadURL(L"client://tests/handler.html");
}

View File

@ -0,0 +1,12 @@
// Copyright (c) 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.
#pragma once
#include "cef.h"
// Register the scheme handler.
void InitSchemeTest();
// Run the test.
void RunSchemeTest(CefRefPtr<CefBrowser> browser);

View File

@ -0,0 +1,84 @@
// Copyright (c) 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 "string_util.h"
#include <sstream>
std::wstring StringToWString(const std::string& s)
{
wchar_t* wch;
UINT bytes = MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size()+1, NULL, 0);
wch = new wchar_t[bytes];
if(wch)
bytes = MultiByteToWideChar(CP_ACP, 0, s.c_str(), s.size()+1, wch, bytes);
std::wstring str = wch;
delete [] wch;
return str;
}
std::string WStringToString(const std::wstring& s)
{
char* ch;
UINT bytes = WideCharToMultiByte(CP_ACP, 0, s.c_str(), s.size()+1, NULL, 0,
NULL, NULL);
ch = new char[bytes];
if(ch)
bytes = WideCharToMultiByte(CP_ACP, 0, s.c_str(), s.size()+1, ch, bytes,
NULL, NULL);
std::string str = ch;
delete [] ch;
return str;
}
void DumpRequestContents(CefRefPtr<CefRequest> request, std::wstring& str)
{
std::wstringstream ss;
ss << L"URL: " << request->GetURL();
ss << L"\nMethod: " << request->GetMethod();
CefRequest::HeaderMap headerMap;
request->GetHeaderMap(headerMap);
if(headerMap.size() > 0) {
ss << L"\nHeaders:";
CefRequest::HeaderMap::const_iterator it = headerMap.begin();
for(; it != headerMap.end(); ++it) {
ss << L"\n\t" << (*it).first << L": " << (*it).second;
}
}
CefRefPtr<CefPostData> postData = request->GetPostData();
if(postData.get()) {
CefPostData::ElementVector elements;
postData->GetElements(elements);
if(elements.size() > 0) {
ss << L"\nPost Data:";
CefRefPtr<CefPostDataElement> element;
CefPostData::ElementVector::const_iterator it = elements.begin();
for(; it != elements.end(); ++it) {
element = (*it);
if(element->GetType() == PDE_TYPE_BYTES) {
// the element is composed of bytes
ss << L"\n\tBytes: ";
if(element->GetBytesCount() == 0)
ss << L"(empty)";
else {
// retrieve the data.
size_t size = element->GetBytesCount();
char* bytes = new char[size];
element->GetBytes(size, bytes);
ss << StringToWString(std::string(bytes, size));
delete [] bytes;
}
} else if(element->GetType() == PDE_TYPE_FILE) {
ss << L"\n\tFile: " << element->GetFile();
}
}
}
}
str = ss.str();
}

View File

@ -0,0 +1,18 @@
// Copyright (c) 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.
#pragma once
#include "cef.h"
#include <string>
// Convert a std::string to a std::wstring
std::wstring StringToWString(const std::string& s);
// Convert a std::wstring to a std::string
std::string WStringToString(const std::wstring& s);
// Dump the contents of the request into a string.
void DumpRequestContents(CefRefPtr<CefRequest> request, std::wstring& str);