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:
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
@@ -14,231 +14,60 @@
|
||||
#include "webkit/api/public/WebURL.h"
|
||||
#include "webkit/glue/webframe.h"
|
||||
|
||||
|
||||
using WebKit::WebScriptSource;
|
||||
using WebKit::WebString;
|
||||
using WebKit::WebURL;
|
||||
|
||||
|
||||
CefBrowserImpl::CefBrowserImpl(CefWindowInfo& windowInfo, bool popup,
|
||||
CefRefPtr<CefHandler> handler,
|
||||
const std::wstring& url)
|
||||
CefRefPtr<CefHandler> handler)
|
||||
: window_info_(windowInfo), is_popup_(popup), is_modal_(false),
|
||||
handler_(handler), webviewhost_(NULL), popuphost_(NULL), url_(url),
|
||||
unique_id_(0)
|
||||
handler_(handler), webviewhost_(NULL), popuphost_(NULL), unique_id_(0),
|
||||
frame_main_(NULL)
|
||||
{
|
||||
delegate_ = new BrowserWebViewDelegate(this);
|
||||
nav_controller_.reset(new BrowserNavigationController(this));
|
||||
}
|
||||
|
||||
CefBrowserImpl::~CefBrowserImpl()
|
||||
{
|
||||
RemoveAllJSHandlers();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::GoBack()
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction, MENU_ID_NAV_BACK, TF_MAIN));
|
||||
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_BACK));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::GoForward()
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_NAV_FORWARD, TF_MAIN));
|
||||
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_FORWARD));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Reload()
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_NAV_RELOAD, TF_MAIN));
|
||||
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_RELOAD));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::StopLoad()
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_NAV_STOP, TF_MAIN));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Undo(TargetFrame targetFrame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_UNDO, targetFrame));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Redo(TargetFrame targetFrame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_REDO, targetFrame));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Cut(TargetFrame targetFrame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_CUT, targetFrame));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Copy(TargetFrame targetFrame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_COPY, targetFrame));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Paste(TargetFrame targetFrame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_PASTE, targetFrame));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Delete(TargetFrame targetFrame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_DELETE, targetFrame));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::SelectAll(TargetFrame targetFrame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_SELECTALL, targetFrame));
|
||||
&CefBrowserImpl::UIT_HandleActionView, MENU_ID_NAV_STOP));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::SetFocus(bool enable)
|
||||
{
|
||||
if (_Context->RunningOnUIThread())
|
||||
{
|
||||
UIT_SetFocus(UIT_GetWebViewHost(), enable);
|
||||
UIT_SetFocus(GetWebViewHost(), enable);
|
||||
}
|
||||
else
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_SetFocus,
|
||||
UIT_GetWebViewHost(), enable));
|
||||
GetWebViewHost(), enable));
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Print(TargetFrame targetFrame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_PRINT, targetFrame));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::ViewSource(TargetFrame targetFrame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction,
|
||||
MENU_ID_VIEWSOURCE, targetFrame));
|
||||
}
|
||||
void CefBrowserImpl::LoadRequest(CefRefPtr<CefRequest> request)
|
||||
{
|
||||
DCHECK(request.get() != NULL);
|
||||
request->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_LoadURLForRequestRef, request.get()));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::LoadURL(const std::wstring& url, const std::wstring& frame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_LoadURLForFrame, url, frame));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::LoadString(const std::wstring& string,
|
||||
const std::wstring& url)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_LoadHTML, string, url));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::LoadStream(CefRefPtr<CefStreamReader> stream,
|
||||
const std::wstring& url)
|
||||
{
|
||||
DCHECK(stream.get() != NULL);
|
||||
stream->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_LoadHTMLForStreamRef, stream.get(), url));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::ExecuteJavaScript(const std::wstring& jsCode,
|
||||
const std::wstring& scriptUrl,
|
||||
int startLine,
|
||||
TargetFrame targetFrame)
|
||||
{
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_ExecuteJavaScript, jsCode, scriptUrl, startLine,
|
||||
targetFrame));
|
||||
}
|
||||
|
||||
bool CefBrowserImpl::AddJSHandler(const std::wstring& classname,
|
||||
CefRefPtr<CefJSHandler> handler)
|
||||
{
|
||||
DCHECK(handler.get());
|
||||
bool rv = false;
|
||||
|
||||
Lock();
|
||||
if(!HasJSHandler(classname)) {
|
||||
CefRefPtr<CefJSContainer> jscon(new CefJSContainer(this, handler));
|
||||
jscontainers_.insert(std::make_pair(classname, jscon));
|
||||
rv = true;
|
||||
}
|
||||
Unlock();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefBrowserImpl::HasJSHandler(const std::wstring& classname)
|
||||
{
|
||||
Lock();
|
||||
bool rv = (jscontainers_.find(classname) != jscontainers_.end());
|
||||
Unlock();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
CefRefPtr<CefJSHandler> CefBrowserImpl::GetJSHandler(const std::wstring& classname)
|
||||
{
|
||||
CefRefPtr<CefJSHandler> handler;
|
||||
|
||||
Lock();
|
||||
JSContainerMap::const_iterator it = jscontainers_.find(classname);
|
||||
if(it != jscontainers_.end())
|
||||
handler = it->second->GetHandler();
|
||||
Unlock();
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
bool CefBrowserImpl::RemoveJSHandler(const std::wstring& classname)
|
||||
{
|
||||
bool rv = false;
|
||||
|
||||
Lock();
|
||||
JSContainerMap::iterator it = jscontainers_.find(classname);
|
||||
if(it != jscontainers_.end()) {
|
||||
jscontainers_.erase(it);
|
||||
rv = true;
|
||||
}
|
||||
Unlock();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::RemoveAllJSHandlers()
|
||||
{
|
||||
Lock();
|
||||
jscontainers_.clear();
|
||||
Unlock();
|
||||
}
|
||||
|
||||
bool CefBrowserImpl::IsPopup()
|
||||
{
|
||||
Lock();
|
||||
@@ -252,21 +81,211 @@ CefRefPtr<CefHandler> CefBrowserImpl::GetHandler()
|
||||
return handler_;
|
||||
}
|
||||
|
||||
std::wstring CefBrowserImpl::GetURL()
|
||||
CefRefPtr<CefFrame> CefBrowserImpl::GetMainFrame()
|
||||
{
|
||||
Lock();
|
||||
std::wstring url = url_;
|
||||
Unlock();
|
||||
return url;
|
||||
return GetCefFrame(GetWebView()->GetMainFrame());
|
||||
}
|
||||
|
||||
void CefBrowserImpl::SetURL(const std::wstring& url)
|
||||
CefRefPtr<CefFrame> CefBrowserImpl::GetFocusedFrame()
|
||||
{
|
||||
return GetCefFrame(GetWebView()->GetFocusedFrame());
|
||||
}
|
||||
|
||||
CefRefPtr<CefFrame> CefBrowserImpl::GetFrame(const std::wstring& name)
|
||||
{
|
||||
WebFrame* frame = GetWebView()->GetFrameWithName(name);
|
||||
if(frame)
|
||||
return GetCefFrame(frame);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::GetFrameNames(std::vector<std::wstring>& names)
|
||||
{
|
||||
WebView* view = GetWebView();
|
||||
WebFrame* main_frame = view->GetMainFrame();
|
||||
WebFrame* it = main_frame;
|
||||
do {
|
||||
if(it != main_frame)
|
||||
names.push_back(it->GetName());
|
||||
it = view->GetNextFrameAfter(it, true);
|
||||
} while (it != main_frame);
|
||||
}
|
||||
|
||||
CefRefPtr<CefFrame> CefBrowserImpl::GetCefFrame(WebFrame* frame)
|
||||
{
|
||||
CefRefPtr<CefFrame> cef_frame;
|
||||
Lock();
|
||||
|
||||
WebView *view = GetWebView();
|
||||
if(view) {
|
||||
if(frame == view->GetMainFrame()) {
|
||||
// Use or create the single main frame reference.
|
||||
if(frame_main_ == NULL)
|
||||
frame_main_ = new CefFrameImpl(this, std::wstring());
|
||||
cef_frame = frame_main_;
|
||||
} else {
|
||||
// Locate or create the appropriate named reference.
|
||||
std::wstring name = frame->GetName();
|
||||
DCHECK(!name.empty());
|
||||
FrameMap::const_iterator it = frames_.find(name);
|
||||
if(it != frames_.end())
|
||||
cef_frame = it->second;
|
||||
else {
|
||||
cef_frame = new CefFrameImpl(this, name);
|
||||
frames_.insert(std::make_pair(name, cef_frame.get()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Unlock();
|
||||
return cef_frame;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::RemoveCefFrame(const std::wstring& name)
|
||||
{
|
||||
Lock();
|
||||
url_ = url;
|
||||
|
||||
if(name.empty())
|
||||
frame_main_ = NULL;
|
||||
else {
|
||||
FrameMap::iterator it = frames_.find(name);
|
||||
if(it != frames_.end())
|
||||
frames_.erase(it);
|
||||
}
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
WebFrame* CefBrowserImpl::GetWebFrame(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
std::wstring name = frame->GetName();
|
||||
if(name.empty())
|
||||
return GetWebView()->GetMainFrame();
|
||||
return GetWebView()->GetFrameWithName(name);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Undo(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction, MENU_ID_UNDO, frame.get()));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Redo(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction, MENU_ID_REDO, frame.get()));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Cut(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction, MENU_ID_CUT, frame.get()));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Copy(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction, MENU_ID_COPY, frame.get()));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Paste(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction, MENU_ID_PASTE, frame.get()));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::Delete(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction, MENU_ID_DELETE, frame.get()));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::SelectAll(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction, MENU_ID_SELECTALL, frame.get()));
|
||||
}
|
||||
|
||||
|
||||
void CefBrowserImpl::Print(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction, MENU_ID_PRINT, frame.get()));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::ViewSource(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_HandleAction, MENU_ID_VIEWSOURCE, frame.get()));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::LoadRequest(CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request)
|
||||
{
|
||||
DCHECK(request.get() != NULL);
|
||||
frame->AddRef();
|
||||
request->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_LoadURLForRequestRef, frame.get(), request.get()));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::LoadURL(CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& url)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_LoadURL, frame.get(), url));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::LoadString(CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& string,
|
||||
const std::wstring& url)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_LoadHTML, frame.get(), string, url));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::LoadStream(CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefStreamReader> stream,
|
||||
const std::wstring& url)
|
||||
{
|
||||
DCHECK(stream.get() != NULL);
|
||||
frame->AddRef();
|
||||
stream->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_LoadHTMLForStreamRef, frame.get(), stream.get(),
|
||||
url));
|
||||
}
|
||||
|
||||
void CefBrowserImpl::ExecuteJavaScript(CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& jsCode,
|
||||
const std::wstring& scriptUrl,
|
||||
int startLine)
|
||||
{
|
||||
frame->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_ExecuteJavaScript, frame.get(), jsCode, scriptUrl,
|
||||
startLine));
|
||||
}
|
||||
|
||||
std::wstring CefBrowserImpl::GetURL(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
WebFrame* web_frame = GetWebFrame(frame);
|
||||
if(web_frame)
|
||||
return UTF8ToWide(web_frame->GetURL().spec());
|
||||
return std::wstring();
|
||||
}
|
||||
|
||||
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
|
||||
CefRefPtr<CefHandler> handler,
|
||||
const std::wstring& url)
|
||||
@@ -287,9 +306,9 @@ bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserImpl> browser(
|
||||
new CefBrowserImpl(windowInfo, popup, handler, newUrl));
|
||||
new CefBrowserImpl(windowInfo, popup, handler));
|
||||
PostTask(FROM_HERE, NewRunnableMethod(browser.get(),
|
||||
&CefBrowserImpl::UIT_CreateBrowser));
|
||||
&CefBrowserImpl::UIT_CreateBrowser, newUrl));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -314,35 +333,23 @@ CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
|
||||
return false;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> browser(
|
||||
new CefBrowserImpl(windowInfo, popup, handler, newUrl));
|
||||
|
||||
static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser();
|
||||
CefRefPtr<CefBrowser> browser(new CefBrowserImpl(windowInfo, popup, handler));
|
||||
static_cast<CefBrowserImpl*>(browser.get())->UIT_CreateBrowser(newUrl);
|
||||
|
||||
return browser;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadURL(const std::wstring& url)
|
||||
void CefBrowserImpl::UIT_LoadURL(CefFrame* frame,
|
||||
const std::wstring& url)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
UIT_LoadURLForRequest(url, std::wstring(), std::wstring(), NULL,
|
||||
UIT_LoadURLForRequest(frame, url, std::wstring(), NULL,
|
||||
WebRequest::HeaderMap());
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadURLForFrame(const std::wstring& url,
|
||||
const std::wstring& frame_name)
|
||||
void CefBrowserImpl::UIT_LoadURLForRequestRef(CefFrame* frame,
|
||||
CefRequest* request)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
UIT_LoadURLForRequest(url, frame_name, std::wstring(), NULL,
|
||||
WebRequest::HeaderMap());
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadURLForRequestRef(CefRequest* request)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
std::wstring url = request->GetURL();
|
||||
std::wstring frame_name = request->GetFrame();
|
||||
std::wstring method = request->GetMethod();
|
||||
|
||||
CefRequestImpl *impl = static_cast<CefRequestImpl*>(request);
|
||||
@@ -358,14 +365,13 @@ void CefBrowserImpl::UIT_LoadURLForRequestRef(CefRequest* request)
|
||||
WebRequest::HeaderMap headers;
|
||||
impl->GetHeaderMap(headers);
|
||||
|
||||
UIT_LoadURLForRequest(url, frame_name, method, upload_data.get(),
|
||||
headers);
|
||||
UIT_LoadURLForRequest(frame, url, method, upload_data.get(), headers);
|
||||
|
||||
request->Release();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadURLForRequest(const std::wstring& url,
|
||||
const std::wstring& frame_name,
|
||||
void CefBrowserImpl::UIT_LoadURLForRequest(CefFrame* frame,
|
||||
const std::wstring& url,
|
||||
const std::wstring& method,
|
||||
net::UploadData *upload_data,
|
||||
const WebRequest::HeaderMap& headers)
|
||||
@@ -384,11 +390,15 @@ void CefBrowserImpl::UIT_LoadURLForRequest(const std::wstring& url,
|
||||
return;
|
||||
}
|
||||
|
||||
nav_controller_->LoadEntry(new BrowserNavigationEntry(
|
||||
-1, gurl, std::wstring(), frame_name, method, upload_data, headers));
|
||||
nav_controller_->LoadEntry(
|
||||
new BrowserNavigationEntry(-1, gurl, std::wstring(), frame->GetName(),
|
||||
method, upload_data, headers));
|
||||
|
||||
frame->Release();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadHTML(const std::wstring& html,
|
||||
void CefBrowserImpl::UIT_LoadHTML(CefFrame* frame,
|
||||
const std::wstring& html,
|
||||
const std::wstring& url)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
@@ -402,10 +412,15 @@ void CefBrowserImpl::UIT_LoadHTML(const std::wstring& html,
|
||||
return;
|
||||
}
|
||||
|
||||
UIT_GetWebView()->GetMainFrame()->LoadHTMLString(WideToUTF8(html), gurl);
|
||||
WebFrame* web_frame = GetWebFrame(frame);
|
||||
if(web_frame)
|
||||
web_frame->LoadHTMLString(WideToUTF8(html), gurl);
|
||||
|
||||
frame->Release();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefStreamReader* stream,
|
||||
void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefFrame* frame,
|
||||
CefStreamReader* stream,
|
||||
const std::wstring& url)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
@@ -432,27 +447,29 @@ void CefBrowserImpl::UIT_LoadHTMLForStreamRef(CefStreamReader* stream,
|
||||
}
|
||||
while(read > 0);
|
||||
|
||||
UIT_GetWebView()->GetMainFrame()->LoadHTMLString(ss.str(), gurl);
|
||||
WebFrame* web_frame = GetWebFrame(frame);
|
||||
if(web_frame)
|
||||
web_frame->LoadHTMLString(ss.str(), gurl);
|
||||
|
||||
stream->Release();
|
||||
frame->Release();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_ExecuteJavaScript(const std::wstring& js_code,
|
||||
void CefBrowserImpl::UIT_ExecuteJavaScript(CefFrame* frame,
|
||||
const std::wstring& js_code,
|
||||
const std::wstring& script_url,
|
||||
int start_line,
|
||||
TargetFrame targetFrame)
|
||||
int start_line)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
WebFrame* frame;
|
||||
if(targetFrame == TF_FOCUSED)
|
||||
frame = UIT_GetWebView()->GetFocusedFrame();
|
||||
else
|
||||
frame = UIT_GetWebView()->GetMainFrame();
|
||||
WebFrame* web_frame = GetWebFrame(frame);
|
||||
if(web_frame) {
|
||||
web_frame->ExecuteScript(
|
||||
WebScriptSource(WebString(js_code), WebURL(GURL(script_url)),
|
||||
start_line));
|
||||
}
|
||||
|
||||
frame->ExecuteScript(
|
||||
WebScriptSource(WebString(js_code), WebURL(GURL(script_url)),
|
||||
start_line));
|
||||
frame->Release();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_GoBackOrForward(int offset)
|
||||
@@ -509,9 +526,9 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
|
||||
}
|
||||
|
||||
// Get the right target frame for the entry.
|
||||
WebFrame* frame = UIT_GetWebView()->GetMainFrame();
|
||||
WebFrame* frame = GetWebView()->GetMainFrame();
|
||||
if (!entry.GetTargetFrame().empty())
|
||||
frame = UIT_GetWebView()->GetFrameWithName(entry.GetTargetFrame());
|
||||
frame = GetWebView()->GetFrameWithName(entry.GetTargetFrame());
|
||||
// TODO(mpcomplete): should we clear the target frame, or should
|
||||
// back/forward navigations maintain the target frame?
|
||||
|
||||
@@ -521,23 +538,12 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
|
||||
// iframe would keep focus when the SetFocus called immediately after
|
||||
// LoadRequest, thus making some tests fail (see http://b/issue?id=845337
|
||||
// for more details).
|
||||
UIT_GetWebView()->SetFocusedFrame(frame);
|
||||
UIT_SetFocus(UIT_GetWebViewHost(), true);
|
||||
GetWebView()->SetFocusedFrame(frame);
|
||||
UIT_SetFocus(GetWebViewHost(), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_BindJSObjectsToWindow(WebFrame* frame)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
Lock();
|
||||
JSContainerMap::const_iterator it = jscontainers_.begin();
|
||||
for(; it != jscontainers_.end(); ++it)
|
||||
it->second->BindToJavascript(frame, it->first);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(const std::wstring& url)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
@@ -557,9 +563,8 @@ CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(const std::wstri
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowserImpl> browser(
|
||||
new CefBrowserImpl(info, true, handler, newUrl));
|
||||
browser->UIT_CreateBrowser();
|
||||
CefRefPtr<CefBrowserImpl> browser(new CefBrowserImpl(info, true, handler));
|
||||
browser->UIT_CreateBrowser(newUrl);
|
||||
|
||||
return browser;
|
||||
}
|
||||
@@ -571,16 +576,19 @@ void CefBrowserImpl::UIT_Show(WebView* webview,
|
||||
delegate_->Show(webview, disposition);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_HandleActionView(CefHandler::MenuId menuId)
|
||||
{
|
||||
return UIT_HandleAction(menuId, NULL);
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId,
|
||||
TargetFrame target)
|
||||
CefFrame* frame)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
WebFrame* frame;
|
||||
if(target == TF_FOCUSED)
|
||||
frame = UIT_GetWebView()->GetFocusedFrame();
|
||||
else
|
||||
frame = UIT_GetWebView()->GetMainFrame();
|
||||
|
||||
WebFrame* web_frame = NULL;
|
||||
if(frame)
|
||||
web_frame = GetWebFrame(frame);
|
||||
|
||||
switch(menuId)
|
||||
{
|
||||
@@ -594,34 +602,46 @@ void CefBrowserImpl::UIT_HandleAction(CefHandler::MenuId menuId,
|
||||
UIT_Reload();
|
||||
break;
|
||||
case MENU_ID_NAV_STOP:
|
||||
UIT_GetWebView()->StopLoading();
|
||||
GetWebView()->StopLoading();
|
||||
break;
|
||||
case MENU_ID_UNDO:
|
||||
frame->Undo();
|
||||
if(web_frame)
|
||||
web_frame->Undo();
|
||||
break;
|
||||
case MENU_ID_REDO:
|
||||
frame->Redo();
|
||||
if(web_frame)
|
||||
web_frame->Redo();
|
||||
break;
|
||||
case MENU_ID_CUT:
|
||||
frame->Cut();
|
||||
if(web_frame)
|
||||
web_frame->Cut();
|
||||
break;
|
||||
case MENU_ID_COPY:
|
||||
frame->Copy();
|
||||
if(web_frame)
|
||||
web_frame->Copy();
|
||||
break;
|
||||
case MENU_ID_PASTE:
|
||||
frame->Paste();
|
||||
if(web_frame)
|
||||
web_frame->Paste();
|
||||
break;
|
||||
case MENU_ID_DELETE:
|
||||
frame->Delete();
|
||||
if(web_frame)
|
||||
web_frame->Delete();
|
||||
break;
|
||||
case MENU_ID_SELECTALL:
|
||||
frame->SelectAll();
|
||||
if(web_frame)
|
||||
web_frame->SelectAll();
|
||||
break;
|
||||
case MENU_ID_PRINT:
|
||||
UIT_PrintPages(frame);
|
||||
if(web_frame)
|
||||
UIT_PrintPages(web_frame);
|
||||
break;
|
||||
case MENU_ID_VIEWSOURCE:
|
||||
UIT_ViewDocumentString(frame);
|
||||
if(web_frame)
|
||||
UIT_ViewDocumentString(web_frame);
|
||||
break;
|
||||
}
|
||||
|
||||
if(frame)
|
||||
frame->Release();
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
@@ -6,8 +6,7 @@
|
||||
#ifndef _BROWSER_IMPL_H
|
||||
#define _BROWSER_IMPL_H
|
||||
|
||||
#include "../include/cef.h"
|
||||
#include "jscontainer.h"
|
||||
#include "include/cef.h"
|
||||
#include "context.h"
|
||||
|
||||
#include "webview_host.h"
|
||||
@@ -21,13 +20,14 @@
|
||||
|
||||
#define BUFFER_SIZE 32768
|
||||
|
||||
|
||||
// Implementation of CefBrowser.
|
||||
class CefBrowserImpl : public CefThreadSafeBase<CefBrowser>
|
||||
{
|
||||
public:
|
||||
CefBrowserImpl(CefWindowInfo& windowInfo, bool popup,
|
||||
CefRefPtr<CefHandler> handler, const std::wstring& url);
|
||||
virtual ~CefBrowserImpl();
|
||||
CefRefPtr<CefHandler> handler);
|
||||
virtual ~CefBrowserImpl() {}
|
||||
|
||||
#if defined(OS_WIN)
|
||||
static LPCTSTR GetWndClass();
|
||||
@@ -42,72 +42,81 @@ public:
|
||||
virtual void GoForward();
|
||||
virtual void Reload();
|
||||
virtual void StopLoad();
|
||||
virtual void Undo(TargetFrame targetFrame);
|
||||
virtual void Redo(TargetFrame targetFrame);
|
||||
virtual void Cut(TargetFrame targetFrame);
|
||||
virtual void Copy(TargetFrame targetFrame);
|
||||
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);
|
||||
virtual std::wstring GetText(TargetFrame targetFrame);
|
||||
virtual void LoadRequest(CefRefPtr<CefRequest> request);
|
||||
virtual void LoadURL(const std::wstring& url, const std::wstring& frame);
|
||||
virtual void LoadString(const std::wstring& string,
|
||||
const std::wstring& url);
|
||||
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
|
||||
const std::wstring& url);
|
||||
virtual void ExecuteJavaScript(const std::wstring& jsCode,
|
||||
const std::wstring& scriptUrl,
|
||||
int startLine, TargetFrame targetFrame);
|
||||
virtual bool AddJSHandler(const std::wstring& classname,
|
||||
CefRefPtr<CefJSHandler> handler);
|
||||
virtual bool HasJSHandler(const std::wstring& classname);
|
||||
virtual CefRefPtr<CefJSHandler> GetJSHandler(const std::wstring& classname);
|
||||
virtual bool RemoveJSHandler(const std::wstring& classname);
|
||||
virtual void RemoveAllJSHandlers();
|
||||
virtual CefWindowHandle GetWindowHandle();
|
||||
virtual bool IsPopup();
|
||||
virtual CefRefPtr<CefHandler> GetHandler();
|
||||
virtual std::wstring GetURL();
|
||||
virtual CefRefPtr<CefFrame> GetMainFrame();
|
||||
virtual CefRefPtr<CefFrame> GetFocusedFrame();
|
||||
virtual CefRefPtr<CefFrame> GetFrame(const std::wstring& name);
|
||||
virtual void GetFrameNames(std::vector<std::wstring>& names);
|
||||
|
||||
void SetURL(const std::wstring& url);
|
||||
// CefFrames are light-weight objects managed by the browser and loosely
|
||||
// coupled to a WebFrame object by name. If a CefFrame object does not
|
||||
// already exist for the specified WebFrame one will be created. There is no
|
||||
// guarantee that the same CefFrame object will be returned across different
|
||||
// calls to this function.
|
||||
CefRefPtr<CefFrame> GetCefFrame(WebFrame* frame);
|
||||
void RemoveCefFrame(const std::wstring& name);
|
||||
|
||||
// Return the WebFrame object associated with the specified CefFrame. This
|
||||
// may return NULL if no WebFrame with the CefFrame's name exists.
|
||||
WebFrame* GetWebFrame(CefRefPtr<CefFrame> frame);
|
||||
|
||||
// Frame-related methods
|
||||
void Undo(CefRefPtr<CefFrame> frame);
|
||||
void Redo(CefRefPtr<CefFrame> frame);
|
||||
void Cut(CefRefPtr<CefFrame> frame);
|
||||
void Copy(CefRefPtr<CefFrame> frame);
|
||||
void Paste(CefRefPtr<CefFrame> frame);
|
||||
void Delete(CefRefPtr<CefFrame> frame);
|
||||
void SelectAll(CefRefPtr<CefFrame> frame);
|
||||
void Print(CefRefPtr<CefFrame> frame);
|
||||
void ViewSource(CefRefPtr<CefFrame> frame);
|
||||
std::wstring GetSource(CefRefPtr<CefFrame> frame);
|
||||
std::wstring GetText(CefRefPtr<CefFrame> frame);
|
||||
void LoadRequest(CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefRequest> request);
|
||||
void LoadURL(CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& url);
|
||||
void LoadString(CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& string,
|
||||
const std::wstring& url);
|
||||
void LoadStream(CefRefPtr<CefFrame> frame,
|
||||
CefRefPtr<CefStreamReader> stream,
|
||||
const std::wstring& url);
|
||||
void ExecuteJavaScript(CefRefPtr<CefFrame> frame,
|
||||
const std::wstring& jsCode,
|
||||
const std::wstring& scriptUrl,
|
||||
int startLine);
|
||||
virtual std::wstring GetURL(CefRefPtr<CefFrame> frame);
|
||||
|
||||
WebView* GetWebView() const {
|
||||
return webviewhost_.get() ? webviewhost_->webview() : NULL;
|
||||
}
|
||||
WebViewHost* GetWebViewHost() const {
|
||||
return webviewhost_.get();
|
||||
}
|
||||
HWND GetWebViewWndHandle() const {
|
||||
return webviewhost_->window_handle();
|
||||
}
|
||||
WebWidget* GetPopup() const {
|
||||
return popuphost_ ? popuphost_->webwidget() : NULL;
|
||||
}
|
||||
WebWidgetHost* GetPopupHost() const {
|
||||
return popuphost_;
|
||||
}
|
||||
HWND GetPopupWndHandle() const {
|
||||
return popuphost_->window_handle();
|
||||
}
|
||||
HWND GetMainWndHandle() const {
|
||||
return window_info_.m_hWnd;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// ALL UIT_* METHODS MUST ONLY BE CALLED ON THE UI THREAD //
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
WebView* UIT_GetWebView() const {
|
||||
REQUIRE_UIT();
|
||||
return webviewhost_.get() ? webviewhost_->webview() : NULL;
|
||||
}
|
||||
WebViewHost* UIT_GetWebViewHost() const {
|
||||
REQUIRE_UIT();
|
||||
return webviewhost_.get();
|
||||
}
|
||||
HWND UIT_GetWebViewWndHandle() const {
|
||||
REQUIRE_UIT();
|
||||
return webviewhost_->window_handle();
|
||||
}
|
||||
WebWidget* UIT_GetPopup() const {
|
||||
REQUIRE_UIT();
|
||||
return popuphost_ ? popuphost_->webwidget() : NULL;
|
||||
}
|
||||
WebWidgetHost* UIT_GetPopupHost() const {
|
||||
REQUIRE_UIT();
|
||||
return popuphost_;
|
||||
}
|
||||
HWND UIT_GetPopupWndHandle() const {
|
||||
REQUIRE_UIT();
|
||||
return popuphost_->window_handle();
|
||||
}
|
||||
HWND UIT_GetMainWndHandle() const {
|
||||
REQUIRE_UIT();
|
||||
return window_info_.m_hWnd;
|
||||
}
|
||||
BrowserNavigationController* UIT_GetNavigationController() {
|
||||
REQUIRE_UIT();
|
||||
return nav_controller_.get();
|
||||
@@ -134,33 +143,32 @@ public:
|
||||
return title_;
|
||||
}
|
||||
|
||||
// UIThread functions must be executed from the UI thread.
|
||||
void UIT_CreateBrowser();
|
||||
void UIT_LoadURL(const std::wstring& url);
|
||||
void UIT_LoadURLForFrame(const std::wstring& url,
|
||||
const std::wstring& frame_name);
|
||||
void UIT_LoadURLForRequest(const std::wstring& url,
|
||||
const std::wstring& frame_name,
|
||||
const std::wstring& method,
|
||||
net::UploadData *upload_data,
|
||||
const WebRequest::HeaderMap& headers);
|
||||
void UIT_LoadURLForRequestRef(CefRequest* request);
|
||||
void UIT_LoadHTML(const std::wstring& html,
|
||||
const std::wstring& url);
|
||||
void UIT_LoadHTMLForStreamRef(CefStreamReader* stream,
|
||||
const std::wstring& url);
|
||||
void UIT_ExecuteJavaScript(const std::wstring& js_code,
|
||||
void UIT_CreateBrowser(const std::wstring& url);
|
||||
|
||||
void UIT_LoadURL(CefFrame* frame,
|
||||
const std::wstring& url);
|
||||
void UIT_LoadURLForRequest(CefFrame* frame,
|
||||
const std::wstring& url,
|
||||
const std::wstring& method,
|
||||
net::UploadData *upload_data,
|
||||
const WebRequest::HeaderMap& headers);
|
||||
void UIT_LoadURLForRequestRef(CefFrame* frame,
|
||||
CefRequest* request);
|
||||
void UIT_LoadHTML(CefFrame* frame,
|
||||
const std::wstring& html,
|
||||
const std::wstring& url);
|
||||
void UIT_LoadHTMLForStreamRef(CefFrame* frame,
|
||||
CefStreamReader* stream,
|
||||
const std::wstring& url);
|
||||
void UIT_ExecuteJavaScript(CefFrame* frame,
|
||||
const std::wstring& js_code,
|
||||
const std::wstring& script_url,
|
||||
int start_line, TargetFrame targetFrame);
|
||||
int start_line);
|
||||
void UIT_GoBackOrForward(int offset);
|
||||
void UIT_Reload();
|
||||
bool UIT_Navigate(const BrowserNavigationEntry& entry, bool reload);
|
||||
void UIT_SetFocus(WebWidgetHost* host, bool enable);
|
||||
|
||||
// Called by the WebView delegate WindowObjectCleared() method, this
|
||||
// binds the C++ controller classes to window JavaScript objects.
|
||||
void UIT_BindJSObjectsToWindow(WebFrame* frame);
|
||||
|
||||
CefRefPtr<CefBrowserImpl> UIT_CreatePopupWindow(const std::wstring& url);
|
||||
WebWidget* UIT_CreatePopupWidget(WebView* webview);
|
||||
void UIT_ClosePopupWidget();
|
||||
@@ -168,16 +176,17 @@ public:
|
||||
void UIT_Show(WebView* webview, WindowOpenDisposition disposition);
|
||||
|
||||
// Handles most simple browser actions
|
||||
void UIT_HandleAction(CefHandler::MenuId menuId, TargetFrame target);
|
||||
void UIT_HandleActionView(CefHandler::MenuId menuId);
|
||||
void UIT_HandleAction(CefHandler::MenuId menuId, CefFrame* frame);
|
||||
|
||||
// Save the document HTML to a temporary file and open in the default viewing
|
||||
// application
|
||||
bool UIT_ViewDocumentString(WebFrame *frame);
|
||||
#if defined(OS_WIN)
|
||||
void UIT_GetDocumentStringNotify(TargetFrame targetFrame,
|
||||
CefStreamWriter* writer, HANDLE hEvent);
|
||||
void UIT_GetDocumentTextNotify(TargetFrame targetFrame,
|
||||
CefStreamWriter* writer, HANDLE hEvent);
|
||||
void UIT_GetDocumentStringNotify(CefFrame* frame,
|
||||
CefStreamWriter* writer, HANDLE hEvent);
|
||||
void UIT_GetDocumentTextNotify(CefFrame* frame,
|
||||
CefStreamWriter* writer, HANDLE hEvent);
|
||||
void UIT_CanGoBackNotify(bool *retVal, HANDLE hEvent);
|
||||
void UIT_CanGoForwardNotify(bool *retVal, HANDLE hEvent);
|
||||
#endif
|
||||
@@ -198,7 +207,6 @@ protected:
|
||||
CefWindowInfo window_info_;
|
||||
bool is_popup_;
|
||||
bool is_modal_;
|
||||
std::wstring url_;
|
||||
CefRefPtr<CefHandler> handler_;
|
||||
scoped_ptr<WebViewHost> webviewhost_;
|
||||
WebWidgetHost* popuphost_;
|
||||
@@ -210,11 +218,59 @@ protected:
|
||||
// Context object used to manage printing.
|
||||
printing::PrintingContext print_context_;
|
||||
|
||||
typedef std::map<std::wstring, CefRefPtr<CefJSContainer> > JSContainerMap;
|
||||
JSContainerMap jscontainers_;
|
||||
typedef std::map<std::wstring, CefFrame*> FrameMap;
|
||||
FrameMap frames_;
|
||||
CefFrame* frame_main_;
|
||||
|
||||
// Unique browser ID assigned by the context.
|
||||
int unique_id_;
|
||||
};
|
||||
|
||||
|
||||
// Implementation of CefFrame.
|
||||
class CefFrameImpl : public CefThreadSafeBase<CefFrame>
|
||||
{
|
||||
public:
|
||||
CefFrameImpl(CefBrowserImpl* browser, const std::wstring& name)
|
||||
: browser_(browser), name_(name) {}
|
||||
virtual ~CefFrameImpl() { browser_->RemoveCefFrame(name_); }
|
||||
|
||||
// CefFrame methods
|
||||
virtual void Undo() { browser_->Undo(this); }
|
||||
virtual void Redo() { browser_->Redo(this); }
|
||||
virtual void Cut() { browser_->Cut(this); }
|
||||
virtual void Copy() { browser_->Copy(this); }
|
||||
virtual void Paste() { browser_->Paste(this); }
|
||||
virtual void Delete() { browser_->Delete(this); }
|
||||
virtual void SelectAll() { browser_->SelectAll(this); }
|
||||
virtual void Print() { browser_->Print(this); }
|
||||
virtual void ViewSource() { browser_->ViewSource(this); }
|
||||
virtual std::wstring GetSource() { return browser_->GetSource(this); }
|
||||
virtual std::wstring GetText() { return browser_->GetText(this); }
|
||||
virtual void LoadRequest(CefRefPtr<CefRequest> request)
|
||||
{ return browser_->LoadRequest(this, request); }
|
||||
virtual void LoadURL(const std::wstring& url)
|
||||
{ return browser_->LoadURL(this, url); }
|
||||
virtual void LoadString(const std::wstring& string,
|
||||
const std::wstring& url)
|
||||
{ return browser_->LoadString(this, string, url); }
|
||||
virtual void LoadStream(CefRefPtr<CefStreamReader> stream,
|
||||
const std::wstring& url)
|
||||
{ return browser_->LoadStream(this, stream, url); }
|
||||
virtual void ExecuteJavaScript(const std::wstring& jsCode,
|
||||
const std::wstring& scriptUrl,
|
||||
int startLine)
|
||||
{ return browser_->ExecuteJavaScript(this, jsCode, scriptUrl, startLine); }
|
||||
virtual bool IsMain() { return name_.empty(); }
|
||||
virtual bool IsFocused()
|
||||
{ return (browser_->GetWebFrame(this) ==
|
||||
browser_->GetWebView()->GetFocusedFrame()); }
|
||||
virtual std::wstring GetName() { return name_; }
|
||||
virtual std::wstring GetURL() { return browser_->GetURL(this); }
|
||||
|
||||
private:
|
||||
CefRefPtr<CefBrowserImpl> browser_;
|
||||
std::wstring name_;
|
||||
};
|
||||
|
||||
#endif // _BROWSER_IMPL_H
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
@@ -44,7 +44,7 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
|
||||
int wmId = LOWORD(wParam);
|
||||
int wmEvent = HIWORD(wParam);
|
||||
|
||||
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -55,34 +55,42 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
|
||||
// Notify the handler that the window is about to be closed
|
||||
handler->HandleBeforeWindowClose(browser);
|
||||
}
|
||||
RevokeDragDrop(browser->UIT_GetWebViewWndHandle());
|
||||
RevokeDragDrop(browser->GetWebViewWndHandle());
|
||||
|
||||
// Call GC twice to clean up garbage.
|
||||
browser->GetWebView()->GetMainFrame()->CallJSGC();
|
||||
browser->GetWebView()->GetMainFrame()->CallJSGC();
|
||||
|
||||
// Clean up anything associated with the WebViewHost widget.
|
||||
browser->GetWebViewHost()->webwidget()->Close();
|
||||
|
||||
// Remove the browser from the list maintained by the context
|
||||
_Context->RemoveBrowser(browser);
|
||||
}
|
||||
return 0;
|
||||
|
||||
case WM_SIZE:
|
||||
if (browser && browser->UIT_GetWebView()) {
|
||||
if (browser && browser->GetWebView()) {
|
||||
// resize the web view window to the full size of the browser window
|
||||
RECT rc;
|
||||
GetClientRect(browser->UIT_GetMainWndHandle(), &rc);
|
||||
MoveWindow(browser->UIT_GetWebViewWndHandle(), 0, 0, rc.right, rc.bottom,
|
||||
GetClientRect(browser->GetMainWndHandle(), &rc);
|
||||
MoveWindow(browser->GetWebViewWndHandle(), 0, 0, rc.right, rc.bottom,
|
||||
TRUE);
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
case WM_SETFOCUS:
|
||||
if (browser && browser->UIT_GetWebView())
|
||||
browser->UIT_GetWebView()->SetFocus(true);
|
||||
return 0;
|
||||
if (browser && browser->GetWebView())
|
||||
browser->GetWebView()->SetFocus(true);
|
||||
return 0;
|
||||
|
||||
case WM_KILLFOCUS:
|
||||
if (browser && browser->UIT_GetWebView())
|
||||
browser->UIT_GetWebView()->SetFocus(false);
|
||||
return 0;
|
||||
case WM_KILLFOCUS:
|
||||
if (browser && browser->GetWebView())
|
||||
browser->GetWebView()->SetFocus(false);
|
||||
return 0;
|
||||
|
||||
case WM_ERASEBKGND:
|
||||
return 0;
|
||||
case WM_ERASEBKGND:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DefWindowProc(hwnd, message, wParam, lParam);
|
||||
@@ -96,7 +104,7 @@ CefWindowHandle CefBrowserImpl::GetWindowHandle()
|
||||
return handle;
|
||||
}
|
||||
|
||||
std::wstring CefBrowserImpl::GetSource(TargetFrame targetFrame)
|
||||
std::wstring CefBrowserImpl::GetSource(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
if(!_Context->RunningOnUIThread())
|
||||
{
|
||||
@@ -110,9 +118,10 @@ std::wstring CefBrowserImpl::GetSource(TargetFrame targetFrame)
|
||||
CefRefPtr<CefStreamWriter> stream(new CefBytesWriter(BUFFER_SIZE));
|
||||
|
||||
// Request the data from the UI thread
|
||||
frame->AddRef();
|
||||
stream->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_GetDocumentStringNotify, targetFrame, stream.get(),
|
||||
&CefBrowserImpl::UIT_GetDocumentStringNotify, frame.get(), stream.get(),
|
||||
hEvent));
|
||||
|
||||
// Wait for the UI thread callback to tell us that the data is available
|
||||
@@ -124,19 +133,15 @@ std::wstring CefBrowserImpl::GetSource(TargetFrame targetFrame)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Retrieve the frame contents directly
|
||||
WebFrame* frame;
|
||||
if(targetFrame == TF_FOCUSED)
|
||||
frame = UIT_GetWebView()->GetFocusedFrame();
|
||||
else
|
||||
frame = UIT_GetWebView()->GetMainFrame();
|
||||
|
||||
// Retrieve the document string
|
||||
return UTF8ToWide(webkit_glue::GetDocumentString(frame));
|
||||
// Retrieve the document string directly
|
||||
WebFrame* web_frame = GetWebFrame(frame);
|
||||
if(web_frame)
|
||||
return UTF8ToWide(webkit_glue::GetDocumentString(web_frame));
|
||||
return std::wstring();
|
||||
}
|
||||
}
|
||||
|
||||
std::wstring CefBrowserImpl::GetText(TargetFrame targetFrame)
|
||||
std::wstring CefBrowserImpl::GetText(CefRefPtr<CefFrame> frame)
|
||||
{
|
||||
if(!_Context->RunningOnUIThread())
|
||||
{
|
||||
@@ -150,9 +155,10 @@ std::wstring CefBrowserImpl::GetText(TargetFrame targetFrame)
|
||||
CefRefPtr<CefStreamWriter> stream(new CefBytesWriter(BUFFER_SIZE));
|
||||
|
||||
// Request the data from the UI thread
|
||||
frame->AddRef();
|
||||
stream->AddRef();
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_GetDocumentTextNotify, targetFrame, stream.get(),
|
||||
&CefBrowserImpl::UIT_GetDocumentTextNotify, frame.get(), stream.get(),
|
||||
hEvent));
|
||||
|
||||
// Wait for the UI thread callback to tell us that the data is available
|
||||
@@ -164,15 +170,11 @@ std::wstring CefBrowserImpl::GetText(TargetFrame targetFrame)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Retrieve the frame contents directly
|
||||
WebFrame* frame;
|
||||
if(targetFrame == TF_FOCUSED)
|
||||
frame = UIT_GetWebView()->GetFocusedFrame();
|
||||
else
|
||||
frame = UIT_GetWebView()->GetMainFrame();
|
||||
|
||||
// Retrieve the document string
|
||||
return webkit_glue::DumpDocumentText(frame);
|
||||
// Retrieve the document text directly
|
||||
WebFrame* web_frame = GetWebFrame(frame);
|
||||
if(web_frame)
|
||||
webkit_glue::DumpDocumentText(web_frame);
|
||||
return std::wstring();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +238,7 @@ bool CefBrowserImpl::CanGoForward()
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_CreateBrowser()
|
||||
void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
@@ -250,22 +252,22 @@ void CefBrowserImpl::UIT_CreateBrowser()
|
||||
|
||||
// Set window user data to this object for future reference from the window
|
||||
// procedure
|
||||
win_util::SetWindowUserData(window_info_.m_hWnd, this);
|
||||
win_util::SetWindowUserData(window_info_.m_hWnd, this);
|
||||
|
||||
// Add the new browser to the list maintained by the context
|
||||
_Context->AddBrowser(this);
|
||||
|
||||
// Create the webview host object
|
||||
|
||||
// Create the webview host object
|
||||
webviewhost_.reset(
|
||||
WebViewHost::Create(window_info_.m_hWnd, delegate_.get(),
|
||||
*_Context->GetWebPreferences()));
|
||||
UIT_GetWebView()->SetUseEditorDelegate(true);
|
||||
GetWebView()->SetUseEditorDelegate(true);
|
||||
delegate_->RegisterDragDrop();
|
||||
|
||||
// Size the web view window to the browser window
|
||||
RECT cr;
|
||||
GetClientRect(window_info_.m_hWnd, &cr);
|
||||
SetWindowPos(UIT_GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
|
||||
RECT cr;
|
||||
GetClientRect(window_info_.m_hWnd, &cr);
|
||||
SetWindowPos(GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
|
||||
cr.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
|
||||
|
||||
if(handler_.get()) {
|
||||
@@ -273,8 +275,11 @@ void CefBrowserImpl::UIT_CreateBrowser()
|
||||
handler_->HandleAfterCreated(this);
|
||||
}
|
||||
|
||||
if(url_.size() > 0)
|
||||
UIT_LoadURL(url_.c_str());
|
||||
if(url.size() > 0) {
|
||||
CefRefPtr<CefFrame> frame = GetMainFrame();
|
||||
frame->AddRef();
|
||||
UIT_LoadURL(frame, url.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable)
|
||||
@@ -293,7 +298,7 @@ WebWidget* CefBrowserImpl::UIT_CreatePopupWidget(WebView* webview)
|
||||
|
||||
DCHECK(!popuphost_);
|
||||
popuphost_ = WebWidgetHost::Create(NULL, delegate_.get());
|
||||
ShowWindow(UIT_GetPopupWndHandle(), SW_SHOW);
|
||||
ShowWindow(GetPopupWndHandle(), SW_SHOW);
|
||||
|
||||
return popuphost_->webwidget();
|
||||
}
|
||||
@@ -302,7 +307,7 @@ void CefBrowserImpl::UIT_ClosePopupWidget()
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
PostMessage(UIT_GetPopupWndHandle(), WM_CLOSE, 0, 0);
|
||||
PostMessage(GetPopupWndHandle(), WM_CLOSE, 0, 0);
|
||||
popuphost_ = NULL;
|
||||
}
|
||||
|
||||
@@ -345,7 +350,7 @@ bool CefBrowserImpl::UIT_ViewDocumentString(WebFrame *frame)
|
||||
wcscpy(szTempName + len - 3, L"txt");
|
||||
WriteTextToFile(webkit_glue::GetDocumentString(frame), szTempName);
|
||||
|
||||
int errorCode = (int)ShellExecute(UIT_GetMainWndHandle(), L"open", szTempName,
|
||||
int errorCode = (int)ShellExecute(GetMainWndHandle(), L"open", szTempName,
|
||||
NULL, NULL, SW_SHOWNORMAL);
|
||||
if(errorCode <= 32)
|
||||
return false;
|
||||
@@ -353,51 +358,47 @@ bool CefBrowserImpl::UIT_ViewDocumentString(WebFrame *frame)
|
||||
return true;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_GetDocumentStringNotify(TargetFrame targetFrame,
|
||||
void CefBrowserImpl::UIT_GetDocumentStringNotify(CefFrame* frame,
|
||||
CefStreamWriter* writer,
|
||||
HANDLE hEvent)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
WebFrame* frame;
|
||||
if(targetFrame == TF_FOCUSED)
|
||||
frame = UIT_GetWebView()->GetFocusedFrame();
|
||||
else
|
||||
frame = UIT_GetWebView()->GetMainFrame();
|
||||
|
||||
// Retrieve the document string
|
||||
std::string str = webkit_glue::GetDocumentString(frame);
|
||||
// Write the document string to the stream
|
||||
writer->Write(str.c_str(), str.size(), 1);
|
||||
WebFrame* web_frame = GetWebFrame(frame);
|
||||
if(web_frame) {
|
||||
// Retrieve the document string
|
||||
std::string str = webkit_glue::GetDocumentString(web_frame);
|
||||
// Write the document string to the stream
|
||||
writer->Write(str.c_str(), str.size(), 1);
|
||||
}
|
||||
|
||||
// Notify the calling thread that the data is now available
|
||||
SetEvent(hEvent);
|
||||
|
||||
writer->Release();
|
||||
frame->Release();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_GetDocumentTextNotify(TargetFrame targetFrame,
|
||||
void CefBrowserImpl::UIT_GetDocumentTextNotify(CefFrame* frame,
|
||||
CefStreamWriter* writer,
|
||||
HANDLE hEvent)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
WebFrame* frame;
|
||||
if(targetFrame == TF_FOCUSED)
|
||||
frame = UIT_GetWebView()->GetFocusedFrame();
|
||||
else
|
||||
frame = UIT_GetWebView()->GetMainFrame();
|
||||
|
||||
// Retrieve the document string
|
||||
std::wstring str = webkit_glue::DumpDocumentText(frame);
|
||||
std::string cstr = WideToUTF8(str);
|
||||
// Write the document string to the stream
|
||||
writer->Write(cstr.c_str(), cstr.size(), 1);
|
||||
WebFrame* web_frame = GetWebFrame(frame);
|
||||
if(web_frame) {
|
||||
// Retrieve the document string
|
||||
std::wstring str = webkit_glue::DumpDocumentText(web_frame);
|
||||
std::string cstr = WideToUTF8(str);
|
||||
// Write the document string to the stream
|
||||
writer->Write(cstr.c_str(), cstr.size(), 1);
|
||||
}
|
||||
|
||||
// Notify the calling thread that the data is now available
|
||||
SetEvent(hEvent);
|
||||
|
||||
writer->Release();
|
||||
frame->Release();
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_CanGoBackNotify(bool *retVal, HANDLE hEvent)
|
||||
@@ -500,9 +501,9 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
|
||||
std::wstring bottomLeft, bottomCenter, bottomRight;
|
||||
|
||||
// allow the handler to format print header and/or footer
|
||||
CefHandler::RetVal rv = handler_->HandlePrintHeaderFooter(this, printInfo,
|
||||
url, title, page_number+1, total_pages, topLeft, topCenter, topRight,
|
||||
bottomLeft, bottomCenter, bottomRight);
|
||||
CefHandler::RetVal rv = handler_->HandlePrintHeaderFooter(this,
|
||||
GetCefFrame(frame), printInfo, url, title, page_number+1, total_pages,
|
||||
topLeft, topCenter, topRight, bottomLeft, bottomCenter, bottomRight);
|
||||
|
||||
if(rv != RV_HANDLED) {
|
||||
// Draw handler-defined headers and/or footers.
|
||||
@@ -548,14 +549,14 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
|
||||
DT_RIGHT | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS
|
||||
| DT_EXPANDTABS | DT_NOPREFIX);
|
||||
}
|
||||
|
||||
SetTextColor(hDC, hOldColor);
|
||||
SelectObject(hDC, hOldFont);
|
||||
DeleteObject(hFont);
|
||||
SetBkMode(hDC, hOldBkMode);
|
||||
}
|
||||
|
||||
res = RestoreDC(hDC, saved_state);
|
||||
SetTextColor(hDC, hOldColor);
|
||||
SelectObject(hDC, hOldFont);
|
||||
DeleteObject(hFont);
|
||||
SetBkMode(hDC, hOldBkMode);
|
||||
}
|
||||
|
||||
res = RestoreDC(hDC, saved_state);
|
||||
DCHECK_NE(res, 0);
|
||||
}
|
||||
|
||||
@@ -563,20 +564,20 @@ void CefBrowserImpl::UIT_PrintPage(int page_number, int total_pages,
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_PrintPages(WebFrame* frame) {
|
||||
|
||||
REQUIRE_UIT();
|
||||
|
||||
|
||||
REQUIRE_UIT();
|
||||
|
||||
TCHAR printername[512];
|
||||
DWORD size = sizeof(printername)-1;
|
||||
if(GetDefaultPrinter(printername, &size)) {
|
||||
printing::PrintSettings settings;
|
||||
settings.set_device_name(printername);
|
||||
// Initialize it.
|
||||
print_context_.InitWithSettings(settings);
|
||||
}
|
||||
DWORD size = sizeof(printername)-1;
|
||||
if(GetDefaultPrinter(printername, &size)) {
|
||||
printing::PrintSettings settings;
|
||||
settings.set_device_name(printername);
|
||||
// Initialize it.
|
||||
print_context_.InitWithSettings(settings);
|
||||
}
|
||||
|
||||
if(print_context_.AskUserForSettings(
|
||||
UIT_GetMainWndHandle(), UIT_GetPagesCount(frame))
|
||||
GetMainWndHandle(), UIT_GetPagesCount(frame))
|
||||
!= printing::PrintingContext::OK)
|
||||
return;
|
||||
|
||||
@@ -605,20 +606,20 @@ void CefBrowserImpl::UIT_PrintPages(WebFrame* frame) {
|
||||
MessageLoop::current()->SetNestableTasksAllowed(false);
|
||||
|
||||
// TODO(cef): Use the page title as the document name
|
||||
print_context_.NewDocument(L"New Document");
|
||||
if(settings.ranges.size() > 0) {
|
||||
for (unsigned x = 0; x < settings.ranges.size(); ++x) {
|
||||
const printing::PageRange& range = settings.ranges[x];
|
||||
for(int i = range.from; i <= range.to; ++i)
|
||||
UIT_PrintPage(i, page_count, canvas_size, frame);
|
||||
}
|
||||
} else {
|
||||
for(int i = 0; i < page_count; ++i)
|
||||
UIT_PrintPage(i, page_count, canvas_size, frame);
|
||||
}
|
||||
print_context_.DocumentDone();
|
||||
print_context_.NewDocument(L"New Document");
|
||||
if(settings.ranges.size() > 0) {
|
||||
for (unsigned x = 0; x < settings.ranges.size(); ++x) {
|
||||
const printing::PageRange& range = settings.ranges[x];
|
||||
for(int i = range.from; i <= range.to; ++i)
|
||||
UIT_PrintPage(i, page_count, canvas_size, frame);
|
||||
}
|
||||
} else {
|
||||
for(int i = 0; i < page_count; ++i)
|
||||
UIT_PrintPage(i, page_count, canvas_size, frame);
|
||||
}
|
||||
print_context_.DocumentDone();
|
||||
|
||||
MessageLoop::current()->SetNestableTasksAllowed(old_state);
|
||||
MessageLoop::current()->SetNestableTasksAllowed(old_state);
|
||||
}
|
||||
|
||||
frame->EndPrint();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
@@ -50,8 +50,6 @@ class BrowserNavigationEntry {
|
||||
const std::wstring& method,
|
||||
net::UploadData *upload,
|
||||
const WebRequest::HeaderMap& headers);
|
||||
|
||||
// Virtual to allow test_shell to extend the class.
|
||||
~BrowserNavigationEntry();
|
||||
|
||||
// Set / Get the URI
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
@@ -10,9 +10,11 @@
|
||||
|
||||
#include "config.h"
|
||||
MSVC_PUSH_WARNING_LEVEL(0);
|
||||
#include "Frame.h"
|
||||
#include "Markup.h"
|
||||
#include "TextEncoding.h"
|
||||
#include "webkit/glue/webframe_impl.h"
|
||||
#include "webkit/port/bindings/v8/v8_proxy.h"
|
||||
MSVC_POP_WARNING();
|
||||
|
||||
#include "browser_webkit_glue.h"
|
||||
@@ -190,4 +192,11 @@ void InitializeTextEncoding() {
|
||||
WebCore::UTF8Encoding();
|
||||
}
|
||||
|
||||
v8::Handle<v8::Context> GetV8Context(WebFrame* frame)
|
||||
{
|
||||
WebFrameImpl* webFrameImpl = static_cast<WebFrameImpl*>(frame);
|
||||
WebCore::Frame* core_frame = webFrameImpl->frame();
|
||||
return WebCore::V8Proxy::GetContext(core_frame);
|
||||
}
|
||||
|
||||
} // namespace webkit_glue
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors. All rights
|
||||
// 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.
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "base/string_piece.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
class WebFrame;
|
||||
class WebView;
|
||||
@@ -32,4 +33,7 @@ void InitializeTextEncoding();
|
||||
// This is called indirectly by the network layer to access resources.
|
||||
StringPiece NetResourceProvider(int key);
|
||||
|
||||
// Retrieve the V8 context associated with the frame.
|
||||
v8::Handle<v8::Context> GetV8Context(WebFrame* frame);
|
||||
|
||||
} // namespace webkit_glue
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "browser_navigation_controller.h"
|
||||
#include "context.h"
|
||||
#include "request_impl.h"
|
||||
#include "v8_impl.h"
|
||||
|
||||
#include "base/file_util.h"
|
||||
#include "base/gfx/gdi_util.h"
|
||||
@@ -38,7 +39,8 @@
|
||||
#include "webkit/glue/plugins/plugin_list.h"
|
||||
#include "webkit/glue/plugins/webplugin_delegate_impl.h"
|
||||
#include "webkit/glue/window_open_disposition.h"
|
||||
|
||||
#include "browser_webkit_glue.h"
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// TODO(port): make these files work everywhere.
|
||||
#include "browser_drag_delegate.h"
|
||||
@@ -66,7 +68,7 @@ WebView* BrowserWebViewDelegate::CreateWebView(WebView* webview,
|
||||
const GURL& creator_url) {
|
||||
CefRefPtr<CefBrowserImpl> browser =
|
||||
browser_->UIT_CreatePopupWindow(std::wstring());
|
||||
return browser.get() ? browser->UIT_GetWebView() : NULL;
|
||||
return browser.get() ? browser->GetWebView() : NULL;
|
||||
}
|
||||
|
||||
WebWidget* BrowserWebViewDelegate::CreatePopupWidget(WebView* webview,
|
||||
@@ -89,7 +91,7 @@ void BrowserWebViewDelegate::OpenURL(WebView* webview, const GURL& url,
|
||||
browser_->UIT_CreatePopupWindow(UTF8ToWide(url.spec()));
|
||||
|
||||
if(browser.get())
|
||||
browser->UIT_Show(browser->UIT_GetWebView(), disposition);
|
||||
browser->UIT_Show(browser->GetWebView(), disposition);
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::DidStartLoading(WebView* webview) {
|
||||
@@ -99,7 +101,7 @@ void BrowserWebViewDelegate::DidStartLoading(WebView* webview) {
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if(handler.get()) {
|
||||
// Notify the handler that loading has started
|
||||
handler->HandleLoadStart(browser_);
|
||||
handler->HandleLoadStart(browser_, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,12 +118,24 @@ void BrowserWebViewDelegate::DidStopLoading(WebView* webview) {
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if(handler.get()) {
|
||||
// Notify the handler that loading has ended
|
||||
handler->HandleLoadEnd(browser_);
|
||||
handler->HandleLoadEnd(browser_, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::WindowObjectCleared(WebFrame* webframe) {
|
||||
browser_->UIT_BindJSObjectsToWindow(webframe);
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if(handler.get()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Handle<v8::Context> context = webkit_glue::GetV8Context(webframe);
|
||||
if(context.IsEmpty())
|
||||
return;
|
||||
|
||||
v8::Context::Scope scope(context);
|
||||
|
||||
CefRefPtr<CefFrame> frame(browser_->GetCefFrame(webframe));
|
||||
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(context->Global());
|
||||
handler->HandleJSBinding(browser_, frame, object);
|
||||
}
|
||||
}
|
||||
|
||||
WindowOpenDisposition BrowserWebViewDelegate::DispositionForNavigationAction(
|
||||
@@ -155,8 +169,9 @@ WindowOpenDisposition BrowserWebViewDelegate::DispositionForNavigationAction(
|
||||
static_cast<CefRequestImpl*>(req.get())->SetHeaderMap(map);
|
||||
|
||||
// Notify the handler of a browse request
|
||||
CefHandler::RetVal rv = handler->HandleBeforeBrowse(browser_, req,
|
||||
(CefHandler::NavType)type, is_redirect);
|
||||
CefHandler::RetVal rv = handler->HandleBeforeBrowse(browser_,
|
||||
browser_->GetCefFrame(frame), req, (CefHandler::NavType)type,
|
||||
is_redirect);
|
||||
if(rv == RV_HANDLED)
|
||||
return IGNORE_ACTION;
|
||||
}
|
||||
@@ -247,6 +262,7 @@ void BrowserWebViewDelegate::DidFailProvisionalLoadWithError(
|
||||
// give the handler an opportunity to generate a custom error message
|
||||
std::wstring error_str;
|
||||
CefHandler::RetVal rv = handler->HandleLoadError(browser_,
|
||||
browser_->GetCefFrame(frame),
|
||||
static_cast<CefHandler::ErrorCode>(error.GetErrorCode()),
|
||||
UTF8ToWide(error.GetFailedURL().spec()), error_str);
|
||||
if(rv == RV_HANDLED && !error_str.empty())
|
||||
@@ -263,6 +279,11 @@ void BrowserWebViewDelegate::DidCommitLoadForFrame(WebView* webview,
|
||||
WebFrame* frame,
|
||||
bool is_new_navigation) {
|
||||
UpdateForCommittedLoad(frame, is_new_navigation);
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if(handler.get()) {
|
||||
// Notify the handler that loading has started
|
||||
handler->HandleLoadStart(browser_, browser_->GetCefFrame(frame));
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::DidReceiveTitle(WebView* webview,
|
||||
@@ -280,6 +301,11 @@ void BrowserWebViewDelegate::DidFinishLoadForFrame(WebView* webview,
|
||||
WebFrame* frame) {
|
||||
UpdateAddressBar(webview);
|
||||
LocationChangeDone(frame);
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if(handler.get()) {
|
||||
// Notify the handler that loading has ended
|
||||
handler->HandleLoadEnd(browser_, browser_->GetCefFrame(frame));
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::DidFailLoadWithError(WebView* webview,
|
||||
@@ -335,11 +361,13 @@ void BrowserWebViewDelegate::AddMessageToConsole(WebView* webview,
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::RunJavaScriptAlert(WebFrame* webframe,
|
||||
const std::wstring& message) {
|
||||
const std::wstring& message) {
|
||||
CefHandler::RetVal rv = RV_CONTINUE;
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if(handler.get())
|
||||
rv = handler->HandleJSAlert(browser_, message);
|
||||
if(handler.get()) {
|
||||
rv = handler->HandleJSAlert(browser_, browser_->GetCefFrame(webframe),
|
||||
message);
|
||||
}
|
||||
if(rv != RV_HANDLED)
|
||||
ShowJavaScriptAlert(webframe, message);
|
||||
}
|
||||
@@ -349,8 +377,10 @@ bool BrowserWebViewDelegate::RunJavaScriptConfirm(WebFrame* webframe,
|
||||
CefHandler::RetVal rv = RV_CONTINUE;
|
||||
bool retval = false;
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if(handler.get())
|
||||
rv = handler->HandleJSConfirm(browser_, message, retval);
|
||||
if(handler.get()) {
|
||||
rv = handler->HandleJSConfirm(browser_, browser_->GetCefFrame(webframe),
|
||||
message, retval);
|
||||
}
|
||||
if(rv != RV_HANDLED)
|
||||
retval = ShowJavaScriptConfirm(webframe, message);
|
||||
return retval;
|
||||
@@ -363,8 +393,8 @@ bool BrowserWebViewDelegate::RunJavaScriptPrompt(WebFrame* webframe,
|
||||
bool retval = false;
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if(handler.get()) {
|
||||
rv = handler->HandleJSPrompt(browser_, message, default_value,
|
||||
retval, *result);
|
||||
rv = handler->HandleJSPrompt(browser_, browser_->GetCefFrame(webframe),
|
||||
message, default_value, retval, *result);
|
||||
}
|
||||
if(rv != RV_HANDLED)
|
||||
retval = ShowJavaScriptPrompt(webframe, message, default_value, result);
|
||||
@@ -382,8 +412,8 @@ void BrowserWebViewDelegate::StartDragging(WebView* webview,
|
||||
// TODO(port): make this work on all platforms.
|
||||
if (!drag_delegate_) {
|
||||
drag_delegate_ = new BrowserDragDelegate(
|
||||
browser_->UIT_GetWebViewWndHandle(),
|
||||
browser_->UIT_GetWebView());
|
||||
browser_->GetWebViewWndHandle(),
|
||||
browser_->GetWebView());
|
||||
}
|
||||
// TODO(tc): Drag and drop is disabled in the test shell because we need
|
||||
// to be able to convert from WebDragData to an IDataObject.
|
||||
@@ -481,14 +511,14 @@ int BrowserWebViewDelegate::GetHistoryForwardListCount() {
|
||||
void BrowserWebViewDelegate::SetUserStyleSheetEnabled(bool is_enabled) {
|
||||
WebPreferences* prefs = _Context->GetWebPreferences();
|
||||
prefs->user_style_sheet_enabled = is_enabled;
|
||||
browser_->UIT_GetWebView()->SetPreferences(*prefs);
|
||||
browser_->GetWebView()->SetPreferences(*prefs);
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::SetUserStyleSheetLocation(const GURL& location) {
|
||||
WebPreferences* prefs = _Context->GetWebPreferences();
|
||||
prefs->user_style_sheet_enabled = true;
|
||||
prefs->user_style_sheet_location = location;
|
||||
browser_->UIT_GetWebView()->SetPreferences(*prefs);
|
||||
browser_->GetWebView()->SetPreferences(*prefs);
|
||||
}
|
||||
|
||||
// WebWidgetDelegate ---------------------------------------------------------
|
||||
@@ -551,8 +581,8 @@ void BrowserWebViewDelegate::RegisterDragDrop() {
|
||||
#if defined(OS_WIN)
|
||||
// TODO(port): add me once drag and drop works.
|
||||
DCHECK(!drop_delegate_);
|
||||
drop_delegate_ = new BrowserDropDelegate(browser_->UIT_GetWebViewWndHandle(),
|
||||
browser_->UIT_GetWebView());
|
||||
drop_delegate_ = new BrowserDropDelegate(browser_->GetWebViewWndHandle(),
|
||||
browser_->GetWebView());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -587,16 +617,16 @@ void BrowserWebViewDelegate::LocationChangeDone(WebFrame* frame) {
|
||||
}
|
||||
|
||||
WebWidgetHost* BrowserWebViewDelegate::GetHostForWidget(WebWidget* webwidget) {
|
||||
if (webwidget == browser_->UIT_GetWebView())
|
||||
return browser_->UIT_GetWebViewHost();
|
||||
if (webwidget == browser_->UIT_GetPopup())
|
||||
return browser_->UIT_GetPopupHost();
|
||||
if (webwidget == browser_->GetWebView())
|
||||
return browser_->GetWebViewHost();
|
||||
if (webwidget == browser_->GetPopup())
|
||||
return browser_->GetPopupHost();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::UpdateForCommittedLoad(WebFrame* frame,
|
||||
bool is_new_navigation) {
|
||||
WebView* webview = browser_->UIT_GetWebView();
|
||||
WebView* webview = browser_->GetWebView();
|
||||
|
||||
// Code duplicated from RenderView::DidCommitLoadForFrame.
|
||||
const WebRequest& request =
|
||||
@@ -641,15 +671,11 @@ void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) {
|
||||
}
|
||||
|
||||
std::wstring url = UTF8ToWide(entry->GetURL().spec().c_str());
|
||||
browser_->SetURL(url);
|
||||
|
||||
if(frame->GetView()->GetMainFrame() == frame) {
|
||||
// only send address changes that originate from the main frame
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if(handler.get()) {
|
||||
// Notify the handler of an address change
|
||||
handler->HandleAddressChange(browser_, url);
|
||||
}
|
||||
CefRefPtr<CefHandler> handler = browser_->GetHandler();
|
||||
if(handler.get()) {
|
||||
// Notify the handler of an address change
|
||||
handler->HandleAddressChange(browser_, browser_->GetCefFrame(frame), url);
|
||||
}
|
||||
|
||||
browser_->UIT_GetNavigationController()->DidNavigateToEntry(entry.release());
|
||||
@@ -670,7 +696,7 @@ void BrowserWebViewDelegate::UpdateSessionHistory(WebFrame* frame) {
|
||||
return;
|
||||
|
||||
std::string state;
|
||||
if (!browser_->UIT_GetWebView()->GetMainFrame()->
|
||||
if (!browser_->GetWebView()->GetMainFrame()->
|
||||
GetPreviousHistoryState(&state))
|
||||
return;
|
||||
|
||||
@@ -680,7 +706,7 @@ void BrowserWebViewDelegate::UpdateSessionHistory(WebFrame* frame) {
|
||||
std::wstring BrowserWebViewDelegate::GetFrameDescription(WebFrame* webframe) {
|
||||
std::wstring name = webframe->GetName();
|
||||
|
||||
if (webframe == browser_->UIT_GetWebView()->GetMainFrame()) {
|
||||
if (webframe == browser_->GetWebView()->GetMainFrame()) {
|
||||
if (name.length())
|
||||
return L"main frame \"" + name + L"\"";
|
||||
else
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
@@ -35,12 +35,12 @@ class WebDataSource;
|
||||
class WebWidgetHost;
|
||||
|
||||
class BrowserWebViewDelegate : public base::RefCounted<BrowserWebViewDelegate>,
|
||||
public WebViewDelegate {
|
||||
public WebViewDelegate {
|
||||
public:
|
||||
BrowserWebViewDelegate(CefBrowserImpl* shell)
|
||||
BrowserWebViewDelegate(CefBrowserImpl* browser)
|
||||
: policy_delegate_enabled_(false),
|
||||
policy_delegate_is_permissive_(false),
|
||||
browser_(shell),
|
||||
browser_(browser),
|
||||
top_loading_frame_(NULL),
|
||||
page_id_(-1),
|
||||
last_page_id_updated_(-1),
|
||||
@@ -55,7 +55,7 @@ class BrowserWebViewDelegate : public base::RefCounted<BrowserWebViewDelegate>,
|
||||
#endif
|
||||
{
|
||||
}
|
||||
virtual ~BrowserWebViewDelegate();
|
||||
virtual ~BrowserWebViewDelegate() {}
|
||||
|
||||
// WebViewDelegate
|
||||
virtual WebView* CreateWebView(WebView* webview,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
@@ -44,9 +44,6 @@ using WebKit::WebRect;
|
||||
|
||||
// WebViewDelegate -----------------------------------------------------------
|
||||
|
||||
BrowserWebViewDelegate::~BrowserWebViewDelegate() {
|
||||
}
|
||||
|
||||
WebPluginDelegate* BrowserWebViewDelegate::CreatePluginDelegate(
|
||||
WebView* webview,
|
||||
const GURL& url,
|
||||
@@ -74,12 +71,12 @@ WebPluginDelegate* BrowserWebViewDelegate::CreatePluginDelegate(
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::Show(WebWidget* webwidget, WindowOpenDisposition) {
|
||||
if (webwidget == browser_->UIT_GetWebView()) {
|
||||
ShowWindow(browser_->UIT_GetMainWndHandle(), SW_SHOW);
|
||||
UpdateWindow(browser_->UIT_GetMainWndHandle());
|
||||
} else if (webwidget == browser_->UIT_GetPopup()) {
|
||||
ShowWindow(browser_->UIT_GetPopupWndHandle(), SW_SHOW);
|
||||
UpdateWindow(browser_->UIT_GetPopupWndHandle());
|
||||
if (webwidget == browser_->GetWebView()) {
|
||||
ShowWindow(browser_->GetMainWndHandle(), SW_SHOW);
|
||||
UpdateWindow(browser_->GetMainWndHandle());
|
||||
} else if (webwidget == browser_->GetPopup()) {
|
||||
ShowWindow(browser_->GetPopupWndHandle(), SW_SHOW);
|
||||
UpdateWindow(browser_->GetPopupWndHandle());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,9 +90,9 @@ void BrowserWebViewDelegate::ShowAsPopupWithItems(
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::CloseWidgetSoon(WebWidget* webwidget) {
|
||||
if (webwidget == browser_->UIT_GetWebView()) {
|
||||
PostMessage(browser_->UIT_GetMainWndHandle(), WM_CLOSE, 0, 0);
|
||||
} else if (webwidget == browser_->UIT_GetPopup()) {
|
||||
if (webwidget == browser_->GetWebView()) {
|
||||
PostMessage(browser_->GetMainWndHandle(), WM_CLOSE, 0, 0);
|
||||
} else if (webwidget == browser_->GetPopup()) {
|
||||
browser_->UIT_ClosePopupWidget();
|
||||
}
|
||||
}
|
||||
@@ -120,10 +117,10 @@ void BrowserWebViewDelegate::GetWindowRect(WebWidget* webwidget,
|
||||
|
||||
void BrowserWebViewDelegate::SetWindowRect(WebWidget* webwidget,
|
||||
const WebRect& rect) {
|
||||
if (webwidget == browser_->UIT_GetWebView()) {
|
||||
if (webwidget == browser_->GetWebView()) {
|
||||
// ignored
|
||||
} else if (webwidget == browser_->UIT_GetPopup()) {
|
||||
MoveWindow(browser_->UIT_GetPopupWndHandle(),
|
||||
} else if (webwidget == browser_->GetPopup()) {
|
||||
MoveWindow(browser_->GetPopupWndHandle(),
|
||||
rect.x, rect.y, rect.width, rect.height, FALSE);
|
||||
}
|
||||
}
|
||||
@@ -183,7 +180,7 @@ void BrowserWebViewDelegate::RunModal(WebWidget* webwidget) {
|
||||
i = list->begin();
|
||||
for (; i != list->end(); ++i) {
|
||||
if (i->get()->IsPopup())
|
||||
EnableWindow(i->get()->UIT_GetMainWndHandle(), FALSE);
|
||||
EnableWindow(i->get()->GetMainWndHandle(), FALSE);
|
||||
}
|
||||
_Context->Unlock();
|
||||
|
||||
@@ -194,7 +191,7 @@ void BrowserWebViewDelegate::RunModal(WebWidget* webwidget) {
|
||||
list = _Context->GetBrowserList();
|
||||
i = list->begin();
|
||||
for (; i != list->end(); ++i)
|
||||
EnableWindow(i->get()->UIT_GetMainWndHandle(), TRUE);
|
||||
EnableWindow(i->get()->GetMainWndHandle(), TRUE);
|
||||
_Context->Unlock();
|
||||
}
|
||||
|
||||
@@ -251,7 +248,7 @@ void BrowserWebViewDelegate::ShowContextMenu(WebView* webview,
|
||||
const std::string& frame_charset) {
|
||||
|
||||
POINT screen_pt = { x, y };
|
||||
MapWindowPoints(browser_->UIT_GetMainWndHandle(), HWND_DESKTOP,
|
||||
MapWindowPoints(browser_->GetMainWndHandle(), HWND_DESKTOP,
|
||||
&screen_pt, 1);
|
||||
|
||||
HMENU menu = NULL;
|
||||
@@ -337,7 +334,7 @@ void BrowserWebViewDelegate::ShowContextMenu(WebView* webview,
|
||||
// show the context menu
|
||||
int selected_id = TrackPopupMenu(menu,
|
||||
TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_RECURSE,
|
||||
screen_pt.x, screen_pt.y, 0, browser_->UIT_GetMainWndHandle(), NULL);
|
||||
screen_pt.x, screen_pt.y, 0, browser_->GetMainWndHandle(), NULL);
|
||||
|
||||
if(selected_id != 0) {
|
||||
// An action was chosen
|
||||
@@ -351,7 +348,9 @@ void BrowserWebViewDelegate::ShowContextMenu(WebView* webview,
|
||||
|
||||
if(!handled) {
|
||||
// Execute the action
|
||||
browser_->UIT_HandleAction(menuId, TF_FOCUSED);
|
||||
CefRefPtr<CefFrame> frame = browser_->GetFocusedFrame();
|
||||
frame->AddRef();
|
||||
browser_->UIT_HandleAction(menuId, frame.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -369,7 +368,7 @@ void BrowserWebViewDelegate::ShowJavaScriptAlert(WebFrame* webframe,
|
||||
const std::wstring& message)
|
||||
{
|
||||
// TODO(cef): Think about what we should be showing as the prompt caption
|
||||
MessageBox(browser_->UIT_GetMainWndHandle(), message.c_str(),
|
||||
MessageBox(browser_->GetMainWndHandle(), message.c_str(),
|
||||
browser_->UIT_GetTitle().c_str(), MB_OK | MB_ICONWARNING);
|
||||
}
|
||||
|
||||
@@ -377,7 +376,7 @@ bool BrowserWebViewDelegate::ShowJavaScriptConfirm(WebFrame* webframe,
|
||||
const std::wstring& message)
|
||||
{
|
||||
// TODO(cef): Think about what we should be showing as the prompt caption
|
||||
int rv = MessageBox(browser_->UIT_GetMainWndHandle(), message.c_str(),
|
||||
int rv = MessageBox(browser_->GetMainWndHandle(), message.c_str(),
|
||||
browser_->UIT_GetTitle().c_str(),
|
||||
MB_YESNO | MB_ICONQUESTION);
|
||||
return (rv == IDYES);
|
||||
|
163
libcef/cef_string.c
Normal file
163
libcef/cef_string.c
Normal file
@@ -0,0 +1,163 @@
|
||||
// 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 "include/cef_string.h"
|
||||
#include <limits.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef unsigned long dword_t;
|
||||
|
||||
CEF_EXPORT size_t cef_string_length(cef_string_t str)
|
||||
{
|
||||
dword_t* ptr;
|
||||
|
||||
if(!str)
|
||||
return 0;
|
||||
|
||||
// The string length, in bytes, is placed in a dword_t immediately proceeding
|
||||
// the string value.
|
||||
ptr = (dword_t*)str;
|
||||
ptr--;
|
||||
|
||||
return (size_t)(*ptr / sizeof(wchar_t));
|
||||
}
|
||||
|
||||
CEF_EXPORT cef_string_t cef_string_alloc(const wchar_t* str)
|
||||
{
|
||||
if(!str)
|
||||
return NULL;
|
||||
|
||||
return cef_string_alloc_length(str, wcslen(str));
|
||||
}
|
||||
|
||||
CEF_EXPORT cef_string_t cef_string_alloc_length(const wchar_t* str,
|
||||
size_t len)
|
||||
{
|
||||
dword_t size, *ptr;
|
||||
wchar_t* newstr;
|
||||
|
||||
// Check that the size can fit in a dword_t.
|
||||
if(len >= (UINT_MAX - sizeof(wchar_t) - sizeof(dword_t)) / sizeof(wchar_t))
|
||||
return NULL;
|
||||
|
||||
// Get the size of the string in bytes.
|
||||
size = sizeof(wchar_t) * len;
|
||||
|
||||
// Allocate the new buffer including space for the proceeding dword_t size
|
||||
// value and the terminating nul.
|
||||
ptr = (dword_t*)malloc(sizeof(dword_t) + size + sizeof(wchar_t));
|
||||
if(!ptr)
|
||||
return NULL;
|
||||
|
||||
// Set the size as the first value in the newly allocated memory and
|
||||
// increment to the string location.
|
||||
*ptr = size;
|
||||
ptr++;
|
||||
|
||||
if(str != NULL)
|
||||
{
|
||||
// Copy the string to the buffer.
|
||||
memcpy(ptr, str, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Initialize the string to zeros.
|
||||
memset(ptr, 0, size);
|
||||
}
|
||||
|
||||
newstr = (wchar_t*)ptr;
|
||||
|
||||
// Nul-terminate the string.
|
||||
newstr[len] = '\0';
|
||||
|
||||
return (cef_string_t)newstr;
|
||||
}
|
||||
|
||||
CEF_EXPORT int cef_string_realloc(cef_string_t* oldstr, const wchar_t* newstr)
|
||||
{
|
||||
if(!oldstr)
|
||||
return 0;
|
||||
|
||||
// Free the old string.
|
||||
cef_string_free(*oldstr);
|
||||
|
||||
// Copy the new string.
|
||||
*oldstr = cef_string_alloc(newstr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
CEF_EXPORT int cef_string_realloc_length(cef_string_t* oldstr,
|
||||
const wchar_t* newstr,
|
||||
size_t len)
|
||||
{
|
||||
if(!oldstr)
|
||||
return 0;
|
||||
|
||||
// Check that the size can fit in a dword_t.
|
||||
if(len >= (UINT_MAX - sizeof(wchar_t) - sizeof(dword_t)) / sizeof(wchar_t))
|
||||
return 0;
|
||||
|
||||
if(*oldstr)
|
||||
{
|
||||
dword_t newsize, *oldptr, *newptr;
|
||||
|
||||
// Get the new size of the string in bytes.
|
||||
newsize = sizeof(wchar_t) * len;
|
||||
|
||||
// Adjust the pointer to account for the dword_t immediately proceeding the
|
||||
// string value.
|
||||
oldptr = (dword_t*)*oldstr;
|
||||
oldptr--;
|
||||
|
||||
// Re-allocate the buffer including space for the proceeding dword_t size
|
||||
// value and the terminating nul.
|
||||
newptr = (dword_t*)realloc(
|
||||
oldptr, sizeof(dword_t) + newsize + sizeof(wchar_t));
|
||||
if(!newptr)
|
||||
return 0;
|
||||
|
||||
// Set the size as the first value in the newly allocated memory and
|
||||
// increment to the string location.
|
||||
*newptr = newsize;
|
||||
newptr++;
|
||||
|
||||
// Set the string pointer to the beginning on the string in the newly
|
||||
// allocated memory.
|
||||
*oldstr = (cef_string_t)newptr;
|
||||
|
||||
if(newstr)
|
||||
{
|
||||
// Copy the new string value. Use of memmove() ensures that any
|
||||
// overlapping region in the old string will be copied before being
|
||||
// overwritten.
|
||||
memmove(*oldstr, newstr, newsize);
|
||||
|
||||
// Nul-terminate the string.
|
||||
*oldstr[len] = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Allocate the string.
|
||||
*oldstr = cef_string_alloc_length(newstr, len);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
CEF_EXPORT void cef_string_free(cef_string_t str)
|
||||
{
|
||||
dword_t* ptr;
|
||||
|
||||
if(!str)
|
||||
return;
|
||||
|
||||
// The size is placed in a dword_t immediately proceeding the string value.
|
||||
ptr = (dword_t*)str;
|
||||
ptr--;
|
||||
|
||||
free(ptr);
|
||||
}
|
56
libcef/cef_string_list.cc
Normal file
56
libcef/cef_string_list.cc
Normal 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.
|
||||
|
||||
#include "precompiled_libcef.h"
|
||||
#include "include/cef_string_list.h"
|
||||
#include "base/logging.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
typedef std::vector<std::wstring> StringList;
|
||||
|
||||
CEF_EXPORT cef_string_list_t cef_string_list_alloc()
|
||||
{
|
||||
return new StringList;
|
||||
}
|
||||
|
||||
CEF_EXPORT int cef_string_list_size(cef_string_list_t list)
|
||||
{
|
||||
DCHECK(list);
|
||||
StringList* impl = (StringList*)list;
|
||||
return impl->size();
|
||||
}
|
||||
|
||||
CEF_EXPORT cef_string_t cef_string_list_value(cef_string_list_t list, int index)
|
||||
{
|
||||
DCHECK(list);
|
||||
StringList* impl = (StringList*)list;
|
||||
DCHECK(index >= 0 && index < (int)impl->size());
|
||||
if(index < 0 || index >= (int)impl->size())
|
||||
return NULL;
|
||||
return cef_string_alloc((*impl)[index].c_str());
|
||||
}
|
||||
|
||||
CEF_EXPORT void cef_string_list_append(cef_string_list_t list, const wchar_t* value)
|
||||
{
|
||||
DCHECK(list);
|
||||
StringList* impl = (StringList*)list;
|
||||
std::wstring valstr;
|
||||
if(value)
|
||||
valstr = value;
|
||||
impl->push_back(valstr);
|
||||
}
|
||||
|
||||
CEF_EXPORT void cef_string_list_clear(cef_string_list_t list)
|
||||
{
|
||||
DCHECK(list);
|
||||
StringList* impl = (StringList*)list;
|
||||
impl->clear();
|
||||
}
|
||||
|
||||
CEF_EXPORT void cef_string_list_free(cef_string_list_t list)
|
||||
{
|
||||
DCHECK(list);
|
||||
delete (StringList*)list;
|
||||
}
|
93
libcef/cef_string_map.cc
Normal file
93
libcef/cef_string_map.cc
Normal file
@@ -0,0 +1,93 @@
|
||||
// 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 "include/cef_string_map.h"
|
||||
#include "base/logging.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
typedef std::map<std::wstring, std::wstring> StringMap;
|
||||
|
||||
CEF_EXPORT cef_string_map_t cef_string_map_alloc()
|
||||
{
|
||||
return new StringMap;
|
||||
}
|
||||
|
||||
CEF_EXPORT int cef_string_map_size(cef_string_map_t map)
|
||||
{
|
||||
DCHECK(map);
|
||||
StringMap* impl = (StringMap*)map;
|
||||
return impl->size();
|
||||
}
|
||||
|
||||
CEF_EXPORT cef_string_t cef_string_map_find(cef_string_map_t map,
|
||||
const wchar_t* key)
|
||||
{
|
||||
DCHECK(map);
|
||||
StringMap* impl = (StringMap*)map;
|
||||
std::wstring keystr;
|
||||
if(key)
|
||||
keystr = key;
|
||||
StringMap::const_iterator it = impl->find(keystr);
|
||||
if(it == impl->end())
|
||||
return NULL;
|
||||
return cef_string_alloc(it->second.c_str());
|
||||
}
|
||||
|
||||
CEF_EXPORT cef_string_t cef_string_map_key(cef_string_map_t map, int index)
|
||||
{
|
||||
DCHECK(map);
|
||||
StringMap* impl = (StringMap*)map;
|
||||
DCHECK(index >= 0 && index < (int)impl->size());
|
||||
if(index < 0 || index >= (int)impl->size())
|
||||
return NULL;
|
||||
StringMap::const_iterator it = impl->begin();
|
||||
for(int ct = 0; it != impl->end(); ++it, ct++) {
|
||||
if(ct == index)
|
||||
return cef_string_alloc(it->first.c_str());
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CEF_EXPORT cef_string_t cef_string_map_value(cef_string_map_t map, int index)
|
||||
{
|
||||
DCHECK(map);
|
||||
StringMap* impl = (StringMap*)map;
|
||||
DCHECK(index >= 0 && index < (int)impl->size());
|
||||
if(index < 0 || index >= (int)impl->size())
|
||||
return NULL;
|
||||
StringMap::const_iterator it = impl->begin();
|
||||
for(int ct = 0; it != impl->end(); ++it, ct++) {
|
||||
if(ct == index)
|
||||
return cef_string_alloc(it->second.c_str());
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CEF_EXPORT void cef_string_map_append(cef_string_map_t map, const wchar_t* key,
|
||||
const wchar_t* value)
|
||||
{
|
||||
DCHECK(map);
|
||||
StringMap* impl = (StringMap*)map;
|
||||
std::wstring keystr, valstr;
|
||||
if(key)
|
||||
keystr = key;
|
||||
if(value)
|
||||
valstr = value;
|
||||
impl->insert(std::pair<std::wstring, std::wstring>(keystr, valstr));
|
||||
}
|
||||
|
||||
CEF_EXPORT void cef_string_map_clear(cef_string_map_t map)
|
||||
{
|
||||
DCHECK(map);
|
||||
StringMap* impl = (StringMap*)map;
|
||||
impl->clear();
|
||||
}
|
||||
|
||||
CEF_EXPORT void cef_string_map_free(cef_string_map_t map)
|
||||
{
|
||||
DCHECK(map);
|
||||
delete (StringMap*)map;
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "base/stats_table.h"
|
||||
#include "base/string_util.h"
|
||||
#include "net/base/net_module.h"
|
||||
#include "webkit/extensions/v8/gc_extension.h"
|
||||
#include "webkit/glue/webplugin.h"
|
||||
#include "webkit/glue/plugins/plugin_lib.h"
|
||||
#include "webkit/glue/plugins/plugin_list.h"
|
||||
@@ -186,6 +187,11 @@ bool CefContext::DoInitialize()
|
||||
kStatsFileCounters);
|
||||
StatsTable::set_current(statstable_);
|
||||
|
||||
// CEF always exposes the GC.
|
||||
webkit_glue::SetJavaScriptFlags(L"--expose-gc");
|
||||
// Expose GCController to JavaScript.
|
||||
WebKit::registerExtension(extensions_v8::GCExtension::Get());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -195,10 +201,10 @@ void CefContext::DoUninitialize()
|
||||
// Task objects get destroyed before we exit, which avoids noise in
|
||||
// purify leak-test results.
|
||||
MessageLoop::current()->RunAllPending();
|
||||
|
||||
|
||||
BrowserResourceLoaderBridge::Shutdown();
|
||||
|
||||
// Tear down shared StatsTable; prevents unit_tests from leaking it.
|
||||
// Tear down the shared StatsTable.
|
||||
StatsTable::set_current(NULL);
|
||||
delete statstable_;
|
||||
statstable_ = NULL;
|
||||
@@ -249,8 +255,6 @@ CefContext::~CefContext()
|
||||
{
|
||||
// Just in case CefShutdown() isn't called
|
||||
Shutdown();
|
||||
|
||||
DoUninitialize();
|
||||
}
|
||||
|
||||
bool CefContext::Initialize(bool multi_threaded_message_loop,
|
||||
@@ -422,6 +426,8 @@ void CefContext::Shutdown()
|
||||
|
||||
hthreadui_ = NULL;
|
||||
heventui_ = NULL;
|
||||
} else {
|
||||
DoUninitialize();
|
||||
}
|
||||
|
||||
Lock();
|
||||
|
@@ -1,302 +0,0 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium 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 "jscontainer.h"
|
||||
#include "variant_impl.h"
|
||||
|
||||
// Here's the control flow of a JS method getting forwarded to a class.
|
||||
// - Something calls our NPObject with a function like "Invoke".
|
||||
// - CefNPObject's static invoke() function forwards it to its attached
|
||||
// CefJSContainer's Invoke() method.
|
||||
// - CefJSContainer has then overridden Invoke() to look up the function
|
||||
// name in its internal map of methods, and then calls the appropriate
|
||||
// method.
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "config.h"
|
||||
|
||||
// This is required for the KJS build due to an artifact of the
|
||||
// npruntime_priv.h file from JavaScriptCore/bindings.
|
||||
MSVC_PUSH_DISABLE_WARNING(4067)
|
||||
#include "npruntime_priv.h"
|
||||
MSVC_POP_WARNING()
|
||||
|
||||
#if USE(JSC)
|
||||
MSVC_PUSH_WARNING_LEVEL(0)
|
||||
#include <runtime/JSLock.h>
|
||||
MSVC_POP_WARNING()
|
||||
#endif
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/scoped_ptr.h"
|
||||
#include "base/string_util.h"
|
||||
#include "webkit/glue/webframe.h"
|
||||
#include "webkit/glue/webview.h"
|
||||
|
||||
|
||||
// Our special NPObject type. We extend an NPObject with a pointer to a
|
||||
// CefJSContainer, which is just a C++ interface that we forward all NPObject
|
||||
// callbacks to.
|
||||
struct CefNPObject {
|
||||
NPObject parent; // This must be the first field in the struct.
|
||||
CefJSContainer* container;
|
||||
WebFrame* webframe;
|
||||
|
||||
//
|
||||
// All following objects and functions are static, and just used to interface
|
||||
// with NPObject/NPClass.
|
||||
//
|
||||
|
||||
// An NPClass associates static functions of CefNPObject with the
|
||||
// function pointers used by the JS runtime.
|
||||
static NPClass np_class_;
|
||||
|
||||
// Allocate a new NPObject with the specified class.
|
||||
static NPObject* allocate(NPP npp, NPClass* aClass);
|
||||
|
||||
// Free an object.
|
||||
static void deallocate(NPObject* obj);
|
||||
|
||||
// Returns true if the C++ class associated with this NPObject exposes the
|
||||
// given property. Called by the JS runtime.
|
||||
static bool hasProperty(NPObject *obj, NPIdentifier ident);
|
||||
|
||||
// Returns true if the C++ class associated with this NPObject exposes the
|
||||
// given method. Called by the JS runtime.
|
||||
static bool hasMethod(NPObject *obj, NPIdentifier ident);
|
||||
|
||||
// If the given method is exposed by the C++ class associated with this
|
||||
// NPObject, invokes it with the given args and returns a result. Otherwise,
|
||||
// returns "undefined" (in the JavaScript sense). Called by the JS runtime.
|
||||
static bool invoke(NPObject *obj, NPIdentifier ident,
|
||||
const NPVariant *args, uint32_t arg_count,
|
||||
NPVariant *result);
|
||||
|
||||
// If the given property is exposed by the C++ class associated with this
|
||||
// NPObject, returns its value. Otherwise, returns "undefined" (in the
|
||||
// JavaScript sense). Called by the JS runtime.
|
||||
static bool getProperty(NPObject *obj, NPIdentifier ident,
|
||||
NPVariant *result);
|
||||
|
||||
// If the given property is exposed by the C++ class associated with this
|
||||
// NPObject, sets its value. Otherwise, does nothing. Called by the JS
|
||||
// runtime.
|
||||
static bool setProperty(NPObject *obj, NPIdentifier ident,
|
||||
const NPVariant *value);
|
||||
};
|
||||
|
||||
// Build CefNPObject's static function pointers into an NPClass, for use
|
||||
// in constructing NPObjects for the C++ classes.
|
||||
NPClass CefNPObject::np_class_ = {
|
||||
NP_CLASS_STRUCT_VERSION,
|
||||
CefNPObject::allocate,
|
||||
CefNPObject::deallocate,
|
||||
/* NPInvalidateFunctionPtr */ NULL,
|
||||
CefNPObject::hasMethod,
|
||||
CefNPObject::invoke,
|
||||
/* NPInvokeDefaultFunctionPtr */ NULL,
|
||||
CefNPObject::hasProperty,
|
||||
CefNPObject::getProperty,
|
||||
CefNPObject::setProperty,
|
||||
/* NPRemovePropertyFunctionPtr */ NULL
|
||||
};
|
||||
|
||||
/* static */ NPObject* CefNPObject::allocate(NPP npp, NPClass* aClass) {
|
||||
CefNPObject* obj = new CefNPObject;
|
||||
// obj->parent will be initialized by the NPObject code calling this.
|
||||
obj->container = NULL;
|
||||
obj->webframe = NULL;
|
||||
return &obj->parent;
|
||||
}
|
||||
|
||||
/* static */ void CefNPObject::deallocate(NPObject* np_obj) {
|
||||
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
|
||||
delete obj;
|
||||
}
|
||||
|
||||
/* static */ bool CefNPObject::hasMethod(NPObject* np_obj,
|
||||
NPIdentifier ident) {
|
||||
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
|
||||
return obj->container->HasMethod(ident);
|
||||
}
|
||||
|
||||
/* static */ bool CefNPObject::hasProperty(NPObject* np_obj,
|
||||
NPIdentifier ident) {
|
||||
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
|
||||
return obj->container->HasProperty(ident);
|
||||
}
|
||||
|
||||
/* static */ bool CefNPObject::invoke(NPObject* np_obj, NPIdentifier ident,
|
||||
const NPVariant* args, uint32_t arg_count,
|
||||
NPVariant* result) {
|
||||
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
|
||||
return obj->container->Invoke(ident, obj->webframe, args, arg_count, result);
|
||||
}
|
||||
|
||||
/* static */ bool CefNPObject::getProperty(NPObject* np_obj,
|
||||
NPIdentifier ident,
|
||||
NPVariant* result) {
|
||||
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
|
||||
return obj->container->GetProperty(ident, obj->webframe, result);
|
||||
}
|
||||
|
||||
/* static */ bool CefNPObject::setProperty(NPObject* np_obj,
|
||||
NPIdentifier ident,
|
||||
const NPVariant* value) {
|
||||
CefNPObject* obj = reinterpret_cast<CefNPObject*>(np_obj);
|
||||
return obj->container->SetProperty(ident, obj->webframe, value);
|
||||
}
|
||||
|
||||
CefJSContainer::CefJSContainer(CefBrowser* browser,
|
||||
CefRefPtr<CefJSHandler> handler)
|
||||
: browser_(browser), handler_(handler)
|
||||
{
|
||||
DCHECK(browser_ != NULL);
|
||||
DCHECK(handler_.get() != NULL);
|
||||
}
|
||||
|
||||
CefJSContainer::~CefJSContainer()
|
||||
{
|
||||
// Unregister objects we created and bound to a frame.
|
||||
for (BoundObjectList::iterator i = bound_objects_.begin();
|
||||
i != bound_objects_.end(); ++i) {
|
||||
#if USE(V8)
|
||||
_NPN_UnregisterObject(*i);
|
||||
#endif
|
||||
NPN_ReleaseObject(*i);
|
||||
}
|
||||
}
|
||||
|
||||
bool CefJSContainer::HasMethod(NPIdentifier ident)
|
||||
{
|
||||
std::wstring name = UTF8ToWide(NPN_UTF8FromIdentifier(ident));
|
||||
return handler_->HasMethod(browser_, name);
|
||||
}
|
||||
|
||||
bool CefJSContainer::HasProperty(NPIdentifier ident)
|
||||
{
|
||||
std::wstring name = UTF8ToWide(NPN_UTF8FromIdentifier(ident));
|
||||
return handler_->HasProperty(browser_, name);
|
||||
}
|
||||
|
||||
bool CefJSContainer::Invoke(NPIdentifier ident,
|
||||
WebFrame* frame,
|
||||
const NPVariant* args,
|
||||
size_t arg_count,
|
||||
NPVariant* result)
|
||||
{
|
||||
std::wstring name = UTF8ToWide(NPN_UTF8FromIdentifier(ident));
|
||||
|
||||
// Build a VariantVector argument vector from the NPVariants coming in.
|
||||
CefJSHandler::VariantVector cef_args(arg_count);
|
||||
for (size_t i = 0; i < arg_count; i++) {
|
||||
cef_args[i] = new CefVariantImpl(frame);
|
||||
static_cast<CefVariantImpl*>(cef_args[i].get())->Set(args[i]);
|
||||
}
|
||||
|
||||
CefRefPtr<CefVariant> cef_retval(new CefVariantImpl(frame));
|
||||
|
||||
// Execute the handler method
|
||||
bool rv = handler_->ExecuteMethod(browser_, name, cef_args, cef_retval);
|
||||
if(rv) {
|
||||
// Assign the return value
|
||||
static_cast<CefVariantImpl*>(cef_retval.get())->CopyToNPVariant(result);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefJSContainer::GetProperty(NPIdentifier ident,
|
||||
WebFrame* frame,
|
||||
NPVariant* result)
|
||||
{
|
||||
CefRefPtr<CefVariant> cef_result(new CefVariantImpl(frame));
|
||||
std::wstring name = UTF8ToWide(NPN_UTF8FromIdentifier(ident));
|
||||
|
||||
// Execute the handler method
|
||||
bool rv = handler_->GetProperty(browser_, name, cef_result);
|
||||
if(rv) {
|
||||
// Assign the return value
|
||||
static_cast<CefVariantImpl*>(cef_result.get())->CopyToNPVariant(result);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefJSContainer::SetProperty(NPIdentifier ident,
|
||||
WebFrame* frame,
|
||||
const NPVariant* value)
|
||||
{
|
||||
std::wstring name = UTF8ToWide(NPN_UTF8FromIdentifier(ident));
|
||||
|
||||
// Assign the input value
|
||||
CefRefPtr<CefVariant> cef_value(new CefVariantImpl(frame));
|
||||
static_cast<CefVariantImpl*>(cef_value.get())->Set(*value);
|
||||
|
||||
// Execute the handler method
|
||||
return handler_->SetProperty(browser_, name, cef_value);
|
||||
}
|
||||
|
||||
// Check if the specified frame exists by comparing to all frames currently
|
||||
// attached to the view.
|
||||
static bool FrameExists(WebView* view, WebFrame* frame) {
|
||||
WebFrame* main_frame = view->GetMainFrame();
|
||||
WebFrame* it = main_frame;
|
||||
do {
|
||||
if (it == frame)
|
||||
return true;
|
||||
it = view->GetNextFrameAfter(it, true);
|
||||
} while (it != main_frame);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CefJSContainer::BindToJavascript(WebFrame* frame,
|
||||
const std::wstring& classname) {
|
||||
#if USE(JSC)
|
||||
JSC::JSLock lock(false);
|
||||
#endif
|
||||
|
||||
NPObject* np_obj = NULL;
|
||||
CefNPObject* obj = NULL;
|
||||
|
||||
Lock();
|
||||
WebView* view = frame->GetView();
|
||||
BoundObjectList::iterator it = bound_objects_.begin();
|
||||
for(; it != bound_objects_.end(); ) {
|
||||
obj = reinterpret_cast<CefNPObject*>(*it);
|
||||
if(obj->webframe == frame) {
|
||||
// An NPObject is already bound to this particular frame.
|
||||
np_obj = *it;
|
||||
} else if(!FrameExists(view, obj->webframe)) {
|
||||
// Remove bindings to non-existent frames.
|
||||
#if USE(V8)
|
||||
_NPN_UnregisterObject(*it);
|
||||
#endif
|
||||
NPN_ReleaseObject(*it);
|
||||
it = bound_objects_.erase(it);
|
||||
continue;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
Unlock();
|
||||
|
||||
if(!np_obj) {
|
||||
// Create an NPObject using our static NPClass. The first argument (a
|
||||
// plugin's instance handle) is passed through to the allocate function
|
||||
// directly, and we don't use it, so it's ok to be 0.
|
||||
np_obj = NPN_CreateObject(0, &CefNPObject::np_class_);
|
||||
obj = reinterpret_cast<CefNPObject*>(np_obj);
|
||||
obj->container = this;
|
||||
obj->webframe = frame;
|
||||
|
||||
Lock();
|
||||
bound_objects_.push_back(np_obj);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
// BindToWindowObject will (indirectly) retain the np_object. We save it
|
||||
// so we can release it when we're destroyed.
|
||||
frame->BindToWindowObject(classname, np_obj);
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef _JSCONTAINER_H
|
||||
#define _JSCONTAINER_H
|
||||
|
||||
#include "../include/cef.h"
|
||||
#include "third_party/npapi/bindings/npruntime.h"
|
||||
|
||||
class WebFrame;
|
||||
|
||||
// CefJSContainer lets you map Javascript method calls and property accesses
|
||||
// directly to C++ method calls and CefVariant* variable access.
|
||||
// Portions of the implementation are borrowed from
|
||||
// webkit\glue\cpp_bound_class.cc
|
||||
class CefJSContainer : public CefThreadSafeBase<CefBase>
|
||||
{
|
||||
public:
|
||||
CefJSContainer(CefBrowser* browser,
|
||||
CefRefPtr<CefJSHandler> handler);
|
||||
~CefJSContainer();
|
||||
|
||||
// Given a WebFrame, BindToJavascript builds the NPObject that will represent
|
||||
// the class and binds it to the frame's window under the given name. This
|
||||
// should generally be called from the WebView delegate's
|
||||
// WindowObjectCleared(). A class so bound will be accessible to JavaScript
|
||||
// as window.<classname>. The owner of the CefJSContainer is responsible for
|
||||
// keeping the object around while the frame is alive, and for destroying it
|
||||
// afterwards.
|
||||
void BindToJavascript(WebFrame* frame,
|
||||
const std::wstring& classname);
|
||||
|
||||
CefRefPtr<CefJSHandler> GetHandler() { return handler_; }
|
||||
|
||||
protected:
|
||||
bool HasMethod(NPIdentifier ident);
|
||||
bool HasProperty(NPIdentifier ident);
|
||||
bool Invoke(NPIdentifier ident,
|
||||
WebFrame* frame,
|
||||
const NPVariant* args,
|
||||
size_t arg_count,
|
||||
NPVariant* result);
|
||||
bool GetProperty(NPIdentifier ident,
|
||||
WebFrame* frame,
|
||||
NPVariant* result);
|
||||
bool SetProperty(NPIdentifier ident,
|
||||
WebFrame* frame,
|
||||
const NPVariant* value);
|
||||
|
||||
friend struct CefNPObject;
|
||||
|
||||
protected:
|
||||
CefBrowser* browser_;
|
||||
CefRefPtr<CefJSHandler> handler_;
|
||||
|
||||
// A list of all NPObjects we created and bound in BindToJavascript(), so we
|
||||
// can clean them up when we're destroyed.
|
||||
typedef std::vector<NPObject*> BoundObjectList;
|
||||
BoundObjectList bound_objects_;
|
||||
};
|
||||
|
||||
|
||||
#endif // _JSHANDLER_CONTAINER_H
|
@@ -198,6 +198,18 @@
|
||||
RelativePath="..\include\cef_ptr.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\include\cef_string.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\include\cef_string_list.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\include\cef_string_map.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\include\cef_types.h"
|
||||
>
|
||||
@@ -291,6 +303,68 @@
|
||||
RelativePath=".\browser_webview_delegate_win.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\cef_string.c"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="BUILDING_CEF_SHARED"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="BUILDING_CEF_SHARED"
|
||||
UsePrecompiledHeader="0"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\cef_string_list.cc"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="BUILDING_CEF_SHARED"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="BUILDING_CEF_SHARED"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\cef_string_map.cc"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="BUILDING_CEF_SHARED"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="BUILDING_CEF_SHARED"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\context.cc"
|
||||
>
|
||||
@@ -299,14 +373,6 @@
|
||||
RelativePath=".\context.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\jscontainer.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\jscontainer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\precompiled_libcef.cc"
|
||||
>
|
||||
@@ -352,19 +418,15 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\variant_impl.cc"
|
||||
RelativePath=".\tracker.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\variant_impl.h"
|
||||
RelativePath=".\v8_impl.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\variant_np_util.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\variant_np_util.h"
|
||||
RelativePath=".\v8_impl.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors. All rights
|
||||
// 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.
|
||||
|
||||
@@ -20,10 +20,6 @@ CefRequestImpl::CefRequestImpl()
|
||||
{
|
||||
}
|
||||
|
||||
CefRequestImpl::~CefRequestImpl()
|
||||
{
|
||||
}
|
||||
|
||||
std::wstring CefRequestImpl::GetURL()
|
||||
{
|
||||
Lock();
|
||||
@@ -39,21 +35,6 @@ void CefRequestImpl::SetURL(const std::wstring& url)
|
||||
Unlock();
|
||||
}
|
||||
|
||||
std::wstring CefRequestImpl::GetFrame()
|
||||
{
|
||||
Lock();
|
||||
std::wstring frame = frame_;
|
||||
Unlock();
|
||||
return frame;
|
||||
}
|
||||
|
||||
void CefRequestImpl::SetFrame(const std::wstring& frame)
|
||||
{
|
||||
Lock();
|
||||
frame_ = frame;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
std::wstring CefRequestImpl::GetMethod()
|
||||
{
|
||||
Lock();
|
||||
@@ -99,14 +80,12 @@ void CefRequestImpl::SetHeaderMap(const HeaderMap& headerMap)
|
||||
}
|
||||
|
||||
void CefRequestImpl::Set(const std::wstring& url,
|
||||
const std::wstring& frame,
|
||||
const std::wstring& method,
|
||||
CefRefPtr<CefPostData> postData,
|
||||
const HeaderMap& headerMap)
|
||||
const std::wstring& method,
|
||||
CefRefPtr<CefPostData> postData,
|
||||
const HeaderMap& headerMap)
|
||||
{
|
||||
Lock();
|
||||
url_ = url;
|
||||
frame_ = frame;
|
||||
method_ = method;
|
||||
postdata_ = postData;
|
||||
headermap_ = headerMap;
|
||||
@@ -150,11 +129,6 @@ CefPostDataImpl::CefPostDataImpl()
|
||||
{
|
||||
}
|
||||
|
||||
CefPostDataImpl::~CefPostDataImpl()
|
||||
{
|
||||
RemoveElements();
|
||||
}
|
||||
|
||||
size_t CefPostDataImpl::GetElementCount()
|
||||
{
|
||||
Lock();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors. All rights
|
||||
// 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.
|
||||
|
||||
@@ -15,12 +15,10 @@ class CefRequestImpl : public CefThreadSafeBase<CefRequest>
|
||||
{
|
||||
public:
|
||||
CefRequestImpl();
|
||||
~CefRequestImpl();
|
||||
~CefRequestImpl() {}
|
||||
|
||||
virtual std::wstring GetURL();
|
||||
virtual void SetURL(const std::wstring& url);
|
||||
virtual std::wstring GetFrame();
|
||||
virtual void SetFrame(const std::wstring& frame);
|
||||
virtual std::wstring GetMethod();
|
||||
virtual void SetMethod(const std::wstring& method);
|
||||
virtual CefRefPtr<CefPostData> GetPostData();
|
||||
@@ -28,7 +26,6 @@ public:
|
||||
virtual void GetHeaderMap(HeaderMap& headerMap);
|
||||
virtual void SetHeaderMap(const HeaderMap& headerMap);
|
||||
virtual void Set(const std::wstring& url,
|
||||
const std::wstring& frame,
|
||||
const std::wstring& method,
|
||||
CefRefPtr<CefPostData> postData,
|
||||
const HeaderMap& headerMap);
|
||||
@@ -38,7 +35,6 @@ public:
|
||||
|
||||
protected:
|
||||
std::wstring url_;
|
||||
std::wstring frame_;
|
||||
std::wstring method_;
|
||||
CefRefPtr<CefPostData> postdata_;
|
||||
HeaderMap headermap_;
|
||||
@@ -49,7 +45,7 @@ class CefPostDataImpl : public CefThreadSafeBase<CefPostData>
|
||||
{
|
||||
public:
|
||||
CefPostDataImpl();
|
||||
~CefPostDataImpl();
|
||||
~CefPostDataImpl() {}
|
||||
|
||||
virtual size_t GetElementCount();
|
||||
virtual void GetElements(ElementVector& elements);
|
||||
|
136
libcef/tracker.h
Normal file
136
libcef/tracker.h
Normal file
@@ -0,0 +1,136 @@
|
||||
// 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.
|
||||
|
||||
#ifndef _TRACKER_H
|
||||
#define _TRACKER_H
|
||||
|
||||
#include "include/cef.h"
|
||||
|
||||
// Class extended by objects that must be tracked. After creating a tracked
|
||||
// object you should add it to the appropriate track manager.
|
||||
class CefTrackObject
|
||||
{
|
||||
public:
|
||||
CefTrackObject()
|
||||
{
|
||||
track_next_ = NULL;
|
||||
track_prev_ = NULL;
|
||||
}
|
||||
virtual ~CefTrackObject()
|
||||
{
|
||||
}
|
||||
|
||||
// Returns true if the object is currently being tracked.
|
||||
bool IsTracked() { return (track_prev_ || track_next_); }
|
||||
|
||||
private:
|
||||
CefTrackObject* GetTrackPrev() { return track_prev_; }
|
||||
void SetTrackPrev(CefTrackObject* base) { track_prev_ = base; }
|
||||
CefTrackObject* GetTrackNext() { return track_next_; }
|
||||
void SetTrackNext(CefTrackObject* base) { track_next_ = base; }
|
||||
|
||||
// Insert a new object into the tracking list before this object.
|
||||
void InsertTrackPrev(CefTrackObject* object)
|
||||
{
|
||||
if(track_prev_)
|
||||
track_prev_->SetTrackNext(object);
|
||||
object->SetTrackNext(this);
|
||||
object->SetTrackPrev(track_prev_);
|
||||
track_prev_ = object;
|
||||
}
|
||||
|
||||
// Insert a new object into the tracking list after this object.
|
||||
void InsertTrackNext(CefTrackObject* object)
|
||||
{
|
||||
if(track_next_)
|
||||
track_next_->SetTrackPrev(object);
|
||||
object->SetTrackPrev(this);
|
||||
object->SetTrackNext(track_next_);
|
||||
track_next_ = object;
|
||||
}
|
||||
|
||||
// Remove this object from the tracking list.
|
||||
void RemoveTracking()
|
||||
{
|
||||
if(track_next_)
|
||||
track_next_->SetTrackPrev(track_prev_);
|
||||
if(track_prev_)
|
||||
track_prev_->SetTrackNext(track_next_);
|
||||
track_next_ = NULL;
|
||||
track_prev_ = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
CefTrackObject* track_next_;
|
||||
CefTrackObject* track_prev_;
|
||||
|
||||
friend class CefTrackManager;
|
||||
};
|
||||
|
||||
// Class used to manage tracked objects. A single instance of this class
|
||||
// should be created for each intended usage. Any objects that have not been
|
||||
// removed by explicit calls to the Destroy() method will be removed when the
|
||||
// manager object is destroyed. A manager object can be created as either a
|
||||
// member variable of another class or by using lazy initialization:
|
||||
// base::LazyInstance<CefTrackManager> g_singleton(base::LINKER_INITIALIZED);
|
||||
class CefTrackManager : public CefThreadSafeBase<CefBase>
|
||||
{
|
||||
public:
|
||||
CefTrackManager() : object_count_(0) {}
|
||||
virtual ~CefTrackManager()
|
||||
{
|
||||
DeleteAll();
|
||||
}
|
||||
|
||||
// Add an object to be tracked by this manager.
|
||||
void Add(CefTrackObject* object)
|
||||
{
|
||||
Lock();
|
||||
if(!object->IsTracked()) {
|
||||
tracker_.InsertTrackNext(object);
|
||||
++object_count_;
|
||||
}
|
||||
Unlock();
|
||||
}
|
||||
|
||||
// Delete an object tracked by this manager.
|
||||
bool Delete(CefTrackObject* object)
|
||||
{
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(object->IsTracked()) {
|
||||
object->RemoveTracking();
|
||||
delete object;
|
||||
--object_count_;
|
||||
rv = true;
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Delete all objects tracked by this manager.
|
||||
void DeleteAll()
|
||||
{
|
||||
Lock();
|
||||
CefTrackObject* next;
|
||||
do {
|
||||
next = tracker_.GetTrackNext();
|
||||
if(next) {
|
||||
next->RemoveTracking();
|
||||
delete next;
|
||||
}
|
||||
} while(next != NULL);
|
||||
object_count_ = 0;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
// Returns the number of objects currently being tracked.
|
||||
long GetCount() { return object_count_; }
|
||||
|
||||
private:
|
||||
CefTrackObject tracker_;
|
||||
long object_count_;
|
||||
};
|
||||
|
||||
#endif // _TRACKER_H
|
687
libcef/v8_impl.cc
Normal file
687
libcef/v8_impl.cc
Normal file
@@ -0,0 +1,687 @@
|
||||
// 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 "v8_impl.h"
|
||||
#include "context.h"
|
||||
#include "tracker.h"
|
||||
#include "base/lazy_instance.h"
|
||||
#include "webkit/api/public/WebKit.h"
|
||||
|
||||
|
||||
// Memory manager.
|
||||
|
||||
base::LazyInstance<CefTrackManager> g_v8_tracker(base::LINKER_INITIALIZED);
|
||||
|
||||
class TrackBase : public CefTrackObject
|
||||
{
|
||||
public:
|
||||
TrackBase(CefBase* base) { base_ = base; }
|
||||
|
||||
protected:
|
||||
CefRefPtr<CefBase> base_;
|
||||
};
|
||||
|
||||
class TrackString : public CefTrackObject
|
||||
{
|
||||
public:
|
||||
TrackString(const std::string& str) : string_(str) {}
|
||||
const char* GetString() { return string_.c_str(); }
|
||||
|
||||
private:
|
||||
std::string string_;
|
||||
};
|
||||
|
||||
|
||||
static void TrackAdd(CefTrackObject* object)
|
||||
{
|
||||
g_v8_tracker.Pointer()->Add(object);
|
||||
}
|
||||
|
||||
static void TrackDelete(CefTrackObject* object)
|
||||
{
|
||||
g_v8_tracker.Pointer()->Delete(object);
|
||||
}
|
||||
|
||||
// Callback for weak persistent reference destruction.
|
||||
static void TrackDestructor(v8::Persistent<v8::Value> object,
|
||||
void* parameter)
|
||||
{
|
||||
if(parameter)
|
||||
TrackDelete(static_cast<CefTrackObject*>(parameter));
|
||||
}
|
||||
|
||||
|
||||
// Convert a wide string to a V8 string.
|
||||
static v8::Handle<v8::String> GetV8String(const std::wstring& str)
|
||||
{
|
||||
return v8::String::New(
|
||||
reinterpret_cast<const uint16_t*>(str.c_str()), str.length());
|
||||
}
|
||||
|
||||
// Convert a V8 string to a wide string.
|
||||
static std::wstring GetWString(v8::Handle<v8::String> str)
|
||||
{
|
||||
uint16_t* buf = new uint16_t[str->Length()+1];
|
||||
str->Write(buf);
|
||||
std::wstring value = reinterpret_cast<wchar_t*>(buf);
|
||||
delete [] buf;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// V8 function callback
|
||||
static v8::Handle<v8::Value> FunctionCallbackImpl(const v8::Arguments& args)
|
||||
{
|
||||
v8::HandleScope handle_scope;
|
||||
CefV8Handler* handler =
|
||||
static_cast<CefV8Handler*>(v8::External::Unwrap(args.Data()));
|
||||
|
||||
CefV8ValueList params;
|
||||
for(int i = 0; i < args.Length(); i++)
|
||||
params.push_back(new CefV8ValueImpl(args[i]));
|
||||
|
||||
std::wstring func_name =
|
||||
GetWString(v8::Handle<v8::String>::Cast(args.Callee()->GetName()));
|
||||
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(args.This());
|
||||
CefRefPtr<CefV8Value> retval;
|
||||
std::wstring exception;
|
||||
v8::Handle<v8::Value> value = v8::Null();
|
||||
|
||||
if(handler->Execute(func_name, object, params, retval, exception)) {
|
||||
if(!exception.empty())
|
||||
value = v8::ThrowException(GetV8String(exception));
|
||||
else {
|
||||
CefV8ValueImpl* rv = static_cast<CefV8ValueImpl*>(retval.get());
|
||||
if(rv)
|
||||
value = rv->GetValue();
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
// V8 extension registration.
|
||||
|
||||
class ExtensionWrapper : public v8::Extension {
|
||||
public:
|
||||
ExtensionWrapper(const char* extension_name,
|
||||
const char* javascript_code,
|
||||
CefV8Handler* handler)
|
||||
: v8::Extension(extension_name, javascript_code), handler_(handler)
|
||||
{
|
||||
// The reference will be released when the application exits.
|
||||
TrackAdd(new TrackBase(handler));
|
||||
}
|
||||
|
||||
virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
|
||||
v8::Handle<v8::String> name)
|
||||
{
|
||||
return v8::FunctionTemplate::New(FunctionCallbackImpl,
|
||||
v8::External::New(handler_));
|
||||
}
|
||||
|
||||
void UIT_RegisterExtension()
|
||||
{
|
||||
WebKit::registerExtension(this);
|
||||
}
|
||||
|
||||
void AddRef() {}
|
||||
void Release() {}
|
||||
|
||||
private:
|
||||
CefV8Handler* handler_;
|
||||
};
|
||||
|
||||
bool CefRegisterExtension(const std::wstring& extension_name,
|
||||
const std::wstring& javascript_code,
|
||||
CefRefPtr<CefV8Handler> handler)
|
||||
{
|
||||
// Verify that the context is already initialized
|
||||
if(!_Context.get())
|
||||
return false;
|
||||
|
||||
if(!handler.get())
|
||||
return false;
|
||||
|
||||
TrackString* name = new TrackString(WideToUTF8(extension_name));
|
||||
TrackAdd(name);
|
||||
TrackString* code = new TrackString(WideToUTF8(javascript_code));
|
||||
TrackAdd(name);
|
||||
|
||||
ExtensionWrapper* wrapper = new ExtensionWrapper(name->GetString(),
|
||||
code->GetString(), handler.get());
|
||||
|
||||
PostTask(FROM_HERE, NewRunnableMethod(wrapper,
|
||||
&ExtensionWrapper::UIT_RegisterExtension));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// CefV8Value
|
||||
|
||||
// static
|
||||
CefRefPtr<CefV8Value> CefV8Value::CreateUndefined()
|
||||
{
|
||||
v8::HandleScope handle_scope;
|
||||
return new CefV8ValueImpl(v8::Undefined());
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefV8Value> CefV8Value::CreateNull()
|
||||
{
|
||||
v8::HandleScope handle_scope;
|
||||
return new CefV8ValueImpl(v8::Null());
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefV8Value> CefV8Value::CreateBool(bool value)
|
||||
{
|
||||
v8::HandleScope handle_scope;
|
||||
return new CefV8ValueImpl(v8::Boolean::New(value));
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefV8Value> CefV8Value::CreateInt(int value)
|
||||
{
|
||||
v8::HandleScope handle_scope;
|
||||
return new CefV8ValueImpl(v8::Int32::New(value));
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefV8Value> CefV8Value::CreateDouble(double value)
|
||||
{
|
||||
v8::HandleScope handle_scope;
|
||||
return new CefV8ValueImpl(v8::Number::New(value));
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefV8Value> CefV8Value::CreateString(const std::wstring& value)
|
||||
{
|
||||
v8::HandleScope handle_scope;
|
||||
return new CefV8ValueImpl(GetV8String(value));
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefV8Value> CefV8Value::CreateObject(CefRefPtr<CefBase> user_data)
|
||||
{
|
||||
v8::HandleScope handle_scope;
|
||||
CefV8ValueImpl* impl = new CefV8ValueImpl();
|
||||
|
||||
// Create the new V8 object.
|
||||
v8::Local<v8::Object> obj = v8::Object::New();
|
||||
|
||||
TrackBase *tracker = NULL;
|
||||
if(user_data.get()) {
|
||||
// Attach the user data to the V8 object.
|
||||
v8::Local<v8::Value> data = v8::External::Wrap(user_data.get());
|
||||
obj->Set(v8::String::New("Cef::UserData"), data);
|
||||
|
||||
// Provide a tracker object that will cause the user data reference to be
|
||||
// released when the V8 object is destroyed.
|
||||
tracker = new TrackBase(user_data);
|
||||
}
|
||||
|
||||
// Attach to the CefV8ValueImpl.
|
||||
impl->Attach(obj, tracker);
|
||||
return impl;
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefV8Value> CefV8Value::CreateArray()
|
||||
{
|
||||
v8::HandleScope handle_scope;
|
||||
return new CefV8ValueImpl(v8::Array::New());
|
||||
}
|
||||
|
||||
// static
|
||||
CefRefPtr<CefV8Value> CefV8Value::CreateFunction(const std::wstring& name,
|
||||
CefRefPtr<CefV8Handler> handler)
|
||||
{
|
||||
v8::HandleScope handle_scope;
|
||||
CefV8ValueImpl* impl = new CefV8ValueImpl();
|
||||
|
||||
// Create a new V8 function template with one internal field.
|
||||
v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New();
|
||||
|
||||
v8::Local<v8::Value> data = v8::External::Wrap(handler.get());
|
||||
|
||||
// Set the function handler callback.
|
||||
tmpl->SetCallHandler(FunctionCallbackImpl, data);
|
||||
|
||||
// Retrieve the function object and set the name.
|
||||
v8::Local<v8::Function> func = tmpl->GetFunction();
|
||||
func->SetName(GetV8String(name));
|
||||
|
||||
// Attach the handler instance to the V8 object.
|
||||
func->Set(v8::String::New("Cef::Handler"), data);
|
||||
|
||||
// Attach to the CefV8ValueImpl and provide a tracker object that will cause
|
||||
// the handler reference to be released when the V8 object is destroyed.
|
||||
impl->Attach(func, new TrackBase(handler));
|
||||
return impl;
|
||||
}
|
||||
|
||||
|
||||
// CefV8ValueImpl
|
||||
|
||||
CefV8ValueImpl::CefV8ValueImpl()
|
||||
: tracker_(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CefV8ValueImpl::CefV8ValueImpl(v8::Handle<v8::Value> value,
|
||||
CefTrackObject* tracker)
|
||||
{
|
||||
Attach(value, tracker);
|
||||
}
|
||||
|
||||
CefV8ValueImpl::~CefV8ValueImpl()
|
||||
{
|
||||
Detach();
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::Attach(v8::Handle<v8::Value> value,
|
||||
CefTrackObject* tracker)
|
||||
{
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(v8_value_.IsEmpty()) {
|
||||
v8_value_ = v8::Persistent<v8::Value>::New(value);
|
||||
tracker_ = tracker;
|
||||
rv = true;
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
void CefV8ValueImpl::Detach()
|
||||
{
|
||||
Lock();
|
||||
if(tracker_)
|
||||
TrackAdd(tracker_);
|
||||
v8_value_.MakeWeak(tracker_, TrackDestructor);
|
||||
v8_value_.Clear();
|
||||
tracker_ = NULL;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
v8::Handle<v8::Value> CefV8ValueImpl::GetValue()
|
||||
{
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Handle<v8::Value> rv;
|
||||
Lock();
|
||||
rv = v8_value_;
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::IsReservedKey(const std::wstring& key)
|
||||
{
|
||||
return (key.find(L"Cef::") == 0 || key.find(L"v8::") == 0);
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::IsUndefined()
|
||||
{
|
||||
Lock();
|
||||
bool rv = v8_value_->IsUndefined();
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::IsNull()
|
||||
{
|
||||
Lock();
|
||||
bool rv = v8_value_->IsNull();
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::IsBool()
|
||||
{
|
||||
Lock();
|
||||
bool rv = (v8_value_->IsBoolean() || v8_value_->IsTrue()
|
||||
|| v8_value_->IsFalse());
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::IsInt()
|
||||
{
|
||||
Lock();
|
||||
bool rv = v8_value_->IsInt32();
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::IsDouble()
|
||||
{
|
||||
Lock();
|
||||
bool rv = (v8_value_->IsNumber() || v8_value_->IsDate());
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::IsString()
|
||||
{
|
||||
Lock();
|
||||
bool rv = v8_value_->IsString();
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::IsObject()
|
||||
{
|
||||
Lock();
|
||||
bool rv = v8_value_->IsObject();
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::IsArray()
|
||||
{
|
||||
Lock();
|
||||
bool rv = v8_value_->IsArray();
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::IsFunction()
|
||||
{
|
||||
Lock();
|
||||
bool rv = v8_value_->IsFunction();
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::GetBoolValue()
|
||||
{
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(v8_value_->IsTrue())
|
||||
rv = true;
|
||||
else if(v8_value_->IsFalse())
|
||||
rv = false;
|
||||
else {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Boolean> val = v8_value_->ToBoolean();
|
||||
rv = val->Value();
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
int CefV8ValueImpl::GetIntValue()
|
||||
{
|
||||
int rv = 0;
|
||||
Lock();
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Int32> val = v8_value_->ToInt32();
|
||||
rv = val->Value();
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
double CefV8ValueImpl::GetDoubleValue()
|
||||
{
|
||||
double rv = 0.;
|
||||
Lock();
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Number> val = v8_value_->ToNumber();
|
||||
rv = val->Value();
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
std::wstring CefV8ValueImpl::GetStringValue()
|
||||
{
|
||||
std::wstring rv;
|
||||
Lock();
|
||||
v8::HandleScope handle_scope;
|
||||
rv = GetWString(v8_value_->ToString());
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::HasValue(const std::wstring& key)
|
||||
{
|
||||
if(IsReservedKey(key))
|
||||
return false;
|
||||
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(v8_value_->IsObject()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
rv = obj->Has(GetV8String(key));
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::HasValue(int index)
|
||||
{
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(v8_value_->IsObject()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
rv = obj->Has(index);
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::DeleteValue(const std::wstring& key)
|
||||
{
|
||||
if(IsReservedKey(key))
|
||||
return false;
|
||||
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(v8_value_->IsObject()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
rv = obj->Delete(GetV8String(key));
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::DeleteValue(int index)
|
||||
{
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(v8_value_->IsObject()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
rv = obj->Delete(index);
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(const std::wstring& key)
|
||||
{
|
||||
if(IsReservedKey(key))
|
||||
return false;
|
||||
|
||||
CefRefPtr<CefV8Value> rv;
|
||||
Lock();
|
||||
if(v8_value_->IsObject()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
rv = new CefV8ValueImpl(obj->Get(GetV8String(key)));
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(int index)
|
||||
{
|
||||
CefRefPtr<CefV8Value> rv;
|
||||
Lock();
|
||||
if(v8_value_->IsObject()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
rv = new CefV8ValueImpl(obj->Get(v8::Number::New(index)));
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::SetValue(const std::wstring& key,
|
||||
CefRefPtr<CefV8Value> value)
|
||||
{
|
||||
if(IsReservedKey(key))
|
||||
return false;
|
||||
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(v8_value_->IsObject()) {
|
||||
CefV8ValueImpl *impl = static_cast<CefV8ValueImpl*>(value.get());
|
||||
if(impl) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
rv = obj->Set(GetV8String(key), impl->GetValue());
|
||||
}
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::SetValue(int index, CefRefPtr<CefV8Value> value)
|
||||
{
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(v8_value_->IsObject()) {
|
||||
CefV8ValueImpl *impl = static_cast<CefV8ValueImpl*>(value.get());
|
||||
if(impl) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
rv = obj->Set(v8::Number::New(index), impl->GetValue());
|
||||
}
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::GetKeys(std::vector<std::wstring>& keys)
|
||||
{
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(v8_value_->IsObject()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
v8::Local<v8::Array> arr_keys = obj->GetPropertyNames();
|
||||
uint32_t len = arr_keys->Length();
|
||||
for(uint32_t i = 0; i < len; ++i) {
|
||||
v8::Local<v8::Value> value = arr_keys->Get(v8::Integer::New(i));
|
||||
std::wstring str = GetWString(value->ToString());
|
||||
if(!IsReservedKey(str))
|
||||
keys.push_back(str);
|
||||
}
|
||||
rv = true;
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBase> CefV8ValueImpl::GetUserData()
|
||||
{
|
||||
CefRefPtr<CefBase> rv;
|
||||
Lock();
|
||||
if(v8_value_->IsObject()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
v8::Local<v8::String> key = v8::String::New("Cef::UserData");
|
||||
if(obj->Has(key))
|
||||
rv = static_cast<CefBase*>(v8::External::Unwrap(obj->Get(key)));
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
int CefV8ValueImpl::GetArrayLength()
|
||||
{
|
||||
int rv = 0;
|
||||
Lock();
|
||||
if(v8_value_->IsArray()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
v8::Local<v8::Array> arr = v8::Local<v8::Array>::Cast(obj);
|
||||
rv = arr->Length();
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
std::wstring CefV8ValueImpl::GetFunctionName()
|
||||
{
|
||||
std::wstring rv;
|
||||
Lock();
|
||||
if(v8_value_->IsFunction()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(obj);
|
||||
rv = GetWString(v8::Handle<v8::String>::Cast(func->GetName()));
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
CefRefPtr<CefV8Handler> CefV8ValueImpl::GetFunctionHandler()
|
||||
{
|
||||
CefRefPtr<CefV8Handler> rv;
|
||||
Lock();
|
||||
if(v8_value_->IsFunction()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
v8::Local<v8::String> key = v8::String::New("Cef::Handler");
|
||||
if(obj->Has(key))
|
||||
rv = static_cast<CefV8Handler*>(v8::External::Unwrap(obj->Get(key)));
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefV8ValueImpl::ExecuteFunction(CefRefPtr<CefV8Value> object,
|
||||
CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
std::wstring& exception)
|
||||
{
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(v8_value_->IsFunction() && object.get() && object->IsObject()) {
|
||||
v8::HandleScope handle_scope;
|
||||
v8::Local<v8::Object> obj = v8_value_->ToObject();
|
||||
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(obj);
|
||||
|
||||
CefV8ValueImpl* recv_impl = static_cast<CefV8ValueImpl*>(object.get());
|
||||
v8::Handle<v8::Object> recv =
|
||||
v8::Handle<v8::Object>::Cast(recv_impl->GetValue());
|
||||
|
||||
int argc = arguments.size();
|
||||
v8::Handle<v8::Value> *argv = NULL;
|
||||
if(argc > 0) {
|
||||
argv = new v8::Handle<v8::Value>[argc];
|
||||
for(int i = 0; i < argc; ++i) {
|
||||
argv[i] =
|
||||
static_cast<CefV8ValueImpl*>(arguments[i].get())->GetValue();
|
||||
}
|
||||
}
|
||||
|
||||
v8::TryCatch try_catch;
|
||||
v8::Local<v8::Value> func_rv = func->Call(recv, argc, argv);
|
||||
if (try_catch.HasCaught())
|
||||
exception = GetWString(try_catch.Message()->Get());
|
||||
else
|
||||
retval = new CefV8ValueImpl(func_rv);
|
||||
|
||||
rv = true;
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
61
libcef/v8_impl.h
Normal file
61
libcef/v8_impl.h
Normal file
@@ -0,0 +1,61 @@
|
||||
// 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.
|
||||
|
||||
#ifndef _V8_IMPL_H
|
||||
#define _V8_IMPL_H
|
||||
|
||||
#include "include/cef.h"
|
||||
#include "v8/include/v8.h"
|
||||
|
||||
class CefTrackObject;
|
||||
|
||||
class CefV8ValueImpl : public CefThreadSafeBase<CefV8Value>
|
||||
{
|
||||
public:
|
||||
CefV8ValueImpl();
|
||||
CefV8ValueImpl(v8::Handle<v8::Value> value, CefTrackObject* tracker = NULL);
|
||||
virtual ~CefV8ValueImpl();
|
||||
|
||||
bool Attach(v8::Handle<v8::Value> value, CefTrackObject* tracker = NULL);
|
||||
void Detach();
|
||||
v8::Handle<v8::Value> GetValue();
|
||||
bool IsReservedKey(const std::wstring& key);
|
||||
|
||||
virtual bool IsUndefined();
|
||||
virtual bool IsNull();
|
||||
virtual bool IsBool();
|
||||
virtual bool IsInt();
|
||||
virtual bool IsDouble();
|
||||
virtual bool IsString();
|
||||
virtual bool IsObject();
|
||||
virtual bool IsArray();
|
||||
virtual bool IsFunction();
|
||||
virtual bool GetBoolValue();
|
||||
virtual int GetIntValue();
|
||||
virtual double GetDoubleValue();
|
||||
virtual std::wstring GetStringValue();
|
||||
virtual bool HasValue(const std::wstring& key);
|
||||
virtual bool HasValue(int index);
|
||||
virtual bool DeleteValue(const std::wstring& key);
|
||||
virtual bool DeleteValue(int index);
|
||||
virtual CefRefPtr<CefV8Value> GetValue(const std::wstring& key);
|
||||
virtual CefRefPtr<CefV8Value> GetValue(int index);
|
||||
virtual bool SetValue(const std::wstring& key, CefRefPtr<CefV8Value> value);
|
||||
virtual bool SetValue(int index, CefRefPtr<CefV8Value> value);
|
||||
virtual bool GetKeys(std::vector<std::wstring>& keys);
|
||||
virtual CefRefPtr<CefBase> GetUserData();
|
||||
virtual int GetArrayLength();
|
||||
virtual std::wstring GetFunctionName();
|
||||
virtual CefRefPtr<CefV8Handler> GetFunctionHandler();
|
||||
virtual bool ExecuteFunction(CefRefPtr<CefV8Value> object,
|
||||
CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval,
|
||||
std::wstring& exception);
|
||||
|
||||
protected:
|
||||
v8::Persistent<v8::Value> v8_value_;
|
||||
CefTrackObject* tracker_;
|
||||
};
|
||||
|
||||
#endif //_V8_IMPL_H
|
@@ -1,370 +0,0 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium 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 "variant_impl.h"
|
||||
#include "variant_np_util.h"
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
|
||||
#include "config.h"
|
||||
MSVC_PUSH_WARNING_LEVEL(0);
|
||||
#include "DOMWindow.h"
|
||||
#include "Frame.h"
|
||||
#include "npruntime_priv.h" // for NPN_InitializeVariantWithStringCopy
|
||||
MSVC_POP_WARNING();
|
||||
|
||||
#undef LOG
|
||||
#include "base/logging.h"
|
||||
#include "base/string_util.h"
|
||||
#include "webkit/glue/webframe.h"
|
||||
|
||||
|
||||
CefVariantImpl::CefVariantImpl()
|
||||
{
|
||||
variant_.type = NPVariantType_Null;
|
||||
webframe_ = NULL;
|
||||
}
|
||||
|
||||
CefVariantImpl::CefVariantImpl(WebFrame *webframe)
|
||||
{
|
||||
variant_.type = NPVariantType_Null;
|
||||
webframe_ = webframe;
|
||||
}
|
||||
|
||||
// Note that Set() performs a deep copy, which is necessary to safely
|
||||
// call SetNull() on the value in the destructor.
|
||||
CefVariantImpl::CefVariantImpl(const CefVariantImpl& original)
|
||||
{
|
||||
Lock();
|
||||
variant_.type = NPVariantType_Null;
|
||||
Set(*original.GetNPVariant());
|
||||
Unlock();
|
||||
}
|
||||
|
||||
// See comment for copy constructor, above.
|
||||
CefVariantImpl& CefVariantImpl::operator=(const CefVariantImpl& original)
|
||||
{
|
||||
if (&original != this) {
|
||||
Lock();
|
||||
Set(*original.GetNPVariant());
|
||||
Unlock();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
CefVariantImpl::~CefVariantImpl()
|
||||
{
|
||||
SetNull();
|
||||
}
|
||||
|
||||
CefVariant::Type CefVariantImpl::GetType()
|
||||
{
|
||||
CefVariant::Type type = VARIANT_TYPE_NULL;
|
||||
|
||||
Lock();
|
||||
|
||||
// determine the data type of the underlying NPVariant value
|
||||
switch (variant_.type) {
|
||||
case NPVariantType_Bool:
|
||||
type = VARIANT_TYPE_BOOL;
|
||||
break;
|
||||
case NPVariantType_Int32:
|
||||
type = VARIANT_TYPE_INT;
|
||||
break;
|
||||
case NPVariantType_Double:
|
||||
type = VARIANT_TYPE_DOUBLE;
|
||||
break;
|
||||
case NPVariantType_String:
|
||||
type = VARIANT_TYPE_STRING;
|
||||
break;
|
||||
case NPVariantType_Object:
|
||||
{
|
||||
// determine the most appropriate array type for the NPVariant object
|
||||
NPVariantType nptype;
|
||||
if(_NPN_ArrayObjectToVectorTypeHint(variant_.value.objectValue, nptype)) {
|
||||
switch(nptype) {
|
||||
case NPVariantType_Bool:
|
||||
type = VARIANT_TYPE_BOOL_ARRAY;
|
||||
break;
|
||||
case NPVariantType_Int32:
|
||||
type = VARIANT_TYPE_INT_ARRAY;
|
||||
break;
|
||||
case NPVariantType_Double:
|
||||
type = VARIANT_TYPE_DOUBLE_ARRAY;
|
||||
break;
|
||||
case NPVariantType_String:
|
||||
type = VARIANT_TYPE_STRING_ARRAY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Unlock();
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
void CefVariantImpl::SetNull()
|
||||
{
|
||||
Lock();
|
||||
NPN_ReleaseVariantValue(&variant_);
|
||||
variant_.type = NPVariantType_Null;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CefVariantImpl::SetBool(bool val)
|
||||
{
|
||||
Lock();
|
||||
if(variant_.type != NPVariantType_Bool) {
|
||||
SetNull();
|
||||
variant_.type = NPVariantType_Bool;
|
||||
}
|
||||
variant_.value.boolValue = val;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CefVariantImpl::SetInt(int val)
|
||||
{
|
||||
Lock();
|
||||
if(variant_.type != NPVariantType_Int32) {
|
||||
SetNull();
|
||||
variant_.type = NPVariantType_Int32;
|
||||
}
|
||||
variant_.value.intValue = val;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CefVariantImpl::SetDouble(double val)
|
||||
{
|
||||
Lock();
|
||||
if(variant_.type != NPVariantType_Double) {
|
||||
SetNull();
|
||||
variant_.type = NPVariantType_Double;
|
||||
}
|
||||
variant_.value.doubleValue = val;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CefVariantImpl::SetString(const std::wstring& val)
|
||||
{
|
||||
Lock();
|
||||
SetNull();
|
||||
variant_.type = NPVariantType_String;
|
||||
std::string str = WideToUTF8(val);
|
||||
NPString new_string = {str.c_str(),
|
||||
static_cast<uint32_t>(str.size())};
|
||||
_NPN_InitializeVariantWithStringCopy(&variant_, &new_string);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CefVariantImpl::SetBoolArray(const std::vector<bool>& val)
|
||||
{
|
||||
Lock();
|
||||
DCHECK(webframe_ != NULL);
|
||||
WebCore::Frame* frame =
|
||||
static_cast<WebCore::Frame*>(webframe_->GetFrameImplementation());
|
||||
WebCore::DOMWindow* domwindow = frame->domWindow();
|
||||
NPObject* npobject = _NPN_BooleanVectorToArrayObject(domwindow, val);
|
||||
DCHECK(npobject != NULL);
|
||||
Set(npobject);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CefVariantImpl::SetIntArray(const std::vector<int>& val)
|
||||
{
|
||||
Lock();
|
||||
DCHECK(webframe_ != NULL);
|
||||
WebCore::Frame* frame =
|
||||
static_cast<WebCore::Frame*>(webframe_->GetFrameImplementation());
|
||||
WebCore::DOMWindow* domwindow = frame->domWindow();
|
||||
NPObject* npobject = _NPN_IntVectorToArrayObject(domwindow, val);
|
||||
DCHECK(npobject != NULL);
|
||||
Set(npobject);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CefVariantImpl::SetDoubleArray(const std::vector<double>& val)
|
||||
{
|
||||
Lock();
|
||||
DCHECK(webframe_ != NULL);
|
||||
WebCore::Frame* frame =
|
||||
static_cast<WebCore::Frame*>(webframe_->GetFrameImplementation());
|
||||
WebCore::DOMWindow* domwindow = frame->domWindow();
|
||||
NPObject* npobject = _NPN_DoubleVectorToArrayObject(domwindow, val);
|
||||
DCHECK(npobject != NULL);
|
||||
Set(npobject);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CefVariantImpl::SetStringArray(const std::vector<std::wstring>& val)
|
||||
{
|
||||
Lock();
|
||||
DCHECK(webframe_ != NULL);
|
||||
WebCore::Frame* frame =
|
||||
static_cast<WebCore::Frame*>(webframe_->GetFrameImplementation());
|
||||
WebCore::DOMWindow* domwindow = frame->domWindow();
|
||||
NPObject* npobject = _NPN_WStringVectorToArrayObject(domwindow, val);
|
||||
DCHECK(npobject != NULL);
|
||||
Set(npobject);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
bool CefVariantImpl::GetBool()
|
||||
{
|
||||
Lock();
|
||||
DCHECK(variant_.type == NPVariantType_Bool);
|
||||
bool rv = variant_.value.boolValue;
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
int CefVariantImpl::GetInt()
|
||||
{
|
||||
Lock();
|
||||
DCHECK(variant_.type == NPVariantType_Int32);
|
||||
int rv = variant_.value.intValue;
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
double CefVariantImpl::GetDouble()
|
||||
{
|
||||
Lock();
|
||||
DCHECK(variant_.type == NPVariantType_Double);
|
||||
double rv = variant_.value.doubleValue;
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
std::wstring CefVariantImpl::GetString()
|
||||
{
|
||||
Lock();
|
||||
DCHECK(variant_.type == NPVariantType_String);
|
||||
std::wstring rv = UTF8ToWide(
|
||||
std::string(
|
||||
variant_.value.stringValue.UTF8Characters,
|
||||
variant_.value.stringValue.UTF8Length));
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefVariantImpl::GetBoolArray(std::vector<bool>& val)
|
||||
{
|
||||
Lock();
|
||||
DCHECK(variant_.type == NPVariantType_Object);
|
||||
bool rv = _NPN_ArrayObjectToBooleanVector(variant_.value.objectValue, val);
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefVariantImpl::GetIntArray(std::vector<int>& val)
|
||||
{
|
||||
Lock();
|
||||
DCHECK(variant_.type == NPVariantType_Object);
|
||||
bool rv = _NPN_ArrayObjectToIntVector(variant_.value.objectValue, val);
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefVariantImpl::GetDoubleArray(std::vector<double>& val)
|
||||
{
|
||||
Lock();
|
||||
DCHECK(variant_.type == NPVariantType_Object);
|
||||
bool rv = _NPN_ArrayObjectToDoubleVector(variant_.value.objectValue, val);
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool CefVariantImpl::GetStringArray(std::vector<std::wstring>& val)
|
||||
{
|
||||
Lock();
|
||||
DCHECK(variant_.type == NPVariantType_Object);
|
||||
bool rv = _NPN_ArrayObjectToWStringVector(variant_.value.objectValue, val);
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
int CefVariantImpl::GetArraySize()
|
||||
{
|
||||
Lock();
|
||||
DCHECK(variant_.type == NPVariantType_Object);
|
||||
int rv = _NPN_ArrayObjectGetVectorSize(variant_.value.objectValue);
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
void CefVariantImpl::CopyToNPVariant(NPVariant* result)
|
||||
{
|
||||
Lock();
|
||||
result->type = variant_.type;
|
||||
switch (variant_.type) {
|
||||
case NPVariantType_Bool:
|
||||
result->value.boolValue = variant_.value.boolValue;
|
||||
break;
|
||||
case NPVariantType_Int32:
|
||||
result->value.intValue = variant_.value.intValue;
|
||||
break;
|
||||
case NPVariantType_Double:
|
||||
result->value.doubleValue = variant_.value.doubleValue;
|
||||
break;
|
||||
case NPVariantType_String:
|
||||
_NPN_InitializeVariantWithStringCopy(result, &variant_.value.stringValue);
|
||||
break;
|
||||
case NPVariantType_Null:
|
||||
case NPVariantType_Void:
|
||||
// Nothing to set.
|
||||
break;
|
||||
case NPVariantType_Object:
|
||||
result->type = NPVariantType_Object;
|
||||
result->value.objectValue = NPN_RetainObject(variant_.value.objectValue);
|
||||
break;
|
||||
}
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CefVariantImpl::Set(NPObject* val)
|
||||
{
|
||||
Lock();
|
||||
SetNull();
|
||||
variant_.type = NPVariantType_Object;
|
||||
variant_.value.objectValue = NPN_RetainObject(val);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CefVariantImpl::Set(const NPString& val)
|
||||
{
|
||||
Lock();
|
||||
SetNull();
|
||||
variant_.type = NPVariantType_String;
|
||||
_NPN_InitializeVariantWithStringCopy(&variant_, &val);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
void CefVariantImpl::Set(const NPVariant& val)
|
||||
{
|
||||
Lock();
|
||||
SetNull();
|
||||
switch (val.type) {
|
||||
case NPVariantType_Bool:
|
||||
SetBool(val.value.boolValue);
|
||||
break;
|
||||
case NPVariantType_Int32:
|
||||
SetInt(val.value.intValue);
|
||||
break;
|
||||
case NPVariantType_Double:
|
||||
SetDouble(val.value.doubleValue);
|
||||
break;
|
||||
case NPVariantType_String:
|
||||
Set(val.value.stringValue);
|
||||
break;
|
||||
case NPVariantType_Object:
|
||||
Set(val.value.objectValue);
|
||||
break;
|
||||
}
|
||||
Unlock();
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
// Copyright (c) 2008 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef _VARIANT_IMPL_H
|
||||
#define _VARIANT_IMPL_H
|
||||
|
||||
#include "../include/cef.h"
|
||||
#include "third_party/npapi/bindings/npruntime.h"
|
||||
|
||||
class WebFrame;
|
||||
|
||||
// Implementation of CefPostDataElement that provides a class wrapper for an
|
||||
// NPVariant structure.
|
||||
// Portions of the implementation are borrowed from webkit\glue\cpp_variant.cc
|
||||
class CefVariantImpl : public CefThreadSafeBase<CefVariant>
|
||||
{
|
||||
public:
|
||||
CefVariantImpl();
|
||||
CefVariantImpl(WebFrame *webframe);
|
||||
~CefVariantImpl();
|
||||
|
||||
virtual Type GetType();
|
||||
virtual void SetNull();
|
||||
virtual void SetBool(bool val);
|
||||
virtual void SetInt(int val);
|
||||
virtual void SetDouble(double val);
|
||||
virtual void SetString(const std::wstring& val);
|
||||
virtual void SetBoolArray(const std::vector<bool>& val);
|
||||
virtual void SetIntArray(const std::vector<int>& val);
|
||||
virtual void SetDoubleArray(const std::vector<double>& val);
|
||||
virtual void SetStringArray(const std::vector<std::wstring>& val);
|
||||
virtual bool GetBool();
|
||||
virtual int GetInt();
|
||||
virtual double GetDouble();
|
||||
virtual std::wstring GetString();
|
||||
virtual bool GetBoolArray(std::vector<bool>& val);
|
||||
virtual bool GetIntArray(std::vector<int>& val);
|
||||
virtual bool GetDoubleArray(std::vector<double>& val);
|
||||
virtual bool GetStringArray(std::vector<std::wstring>& val);
|
||||
virtual int GetArraySize();
|
||||
|
||||
// These three methods all perform deep copies of any string data. This
|
||||
// allows the local CefVariantImpl to be released by the destructor without
|
||||
// corrupting their sources. In performance-critical code, or when strings
|
||||
// are very long, avoid creating new CefVariantImpl.
|
||||
// In case of NPObject as the data, the copying involves ref-counting
|
||||
// as opposed to deep-copying. The ref-counting ensures that sources don't
|
||||
// get corrupted when the copies get destroyed.
|
||||
void CopyToNPVariant(NPVariant* result);
|
||||
CefVariantImpl& operator=(const CefVariantImpl& original);
|
||||
CefVariantImpl(const CefVariantImpl& original);
|
||||
|
||||
// Note that setting a CefVariant to an NPObject involves ref-counting
|
||||
// the actual object. SetNull() should only be called if the CefVariant
|
||||
// is no longer needed. The other Set() methods handle this internally.
|
||||
// Also, the object's NPClass is expected to be a static object: neither
|
||||
// the NP runtime nor CefVariant will ever free it.
|
||||
void Set(NPObject* val);
|
||||
|
||||
void Set(const NPString& val);
|
||||
void Set(const NPVariant& val);
|
||||
|
||||
const NPVariant* GetNPVariant() const { return &variant_; }
|
||||
|
||||
protected:
|
||||
// Underlying NPVariant structure.
|
||||
NPVariant variant_;
|
||||
|
||||
// Pointer to the WebFrame that represents the context for this CefVariant
|
||||
// object. This pointer is used for creating new NPObjects in the Set*()
|
||||
// methods that accept array arguments.
|
||||
WebFrame* webframe_;
|
||||
};
|
||||
|
||||
#endif // _VARIANT_IMPL_H
|
@@ -1,227 +0,0 @@
|
||||
// Copyright (c) 2008 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 "variant_np_util.h"
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <v8.h>
|
||||
#include "NPV8Object.h"
|
||||
#include "v8_proxy.h"
|
||||
|
||||
#undef LOG
|
||||
#include "base/string_util.h"
|
||||
#include "bindings/npruntime.h"
|
||||
|
||||
|
||||
// npScriptObjectClass defined in webkit\port\bindings\v8\NPV8Object.cpp
|
||||
extern NPClass* npScriptObjectClass;
|
||||
|
||||
|
||||
NPObject* _NPN_StringVectorToArrayObject(WebCore::DOMWindow* domwindow,
|
||||
const std::vector<std::string>& vec) {
|
||||
v8::Local<v8::Array> array = v8::Array::New();
|
||||
for (uint32_t index = 0; index < vec.size(); ++index) {
|
||||
array->Set(v8::Integer::New(index),
|
||||
v8::String::New(vec[index].c_str(), vec[index].length()));
|
||||
}
|
||||
|
||||
return npCreateV8ScriptObject(0, array, domwindow);
|
||||
}
|
||||
|
||||
NPObject* _NPN_WStringVectorToArrayObject(WebCore::DOMWindow* domwindow,
|
||||
const std::vector<std::wstring>& vec) {
|
||||
v8::Local<v8::Array> array = v8::Array::New();
|
||||
for (uint32_t index = 0; index < vec.size(); ++index) {
|
||||
std::string str = WideToUTF8(vec[index].c_str());
|
||||
array->Set(v8::Integer::New(index),
|
||||
v8::String::New(str.c_str(), str.length()));
|
||||
}
|
||||
|
||||
return npCreateV8ScriptObject(0, array, domwindow);
|
||||
}
|
||||
|
||||
NPObject* _NPN_IntVectorToArrayObject(WebCore::DOMWindow* domwindow,
|
||||
const std::vector<int>& vec) {
|
||||
v8::Local<v8::Array> array = v8::Array::New();
|
||||
for (uint32_t index = 0; index < vec.size(); ++index) {
|
||||
array->Set(v8::Integer::New(index), v8::Int32::New(vec[index]));
|
||||
}
|
||||
|
||||
return npCreateV8ScriptObject(0, array, domwindow);
|
||||
}
|
||||
|
||||
NPObject* _NPN_DoubleVectorToArrayObject(WebCore::DOMWindow* domwindow,
|
||||
const std::vector<double>& vec) {
|
||||
v8::Local<v8::Array> array = v8::Array::New();
|
||||
for (uint32_t index = 0; index < vec.size(); ++index) {
|
||||
array->Set(v8::Integer::New(index), v8::Number::New(vec[index]));
|
||||
}
|
||||
|
||||
return npCreateV8ScriptObject(0, array, domwindow);
|
||||
}
|
||||
|
||||
NPObject* _NPN_BooleanVectorToArrayObject(WebCore::DOMWindow* domwindow,
|
||||
const std::vector<bool>& vec) {
|
||||
v8::Local<v8::Array> array = v8::Array::New();
|
||||
for (uint32_t index = 0; index < vec.size(); ++index) {
|
||||
array->Set(v8::Integer::New(index), v8::Boolean::New(vec[index]));
|
||||
}
|
||||
|
||||
return npCreateV8ScriptObject(0, array, domwindow);
|
||||
}
|
||||
|
||||
bool _NPN_ArrayObjectToStringVector(NPObject* npobject,
|
||||
std::vector<std::string>& vec) {
|
||||
if (npobject == NULL || npobject->_class != npScriptObjectClass)
|
||||
return false;
|
||||
|
||||
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
|
||||
if (!object->v8Object->IsArray())
|
||||
return false;
|
||||
|
||||
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
|
||||
for (uint32_t i = 0; i < array->Length(); i++) {
|
||||
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
|
||||
v8::Local<v8::String> sval = value->ToString();
|
||||
uint16_t* buf = new uint16_t[sval->Length()+1];
|
||||
sval->Write(buf);
|
||||
std::string utf8 = WideToUTF8(reinterpret_cast<wchar_t*>(buf));
|
||||
vec.push_back(utf8);
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _NPN_ArrayObjectToWStringVector(NPObject* npobject,
|
||||
std::vector<std::wstring>& vec) {
|
||||
if (npobject == NULL || npobject->_class != npScriptObjectClass)
|
||||
return false;
|
||||
|
||||
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
|
||||
if (!object->v8Object->IsArray())
|
||||
return false;
|
||||
|
||||
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
|
||||
for (uint32_t i = 0; i < array->Length(); i++) {
|
||||
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
|
||||
v8::Local<v8::String> sval = value->ToString();
|
||||
uint16_t* buf = new uint16_t[sval->Length()+1];
|
||||
sval->Write(buf);
|
||||
std::wstring utf16 = reinterpret_cast<wchar_t*>(buf);
|
||||
vec.push_back(utf16);
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _NPN_ArrayObjectToIntVector(NPObject* npobject,
|
||||
std::vector<int>& vec) {
|
||||
if (npobject == NULL || npobject->_class != npScriptObjectClass)
|
||||
return false;
|
||||
|
||||
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
|
||||
if (!object->v8Object->IsArray())
|
||||
return false;
|
||||
|
||||
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
|
||||
for (uint32_t i = 0; i < array->Length(); i++) {
|
||||
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
|
||||
v8::Local<v8::Int32> ival = value->ToInt32();
|
||||
vec.push_back(ival->Value());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _NPN_ArrayObjectToDoubleVector(NPObject* npobject,
|
||||
std::vector<double>& vec) {
|
||||
if (npobject == NULL || npobject->_class != npScriptObjectClass)
|
||||
return false;
|
||||
|
||||
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
|
||||
if (!object->v8Object->IsArray())
|
||||
return false;
|
||||
|
||||
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
|
||||
for (uint32_t i = 0; i < array->Length(); i++) {
|
||||
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
|
||||
v8::Local<v8::Number> dval = value->ToNumber();
|
||||
vec.push_back(dval->Value());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _NPN_ArrayObjectToBooleanVector(NPObject* npobject,
|
||||
std::vector<bool>& vec) {
|
||||
if (npobject == NULL || npobject->_class != npScriptObjectClass)
|
||||
return false;
|
||||
|
||||
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
|
||||
if (!object->v8Object->IsArray())
|
||||
return false;
|
||||
|
||||
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
|
||||
for (uint32_t i = 0; i < array->Length(); i++) {
|
||||
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
|
||||
v8::Local<v8::Boolean> bval = value->ToBoolean();
|
||||
vec.push_back(bval->Value());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int _NPN_ArrayObjectGetVectorSize(NPObject* npobject)
|
||||
{
|
||||
if (npobject == NULL || npobject->_class != npScriptObjectClass)
|
||||
return -1;
|
||||
|
||||
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
|
||||
if (!object->v8Object->IsArray())
|
||||
return -1;
|
||||
|
||||
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
|
||||
return array->Length();
|
||||
}
|
||||
|
||||
bool _NPN_ArrayObjectToVectorTypeHint(NPObject* npobject,
|
||||
NPVariantType &typehint)
|
||||
{
|
||||
if (npobject == NULL || npobject->_class != npScriptObjectClass)
|
||||
return false;
|
||||
|
||||
V8NPObject *object = reinterpret_cast<V8NPObject*>(npobject);
|
||||
if (!object->v8Object->IsArray())
|
||||
return false;
|
||||
|
||||
v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(object->v8Object);
|
||||
if (array->Length() == 0)
|
||||
return false;
|
||||
|
||||
typehint = NPVariantType_Null;
|
||||
|
||||
for (uint32_t i = 0; i < array->Length(); i++) {
|
||||
v8::Local<v8::Value> value = array->Get(v8::Integer::New(i));
|
||||
if (value->IsBoolean() && typehint <= NPVariantType_Bool) {
|
||||
if (typehint != NPVariantType_Bool)
|
||||
typehint = NPVariantType_Bool;
|
||||
} else if (value->IsInt32() && typehint <= NPVariantType_Int32) {
|
||||
if (typehint != NPVariantType_Int32)
|
||||
typehint = NPVariantType_Int32;
|
||||
} else if (value->IsNumber() && typehint <= NPVariantType_Double) {
|
||||
if (typehint != NPVariantType_Double)
|
||||
typehint = NPVariantType_Double;
|
||||
} else {
|
||||
typehint = NPVariantType_String;
|
||||
// String is the least restrictive type, so we don't need to keep looking
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
@@ -1,69 +0,0 @@
|
||||
// Copyright (c) 2008 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.
|
||||
|
||||
#ifndef _VARIANT_NP_UTIL_H
|
||||
#define _VARIANT_NP_UTIL_H
|
||||
|
||||
#include "third_party/npapi/bindings/npruntime.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
namespace WebCore {
|
||||
class DOMWindow;
|
||||
}
|
||||
|
||||
// Convert a vector of values to an NPObject, attached to the specified
|
||||
// DOM Window, that represents a JavaScript Array of the same values.
|
||||
NPObject* _NPN_StringVectorToArrayObject(WebCore::DOMWindow* domwindow,
|
||||
const std::vector<std::string>& vec);
|
||||
NPObject* _NPN_WStringVectorToArrayObject(WebCore::DOMWindow* domwindow,
|
||||
const std::vector<std::wstring>& vec);
|
||||
NPObject* _NPN_IntVectorToArrayObject(WebCore::DOMWindow* domwindow,
|
||||
const std::vector<int>& vec);
|
||||
NPObject* _NPN_DoubleVectorToArrayObject(WebCore::DOMWindow* domwindow,
|
||||
const std::vector<double>& vec);
|
||||
NPObject* _NPN_BooleanVectorToArrayObject(WebCore::DOMWindow* domwindow,
|
||||
const std::vector<bool>& vec);
|
||||
|
||||
// Convert an NPObject that represents a JavaScript Array to a vector of
|
||||
// values.
|
||||
bool _NPN_ArrayObjectToStringVector(NPObject* npobject,
|
||||
std::vector<std::string>& vec);
|
||||
bool _NPN_ArrayObjectToWStringVector(NPObject* npobject,
|
||||
std::vector<std::wstring>& vec);
|
||||
bool _NPN_ArrayObjectToIntVector(NPObject* npobject,
|
||||
std::vector<int>& vec);
|
||||
bool _NPN_ArrayObjectToDoubleVector(NPObject* npobject,
|
||||
std::vector<double>& vec);
|
||||
bool _NPN_ArrayObjectToBooleanVector(NPObject* npobject,
|
||||
std::vector<bool>& vec);
|
||||
|
||||
// Return the number of elements in a JavaScript Array. Returns -1 if the
|
||||
// JavaScript object does not represent an array.
|
||||
int _NPN_ArrayObjectGetVectorSize(NPObject* npobject);
|
||||
|
||||
// Evaluate the types of values contained in an NPObject representing a
|
||||
// JavaScript Array and suggest the most restrictive type that can safely store
|
||||
// all of the Array values. For instance, if the Array contains all Int32
|
||||
// values, the suggested type will be NPVariantType_Int32. If, on the other
|
||||
// hand, the Array contains a mix of Int32 values and String values, then the
|
||||
// suggested type will be NPVariantType_String. The supported values, from
|
||||
// most restrictive to least restrictive, are NPVariantType_Bool,
|
||||
// NPVariantType_Int32, NPVariantType_Double and NPVariantType_String. Arrays
|
||||
// that contain values of type NPVariantType_Void, NPVariantType_Null or
|
||||
// NPVariantType_Object will always result in a suggestion of type
|
||||
// NPVariantType_String.
|
||||
bool _NPN_ArrayObjectToVectorTypeHint(NPObject* npobject,
|
||||
NPVariantType &typehint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* end extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _VARIANT_NP_UTIL_H
|
@@ -1,4 +1,5 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2008-2009 The Chromium Embedded Framework Authors.
|
||||
// Portions copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -196,8 +197,6 @@ WebWidgetHost::~WebWidgetHost() {
|
||||
win_util::SetWindowUserData(view_, 0);
|
||||
|
||||
TrackMouseLeave(false);
|
||||
|
||||
webwidget_->Close();
|
||||
}
|
||||
|
||||
bool WebWidgetHost::WndProc(UINT message, WPARAM wparam, LPARAM lparam) {
|
||||
|
Reference in New Issue
Block a user