cef/libcef_dll/ctocpp/request_ctocpp.cc
Marshall Greenblatt c295931b1e - Move frame-related methods from CefBrowser into a new CefFrame class.
- Add CefBrowser::Get*Frame() methods for retrieving the appropriate CefFrame instance.
- Add a CefFrame attribute to CefHandler callback methods where appropriate.
- Add support for V8 JavaScript extensions and values via CefV8Value and CefV8Handler.  Native C++ and user-defined JavaScript object hierarchies may now be created and accessed using the CEF API.
- Remove the CefHandler and CefVariant classes and related CefBrowser methods that have been obsoleted by the addition of CEF V8 support.
- Add the CefRegisterExtension() function for registering system-wide V8 extensions.
- Add the CefHandler::HandleJSBinding() callback method for attaching V8 values to the global frame JavaScript object.  This method replaces the previous technique of calling CefBrowser::AddJSHandler().
- Add new wrapper template methods for simplifying DLL wrapper implementations.
- Move cef_string* files from libcef_dll to libcef so that projects can link libcef statically without errors.
- Fix crashes when CEF exits due to object constructors being executed on non-UI threads if the application is closed while a page is still loading.
- Update the cefclient project to reflect changes and demonstrate the new APIs.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@26 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
2009-05-28 00:31:21 +00:00

264 lines
6.2 KiB
C++

