mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
libcef:
- 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:
@ -33,6 +33,7 @@ CefBrowserImpl::~CefBrowserImpl()
|
||||
if(webview_bitmap_ != NULL)
|
||||
DeleteObject(webview_bitmap_);
|
||||
#endif
|
||||
RemoveAllJSHandlers();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::GoBack()
|
||||
@ -111,6 +112,20 @@ void CefBrowserImpl::SelectAll(TargetFrame targetFrame)
|
||||
MENU_ID_SELECTALL, targetFrame));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::SetFocus(bool enable)
|
||||
{
|
||||
if (_Context->RunningOnUIThread())
|
||||
{
|
||||
UIT_SetFocus(UIT_GetWebViewHost(), enable);
|
||||
}
|
||||
else
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_SetFocus,
|
||||
UIT_GetWebViewHost(), enable));
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Print(TargetFrame targetFrame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
@ -279,6 +294,35 @@ bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
|
||||
return true;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
|
||||
bool popup,
|
||||
CefRefPtr<CefHandler> handler,
|
||||
const std::wstring& url)
|
||||
{
|
||||
if(!_Context.get() || !_Context->RunningOnUIThread())
|
||||
return NULL;
|
||||
|
||||
std::wstring newUrl = url;
|
||||
CefRefPtr<CefBrowser> alternateBrowser;
|
||||
|
||||
if(handler.get())
|
||||
{
|
||||
// Give the handler an opportunity to modify window attributes, handler,
|
||||
// or cancel the window creation.
|
||||
CefHandler::RetVal rv = handler->HandleBeforeCreated(NULL, windowInfo,
|
||||
popup, handler, newUrl);
|
||||
if(rv == RV_HANDLED)
|
||||
return false;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> browser(
|
||||
new CefBrowserImpl(windowInfo, popup, handler, newUrl));
|
||||
|
||||
static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser();
|
||||
|
||||
return browser;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadURL(const std::wstring& url)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
@ -321,6 +365,79 @@ void CefBrowserImpl::UIT_LoadURLForRequestRef(CefRequest* request)
|
||||
request->Release();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadURLForRequest(const std::wstring& url,
|
||||
const std::wstring& frame_name,
|
||||
const std::wstring& method,
|
||||
net::UploadData *upload_data,
|
||||
const WebRequest::HeaderMap& headers)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
if (url.empty())
|
||||
return;
|
||||
|
||||
GURL gurl(url);
|
||||
|
||||
if (!gurl.is_valid() && !gurl.has_scheme()) {
|
||||
// Try to add "http://" at the beginning
|
||||
gurl = GURL(std::wstring(L"http://") + url);
|
||||
if (!gurl.is_valid())
|
||||
return;
|
||||
}
|
||||
|
||||
nav_controller_->LoadEntry(new BrowserNavigationEntry(
|
||||
-1, gurl, std::wstring(), frame_name, method, upload_data, headers));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadHTML(const std::wstring& html,
|
||||
const std::wstring& url)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
GURL gurl(url);
|
||||
|
||||
if (!gurl.is_valid() && !gurl.has_scheme()) {
|
||||
// Try to add "http://" at the beginning
|
||||
gurl = GURL(std::wstring(L"http://") + url);
|
||||
if (!gurl.is_valid())
|
||||
return;
|
||||
}
|
||||
|
||||
UIT_GetWebView()->GetMainFrame()->LoadHTMLString(WideToUTF8(html), gurl);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefStreamReader* stream,
|
||||
const std::wstring& url)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
GURL gurl(url);
|
||||
|
||||
if (!gurl.is_valid() && !gurl.has_scheme()) {
|
||||
// Try to add "http://" at the beginning
|
||||
gurl = GURL(std::wstring(L"http://") + url);
|
||||
if (!gurl.is_valid())
|
||||
return;
|
||||
}
|
||||
|
||||
// read all of the stream data into a std::string.
|
||||
std::stringstream ss;
|
||||
char buff[BUFFER_SIZE];
|
||||
size_t read;
|
||||
do {
|
||||
read = stream->Read(buff, sizeof(char), BUFFER_SIZE-1);
|
||||
if(read > 0) {
|
||||
buff[read] = 0;
|
||||
ss << buff;
|
||||
}
|
||||
}
|
||||
while(read > 0);
|
||||
|
||||
UIT_GetWebView()->GetMainFrame()->LoadHTMLString(ss.str(), gurl);
|
||||
|
||||
stream->Release();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_ExecuteJavaScript(const std::wstring& js_code,
|
||||
const std::wstring& script_url,
|
||||
int start_line,
|
||||
@ -439,8 +556,8 @@ CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(const std::wstri
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserImpl> browser(
|
||||
new CefBrowserImpl(info, true, handler, newUrl));
|
||||
CefRefPtr<CefBrowserImpl> browser(
|
||||
new CefBrowserImpl(info, true, handler, newUrl));
|
||||
browser->UIT_CreateBrowser();
|
||||
|
||||
return browser;
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "webkit/glue/webview.h"
|
||||
|
||||
#define BUFFER_SIZE 32768
|
||||
|
||||
// Implementation of CefBrowser.
|
||||
class CefBrowserImpl : public CefThreadSafeBase<CefBrowser>
|
||||
@ -48,6 +49,7 @@ public:
|
||||
virtual void Paste(TargetFrame targetFrame);
|
||||
virtual void Delete(TargetFrame targetFrame);
|
||||
virtual void SelectAll(TargetFrame targetFrame);
|
||||
virtual void SetFocus(bool enable);
|
||||
virtual void Print(TargetFrame targetFrame);
|
||||
virtual void ViewSource(TargetFrame targetFrame);
|
||||
virtual std::wstring GetSource(TargetFrame targetFrame);
|
||||
|
@ -20,8 +20,6 @@
|
||||
#include <wininet.h>
|
||||
#include <winspool.h>
|
||||
|
||||
#define BUFFER_SIZE 32768
|
||||
|
||||
|
||||
LPCTSTR CefBrowserImpl::GetWndClass()
|
||||
{
|
||||
@ -46,6 +44,11 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
|
||||
|
||||
case WM_DESTROY:
|
||||
{
|
||||
CefRefPtr<CefHandler> handler = browser->GetHandler();
|
||||
if(handler.get()) {
|
||||
// Notify the handler that the window is about to be closed
|
||||
handler->HandleBeforeWindowClose(browser);
|
||||
}
|
||||
// Remove the browser from the list maintained by the context
|
||||
_Context->RemoveBrowser(browser);
|
||||
}
|
||||
@ -295,78 +298,6 @@ void CefBrowserImpl::UIT_CreateBrowser()
|
||||
if(url_.size() > 0)
|
||||
UIT_LoadURL(url_.c_str());
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadURLForRequest(const std::wstring& url,
|
||||
const std::wstring& frame_name,
|
||||
const std::wstring& method,
|
||||
net::UploadData *upload_data,
|
||||
const WebRequest::HeaderMap& headers)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
if (url.empty())
|
||||
return;
|
||||
|
||||
std::wstring urlString(url);
|
||||
if (PathFileExists(url.c_str()) || PathIsUNC(url.c_str())) {
|
||||
TCHAR fileURL[INTERNET_MAX_URL_LENGTH];
|
||||
DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]);
|
||||
if (SUCCEEDED(UrlCreateFromPath(url.c_str(), fileURL, &fileURLLength, 0)))
|
||||
urlString.assign(fileURL);
|
||||
}
|
||||
|
||||
nav_controller_->LoadEntry(new BrowserNavigationEntry(
|
||||
-1, GURL(urlString), std::wstring(), frame_name, method, upload_data,
|
||||
headers));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadHTML(const std::wstring& html,
|
||||
const std::wstring& url)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
std::wstring urlString(url);
|
||||
if (PathFileExists(url.c_str()) || PathIsUNC(url.c_str())) {
|
||||
TCHAR fileURL[INTERNET_MAX_URL_LENGTH];
|
||||
DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]);
|
||||
if (SUCCEEDED(UrlCreateFromPath(url.c_str(), fileURL, &fileURLLength, 0)))
|
||||
urlString.assign(fileURL);
|
||||
}
|
||||
|
||||
UIT_GetWebView()->GetMainFrame()->LoadHTMLString(
|
||||
WideToUTF8(html), GURL(urlString));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefStreamReader* stream,
|
||||
const std::wstring& url)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
std::wstring urlString(url);
|
||||
if (PathFileExists(url.c_str()) || PathIsUNC(url.c_str())) {
|
||||
TCHAR fileURL[INTERNET_MAX_URL_LENGTH];
|
||||
DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]);
|
||||
if (SUCCEEDED(UrlCreateFromPath(url.c_str(), fileURL, &fileURLLength, 0)))
|
||||
urlString.assign(fileURL);
|
||||
}
|
||||
|
||||
// read all of the stream data into a std::string.
|
||||
std::stringstream ss;
|
||||
char buff[BUFFER_SIZE];
|
||||
size_t read;
|
||||
do {
|
||||
read = stream->Read(buff, sizeof(char), BUFFER_SIZE-1);
|
||||
if(read > 0) {
|
||||
buff[read] = 0;
|
||||
ss << buff;
|
||||
}
|
||||
}
|
||||
while(read > 0);
|
||||
|
||||
UIT_GetWebView()->GetMainFrame()->LoadHTMLString(ss.str(), GURL(urlString));
|
||||
|
||||
stream->Release();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable)
|
||||
{
|
||||
|
@ -643,3 +643,11 @@ std::wstring BrowserWebViewDelegate::GetFrameDescription(WebFrame* webframe) {
|
||||
return L"frame (anonymous)";
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::TakeFocus(WebView* webview, bool reverse) {
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if(handler.get()) {
|
||||
// Notify the handler that it should take a focus
|
||||
handler->HandleTakeFocus(browser_, reverse);
|
||||
}
|
||||
}
|
||||
|
@ -203,6 +203,7 @@ class BrowserWebViewDelegate : public base::RefCounted<BrowserWebViewDelegate>,
|
||||
virtual void Release() {
|
||||
base::RefCounted<BrowserWebViewDelegate>::Release();
|
||||
}
|
||||
virtual void TakeFocus(WebView* webview, bool reverse);
|
||||
|
||||
// Additional accessors
|
||||
WebFrame* top_loading_frame() { return top_loading_frame_; }
|
||||
|
@ -273,7 +273,7 @@ bool CefContext::Initialize(bool multi_threaded_message_loop,
|
||||
Lock();
|
||||
|
||||
// We only need to initialize if the UI thread is not currently running
|
||||
if(!hthreadui_) {
|
||||
if(!idthreadui_) {
|
||||
// Only start the initialization if we're not currently in a transitional
|
||||
// state
|
||||
intransition = in_transition_;
|
||||
@ -351,6 +351,7 @@ bool CefContext::Initialize(bool multi_threaded_message_loop,
|
||||
hthreadui_ = CreateThread(
|
||||
NULL, 0, ThreadHandlerUI, this, 0, &idthreadui_);
|
||||
DCHECK(hthreadui_ != NULL);
|
||||
DCHECK(idthreadui_ != 0);
|
||||
} else {
|
||||
if (!DoInitialize()) {
|
||||
// TODO: Process initialization errors
|
||||
@ -358,6 +359,7 @@ bool CefContext::Initialize(bool multi_threaded_message_loop,
|
||||
// Create our own message loop there
|
||||
SetMessageLoopForUI(new CefMessageLoopForUI());
|
||||
idthreadui_ = GetCurrentThreadId();
|
||||
DCHECK(idthreadui_ != 0);
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
@ -390,7 +392,7 @@ void CefContext::Shutdown()
|
||||
Lock();
|
||||
|
||||
// We only need to shut down if the UI thread is currently running
|
||||
if(hthreadui_) {
|
||||
if(idthreadui_) {
|
||||
// Only start the shutdown if we're not currently in a transitional state
|
||||
intransition = in_transition_;
|
||||
if(!intransition) {
|
||||
@ -417,21 +419,24 @@ void CefContext::Shutdown()
|
||||
Unlock();
|
||||
|
||||
if(shutdown) {
|
||||
// Wait for the UI thread to exit
|
||||
WaitForSingleObject(hthreadui_, INFINITE);
|
||||
if (hthreadui_) {
|
||||
// Wait for the UI thread to exit
|
||||
WaitForSingleObject(hthreadui_, INFINITE);
|
||||
|
||||
// Clean up thread and event handles
|
||||
CloseHandle(hthreadui_);
|
||||
CloseHandle(heventui_);
|
||||
|
||||
hthreadui_ = NULL;
|
||||
heventui_ = NULL;
|
||||
}
|
||||
|
||||
Lock();
|
||||
|
||||
// Unregister the window class
|
||||
UnregisterClass(CefBrowserImpl::GetWndClass(), hinstance_);
|
||||
|
||||
// Clean up thread and event handles
|
||||
CloseHandle(hthreadui_);
|
||||
CloseHandle(heventui_);
|
||||
|
||||
hthreadui_ = NULL;
|
||||
idthreadui_ = 0;
|
||||
heventui_ = NULL;
|
||||
messageloopui_ = NULL;
|
||||
|
||||
// We have exited the transitional state
|
||||
|
@ -41,7 +41,7 @@ MSVC_POP_WARNING()
|
||||
// callbacks to.
|
||||
struct CefNPObject {
|
||||
NPObject parent; // This must be the first field in the struct.
|
||||
CefRefPtr<CefJSContainer> container;
|
||||
CefJSContainer* container;
|
||||
WebFrame* webframe;
|
||||
|
||||
//
|
||||
@ -148,11 +148,11 @@ NPClass CefNPObject::np_class_ = {
|
||||
return obj->container->SetProperty(ident, obj->webframe, value);
|
||||
}
|
||||
|
||||
CefJSContainer::CefJSContainer(CefRefPtr<CefBrowser> browser,
|
||||
CefJSContainer::CefJSContainer(CefBrowser* browser,
|
||||
CefRefPtr<CefJSHandler> handler)
|
||||
: browser_(browser), handler_(handler)
|
||||
{
|
||||
DCHECK(browser_.get() != NULL);
|
||||
DCHECK(browser_ != NULL);
|
||||
DCHECK(handler_.get() != NULL);
|
||||
}
|
||||
|
||||
@ -275,4 +275,3 @@ void CefJSContainer::BindToJavascript(WebFrame* frame,
|
||||
// so we can release it when we're destroyed.
|
||||
frame->BindToWindowObject(classname, np_obj);
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ class WebFrame;
|
||||
class CefJSContainer : public CefThreadSafeBase<CefBase>
|
||||
{
|
||||
public:
|
||||
CefJSContainer(CefRefPtr<CefBrowser> browser,
|
||||
CefJSContainer(CefBrowser* browser,
|
||||
CefRefPtr<CefJSHandler> handler);
|
||||
~CefJSContainer();
|
||||
|
||||
@ -52,7 +52,7 @@ protected:
|
||||
friend struct CefNPObject;
|
||||
|
||||
protected:
|
||||
CefRefPtr<CefBrowser> browser_;
|
||||
CefBrowser* browser_;
|
||||
CefRefPtr<CefJSHandler> handler_;
|
||||
|
||||
// A list of all NPObjects we created and bound in BindToJavascript(), so we
|
||||
|
Reference in New Issue
Block a user