- Add the CefBrowser::CreateBrowserSync() method for synchronously creating a browser instance. (Issue #13, Suggested implementation by: vridosh)
- Add CefBrowser::SetFocus() and CefHandler::HandleTakeFocus() methods to deal with keyboard focus changes. (Issue #13, Suggested implementation by: vridosh)
- Add CefHandler::HandleBeforeWindowClose() to perform actions immediately before the browser window is destroyed. (Issue #13, Suggested implementation by: vridosh)
- Replace windows-specific address resolution code with GURL() in CefBrowserImpl::UIT_LoadURLForRequest(), CefBrowserImpl::UIT_LoadHTML() and CefBrowserImpl::UIT_LoadHTMLForStreamRef(), and move the methods from browser_impl_win.cc to browser_impl.cc. (Issue #13, Suggested implementation by: vridosh)
- Fix reference counting bugs, class definition problems and CefContext::Shutdown() bug resulting in Cef object leaks. (Issue #15)
- Add WebKit dependancy to libcef project.
- Add basic object count debugging for CefCToCpp and CefCppToC classes.

cefclient:
- Initialize the strPtr parameter to avoid URLs suffixed with garbage. (Issue #13, Fix by: vridosh)

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@19 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2009-03-08 02:26:16 +00:00
parent 3aa0d4c0fa
commit 08a19d5384
37 changed files with 628 additions and 195 deletions

View File

@ -10,6 +10,7 @@
#include "ctocpp/jshandler_ctocpp.h"
#include "base/logging.h"
int CEF_CALLBACK browser_can_go_back(cef_browser_t* browser)
{
DCHECK(browser);
@ -160,6 +161,17 @@ void CEF_CALLBACK browser_select_all(cef_browser_t* browser,
impl->class_->GetClass()->SelectAll(targetFrame);
}
void CEF_CALLBACK browser_set_focus(struct _cef_browser_t* browser, int enable)
{
DCHECK(browser);
if(!browser)
return;
CefBrowserCppToC::Struct* impl =
reinterpret_cast<CefBrowserCppToC::Struct*>(browser);
impl->class_->GetClass()->SetFocus(enable ? true : false);
}
void CEF_CALLBACK browser_print(cef_browser_t* browser,
enum cef_targetframe_t targetFrame)
{
@ -460,7 +472,7 @@ cef_string_t CEF_CALLBACK browser_get_url(cef_browser_t* browser)
return cef_string_alloc(urlStr.c_str());
}
CefBrowserCppToC::CefBrowserCppToC(CefRefPtr<CefBrowser> cls)
CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
: CefCppToC<CefBrowser, cef_browser_t>(cls)
{
struct_.struct_.can_go_back = browser_can_go_back;
@ -476,6 +488,7 @@ CefBrowserCppToC::CefBrowserCppToC(CefRefPtr<CefBrowser> cls)
struct_.struct_.paste = browser_paste;
struct_.struct_.del = browser_delete;
struct_.struct_.select_all = browser_select_all;
struct_.struct_.set_focus = browser_set_focus;
struct_.struct_.print = browser_print;
struct_.struct_.view_source = browser_view_source;
struct_.struct_.get_source = browser_get_source;
@ -495,3 +508,7 @@ CefBrowserCppToC::CefBrowserCppToC(CefRefPtr<CefBrowser> cls)
struct_.struct_.get_handler = browser_get_handler;
struct_.struct_.get_url = browser_get_url;
}
#ifdef _DEBUG
long CefCppToC<CefBrowser, cef_browser_t>::DebugObjCt = 0;
#endif

View File

@ -19,7 +19,7 @@
class CefBrowserCppToC : public CefCppToC<CefBrowser, cef_browser_t>
{
public:
CefBrowserCppToC(CefRefPtr<CefBrowser> cls);
CefBrowserCppToC(CefBrowser* cls);
virtual ~CefBrowserCppToC() {}
};

View File

@ -22,10 +22,10 @@ public:
CefCppToC<ClassName, StructName>* class_;
};
CefCppToC(CefRefPtr<ClassName> cls)
CefCppToC(ClassName* cls)
: class_(cls)
{
DCHECK(cls.get());
DCHECK(cls);
struct_.class_ = this;
@ -34,12 +34,20 @@ public:
struct_.struct_.base.size = sizeof(StructName);
struct_.struct_.base.add_ref = struct_add_ref;
struct_.struct_.base.release = struct_release;
struct_.struct_.base.get_refct = struct_get_refct;
#ifdef _DEBUG
CefAtomicIncrement(&DebugObjCt);
#endif
}
virtual ~CefCppToC()
{
#ifdef _DEBUG
CefAtomicDecrement(&DebugObjCt);
#endif
}
CefRefPtr<ClassName> GetClass() { return class_; }
ClassName* GetClass() { return class_; }
// If returning the structure across the DLL boundary you should call
// AddRef() on this CefCppToC object. On the other side of the DLL boundary,
@ -62,6 +70,12 @@ public:
// Increment/decrement reference counts on only the underlying class.
int UnderlyingAddRef() { return class_->AddRef(); }
int UnderlyingRelease() { return class_->Release(); }
int UnderlyingGetRefCt() { return class_->GetRefCt(); }
#ifdef _DEBUG
// Simple tracking of allocated objects.
static long DebugObjCt;
#endif
private:
static int CEF_CALLBACK struct_add_ref(struct _cef_base_t* base)
@ -84,9 +98,19 @@ private:
return impl->class_->Release();
}
static int CEF_CALLBACK struct_get_refct(struct _cef_base_t* base)
{
DCHECK(base);
if(!base)
return 0;
Struct* impl = reinterpret_cast<Struct*>(base);
return impl->class_->GetRefCt();
}
protected:
Struct struct_;
CefRefPtr<ClassName> class_;
ClassName* class_;
};
#endif // _CPPTOC_H

View File

@ -53,7 +53,7 @@ enum cef_retval_t CEF_CALLBACK handler_handle_before_created(
transfer_string_contents(urlStr, url);
if(handlerPtr.get() != structPtr->class_->GetClass().get())
if(handlerPtr.get() != structPtr->class_->GetClass())
{
// The handler has been changed.
CefHandlerCppToC* hobj = new CefHandlerCppToC(handlerPtr);
@ -501,8 +501,45 @@ enum cef_retval_t CEF_CALLBACK handler_handle_jsprompt(
return rv;
}
enum cef_retval_t CEF_CALLBACK handler_handle_before_window_close(
struct _cef_handler_t* handler, cef_browser_t* browser)
{
DCHECK(handler);
DCHECK(browser);
if(!handler || !browser)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
return impl->class_->GetClass()->HandleBeforeWindowClose(browserPtr);
}
CefHandlerCppToC::CefHandlerCppToC(CefRefPtr<CefHandler> cls)
enum cef_retval_t CEF_CALLBACK handler_handle_take_focus(
struct _cef_handler_t* handler, cef_browser_t* browser, int reverse)
{
DCHECK(handler);
DCHECK(browser);
if(!handler || !browser)
return RV_CONTINUE;
CefHandlerCppToC::Struct* impl =
reinterpret_cast<CefHandlerCppToC::Struct*>(handler);
CefBrowserCToCpp* bp = new CefBrowserCToCpp(browser);
CefRefPtr<CefBrowser> browserPtr(bp);
bp->UnderlyingRelease();
return impl->class_->GetClass()->
HandleTakeFocus(browserPtr, (reverse ? true : false));
}
CefHandlerCppToC::CefHandlerCppToC(CefHandler* cls)
: CefCppToC<CefHandler, cef_handler_t>(cls)
{
struct_.struct_.handle_before_created = handler_handle_before_created;
@ -523,4 +560,11 @@ CefHandlerCppToC::CefHandlerCppToC(CefRefPtr<CefHandler> cls)
struct_.struct_.handle_jsalert = handler_handle_jsalert;
struct_.struct_.handle_jsconfirm = handler_handle_jsconfirm;
struct_.struct_.handle_jsprompt = handler_handle_jsprompt;
struct_.struct_.handle_before_window_close =
handler_handle_before_window_close;
struct_.struct_.handle_take_focus = handler_handle_take_focus;
}
#ifdef _DEBUG
long CefCppToC<CefHandler, cef_handler_t>::DebugObjCt = 0;
#endif

View File

@ -19,7 +19,7 @@
class CefHandlerCppToC : public CefCppToC<CefHandler, cef_handler_t>
{
public:
CefHandlerCppToC(CefRefPtr<CefHandler> cls);
CefHandlerCppToC(CefHandler* cls);
virtual ~CefHandlerCppToC() {}
};

View File

@ -144,7 +144,7 @@ bool CEF_CALLBACK jshandler_execute_method(struct _cef_jshandler_t* jshandler,
}
CefJSHandlerCppToC::CefJSHandlerCppToC(CefRefPtr<CefJSHandler> cls)
CefJSHandlerCppToC::CefJSHandlerCppToC(CefJSHandler* cls)
: CefCppToC<CefJSHandler, cef_jshandler_t>(cls)
{
struct_.struct_.has_method = jshandler_has_method;
@ -153,3 +153,7 @@ CefJSHandlerCppToC::CefJSHandlerCppToC(CefRefPtr<CefJSHandler> cls)
struct_.struct_.get_property = jshandler_get_property;
struct_.struct_.execute_method = jshandler_execute_method;
}
#ifdef _DEBUG
long CefCppToC<CefJSHandler, cef_jshandler_t>::DebugObjCt = 0;
#endif

View File

@ -19,7 +19,7 @@
class CefJSHandlerCppToC : public CefCppToC<CefJSHandler, cef_jshandler_t>
{
public:
CefJSHandlerCppToC(CefRefPtr<CefJSHandler> cls);
CefJSHandlerCppToC(CefJSHandler* cls);
virtual ~CefJSHandlerCppToC() {}
};

View File

@ -207,7 +207,7 @@ void CEF_CALLBACK request_set(struct _cef_request_t* request,
}
CefRequestCppToC::CefRequestCppToC(CefRefPtr<CefRequest> cls)
CefRequestCppToC::CefRequestCppToC(CefRequest* cls)
: CefCppToC<CefRequest, cef_request_t>(cls)
{
struct_.struct_.get_url = request_get_url;
@ -222,7 +222,10 @@ CefRequestCppToC::CefRequestCppToC(CefRefPtr<CefRequest> cls)
struct_.struct_.set_header_map = request_set_header_map;
struct_.struct_.set = request_set;
}
#ifdef _DEBUG
long CefCppToC<CefRequest, cef_request_t>::DebugObjCt = 0;
#endif
size_t CEF_CALLBACK post_data_get_element_count(
@ -303,7 +306,7 @@ void CEF_CALLBACK post_data_remove_elements(struct _cef_post_data_t* postData)
}
CefPostDataCppToC::CefPostDataCppToC(CefRefPtr<CefPostData> cls)
CefPostDataCppToC::CefPostDataCppToC(CefPostData* cls)
: CefCppToC<CefPostData, cef_post_data_t>(cls)
{
struct_.struct_.get_element_count = post_data_get_element_count;
@ -312,7 +315,10 @@ CefPostDataCppToC::CefPostDataCppToC(CefRefPtr<CefPostData> cls)
struct_.struct_.add_element = post_data_add_element;
struct_.struct_.remove_elements = post_data_remove_elements;
}
#ifdef _DEBUG
long CefCppToC<CefPostData, cef_post_data_t>::DebugObjCt = 0;
#endif
void CEF_CALLBACK post_data_element_set_to_empty(
@ -411,8 +417,7 @@ size_t CEF_CALLBACK post_data_element_get_bytes(
}
CefPostDataElementCppToC::CefPostDataElementCppToC(
CefRefPtr<CefPostDataElement> cls)
CefPostDataElementCppToC::CefPostDataElementCppToC(CefPostDataElement* cls)
: CefCppToC<CefPostDataElement, cef_post_data_element_t>(cls)
{
struct_.struct_.set_to_empty = post_data_element_set_to_empty;
@ -423,3 +428,7 @@ CefPostDataElementCppToC::CefPostDataElementCppToC(
struct_.struct_.get_bytes_count = post_data_element_get_bytes_count;
struct_.struct_.get_bytes = post_data_element_get_bytes;
}
#ifdef _DEBUG
long CefCppToC<CefPostDataElement, cef_post_data_element_t>::DebugObjCt = 0;
#endif

View File

@ -19,7 +19,7 @@
class CefRequestCppToC : public CefCppToC<CefRequest, cef_request_t>
{
public:
CefRequestCppToC(CefRefPtr<CefRequest> cls);
CefRequestCppToC(CefRequest* cls);
virtual ~CefRequestCppToC() {}
};
@ -29,7 +29,7 @@ public:
class CefPostDataCppToC : public CefCppToC<CefPostData, cef_post_data_t>
{
public:
CefPostDataCppToC(CefRefPtr<CefPostData> cls);
CefPostDataCppToC(CefPostData* cls);
virtual ~CefPostDataCppToC() {}
};
@ -42,7 +42,7 @@ class CefPostDataElementCppToC :
public CefCppToC<CefPostDataElement, cef_post_data_element_t>
{
public:
CefPostDataElementCppToC(CefRefPtr<CefPostDataElement> cls);
CefPostDataElementCppToC(CefPostDataElement* cls);
virtual ~CefPostDataElementCppToC() {}
};

View File

@ -54,7 +54,7 @@ int CEF_CALLBACK stream_reader_eof(struct _cef_stream_reader_t* stream)
}
CefStreamReaderCppToC::CefStreamReaderCppToC(CefRefPtr<CefStreamReader> cls)
CefStreamReaderCppToC::CefStreamReaderCppToC(CefStreamReader* cls)
: CefCppToC<CefStreamReader, cef_stream_reader_t>(cls)
{
struct_.struct_.read = stream_reader_read;
@ -62,7 +62,10 @@ CefStreamReaderCppToC::CefStreamReaderCppToC(CefRefPtr<CefStreamReader> cls)
struct_.struct_.tell = stream_reader_tell;
struct_.struct_.eof = stream_reader_eof;
}
#ifdef _DEBUG
long CefCppToC<CefStreamReader, cef_stream_reader_t>::DebugObjCt = 0;
#endif
size_t CEF_CALLBACK stream_writer_write(struct _cef_stream_writer_t* stream,
@ -112,7 +115,7 @@ int CEF_CALLBACK stream_writer_flush(struct _cef_stream_writer_t* stream)
}
CefStreamWriterCppToC::CefStreamWriterCppToC(CefRefPtr<CefStreamWriter> cls)
CefStreamWriterCppToC::CefStreamWriterCppToC(CefStreamWriter* cls)
: CefCppToC<CefStreamWriter, cef_stream_writer_t>(cls)
{
struct_.struct_.write = stream_writer_write;
@ -120,3 +123,7 @@ CefStreamWriterCppToC::CefStreamWriterCppToC(CefRefPtr<CefStreamWriter> cls)
struct_.struct_.tell = stream_writer_tell;
struct_.struct_.flush = stream_writer_flush;
}
#ifdef _DEBUG
long CefCppToC<CefStreamWriter, cef_stream_writer_t>::DebugObjCt = 0;
#endif

View File

@ -20,7 +20,7 @@ class CefStreamReaderCppToC :
public CefCppToC<CefStreamReader, cef_stream_reader_t>
{
public:
CefStreamReaderCppToC(CefRefPtr<CefStreamReader> cls);
CefStreamReaderCppToC(CefStreamReader* cls);
virtual ~CefStreamReaderCppToC() {}
};
@ -31,7 +31,7 @@ class CefStreamWriterCppToC :
public CefCppToC<CefStreamWriter, cef_stream_writer_t>
{
public:
CefStreamWriterCppToC(CefRefPtr<CefStreamWriter> cls);
CefStreamWriterCppToC(CefStreamWriter* cls);
virtual ~CefStreamWriterCppToC() {}
};

View File

@ -282,7 +282,7 @@ size_t CEF_CALLBACK variant_get_string_array(struct _cef_variant_t* variant,
}
CefVariantCppToC::CefVariantCppToC(CefRefPtr<CefVariant> cls)
CefVariantCppToC::CefVariantCppToC(CefVariant* cls)
: CefCppToC<CefVariant, cef_variant_t>(cls)
{
struct_.struct_.get_type = variant_get_type;
@ -305,3 +305,7 @@ CefVariantCppToC::CefVariantCppToC(CefRefPtr<CefVariant> cls)
struct_.struct_.get_double_array = variant_get_double_array;
struct_.struct_.get_string_array = variant_get_string_array;
}
#ifdef _DEBUG
long CefCppToC<CefVariant, cef_variant_t>::DebugObjCt = 0;
#endif

View File

@ -19,7 +19,7 @@
class CefVariantCppToC : public CefCppToC<CefVariant, cef_variant_t>
{
public:
CefVariantCppToC(CefRefPtr<CefVariant> cls);
CefVariantCppToC(CefVariant* cls);
virtual ~CefVariantCppToC() {}
};