From 605753c3b829a5d53102e401fe4bd42e0407e17a Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 21 Nov 2011 21:21:55 +0000 Subject: [PATCH] Replace JSBindingHandler with a new V8ContextHandler interface that contains callbacks for V8 context creation and release (issue #359). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@392 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef.gyp | 4 +- cef_paths.gypi | 4 +- include/cef.h | 42 ++++++++---- include/cef_capi.h | 41 +++++++---- libcef/browser_webview_delegate.cc | 47 +++++++++---- libcef/browser_webview_delegate.h | 5 +- libcef/v8_impl.cc | 16 +++++ libcef/v8_impl.h | 1 + libcef_dll/cpptoc/client_cpptoc.cc | 12 ++-- libcef_dll/cpptoc/jsbinding_handler_cpptoc.cc | 51 -------------- libcef_dll/cpptoc/v8context_cpptoc.cc | 13 ++++ libcef_dll/cpptoc/v8context_handler_cpptoc.cc | 68 +++++++++++++++++++ ...er_cpptoc.h => v8context_handler_cpptoc.h} | 16 ++--- libcef_dll/ctocpp/client_ctocpp.cc | 12 ++-- libcef_dll/ctocpp/client_ctocpp.h | 2 +- libcef_dll/ctocpp/jsbinding_handler_ctocpp.cc | 36 ---------- libcef_dll/ctocpp/v8context_ctocpp.cc | 8 +++ libcef_dll/ctocpp/v8context_ctocpp.h | 1 + libcef_dll/ctocpp/v8context_handler_ctocpp.cc | 46 +++++++++++++ ...er_ctocpp.h => v8context_handler_ctocpp.h} | 28 ++++---- tests/cefclient/client_handler.cpp | 8 +-- tests/cefclient/client_handler.h | 12 ++-- tests/unittests/storage_unittest.cc | 9 ++- tests/unittests/test_handler.h | 4 +- tests/unittests/v8_unittest.cc | 44 +++++++----- 25 files changed, 335 insertions(+), 195 deletions(-) delete mode 100644 libcef_dll/cpptoc/jsbinding_handler_cpptoc.cc create mode 100644 libcef_dll/cpptoc/v8context_handler_cpptoc.cc rename libcef_dll/cpptoc/{jsbinding_handler_cpptoc.h => v8context_handler_cpptoc.h} (71%) delete mode 100644 libcef_dll/ctocpp/jsbinding_handler_ctocpp.cc create mode 100644 libcef_dll/ctocpp/v8context_handler_ctocpp.cc rename libcef_dll/ctocpp/{jsbinding_handler_ctocpp.h => v8context_handler_ctocpp.h} (52%) diff --git a/cef.gyp b/cef.gyp index 320c38039..06bec05a9 100644 --- a/cef.gyp +++ b/cef.gyp @@ -451,8 +451,6 @@ 'libcef_dll/ctocpp/find_handler_ctocpp.h', 'libcef_dll/ctocpp/focus_handler_ctocpp.cc', 'libcef_dll/ctocpp/focus_handler_ctocpp.h', - 'libcef_dll/ctocpp/jsbinding_handler_ctocpp.cc', - 'libcef_dll/ctocpp/jsbinding_handler_ctocpp.h', 'libcef_dll/ctocpp/jsdialog_handler_ctocpp.cc', 'libcef_dll/ctocpp/jsdialog_handler_ctocpp.h', 'libcef_dll/ctocpp/keyboard_handler_ctocpp.cc', @@ -481,6 +479,8 @@ 'libcef_dll/ctocpp/task_ctocpp.h', 'libcef_dll/ctocpp/v8accessor_ctocpp.cc', 'libcef_dll/ctocpp/v8accessor_ctocpp.h', + 'libcef_dll/ctocpp/v8context_handler_ctocpp.cc', + 'libcef_dll/ctocpp/v8context_handler_ctocpp.h', 'libcef_dll/ctocpp/v8handler_ctocpp.cc', 'libcef_dll/ctocpp/v8handler_ctocpp.h', 'libcef_dll/ctocpp/web_urlrequest_client_ctocpp.cc', diff --git a/cef_paths.gypi b/cef_paths.gypi index cc24cca92..5f79eb3bf 100644 --- a/cef_paths.gypi +++ b/cef_paths.gypi @@ -147,8 +147,6 @@ 'libcef_dll/cpptoc/find_handler_cpptoc.h', 'libcef_dll/cpptoc/focus_handler_cpptoc.cc', 'libcef_dll/cpptoc/focus_handler_cpptoc.h', - 'libcef_dll/cpptoc/jsbinding_handler_cpptoc.cc', - 'libcef_dll/cpptoc/jsbinding_handler_cpptoc.h', 'libcef_dll/cpptoc/jsdialog_handler_cpptoc.cc', 'libcef_dll/cpptoc/jsdialog_handler_cpptoc.h', 'libcef_dll/cpptoc/keyboard_handler_cpptoc.cc', @@ -177,6 +175,8 @@ 'libcef_dll/cpptoc/task_cpptoc.h', 'libcef_dll/cpptoc/v8accessor_cpptoc.cc', 'libcef_dll/cpptoc/v8accessor_cpptoc.h', + 'libcef_dll/cpptoc/v8context_handler_cpptoc.cc', + 'libcef_dll/cpptoc/v8context_handler_cpptoc.h', 'libcef_dll/cpptoc/v8handler_cpptoc.cc', 'libcef_dll/cpptoc/v8handler_cpptoc.h', 'libcef_dll/cpptoc/web_urlrequest_client_cpptoc.cc', diff --git a/include/cef.h b/include/cef.h index 9a50e6189..83893d134 100644 --- a/include/cef.h +++ b/include/cef.h @@ -1588,20 +1588,31 @@ public: /// -// Implement this interface to handle JavaScript binding. The methods of this +// Implement this interface to handle V8 context events. The methods of this // class will be called on the UI thread. /// /*--cef(source=client)--*/ -class CefJSBindingHandler : public virtual CefBase +class CefV8ContextHandler : public virtual CefBase { public: /// - // Called for adding values to a frame's JavaScript 'window' object. + // Called immediately after the V8 context for a frame has been created. To + // retrieve the JavaScript 'window' object use the CefV8Context::GetGlobal() + // method. /// /*--cef()--*/ - virtual void OnJSBinding(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr object) {} + virtual void OnContextCreated(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr context) {} + + /// + // Called immediately before the V8 context for a frame is released. No + // references to the context should be kept after this method is called. + /// + /*--cef()--*/ + virtual void OnContextReleased(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr context) {} }; @@ -1783,10 +1794,10 @@ public: virtual CefRefPtr GetJSDialogHandler() { return NULL; } /// - // Return the handler for JavaScript binding events. + // Return the handler for V8 context events. /// /*--cef()--*/ - virtual CefRefPtr GetJSBindingHandler() { return NULL; } + virtual CefRefPtr GetV8ContextHandler() { return NULL; } /// // Return the handler for off-screen rendering events. @@ -2304,6 +2315,13 @@ public: /// /*--cef()--*/ virtual bool Exit() =0; + + /// + // Returns true if this object is pointing to the same handle as |that| + // object. + /// + /*--cef()--*/ + virtual bool IsSame(CefRefPtr that) =0; }; @@ -2478,7 +2496,7 @@ public: static CefRefPtr CreateString(const CefString& value); /// // Create a new CefV8Value object of type object. This method should only be - // called from within the scope of a CefJSBindingHandler, CefV8Handler or + // called from within the scope of a CefV8ContextHandler, CefV8Handler or // CefV8Accessor callback, or in combination with calling Enter() and Exit() // on a stored CefV8Context reference. /// @@ -2486,7 +2504,7 @@ public: static CefRefPtr CreateObject(CefRefPtr user_data); /// // Create a new CefV8Value object of type object with accessors. This method - // should only be called from within the scope of a CefJSBindingHandler, + // should only be called from within the scope of a CefV8ContextHandler, // CefV8Handler or CefV8Accessor callback, or in combination with calling // Enter() and Exit() on a stored CefV8Context reference. /// @@ -2495,7 +2513,7 @@ public: CefRefPtr accessor); /// // Create a new CefV8Value object of type array. This method should only be - // called from within the scope of a CefJSBindingHandler, CefV8Handler or + // called from within the scope of a CefV8ContextHandler, CefV8Handler or // CefV8Accessor callback, or in combination with calling Enter() and Exit() // on a stored CefV8Context reference. /// @@ -2503,7 +2521,7 @@ public: static CefRefPtr CreateArray(); /// // Create a new CefV8Value object of type function. This method should only be - // called from within the scope of a CefJSBindingHandler, CefV8Handler or + // called from within the scope of a CefV8ContextHandler, CefV8Handler or // CefV8Accessor callback, or in combination with calling Enter() and Exit() // on a stored CefV8Context reference. /// diff --git a/include/cef_capi.h b/include/cef_capi.h index 91913f7fd..975f8bf3b 100644 --- a/include/cef_capi.h +++ b/include/cef_capi.h @@ -1375,22 +1375,32 @@ typedef struct _cef_jsdialog_handler_t /// -// Implement this structure to handle JavaScript binding. The functions of this +// Implement this structure to handle V8 context events. The functions of this // structure will be called on the UI thread. /// -typedef struct _cef_jsbinding_handler_t +typedef struct _cef_v8context_handler_t { // Base structure. cef_base_t base; /// - // Called for adding values to a frame's JavaScript 'window' object. + // Called immediately after the V8 context for a frame has been created. To + // retrieve the JavaScript 'window' object use the + // cef_v8context_t::get_global() function. /// - void (CEF_CALLBACK *on_jsbinding)(struct _cef_jsbinding_handler_t* self, + void (CEF_CALLBACK *on_context_created)(struct _cef_v8context_handler_t* self, struct _cef_browser_t* browser, struct _cef_frame_t* frame, - struct _cef_v8value_t* object); + struct _cef_v8context_t* context); -} cef_jsbinding_handler_t; + /// + // Called immediately before the V8 context for a frame is released. No + // references to the context should be kept after this function is called. + /// + void (CEF_CALLBACK *on_context_released)( + struct _cef_v8context_handler_t* self, struct _cef_browser_t* browser, + struct _cef_frame_t* frame, struct _cef_v8context_t* context); + +} cef_v8context_handler_t; /// @@ -1560,9 +1570,9 @@ typedef struct _cef_client_t struct _cef_client_t* self); /// - // Return the handler for JavaScript binding events. + // Return the handler for V8 context events. /// - struct _cef_jsbinding_handler_t* (CEF_CALLBACK *get_jsbinding_handler)( + struct _cef_v8context_handler_t* (CEF_CALLBACK *get_v8context_handler)( struct _cef_client_t* self); /// @@ -2068,6 +2078,13 @@ typedef struct _cef_v8context_t /// int (CEF_CALLBACK *exit)(struct _cef_v8context_t* self); + /// + // Returns true (1) if this object is pointing to the same handle as |that| + // object. + /// + int (CEF_CALLBACK *is_same)(struct _cef_v8context_t* self, + struct _cef_v8context_t* that); + } cef_v8context_t; @@ -2478,7 +2495,7 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_string(const cef_string_t* value); /// // Create a new cef_v8value_t object of type object. This function should only -// be called from within the scope of a cef_jsbinding_handler_t, cef_v8handler_t +// be called from within the scope of a cef_v8context_tHandler, cef_v8handler_t // or cef_v8accessor_t callback, or in combination with calling enter() and // exit() on a stored cef_v8context_t reference. /// @@ -2487,7 +2504,7 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_object(cef_base_t* user_data); /// // Create a new cef_v8value_t object of type object with accessors. This // function should only be called from within the scope of a -// cef_jsbinding_handler_t, cef_v8handler_t or cef_v8accessor_t callback, or in +// cef_v8context_tHandler, cef_v8handler_t or cef_v8accessor_t callback, or in // combination with calling enter() and exit() on a stored cef_v8context_t // reference. /// @@ -2496,7 +2513,7 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_object_with_accessor( /// // Create a new cef_v8value_t object of type array. This function should only be -// called from within the scope of a cef_jsbinding_handler_t, cef_v8handler_t or +// called from within the scope of a cef_v8context_tHandler, cef_v8handler_t or // cef_v8accessor_t callback, or in combination with calling enter() and exit() // on a stored cef_v8context_t reference. /// @@ -2504,7 +2521,7 @@ CEF_EXPORT cef_v8value_t* cef_v8value_create_array(); /// // Create a new cef_v8value_t object of type function. This function should only -// be called from within the scope of a cef_jsbinding_handler_t, cef_v8handler_t +// be called from within the scope of a cef_v8context_tHandler, cef_v8handler_t // or cef_v8accessor_t callback, or in combination with calling enter() and // exit() on a stored cef_v8context_t reference. /// diff --git a/libcef/browser_webview_delegate.cc b/libcef/browser_webview_delegate.cc index b0de7eb68..32fc98591 100644 --- a/libcef/browser_webview_delegate.cc +++ b/libcef/browser_webview_delegate.cc @@ -844,23 +844,42 @@ void BrowserWebViewDelegate::didCommitProvisionalLoad( } } -void BrowserWebViewDelegate::didClearWindowObject(WebFrame* frame) { +void BrowserWebViewDelegate::didCreateScriptContext( + WebFrame* frame, v8::Handle context, int worldId) { CefRefPtr client = browser_->GetClient(); - if (client.get()) { - CefRefPtr handler = client->GetJSBindingHandler(); - if (handler.get()) { - v8::HandleScope handle_scope; - v8::Handle context = webkit_glue::GetV8Context(frame); - if(context.IsEmpty()) - return; + if (!client.get()) + return; - v8::Context::Scope scope(context); + CefRefPtr handler = client->GetV8ContextHandler(); + if (!handler.get()) + return; - CefRefPtr cframe(browser_->UIT_GetCefFrame(frame)); - CefRefPtr object = new CefV8ValueImpl(context->Global()); - handler->OnJSBinding(browser_, cframe, object); - } - } + v8::HandleScope handle_scope; + v8::Context::Scope scope(context); + + CefRefPtr framePtr(browser_->UIT_GetCefFrame(frame)); + CefRefPtr contextPtr(new CefV8ContextImpl(context)); + + handler->OnContextCreated(browser_, framePtr, contextPtr); +} + +void BrowserWebViewDelegate::willReleaseScriptContext( + WebFrame* frame, v8::Handle context, int worldId) { + CefRefPtr client = browser_->GetClient(); + if (!client.get()) + return; + + CefRefPtr handler = client->GetV8ContextHandler(); + if (!handler.get()) + return; + + v8::HandleScope handle_scope; + v8::Context::Scope scope(context); + + CefRefPtr framePtr(browser_->UIT_GetCefFrame(frame)); + CefRefPtr contextPtr(new CefV8ContextImpl(context)); + + handler->OnContextReleased(browser_, framePtr, contextPtr); } void BrowserWebViewDelegate::didReceiveTitle( diff --git a/libcef/browser_webview_delegate.h b/libcef/browser_webview_delegate.h index e6dc84a28..6da18e351 100644 --- a/libcef/browser_webview_delegate.h +++ b/libcef/browser_webview_delegate.h @@ -166,7 +166,10 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient, WebKit::WebFrame*, const WebKit::WebURLError&) OVERRIDE; virtual void didCommitProvisionalLoad( WebKit::WebFrame*, bool is_new_navigation) OVERRIDE; - virtual void didClearWindowObject(WebKit::WebFrame*) OVERRIDE; + virtual void didCreateScriptContext( + WebKit::WebFrame*, v8::Handle, int worldId) OVERRIDE; + virtual void willReleaseScriptContext( + WebKit::WebFrame*, v8::Handle, int worldId) OVERRIDE; virtual void didReceiveTitle( WebKit::WebFrame*, const WebKit::WebString& title, WebKit::WebTextDirection direction) OVERRIDE; diff --git a/libcef/v8_impl.cc b/libcef/v8_impl.cc index 8849af6c4..0a767f110 100644 --- a/libcef/v8_impl.cc +++ b/libcef/v8_impl.cc @@ -470,6 +470,22 @@ bool CefV8ContextImpl::Exit() return true; } +bool CefV8ContextImpl::IsSame(CefRefPtr that) +{ + CEF_REQUIRE_UI_THREAD(false); + + v8::HandleScope handle_scope; + + v8::Local thatHandle; + v8::Local thisHandle = GetContext(); + + CefV8ContextImpl *impl = static_cast(that.get()); + if (impl) + thatHandle = impl->GetContext(); + + return (thisHandle == thatHandle); +} + v8::Local CefV8ContextImpl::GetContext() { return v8::Local::New(v8_context_->GetHandle()); diff --git a/libcef/v8_impl.h b/libcef/v8_impl.h index 342a54d55..4eec22753 100644 --- a/libcef/v8_impl.h +++ b/libcef/v8_impl.h @@ -70,6 +70,7 @@ public: virtual CefRefPtr GetGlobal() OVERRIDE; virtual bool Enter() OVERRIDE; virtual bool Exit() OVERRIDE; + virtual bool IsSame(CefRefPtr that) OVERRIDE; v8::Local GetContext(); WebKit::WebFrame* GetWebFrame(); diff --git a/libcef_dll/cpptoc/client_cpptoc.cc b/libcef_dll/cpptoc/client_cpptoc.cc index 4d5770149..0688f9544 100644 --- a/libcef_dll/cpptoc/client_cpptoc.cc +++ b/libcef_dll/cpptoc/client_cpptoc.cc @@ -15,7 +15,6 @@ #include "libcef_dll/cpptoc/drag_handler_cpptoc.h" #include "libcef_dll/cpptoc/find_handler_cpptoc.h" #include "libcef_dll/cpptoc/focus_handler_cpptoc.h" -#include "libcef_dll/cpptoc/jsbinding_handler_cpptoc.h" #include "libcef_dll/cpptoc/jsdialog_handler_cpptoc.h" #include "libcef_dll/cpptoc/keyboard_handler_cpptoc.h" #include "libcef_dll/cpptoc/life_span_handler_cpptoc.h" @@ -24,6 +23,7 @@ #include "libcef_dll/cpptoc/print_handler_cpptoc.h" #include "libcef_dll/cpptoc/render_handler_cpptoc.h" #include "libcef_dll/cpptoc/request_handler_cpptoc.h" +#include "libcef_dll/cpptoc/v8context_handler_cpptoc.h" // MEMBER FUNCTIONS - Body may be edited by hand. @@ -178,17 +178,17 @@ cef_jsdialog_handler_t* CEF_CALLBACK client_get_jsdialog_handler( return NULL; } -cef_jsbinding_handler_t* CEF_CALLBACK client_get_jsbinding_handler( +cef_v8context_handler_t* CEF_CALLBACK client_get_v8context_handler( struct _cef_client_t* self) { DCHECK(self); if (!self) return NULL; - CefRefPtr handlerPtr = - CefClientCppToC::Get(self)->GetJSBindingHandler(); + CefRefPtr handlerPtr = + CefClientCppToC::Get(self)->GetV8ContextHandler(); if(handlerPtr.get()) - return CefJSBindingHandlerCppToC::Wrap(handlerPtr); + return CefV8ContextHandlerCppToC::Wrap(handlerPtr); return NULL; } @@ -239,7 +239,7 @@ CefClientCppToC::CefClientCppToC(CefClient* cls) struct_.struct_.get_print_handler = client_get_print_handler; struct_.struct_.get_find_handler = client_get_find_handler; struct_.struct_.get_jsdialog_handler = client_get_jsdialog_handler; - struct_.struct_.get_jsbinding_handler = client_get_jsbinding_handler; + struct_.struct_.get_v8context_handler = client_get_v8context_handler; struct_.struct_.get_render_handler = client_get_render_handler; struct_.struct_.get_drag_handler = client_get_drag_handler; } diff --git a/libcef_dll/cpptoc/jsbinding_handler_cpptoc.cc b/libcef_dll/cpptoc/jsbinding_handler_cpptoc.cc deleted file mode 100644 index 2723fec5d..000000000 --- a/libcef_dll/cpptoc/jsbinding_handler_cpptoc.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2011 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. -// -// --------------------------------------------------------------------------- -// -// A portion of this file was generated by the CEF translator tool. When -// making changes by hand only do so within the body of existing function -// implementations. See the translator.README.txt file in the tools directory -// for more information. -// - -#include "libcef_dll/cpptoc/jsbinding_handler_cpptoc.h" -#include "libcef_dll/ctocpp/browser_ctocpp.h" -#include "libcef_dll/ctocpp/frame_ctocpp.h" -#include "libcef_dll/ctocpp/v8value_ctocpp.h" - - -// MEMBER FUNCTIONS - Body may be edited by hand. - -void CEF_CALLBACK jsbinding_handler_on_jsbinding( - struct _cef_jsbinding_handler_t* self, cef_browser_t* browser, - cef_frame_t* frame, struct _cef_v8value_t* object) -{ - DCHECK(self); - DCHECK(browser); - DCHECK(frame); - DCHECK(object); - if (!self || !browser || !frame || !object) - return; - - return CefJSBindingHandlerCppToC::Get(self)->OnJSBinding( - CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), - CefV8ValueCToCpp::Wrap(object)); -} - - -// CONSTRUCTOR - Do not edit by hand. - -CefJSBindingHandlerCppToC::CefJSBindingHandlerCppToC(CefJSBindingHandler* cls) - : CefCppToC(cls) -{ - struct_.struct_.on_jsbinding = jsbinding_handler_on_jsbinding; -} - -#ifndef NDEBUG -template<> long CefCppToC::DebugObjCt = 0; -#endif - diff --git a/libcef_dll/cpptoc/v8context_cpptoc.cc b/libcef_dll/cpptoc/v8context_cpptoc.cc index 93f75d86a..f38a5c045 100644 --- a/libcef_dll/cpptoc/v8context_cpptoc.cc +++ b/libcef_dll/cpptoc/v8context_cpptoc.cc @@ -104,6 +104,18 @@ int CEF_CALLBACK v8context_exit(struct _cef_v8context_t* self) return contextPtr->Exit(); } +int CEF_CALLBACK v8context_is_same(struct _cef_v8context_t* self, + struct _cef_v8context_t* that) +{ + DCHECK(self); + DCHECK(that); + if (!self || !that) + return false; + + return CefV8ContextCppToC::Get(self)->IsSame( + CefV8ContextCppToC::Unwrap(that)); +} + // CONSTRUCTOR - Do not edit by hand. @@ -115,6 +127,7 @@ CefV8ContextCppToC::CefV8ContextCppToC(CefV8Context* cls) struct_.struct_.get_global = v8context_get_global; struct_.struct_.enter = v8context_enter; struct_.struct_.exit = v8context_exit; + struct_.struct_.is_same = v8context_is_same; } #ifndef NDEBUG diff --git a/libcef_dll/cpptoc/v8context_handler_cpptoc.cc b/libcef_dll/cpptoc/v8context_handler_cpptoc.cc new file mode 100644 index 000000000..112cd7a2a --- /dev/null +++ b/libcef_dll/cpptoc/v8context_handler_cpptoc.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2011 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. +// +// --------------------------------------------------------------------------- +// +// A portion of this file was generated by the CEF translator tool. When +// making changes by hand only do so within the body of existing function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// + +#include "libcef_dll/cpptoc/v8context_handler_cpptoc.h" +#include "libcef_dll/ctocpp/browser_ctocpp.h" +#include "libcef_dll/ctocpp/frame_ctocpp.h" +#include "libcef_dll/ctocpp/v8context_ctocpp.h" + + +// MEMBER FUNCTIONS - Body may be edited by hand. + +void CEF_CALLBACK v8context_handler_on_context_created( + struct _cef_v8context_handler_t* self, cef_browser_t* browser, + cef_frame_t* frame, struct _cef_v8context_t* context) +{ + DCHECK(self); + DCHECK(browser); + DCHECK(frame); + DCHECK(context); + if (!self || !browser || !frame || !context) + return; + + CefV8ContextHandlerCppToC::Get(self)->OnContextCreated( + CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), + CefV8ContextCToCpp::Wrap(context)); +} + +void CEF_CALLBACK v8context_handler_on_context_released( + struct _cef_v8context_handler_t* self, cef_browser_t* browser, + cef_frame_t* frame, struct _cef_v8context_t* context) +{ + DCHECK(self); + DCHECK(browser); + DCHECK(frame); + DCHECK(context); + if (!self || !browser || !frame || !context) + return; + + CefV8ContextHandlerCppToC::Get(self)->OnContextReleased( + CefBrowserCToCpp::Wrap(browser), CefFrameCToCpp::Wrap(frame), + CefV8ContextCToCpp::Wrap(context)); +} + + +// CONSTRUCTOR - Do not edit by hand. + +CefV8ContextHandlerCppToC::CefV8ContextHandlerCppToC(CefV8ContextHandler* cls) + : CefCppToC(cls) +{ + struct_.struct_.on_context_created = v8context_handler_on_context_created; + struct_.struct_.on_context_released = v8context_handler_on_context_released; +} + +#ifndef NDEBUG +template<> long CefCppToC::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/cpptoc/jsbinding_handler_cpptoc.h b/libcef_dll/cpptoc/v8context_handler_cpptoc.h similarity index 71% rename from libcef_dll/cpptoc/jsbinding_handler_cpptoc.h rename to libcef_dll/cpptoc/v8context_handler_cpptoc.h index 3a9b3ed4d..f67422bc4 100644 --- a/libcef_dll/cpptoc/jsbinding_handler_cpptoc.h +++ b/libcef_dll/cpptoc/v8context_handler_cpptoc.h @@ -8,8 +8,8 @@ // by hand. See the translator.README.txt file in the tools directory for // more information. // -#ifndef _JSBINDINGHANDLER_CPPTOC_H -#define _JSBINDINGHANDLER_CPPTOC_H +#ifndef _V8CONTEXTHANDLER_CPPTOC_H +#define _V8CONTEXTHANDLER_CPPTOC_H #ifndef USING_CEF_SHARED #pragma message("Warning: "__FILE__" may be accessed wrapper-side only") @@ -21,15 +21,15 @@ // Wrap a C++ class with a C structure. // This class may be instantiated and accessed wrapper-side only. -class CefJSBindingHandlerCppToC - : public CefCppToC +class CefV8ContextHandlerCppToC + : public CefCppToC { public: - CefJSBindingHandlerCppToC(CefJSBindingHandler* cls); - virtual ~CefJSBindingHandlerCppToC() {} + CefV8ContextHandlerCppToC(CefV8ContextHandler* cls); + virtual ~CefV8ContextHandlerCppToC() {} }; #endif // USING_CEF_SHARED -#endif // _JSBINDINGHANDLER_CPPTOC_H +#endif // _V8CONTEXTHANDLER_CPPTOC_H diff --git a/libcef_dll/ctocpp/client_ctocpp.cc b/libcef_dll/ctocpp/client_ctocpp.cc index 9bce2b6f2..4be57bc3e 100644 --- a/libcef_dll/ctocpp/client_ctocpp.cc +++ b/libcef_dll/ctocpp/client_ctocpp.cc @@ -15,7 +15,6 @@ #include "libcef_dll/ctocpp/drag_handler_ctocpp.h" #include "libcef_dll/ctocpp/find_handler_ctocpp.h" #include "libcef_dll/ctocpp/focus_handler_ctocpp.h" -#include "libcef_dll/ctocpp/jsbinding_handler_ctocpp.h" #include "libcef_dll/ctocpp/jsdialog_handler_ctocpp.h" #include "libcef_dll/ctocpp/keyboard_handler_ctocpp.h" #include "libcef_dll/ctocpp/life_span_handler_ctocpp.h" @@ -24,6 +23,7 @@ #include "libcef_dll/ctocpp/print_handler_ctocpp.h" #include "libcef_dll/ctocpp/render_handler_ctocpp.h" #include "libcef_dll/ctocpp/request_handler_ctocpp.h" +#include "libcef_dll/ctocpp/v8context_handler_ctocpp.h" // VIRTUAL METHODS - Body may be edited by hand. @@ -151,15 +151,15 @@ CefRefPtr CefClientCToCpp::GetJSDialogHandler() return NULL; } -CefRefPtr CefClientCToCpp::GetJSBindingHandler() +CefRefPtr CefClientCToCpp::GetV8ContextHandler() { - if (CEF_MEMBER_MISSING(struct_, get_jsbinding_handler)) + if (CEF_MEMBER_MISSING(struct_, get_v8context_handler)) return NULL; - cef_jsbinding_handler_t* handlerStruct = - struct_->get_jsbinding_handler(struct_); + cef_v8context_handler_t* handlerStruct = + struct_->get_v8context_handler(struct_); if(handlerStruct) - return CefJSBindingHandlerCToCpp::Wrap(handlerStruct); + return CefV8ContextHandlerCToCpp::Wrap(handlerStruct); return NULL; } diff --git a/libcef_dll/ctocpp/client_ctocpp.h b/libcef_dll/ctocpp/client_ctocpp.h index 962794bd8..ae4d13706 100644 --- a/libcef_dll/ctocpp/client_ctocpp.h +++ b/libcef_dll/ctocpp/client_ctocpp.h @@ -41,7 +41,7 @@ public: virtual CefRefPtr GetPrintHandler() OVERRIDE; virtual CefRefPtr GetFindHandler() OVERRIDE; virtual CefRefPtr GetJSDialogHandler() OVERRIDE; - virtual CefRefPtr GetJSBindingHandler() OVERRIDE; + virtual CefRefPtr GetV8ContextHandler() OVERRIDE; virtual CefRefPtr GetRenderHandler() OVERRIDE; virtual CefRefPtr GetDragHandler() OVERRIDE; }; diff --git a/libcef_dll/ctocpp/jsbinding_handler_ctocpp.cc b/libcef_dll/ctocpp/jsbinding_handler_ctocpp.cc deleted file mode 100644 index 07b6c3e5f..000000000 --- a/libcef_dll/ctocpp/jsbinding_handler_ctocpp.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2011 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. -// -// --------------------------------------------------------------------------- -// -// A portion of this file was generated by the CEF translator tool. When -// making changes by hand only do so within the body of existing static and -// virtual method implementations. See the translator.README.txt file in the -// tools directory for more information. -// - -#include "libcef_dll/cpptoc/browser_cpptoc.h" -#include "libcef_dll/cpptoc/frame_cpptoc.h" -#include "libcef_dll/cpptoc/v8value_cpptoc.h" -#include "libcef_dll/ctocpp/jsbinding_handler_ctocpp.h" - - -// VIRTUAL METHODS - Body may be edited by hand. - -void CefJSBindingHandlerCToCpp::OnJSBinding(CefRefPtr browser, - CefRefPtr frame, CefRefPtr object) -{ - if (CEF_MEMBER_MISSING(struct_, on_jsbinding)) - return; - - struct_->on_jsbinding(struct_, CefBrowserCppToC::Wrap(browser), - CefFrameCppToC::Wrap(frame), CefV8ValueCppToC::Wrap(object)); -} - - -#ifndef NDEBUG -template<> long CefCToCpp::DebugObjCt = 0; -#endif - diff --git a/libcef_dll/ctocpp/v8context_ctocpp.cc b/libcef_dll/ctocpp/v8context_ctocpp.cc index ad63bfeac..9a86c8881 100644 --- a/libcef_dll/ctocpp/v8context_ctocpp.cc +++ b/libcef_dll/ctocpp/v8context_ctocpp.cc @@ -94,6 +94,14 @@ bool CefV8ContextCToCpp::Exit() return struct_->exit(struct_)?true:false; } +bool CefV8ContextCToCpp::IsSame(CefRefPtr that) +{ + if (CEF_MEMBER_MISSING(struct_, is_same)) + return false; + + return struct_->is_same(struct_, CefV8ContextCToCpp::Unwrap(that))?true:false; +} + #ifndef NDEBUG template<> long CefCToCpp GetGlobal() OVERRIDE; virtual bool Enter() OVERRIDE; virtual bool Exit() OVERRIDE; + virtual bool IsSame(CefRefPtr that) OVERRIDE; }; #endif // USING_CEF_SHARED diff --git a/libcef_dll/ctocpp/v8context_handler_ctocpp.cc b/libcef_dll/ctocpp/v8context_handler_ctocpp.cc new file mode 100644 index 000000000..7438c9221 --- /dev/null +++ b/libcef_dll/ctocpp/v8context_handler_ctocpp.cc @@ -0,0 +1,46 @@ +// Copyright (c) 2011 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. +// +// --------------------------------------------------------------------------- +// +// A portion of this file was generated by the CEF translator tool. When +// making changes by hand only do so within the body of existing static and +// virtual method implementations. See the translator.README.txt file in the +// tools directory for more information. +// + +#include "libcef_dll/cpptoc/browser_cpptoc.h" +#include "libcef_dll/cpptoc/frame_cpptoc.h" +#include "libcef_dll/cpptoc/v8context_cpptoc.h" +#include "libcef_dll/ctocpp/v8context_handler_ctocpp.h" + + +// VIRTUAL METHODS - Body may be edited by hand. + +void CefV8ContextHandlerCToCpp::OnContextCreated(CefRefPtr browser, + CefRefPtr frame, CefRefPtr context) +{ + if (CEF_MEMBER_MISSING(struct_, on_context_created)) + return; + + struct_->on_context_created(struct_, CefBrowserCppToC::Wrap(browser), + CefFrameCppToC::Wrap(frame), CefV8ContextCppToC::Wrap(context)); +} + +void CefV8ContextHandlerCToCpp::OnContextReleased(CefRefPtr browser, + CefRefPtr frame, CefRefPtr context) +{ + if (CEF_MEMBER_MISSING(struct_, on_context_released)) + return; + + struct_->on_context_released(struct_, CefBrowserCppToC::Wrap(browser), + CefFrameCppToC::Wrap(frame), CefV8ContextCppToC::Wrap(context)); +} + + +#ifndef NDEBUG +template<> long CefCToCpp::DebugObjCt = 0; +#endif + diff --git a/libcef_dll/ctocpp/jsbinding_handler_ctocpp.h b/libcef_dll/ctocpp/v8context_handler_ctocpp.h similarity index 52% rename from libcef_dll/ctocpp/jsbinding_handler_ctocpp.h rename to libcef_dll/ctocpp/v8context_handler_ctocpp.h index 8b4b0c4ee..eb81531b5 100644 --- a/libcef_dll/ctocpp/jsbinding_handler_ctocpp.h +++ b/libcef_dll/ctocpp/v8context_handler_ctocpp.h @@ -9,8 +9,8 @@ // more information. // -#ifndef _JSBINDINGHANDLER_CTOCPP_H -#define _JSBINDINGHANDLER_CTOCPP_H +#ifndef _V8CONTEXTHANDLER_CTOCPP_H +#define _V8CONTEXTHANDLER_CTOCPP_H #ifndef BUILDING_CEF_SHARED #pragma message("Warning: "__FILE__" may be accessed DLL-side only") @@ -22,21 +22,23 @@ // Wrap a C structure with a C++ class. // This class may be instantiated and accessed DLL-side only. -class CefJSBindingHandlerCToCpp - : public CefCToCpp +class CefV8ContextHandlerCToCpp + : public CefCToCpp { public: - CefJSBindingHandlerCToCpp(cef_jsbinding_handler_t* str) - : CefCToCpp(str) {} - virtual ~CefJSBindingHandlerCToCpp() {} + CefV8ContextHandlerCToCpp(cef_v8context_handler_t* str) + : CefCToCpp(str) {} + virtual ~CefV8ContextHandlerCToCpp() {} - // CefJSBindingHandler methods - virtual void OnJSBinding(CefRefPtr browser, - CefRefPtr frame, CefRefPtr object) OVERRIDE; + // CefV8ContextHandler methods + virtual void OnContextCreated(CefRefPtr browser, + CefRefPtr frame, CefRefPtr context) OVERRIDE; + virtual void OnContextReleased(CefRefPtr browser, + CefRefPtr frame, CefRefPtr context) OVERRIDE; }; #endif // BUILDING_CEF_SHARED -#endif // _JSBINDINGHANDLER_CTOCPP_H +#endif // _V8CONTEXTHANDLER_CTOCPP_H diff --git a/tests/cefclient/client_handler.cpp b/tests/cefclient/client_handler.cpp index 584b3810e..a800874ca 100644 --- a/tests/cefclient/client_handler.cpp +++ b/tests/cefclient/client_handler.cpp @@ -263,14 +263,14 @@ bool ClientHandler::GetPrintHeaderFooter(CefRefPtr browser, return false; } -void ClientHandler::OnJSBinding(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr object) +void ClientHandler::OnContextCreated(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr context) { REQUIRE_UI_THREAD(); // Add the V8 bindings. - InitBindingTest(browser, frame, object); + InitBindingTest(browser, frame, context->GetGlobal()); } bool ClientHandler::OnDragStart(CefRefPtr browser, diff --git a/tests/cefclient/client_handler.h b/tests/cefclient/client_handler.h index fe7f9e4a0..42983c93b 100644 --- a/tests/cefclient/client_handler.h +++ b/tests/cefclient/client_handler.h @@ -24,7 +24,7 @@ class ClientHandler : public CefClient, public CefFocusHandler, public CefKeyboardHandler, public CefPrintHandler, - public CefJSBindingHandler, + public CefV8ContextHandler, public CefDragHandler, public DownloadListener { @@ -47,7 +47,7 @@ public: { return this; } virtual CefRefPtr GetPrintHandler() OVERRIDE { return this; } - virtual CefRefPtr GetJSBindingHandler() OVERRIDE + virtual CefRefPtr GetV8ContextHandler() OVERRIDE { return this; } virtual CefRefPtr GetDragHandler() OVERRIDE { return this; } @@ -131,10 +131,10 @@ public: CefString& bottomCenter, CefString& bottomRight) OVERRIDE; - // CefJSBindingHandler methods - virtual void OnJSBinding(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr object) OVERRIDE; + // CefV8ContextHandler methods + virtual void OnContextCreated(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr context) OVERRIDE; // CefDragHandler methods. virtual bool OnDragStart(CefRefPtr browser, diff --git a/tests/unittests/storage_unittest.cc b/tests/unittests/storage_unittest.cc index 7dc34eaff..c748efc84 100644 --- a/tests/unittests/storage_unittest.cc +++ b/tests/unittests/storage_unittest.cc @@ -323,10 +323,13 @@ public: } } - virtual void OnJSBinding(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr object) OVERRIDE + virtual void OnContextCreated(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr context) OVERRIDE { + // Retrieve the 'window' object. + CefRefPtr object = context->GetGlobal(); + CefRefPtr handler = new V8Handler(this); CefRefPtr testObj = CefV8Value::CreateObject(NULL, NULL); testObj->SetValue("result", CefV8Value::CreateFunction("result", handler), diff --git a/tests/unittests/test_handler.h b/tests/unittests/test_handler.h index a0e29cf3c..d014fe18e 100644 --- a/tests/unittests/test_handler.h +++ b/tests/unittests/test_handler.h @@ -28,7 +28,7 @@ class TestHandler : public CefClient, public CefLifeSpanHandler, public CefLoadHandler, public CefRequestHandler, - public CefJSBindingHandler + public CefV8ContextHandler { public: TestHandler() : browser_hwnd_(NULL), completion_event_(true, false) @@ -51,7 +51,7 @@ public: { return this; } virtual CefRefPtr GetRequestHandler() OVERRIDE { return this; } - virtual CefRefPtr GetJSBindingHandler() OVERRIDE + virtual CefRefPtr GetV8ContextHandler() OVERRIDE { return this; } // CefLifeSpanHandler methods diff --git a/tests/unittests/v8_unittest.cc b/tests/unittests/v8_unittest.cc index eda4bc794..4624347e2 100644 --- a/tests/unittests/v8_unittest.cc +++ b/tests/unittests/v8_unittest.cc @@ -286,12 +286,12 @@ public: DestroyTest(); } - virtual void OnJSBinding(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr object) OVERRIDE + virtual void OnContextCreated(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr context) OVERRIDE { if(binding_test_) - TestHandleJSBinding(browser, frame, object); + TestHandleJSBinding(browser, frame, context->GetGlobal()); } void TestHandleJSBinding(CefRefPtr browser, @@ -453,10 +453,13 @@ public: DestroyTest(); } - virtual void OnJSBinding(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr object) OVERRIDE + virtual void OnContextCreated(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr context) OVERRIDE { + // Retrieve the 'window' object. + CefRefPtr object = context->GetGlobal(); + // Create the functions that will be used during the test. CefRefPtr obj = CefV8Value::CreateObject(NULL, NULL); CefRefPtr handler = new TestHandler(this); @@ -683,10 +686,13 @@ public: { } - virtual void OnJSBinding(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr object) OVERRIDE + virtual void OnContextCreated(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr context) OVERRIDE { + // Retrieve the 'window' object. + CefRefPtr object = context->GetGlobal(); + CefRefPtr cc = CefV8Context::GetCurrentContext(); CefRefPtr currentBrowser = cc->GetBrowser(); CefRefPtr currentFrame = cc->GetFrame(); @@ -1374,10 +1380,13 @@ public: nav_++; } - virtual void OnJSBinding(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr object) OVERRIDE + virtual void OnContextCreated(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr context) OVERRIDE { + // Retrieve the 'window' object. + CefRefPtr object = context->GetGlobal(); + if (nav_ == 0) { // Create an object without any internal values. CefRefPtr obj1 = CefV8Value::CreateObject(NULL, NULL); @@ -1669,10 +1678,13 @@ public: 3, false)); } - virtual void OnJSBinding(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr object) OVERRIDE + virtual void OnContextCreated(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr context) OVERRIDE { + // Retrieve the 'window' object. + CefRefPtr object = context->GetGlobal(); + // Create the functions that will be used during the test. CefRefPtr obj = CefV8Value::CreateObject(NULL, NULL); CefRefPtr handler = new TestHandler(this);