From c8a5cc9e33a6ff53413d8d772a5a200219bd0aa5 Mon Sep 17 00:00:00 2001
From: Marshall Greenblatt <magreenblatt@gmail.com>
Date: Tue, 4 Sep 2012 15:18:04 +0000
Subject: [PATCH] Allow creation of V8 objects from CEF callbacks (issue #708).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@752 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
---
 libcef/renderer/content_renderer_client.cc | 13 +++++++++++++
 libcef/renderer/v8_impl.cc                 |  6 ++++++
 2 files changed, 19 insertions(+)

diff --git a/libcef/renderer/content_renderer_client.cc b/libcef/renderer/content_renderer_client.cc
index 142141175..bc74c6fd8 100644
--- a/libcef/renderer/content_renderer_client.cc
+++ b/libcef/renderer/content_renderer_client.cc
@@ -2,6 +2,15 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include "base/compiler_specific.h"
+
+#include "third_party/WebKit/Source/WebCore/config.h"
+MSVC_PUSH_WARNING_LEVEL(0);
+#include "V8RecursionScope.h"  // NOLINT(build/include)
+#include "V8Utilities.h"  // NOLINT(build/include)
+MSVC_POP_WARNING();
+#undef LOG
+
 #include "libcef/renderer/content_renderer_client.h"
 
 #include "libcef/common/cef_messages.h"
@@ -190,6 +199,8 @@ void CefContentRendererClient::DidCreateScriptContext(
 
   v8::HandleScope handle_scope;
   v8::Context::Scope scope(context);
+  WebCore::V8RecursionScope recursion_scope(
+      WebCore::getScriptExecutionContext());
 
   CefRefPtr<CefV8Context> contextPtr(new CefV8ContextImpl(context));
 
@@ -218,6 +229,8 @@ void CefContentRendererClient::WillReleaseScriptContext(
 
   v8::HandleScope handle_scope;
   v8::Context::Scope scope(context);
+  WebCore::V8RecursionScope recursion_scope(
+      WebCore::getScriptExecutionContext());
 
   CefRefPtr<CefV8Context> contextPtr(new CefV8ContextImpl(context));
 
diff --git a/libcef/renderer/v8_impl.cc b/libcef/renderer/v8_impl.cc
index 53a19b92a..bd67a40ff 100644
--- a/libcef/renderer/v8_impl.cc
+++ b/libcef/renderer/v8_impl.cc
@@ -212,6 +212,8 @@ void GetCefString(v8::Handle<v8::String> str, CefString& out) {
 // V8 function callback.
 v8::Handle<v8::Value> FunctionCallbackImpl(const v8::Arguments& args) {
   v8::HandleScope handle_scope;
+  WebCore::V8RecursionScope recursion_scope(
+      WebCore::getScriptExecutionContext());
 
   CefV8Handler* handler =
       static_cast<CefV8Handler*>(v8::External::Unwrap(args.Data()));
@@ -244,6 +246,8 @@ v8::Handle<v8::Value> FunctionCallbackImpl(const v8::Arguments& args) {
 v8::Handle<v8::Value> AccessorGetterCallbackImpl(v8::Local<v8::String> property,
                                                  const v8::AccessorInfo& info) {
   v8::HandleScope handle_scope;
+  WebCore::V8RecursionScope recursion_scope(
+      WebCore::getScriptExecutionContext());
 
   v8::Handle<v8::Object> obj = info.This();
 
@@ -277,6 +281,8 @@ void AccessorSetterCallbackImpl(v8::Local<v8::String> property,
                                 v8::Local<v8::Value> value,
                                 const v8::AccessorInfo& info) {
   v8::HandleScope handle_scope;
+  WebCore::V8RecursionScope recursion_scope(
+      WebCore::getScriptExecutionContext());
 
   v8::Handle<v8::Object> obj = info.This();