mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Update to Chromium revision c78c0ad7 (#363565)
This commit is contained in:
@ -51,6 +51,45 @@ static const char kCefContextState[] = "Cef::ContextState";
|
||||
void MessageListenerCallbackImpl(v8::Handle<v8::Message> message,
|
||||
v8::Handle<v8::Value> data);
|
||||
|
||||
// The following *Private functions are convenience wrappers for methods on
|
||||
// v8::Object with the corresponding names.
|
||||
// Based on extensions/renderer/object_backed_native_handler.cc.
|
||||
|
||||
void SetPrivate(v8::Local<v8::Context> context,
|
||||
v8::Local<v8::Object> obj,
|
||||
const char* key,
|
||||
v8::Local<v8::Value> value) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
obj->SetPrivate(context,
|
||||
v8::Private::ForApi(isolate,
|
||||
v8::String::NewFromUtf8(isolate, key)),
|
||||
value)
|
||||
.FromJust();
|
||||
}
|
||||
|
||||
bool GetPrivate(v8::Local<v8::Context> context,
|
||||
v8::Local<v8::Object> obj,
|
||||
const char* key,
|
||||
v8::Local<v8::Value>* result) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
return obj->GetPrivate(context,
|
||||
v8::Private::ForApi(
|
||||
isolate,
|
||||
v8::String::NewFromUtf8(isolate, key)))
|
||||
.ToLocal(result);
|
||||
}
|
||||
|
||||
void DeletePrivate(v8::Local<v8::Context> context,
|
||||
v8::Local<v8::Object> obj,
|
||||
const char* key) {
|
||||
v8::Isolate* isolate = context->GetIsolate();
|
||||
obj->DeletePrivate(context,
|
||||
v8::Private::ForApi(
|
||||
isolate,
|
||||
v8::String::NewFromUtf8(isolate, key)))
|
||||
.FromJust();
|
||||
}
|
||||
|
||||
// Manages memory and state information associated with a single Isolate.
|
||||
class CefV8IsolateManager {
|
||||
public:
|
||||
@ -108,18 +147,17 @@ class CefV8IsolateManager {
|
||||
|
||||
return state;
|
||||
} else {
|
||||
v8::Local<v8::String> key =
|
||||
v8::String::NewFromUtf8(isolate_, kCefContextState);
|
||||
|
||||
v8::Local<v8::Object> object = context->Global();
|
||||
v8::Local<v8::Value> value = object->GetHiddenValue(key);
|
||||
if (!value.IsEmpty()) {
|
||||
|
||||
v8::Local<v8::Value> value;
|
||||
if (GetPrivate(context, object, kCefContextState, &value)) {
|
||||
return static_cast<CefV8ContextState*>(
|
||||
v8::External::Cast(*value)->Value());
|
||||
}
|
||||
|
||||
scoped_refptr<CefV8ContextState> state = new CefV8ContextState();
|
||||
object->SetHiddenValue(key, v8::External::New(isolate_, state.get()));
|
||||
SetPrivate(context, object, kCefContextState,
|
||||
v8::External::New(isolate_, state.get()));
|
||||
|
||||
// Reference will be released in ReleaseContext.
|
||||
state->AddRef();
|
||||
@ -143,20 +181,19 @@ class CefV8IsolateManager {
|
||||
context_map_.erase(it);
|
||||
}
|
||||
} else {
|
||||
v8::Local<v8::String> key =
|
||||
v8::String::NewFromUtf8(isolate_, kCefContextState);
|
||||
v8::Local<v8::Object> object = context->Global();
|
||||
v8::Local<v8::Value> value = object->GetHiddenValue(key);
|
||||
if (value.IsEmpty())
|
||||
return;
|
||||
|
||||
scoped_refptr<CefV8ContextState> state =
|
||||
static_cast<CefV8ContextState*>(v8::External::Cast(*value)->Value());
|
||||
state->Detach();
|
||||
object->DeleteHiddenValue(key);
|
||||
v8::Local<v8::Value> value;
|
||||
if (GetPrivate(context, object, kCefContextState, &value)) {
|
||||
scoped_refptr<CefV8ContextState> state =
|
||||
static_cast<CefV8ContextState*>(
|
||||
v8::External::Cast(*value)->Value());
|
||||
state->Detach();
|
||||
DeletePrivate(context, object, kCefContextState);
|
||||
|
||||
// Match the AddRef in GetContextState.
|
||||
state->Release();
|
||||
// Match the AddRef in GetContextState.
|
||||
state->Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,19 +360,17 @@ class V8TrackObject : public CefTrackNode {
|
||||
}
|
||||
|
||||
// Attach this track object to the specified V8 object.
|
||||
void AttachTo(v8::Local<v8::Object> object) {
|
||||
object->SetHiddenValue(v8::String::NewFromUtf8(isolate_, kCefTrackObject),
|
||||
v8::External::New(isolate_, this));
|
||||
void AttachTo(v8::Local<v8::Context> context,
|
||||
v8::Local<v8::Object> object) {
|
||||
SetPrivate(context, object, kCefTrackObject,
|
||||
v8::External::New(isolate_, this));
|
||||
}
|
||||
|
||||
// Retrieve the track object for the specified V8 object.
|
||||
static V8TrackObject* Unwrap(v8::Isolate* isolate,
|
||||
static V8TrackObject* Unwrap(v8::Local<v8::Context> context,
|
||||
v8::Local<v8::Object> object) {
|
||||
DCHECK(isolate);
|
||||
v8::Local<v8::Value> value =
|
||||
object->GetHiddenValue(
|
||||
v8::String::NewFromUtf8(isolate, kCefTrackObject));
|
||||
if (!value.IsEmpty())
|
||||
v8::Local<v8::Value> value;
|
||||
if (GetPrivate(context, object, kCefTrackObject, &value))
|
||||
return static_cast<V8TrackObject*>(v8::External::Cast(*value)->Value());
|
||||
|
||||
return NULL;
|
||||
@ -480,12 +515,13 @@ void AccessorGetterCallbackImpl(
|
||||
v8::Local<v8::String> property,
|
||||
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
v8::Local<v8::Object> obj = info.This();
|
||||
|
||||
CefRefPtr<CefV8Accessor> accessorPtr;
|
||||
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(isolate, obj);
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
||||
if (tracker)
|
||||
accessorPtr = tracker->GetAccessor();
|
||||
|
||||
@ -518,12 +554,13 @@ void AccessorSetterCallbackImpl(
|
||||
v8::Local<v8::Value> value,
|
||||
const v8::PropertyCallbackInfo<void>& info) {
|
||||
v8::Isolate* isolate = info.GetIsolate();
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
|
||||
v8::Local<v8::Object> obj = info.This();
|
||||
|
||||
CefRefPtr<CefV8Accessor> accessorPtr;
|
||||
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(isolate, obj);
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
||||
if (tracker)
|
||||
accessorPtr = tracker->GetAccessor();
|
||||
|
||||
@ -947,7 +984,7 @@ bool CefV8ContextImpl::Eval(const CefString& code,
|
||||
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(val);
|
||||
v8::Local<v8::Value> code_val = GetV8String(isolate, code);
|
||||
|
||||
v8::TryCatch try_catch;
|
||||
v8::TryCatch try_catch(isolate);
|
||||
try_catch.SetVerbose(true);
|
||||
|
||||
retval = NULL;
|
||||
@ -1172,7 +1209,7 @@ CefRefPtr<CefV8Value> CefV8Value::CreateObject(
|
||||
tracker->SetAccessor(accessor);
|
||||
|
||||
// Attach the tracker object.
|
||||
tracker->AttachTo(obj);
|
||||
tracker->AttachTo(context, obj);
|
||||
|
||||
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
||||
impl->InitObject(obj, tracker);
|
||||
@ -1200,7 +1237,7 @@ CefRefPtr<CefV8Value> CefV8Value::CreateArray(int length) {
|
||||
v8::Local<v8::Array> arr = v8::Array::New(isolate, length);
|
||||
|
||||
// Attach the tracker object.
|
||||
tracker->AttachTo(arr);
|
||||
tracker->AttachTo(context, arr);
|
||||
|
||||
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
||||
impl->InitObject(arr, tracker);
|
||||
@ -1250,7 +1287,7 @@ CefRefPtr<CefV8Value> CefV8Value::CreateFunction(
|
||||
tracker->SetHandler(handler);
|
||||
|
||||
// Attach the tracker object.
|
||||
tracker->AttachTo(func);
|
||||
tracker->AttachTo(context, func);
|
||||
|
||||
// Create the CefV8ValueImpl and provide a tracker object that will cause
|
||||
// the handler reference to be released when the V8 object is destroyed.
|
||||
@ -1567,10 +1604,17 @@ bool CefV8ValueImpl::IsUserCreated() {
|
||||
|
||||
v8::Isolate* isolate = handle_->isolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (context.IsEmpty()) {
|
||||
NOTREACHED() << "not currently in a V8 context";
|
||||
return false;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(isolate, obj);
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
||||
return (tracker != NULL);
|
||||
}
|
||||
|
||||
@ -1638,7 +1682,7 @@ bool CefV8ValueImpl::DeleteValue(const CefString& key) {
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
v8::TryCatch try_catch;
|
||||
v8::TryCatch try_catch(isolate);
|
||||
try_catch.SetVerbose(true);
|
||||
bool del = obj->Delete(GetV8String(isolate, key));
|
||||
return (!HasCaught(try_catch) && del);
|
||||
@ -1652,11 +1696,12 @@ bool CefV8ValueImpl::DeleteValue(int index) {
|
||||
return false;
|
||||
}
|
||||
|
||||
v8::HandleScope handle_scope(handle_->isolate());
|
||||
v8::Isolate* isolate = handle_->isolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
v8::TryCatch try_catch;
|
||||
v8::TryCatch try_catch(isolate);
|
||||
try_catch.SetVerbose(true);
|
||||
bool del = obj->Delete(index);
|
||||
return (!HasCaught(try_catch) && del);
|
||||
@ -1670,7 +1715,7 @@ CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(const CefString& key) {
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
v8::TryCatch try_catch;
|
||||
v8::TryCatch try_catch(isolate);
|
||||
try_catch.SetVerbose(true);
|
||||
v8::Local<v8::Value> ret_value = obj->Get(GetV8String(isolate, key));
|
||||
if (!HasCaught(try_catch) && !ret_value.IsEmpty())
|
||||
@ -1691,7 +1736,7 @@ CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(int index) {
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
v8::TryCatch try_catch;
|
||||
v8::TryCatch try_catch(isolate);
|
||||
try_catch.SetVerbose(true);
|
||||
v8::Local<v8::Value> ret_value = obj->Get(v8::Number::New(isolate, index));
|
||||
if (!HasCaught(try_catch) && !ret_value.IsEmpty())
|
||||
@ -1711,7 +1756,7 @@ bool CefV8ValueImpl::SetValue(const CefString& key,
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
v8::TryCatch try_catch;
|
||||
v8::TryCatch try_catch(isolate);
|
||||
try_catch.SetVerbose(true);
|
||||
bool set;
|
||||
// TODO(cef): This usage may not exactly match the previous implementation.
|
||||
@ -1741,11 +1786,12 @@ bool CefV8ValueImpl::SetValue(int index, CefRefPtr<CefV8Value> value) {
|
||||
|
||||
CefV8ValueImpl* impl = static_cast<CefV8ValueImpl*>(value.get());
|
||||
if (impl && impl->IsValid()) {
|
||||
v8::HandleScope handle_scope(handle_->isolate());
|
||||
v8::Isolate* isolate = handle_->isolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
v8::TryCatch try_catch;
|
||||
v8::TryCatch try_catch(isolate);
|
||||
try_catch.SetVerbose(true);
|
||||
bool set = obj->Set(index, impl->GetV8Value(true));
|
||||
return (!HasCaught(try_catch) && set);
|
||||
@ -1761,12 +1807,19 @@ bool CefV8ValueImpl::SetValue(const CefString& key, AccessControl settings,
|
||||
|
||||
v8::Isolate* isolate = handle_->isolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (context.IsEmpty()) {
|
||||
NOTREACHED() << "not currently in a V8 context";
|
||||
return false;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
CefRefPtr<CefV8Accessor> accessorPtr;
|
||||
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(isolate, obj);
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
||||
if (tracker)
|
||||
accessorPtr = tracker->GetAccessor();
|
||||
|
||||
@ -1779,7 +1832,7 @@ bool CefV8ValueImpl::SetValue(const CefString& key, AccessControl settings,
|
||||
(attribute & V8_PROPERTY_ATTRIBUTE_READONLY) ?
|
||||
NULL : AccessorSetterCallbackImpl;
|
||||
|
||||
v8::TryCatch try_catch;
|
||||
v8::TryCatch try_catch(isolate);
|
||||
try_catch.SetVerbose(true);
|
||||
bool set = obj->SetAccessor(GetV8String(isolate, key), getter, setter, obj,
|
||||
static_cast<v8::AccessControl>(settings),
|
||||
@ -1811,10 +1864,17 @@ bool CefV8ValueImpl::SetUserData(CefRefPtr<CefBase> user_data) {
|
||||
|
||||
v8::Isolate* isolate = handle_->isolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (context.IsEmpty()) {
|
||||
NOTREACHED() << "not currently in a V8 context";
|
||||
return false;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(isolate, obj);
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
||||
if (tracker) {
|
||||
tracker->SetUserData(user_data);
|
||||
return true;
|
||||
@ -1828,10 +1888,17 @@ CefRefPtr<CefBase> CefV8ValueImpl::GetUserData() {
|
||||
|
||||
v8::Isolate* isolate = handle_->isolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (context.IsEmpty()) {
|
||||
NOTREACHED() << "not currently in a V8 context";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(isolate, obj);
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
||||
if (tracker)
|
||||
return tracker->GetUserData();
|
||||
|
||||
@ -1843,10 +1910,17 @@ int CefV8ValueImpl::GetExternallyAllocatedMemory() {
|
||||
|
||||
v8::Isolate* isolate = handle_->isolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (context.IsEmpty()) {
|
||||
NOTREACHED() << "not currently in a V8 context";
|
||||
return 0;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(isolate, obj);
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
||||
if (tracker)
|
||||
return tracker->GetExternallyAllocatedMemory();
|
||||
|
||||
@ -1858,10 +1932,17 @@ int CefV8ValueImpl::AdjustExternallyAllocatedMemory(int change_in_bytes) {
|
||||
|
||||
v8::Isolate* isolate = handle_->isolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (context.IsEmpty()) {
|
||||
NOTREACHED() << "not currently in a V8 context";
|
||||
return 0;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(isolate, obj);
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
||||
if (tracker)
|
||||
return tracker->AdjustExternallyAllocatedMemory(change_in_bytes);
|
||||
|
||||
@ -1905,14 +1986,21 @@ CefRefPtr<CefV8Handler> CefV8ValueImpl::GetFunctionHandler() {
|
||||
|
||||
v8::Isolate* isolate = handle_->isolate();
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
|
||||
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
||||
if (context.IsEmpty()) {
|
||||
NOTREACHED() << "not currently in a V8 context";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
||||
if (!value->IsFunction()) {
|
||||
NOTREACHED() << "V8 value is not a function";
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> obj = value->ToObject();
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(isolate, obj);
|
||||
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
||||
if (tracker)
|
||||
return tracker->GetHandler();
|
||||
|
||||
@ -1995,7 +2083,7 @@ CefRefPtr<CefV8Value> CefV8ValueImpl::ExecuteFunctionWithContext(
|
||||
CefRefPtr<CefV8Value> retval;
|
||||
|
||||
{
|
||||
v8::TryCatch try_catch;
|
||||
v8::TryCatch try_catch(isolate);
|
||||
try_catch.SetVerbose(true);
|
||||
|
||||
v8::MaybeLocal<v8::Value> func_rv =
|
||||
|
Reference in New Issue
Block a user