mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- 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
This commit is contained in:
262
libcef_dll/cpptoc/frame_cpptoc.cc
Normal file
262
libcef_dll/cpptoc/frame_cpptoc.cc
Normal file
@ -0,0 +1,262 @@
|
||||
// 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 "cpptoc/frame_cpptoc.h"
|
||||
#include "cpptoc/request_cpptoc.h"
|
||||
#include "cpptoc/stream_cpptoc.h"
|
||||
|
||||
|
||||
void CEF_CALLBACK frame_undo(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Undo();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_redo(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Redo();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_cut(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Cut();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_copy(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Copy();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_paste(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Paste();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_delete(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Delete();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_select_all(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->SelectAll();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_print(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->Print();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_view_source(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
CefFrameCppToC::Get(frame)->ViewSource();
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK frame_get_source(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return NULL;
|
||||
|
||||
std::wstring sourceStr = CefFrameCppToC::Get(frame)->GetSource();
|
||||
if(!sourceStr.empty())
|
||||
return cef_string_alloc(sourceStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK frame_get_text(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return NULL;
|
||||
|
||||
std::wstring textStr = CefFrameCppToC::Get(frame)->GetText();
|
||||
if(!textStr.empty())
|
||||
return cef_string_alloc(textStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_load_request(cef_frame_t* frame,
|
||||
cef_request_t* request)
|
||||
{
|
||||
DCHECK(frame);
|
||||
DCHECK(request);
|
||||
if(!frame || !request)
|
||||
return;
|
||||
|
||||
CefRefPtr<CefRequest> requestPtr = CefRequestCppToC::Unwrap(request);
|
||||
CefFrameCppToC::Get(frame)->LoadRequest(requestPtr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_load_url(cef_frame_t* frame, const wchar_t* url)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
std::wstring urlStr;
|
||||
if(url)
|
||||
urlStr = url;
|
||||
CefFrameCppToC::Get(frame)->LoadURL(urlStr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_load_string(cef_frame_t* frame,
|
||||
const wchar_t* string,
|
||||
const wchar_t* url)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
std::wstring stringStr, urlStr;
|
||||
if(string)
|
||||
stringStr = string;
|
||||
if(url)
|
||||
urlStr = url;
|
||||
CefFrameCppToC::Get(frame)->LoadString(stringStr, urlStr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_load_stream(cef_frame_t* frame,
|
||||
cef_stream_reader_t* stream,
|
||||
const wchar_t* url)
|
||||
{
|
||||
DCHECK(frame);
|
||||
DCHECK(stream);
|
||||
if(!frame || !stream)
|
||||
return;
|
||||
|
||||
CefRefPtr<CefStreamReader> streamPtr = CefStreamReaderCppToC::Unwrap(stream);
|
||||
std::wstring urlStr;
|
||||
if(url)
|
||||
urlStr = url;
|
||||
|
||||
CefFrameCppToC::Get(frame)->LoadStream(streamPtr, urlStr);
|
||||
}
|
||||
|
||||
void CEF_CALLBACK frame_execute_javascript(cef_frame_t* frame,
|
||||
const wchar_t* jsCode,
|
||||
const wchar_t* scriptUrl,
|
||||
int startLine)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return;
|
||||
|
||||
std::wstring jsCodeStr, scriptUrlStr;
|
||||
if(jsCode)
|
||||
jsCodeStr = jsCode;
|
||||
if(scriptUrl)
|
||||
scriptUrlStr = scriptUrl;
|
||||
|
||||
CefFrameCppToC::Get(frame)->ExecuteJavaScript(jsCodeStr, scriptUrlStr,
|
||||
startLine);
|
||||
}
|
||||
|
||||
int CEF_CALLBACK frame_is_main(struct _cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return 0;
|
||||
|
||||
return CefFrameCppToC::Get(frame)->IsMain();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK frame_is_focused(struct _cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return 0;
|
||||
|
||||
return CefFrameCppToC::Get(frame)->IsFocused();
|
||||
}
|
||||
|
||||
|
||||
cef_string_t CEF_CALLBACK frame_get_name(struct _cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return 0;
|
||||
|
||||
std::wstring nameStr = CefFrameCppToC::Get(frame)->GetName();
|
||||
if(!nameStr.empty())
|
||||
return cef_string_alloc(nameStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cef_string_t CEF_CALLBACK frame_get_url(cef_frame_t* frame)
|
||||
{
|
||||
DCHECK(frame);
|
||||
if(!frame)
|
||||
return NULL;
|
||||
|
||||
std::wstring urlStr = CefFrameCppToC::Get(frame)->GetURL();
|
||||
if(!urlStr.empty())
|
||||
return cef_string_alloc(urlStr.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CefFrameCppToC::CefFrameCppToC(CefFrame* cls)
|
||||
: CefCppToC<CefFrameCppToC, CefFrame, cef_frame_t>(cls)
|
||||
{
|
||||
struct_.struct_.undo = frame_undo;
|
||||
struct_.struct_.redo = frame_redo;
|
||||
struct_.struct_.cut = frame_cut;
|
||||
struct_.struct_.copy = frame_copy;
|
||||
struct_.struct_.paste = frame_paste;
|
||||
struct_.struct_.del = frame_delete;
|
||||
struct_.struct_.select_all = frame_select_all;
|
||||
struct_.struct_.print = frame_print;
|
||||
struct_.struct_.view_source = frame_view_source;
|
||||
struct_.struct_.get_source = frame_get_source;
|
||||
struct_.struct_.get_text = frame_get_text;
|
||||
struct_.struct_.load_request = frame_load_request;
|
||||
struct_.struct_.load_url = frame_load_url;
|
||||
struct_.struct_.load_string = frame_load_string;
|
||||
struct_.struct_.load_stream = frame_load_stream;
|
||||
struct_.struct_.execute_javascript = frame_execute_javascript;
|
||||
struct_.struct_.is_main = frame_is_main;
|
||||
struct_.struct_.is_focused = frame_is_focused;
|
||||
struct_.struct_.get_name = frame_get_name;
|
||||
struct_.struct_.get_url = frame_get_url;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
long CefCppToC<CefFrameCppToC, CefFrame, cef_frame_t>::DebugObjCt = 0;
|
||||
#endif
|
Reference in New Issue
Block a user