// 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 "../precompiled_libcef.h"
#include "ctocpp/request_ctocpp.h"
#include "transfer_util.h"
std::wstring CefRequestCToCpp::GetURL()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_url))
return str;
cef_string_t cef_str = struct_->get_url(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
void CefRequestCToCpp::SetURL(const std::wstring& url)
{
if(CEF_MEMBER_MISSING(struct_, set_url))
return;
struct_->set_url(struct_, url.c_str());
}
std::wstring CefRequestCToCpp::GetMethod()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_method))
return str;
cef_string_t cef_str = struct_->get_method(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
void CefRequestCToCpp::SetMethod(const std::wstring& method)
{
if(CEF_MEMBER_MISSING(struct_, set_method))
return;
struct_->set_method(struct_, method.c_str());
}
CefRefPtr<CefPostData> CefRequestCToCpp::GetPostData()
{
if(CEF_MEMBER_MISSING(struct_, get_post_data))
return NULL;
cef_post_data_t* postDataStruct = struct_->get_post_data(struct_);
if(postDataStruct)
return CefPostDataCToCpp::Wrap(postDataStruct);
return NULL;
}
void CefRequestCToCpp::SetPostData(CefRefPtr<CefPostData> postData)
{
if(CEF_MEMBER_MISSING(struct_, set_post_data))
return;
cef_post_data_t* postDataStruct = NULL;
if(postData.get())
postDataStruct = CefPostDataCToCpp::Unwrap(postData);
struct_->set_post_data(struct_, postDataStruct);
}
void CefRequestCToCpp::GetHeaderMap(HeaderMap& headerMap)
{
if(CEF_MEMBER_MISSING(struct_, get_header_map))
return;
cef_string_map_t map = cef_string_map_alloc();
if(!map)
return;
struct_->get_header_map(struct_, map);
transfer_string_map_contents(map, headerMap);
cef_string_map_free(map);
}
void CefRequestCToCpp::SetHeaderMap(const HeaderMap& headerMap)
{
if(CEF_MEMBER_MISSING(struct_, set_header_map))
return;
cef_string_map_t map = NULL;
if(!headerMap.empty()) {
map = cef_string_map_alloc();
if(!map)
return;
transfer_string_map_contents(headerMap, map);
}
struct_->set_header_map(struct_, map);
if(map)
cef_string_map_free(map);
}
void CefRequestCToCpp::Set(const std::wstring& url,
const std::wstring& method,
CefRefPtr<CefPostData> postData,
const HeaderMap& headerMap)
{
if(CEF_MEMBER_MISSING(struct_, set))
return;
cef_post_data_t* postDataStruct = NULL;
if(postData.get())
postDataStruct = CefPostDataCToCpp::Unwrap(postData);
cef_string_map_t map = NULL;
if(!headerMap.empty()) {
map = cef_string_map_alloc();
if(!map)
return;
transfer_string_map_contents(headerMap, map);
}
struct_->set(struct_, url.c_str(), method.c_str(), postDataStruct, map);
if(map)
cef_string_map_free(map);
}
#ifdef _DEBUG
long CefCToCpp<CefRequestCToCpp, CefRequest, cef_request_t>::DebugObjCt = 0;
#endif
size_t CefPostDataCToCpp::GetElementCount()
{
if(CEF_MEMBER_MISSING(struct_, get_element_count))
return 0;
return struct_->get_element_count(struct_);
}
void CefPostDataCToCpp::GetElements(ElementVector& elements)
{
if(CEF_MEMBER_MISSING(struct_, get_element))
return;
int count = (int)GetElementCount();
cef_post_data_element_t* structPtr;
for(int i = 0; i < count; ++i) {
structPtr = struct_->get_element(struct_, i);
if(structPtr)
elements.push_back(CefPostDataElementCToCpp::Wrap(structPtr));
}
}
bool CefPostDataCToCpp::RemoveElement(CefRefPtr<CefPostDataElement> element)
{
DCHECK(element.get());
if(CEF_MEMBER_MISSING(struct_, remove_element) || !element.get())
return false;
return struct_->remove_element(struct_,
CefPostDataElementCToCpp::Unwrap(element));
}
bool CefPostDataCToCpp::AddElement(CefRefPtr<CefPostDataElement> element)
{
DCHECK(element.get());
if(CEF_MEMBER_MISSING(struct_, add_element) || !element.get())
return false;
return struct_->add_element(struct_,
CefPostDataElementCToCpp::Unwrap(element));
}
void CefPostDataCToCpp::RemoveElements()
{
if(CEF_MEMBER_MISSING(struct_, remove_elements))
return;
return struct_->remove_elements(struct_);
}
#ifdef _DEBUG
long CefCToCpp<CefPostDataCToCpp, CefPostData, cef_post_data_t>::DebugObjCt = 0;
#endif
void CefPostDataElementCToCpp::SetToEmpty()
{
if(CEF_MEMBER_MISSING(struct_, set_to_empty))
return;
return struct_->set_to_empty(struct_);
}
void CefPostDataElementCToCpp::SetToFile(const std::wstring& fileName)
{
if(CEF_MEMBER_MISSING(struct_, set_to_file))
return;
return struct_->set_to_file(struct_, fileName.c_str());
}
void CefPostDataElementCToCpp::SetToBytes(size_t size, const void* bytes)
{
if(CEF_MEMBER_MISSING(struct_, set_to_bytes))
return;
return struct_->set_to_bytes(struct_, size, bytes);
}
CefPostDataElement::Type CefPostDataElementCToCpp::GetType()
{
if(CEF_MEMBER_MISSING(struct_, get_type))
return PDE_TYPE_EMPTY;
return struct_->get_type(struct_);
}
std::wstring CefPostDataElementCToCpp::GetFile()
{
std::wstring str;
if(CEF_MEMBER_MISSING(struct_, get_file))
return str;
cef_string_t cef_str = struct_->get_file(struct_);
if(cef_str) {
str = cef_str;
cef_string_free(cef_str);
}
return str;
}
size_t CefPostDataElementCToCpp::GetBytesCount()
{
if(CEF_MEMBER_MISSING(struct_, get_bytes_count))
return 0;
return struct_->get_bytes_count(struct_);
}
size_t CefPostDataElementCToCpp::GetBytes(size_t size, void *bytes)
{
if(CEF_MEMBER_MISSING(struct_, get_bytes))
return 0;
return struct_->get_bytes(struct_, size, bytes);
}
#ifdef _DEBUG
long CefCToCpp<CefPostDataElementCToCpp, CefPostDataElement,
cef_post_data_element_t>::DebugObjCt = 0;
#endif