mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Support implicit detachment of CEF V8 references when the associated context is released (issue #484).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@883 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@ -19,25 +19,65 @@ namespace WebKit {
|
||||
class WebFrame;
|
||||
};
|
||||
|
||||
// Call to detach all handles associated with the specified contxt.
|
||||
void CefV8ReleaseContext(v8::Handle<v8::Context> context);
|
||||
|
||||
// Used to detach handles when the associated context is released.
|
||||
class CefV8ContextState : public base::RefCounted<CefV8ContextState> {
|
||||
public:
|
||||
CefV8ContextState() : valid_(true) {}
|
||||
virtual ~CefV8ContextState() {}
|
||||
|
||||
bool IsValid() { return valid_; }
|
||||
void Detach() { valid_ = false; }
|
||||
|
||||
private:
|
||||
bool valid_;
|
||||
};
|
||||
|
||||
// Base class for V8 Handle types.
|
||||
class CefV8HandleBase :
|
||||
public base::RefCountedThreadSafe<CefV8HandleBase,
|
||||
CefThread::DeleteOnUIThread> {
|
||||
public:
|
||||
virtual ~CefV8HandleBase() {}
|
||||
|
||||
// Returns true if there is no underlying context or if the underlying context
|
||||
// is valid.
|
||||
bool IsValid() {
|
||||
return (!context_state_.get() || context_state_->IsValid());
|
||||
}
|
||||
|
||||
protected:
|
||||
// |context| is the context that owns this handle. If empty the current
|
||||
// context will be used.
|
||||
explicit CefV8HandleBase(v8::Handle<v8::Context> context);
|
||||
|
||||
private:
|
||||
scoped_refptr<CefV8ContextState> context_state_;
|
||||
};
|
||||
|
||||
// Template for V8 Handle types. This class is used to ensure that V8 objects
|
||||
// are only released on the UI thread.
|
||||
template <typename v8class>
|
||||
class CefV8Handle :
|
||||
public base::RefCountedThreadSafe<CefV8Handle<v8class>,
|
||||
CefThread::DeleteOnUIThread> {
|
||||
class CefV8Handle : public CefV8HandleBase {
|
||||
public:
|
||||
typedef v8::Handle<v8class> handleType;
|
||||
typedef v8::Persistent<v8class> persistentType;
|
||||
|
||||
CefV8Handle(handleType v)
|
||||
: handle_(persistentType::New(v)) {
|
||||
CefV8Handle(v8::Handle<v8::Context> context, handleType v)
|
||||
: CefV8HandleBase(context),
|
||||
handle_(persistentType::New(v)) {
|
||||
}
|
||||
~CefV8Handle() {
|
||||
virtual ~CefV8Handle() {
|
||||
handle_.Dispose();
|
||||
handle_.Clear();
|
||||
}
|
||||
|
||||
handleType GetHandle() { return handle_; }
|
||||
handleType GetHandle() {
|
||||
DCHECK(IsValid());
|
||||
return handle_;
|
||||
}
|
||||
|
||||
protected:
|
||||
persistentType handle_;
|
||||
@ -57,6 +97,7 @@ class CefV8ContextImpl : public CefV8Context {
|
||||
explicit CefV8ContextImpl(v8::Handle<v8::Context> context);
|
||||
virtual ~CefV8ContextImpl();
|
||||
|
||||
virtual bool IsValid() OVERRIDE;
|
||||
virtual CefRefPtr<CefBrowser> GetBrowser() OVERRIDE;
|
||||
virtual CefRefPtr<CefFrame> GetFrame() OVERRIDE;
|
||||
virtual CefRefPtr<CefV8Value> GetGlobal() OVERRIDE;
|
||||
@ -90,6 +131,7 @@ class CefV8ValueImpl : public CefV8Value {
|
||||
CefV8ValueImpl(v8::Handle<v8::Value> value, CefTrackNode* tracker = NULL);
|
||||
virtual ~CefV8ValueImpl();
|
||||
|
||||
virtual bool IsValid() OVERRIDE;
|
||||
virtual bool IsUndefined() OVERRIDE;
|
||||
virtual bool IsNull() OVERRIDE;
|
||||
virtual bool IsBool() OVERRIDE;
|
||||
@ -147,19 +189,22 @@ class CefV8ValueImpl : public CefV8Value {
|
||||
// Test for and record any exception.
|
||||
bool HasCaught(v8::TryCatch& try_catch);
|
||||
|
||||
class Handle :
|
||||
public base::RefCountedThreadSafe<Handle, CefThread::DeleteOnUIThread> {
|
||||
class Handle : public CefV8HandleBase {
|
||||
public:
|
||||
typedef v8::Handle<v8::Value> handleType;
|
||||
typedef v8::Persistent<v8::Value> persistentType;
|
||||
|
||||
Handle(handleType v, CefTrackNode* tracker)
|
||||
: handle_(persistentType::New(v)),
|
||||
Handle(v8::Handle<v8::Context> context, handleType v, CefTrackNode* tracker)
|
||||
: CefV8HandleBase(context),
|
||||
handle_(persistentType::New(v)),
|
||||
tracker_(tracker) {
|
||||
}
|
||||
~Handle();
|
||||
virtual ~Handle();
|
||||
|
||||
handleType GetHandle() { return handle_; }
|
||||
handleType GetHandle() {
|
||||
DCHECK(IsValid());
|
||||
return handle_;
|
||||
}
|
||||
|
||||
private:
|
||||
persistentType handle_;
|
||||
@ -184,6 +229,7 @@ class CefV8StackTraceImpl : public CefV8StackTrace {
|
||||
explicit CefV8StackTraceImpl(v8::Handle<v8::StackTrace> handle);
|
||||
virtual ~CefV8StackTraceImpl();
|
||||
|
||||
virtual bool IsValid() OVERRIDE;
|
||||
virtual int GetFrameCount() OVERRIDE;
|
||||
virtual CefRefPtr<CefV8StackFrame> GetFrame(int index) OVERRIDE;
|
||||
|
||||
@ -202,6 +248,7 @@ class CefV8StackFrameImpl : public CefV8StackFrame {
|
||||
explicit CefV8StackFrameImpl(v8::Handle<v8::StackFrame> handle);
|
||||
virtual ~CefV8StackFrameImpl();
|
||||
|
||||
virtual bool IsValid() OVERRIDE;
|
||||
virtual CefString GetScriptName() OVERRIDE;
|
||||
virtual CefString GetScriptNameOrSourceURL() OVERRIDE;
|
||||
virtual CefString GetFunctionName() OVERRIDE;
|
||||
|
Reference in New Issue
Block a user