Commit 7f1e19ef authored by raymes@chromium.org's avatar raymes@chromium.org

Change V8ObjectVar to store a pointer to the instance rather than an ID

This changes the currently unused V8ObjectVar to store a pointer to the
instance rather than a PP_Instance ID. This is just more convenient for
the code which uses the V8ObjectVar. When the instance is deleted, the
pointer will be cleared so it should always be valid or NULL.

BUG=351636

Review URL: https://codereview.chromium.org/464653003

Cr-Commit-Position: refs/heads/master@{#289191}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289191 0039d316-1c4b-4281-b951-d872f2087c98
parent 887a7eb8
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "content/public/renderer/pepper_plugin_instance.h" #include "content/public/renderer/pepper_plugin_instance.h"
#include "content/renderer/pepper/host_globals.h" #include "content/renderer/pepper/host_globals.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
#include "ppapi/c/pp_var.h" #include "ppapi/c/pp_var.h"
namespace ppapi { namespace ppapi {
...@@ -15,9 +16,8 @@ namespace ppapi { ...@@ -15,9 +16,8 @@ namespace ppapi {
V8ObjectVar::V8ObjectVar(PP_Instance instance, V8ObjectVar::V8ObjectVar(PP_Instance instance,
v8::Handle<v8::Object> v8_object) v8::Handle<v8::Object> v8_object)
: instance_(instance) { : instance_(content::HostGlobals::Get()->GetInstance(instance)) {
v8_object_.Reset( v8_object_.Reset(instance_->GetIsolate(), v8_object);
content::PepperPluginInstance::Get(instance_)->GetIsolate(), v8_object);
content::HostGlobals::Get()->host_var_tracker()->AddV8ObjectVar(this); content::HostGlobals::Get()->host_var_tracker()->AddV8ObjectVar(this);
} }
...@@ -36,10 +36,8 @@ PP_VarType V8ObjectVar::GetType() const { ...@@ -36,10 +36,8 @@ PP_VarType V8ObjectVar::GetType() const {
} }
v8::Local<v8::Object> V8ObjectVar::GetHandle() const { v8::Local<v8::Object> V8ObjectVar::GetHandle() const {
content::PepperPluginInstance* instance = if (instance_)
content::PepperPluginInstance::Get(instance_); return v8::Local<v8::Object>::New(instance_->GetIsolate(), v8_object_);
if (instance)
return v8::Local<v8::Object>::New(instance->GetIsolate(), v8_object_);
return v8::Local<v8::Object>(); return v8::Local<v8::Object>();
} }
...@@ -47,7 +45,7 @@ void V8ObjectVar::InstanceDeleted() { ...@@ -47,7 +45,7 @@ void V8ObjectVar::InstanceDeleted() {
// This is called by the HostVarTracker which will take care of removing us // This is called by the HostVarTracker which will take care of removing us
// from its set. // from its set.
DCHECK(instance_); DCHECK(instance_);
instance_ = 0; instance_ = NULL;
} }
// static // static
......
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
#include "ppapi/shared_impl/var.h" #include "ppapi/shared_impl/var.h"
#include "v8/include/v8.h" #include "v8/include/v8.h"
namespace content {
class PepperPluginInstanceImpl;
} // namespace content
namespace ppapi { namespace ppapi {
// V8ObjectVar ----------------------------------------------------------------- // V8ObjectVar -----------------------------------------------------------------
...@@ -40,8 +44,8 @@ class V8ObjectVar : public Var { ...@@ -40,8 +44,8 @@ class V8ObjectVar : public Var {
// zeroed out. // zeroed out.
void InstanceDeleted(); void InstanceDeleted();
// Possibly 0 if the object has outlived its instance. // Possibly NULL if the object has outlived its instance.
PP_Instance instance() const { return instance_; } content::PepperPluginInstanceImpl* instance() const { return instance_; }
// Helper function that converts a PP_Var to an object. This will return NULL // Helper function that converts a PP_Var to an object. This will return NULL
// if the PP_Var is not of object type or the object is invalid. // if the PP_Var is not of object type or the object is invalid.
...@@ -50,7 +54,7 @@ class V8ObjectVar : public Var { ...@@ -50,7 +54,7 @@ class V8ObjectVar : public Var {
private: private:
virtual ~V8ObjectVar(); virtual ~V8ObjectVar();
PP_Instance instance_; content::PepperPluginInstanceImpl* instance_;
v8::Persistent<v8::Object> v8_object_; v8::Persistent<v8::Object> v8_object_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment