Index: content/renderer/pepper/plugin_object.h |
diff --git a/content/renderer/pepper/plugin_object.h b/content/renderer/pepper/plugin_object.h |
index 62ffd2ebfbdc6806af5978a1c89a6891e19b699f..096b85a75ecda7f823e0e007546ea7229c8c07fe 100644 |
--- a/content/renderer/pepper/plugin_object.h |
+++ b/content/renderer/pepper/plugin_object.h |
@@ -8,11 +8,16 @@ |
#include <string> |
#include "base/basictypes.h" |
+#include "base/memory/weak_ptr.h" |
+#include "gin/interceptor.h" |
+#include "gin/wrappable.h" |
+#include "ppapi/c/pp_var.h" |
-struct PP_Var; |
struct PPP_Class_Deprecated; |
-typedef struct NPObject NPObject; |
-typedef struct _NPVariant NPVariant; |
+ |
+namespace gin { |
+ class Arguments; |
+} // namespace gin |
namespace content { |
@@ -22,71 +27,79 @@ class PepperPluginInstanceImpl; |
// |
// In contrast, a var of type PP_VARTYPE_OBJECT is a reference to a JS object, |
// which might be implemented by the plugin (here) or by the JS engine. |
-class PluginObject { |
+class PluginObject : public gin::Wrappable<PluginObject>, |
+ public gin::NamedPropertyInterceptor, |
+ public gin::IndexedPropertyInterceptor { |
public: |
+ static gin::WrapperInfo kWrapperInfo; |
+ |
virtual ~PluginObject(); |
+ // Returns the PluginObject which is contained in the given v8 object, or NULL |
+ // if the object isn't backed by a PluginObject. |
+ static PluginObject* FromV8Object(v8::Isolate* isolate, |
+ v8::Handle<v8::Object> v8_object); |
+ |
// Allocates a new PluginObject and returns it as a PP_Var with a |
// refcount of 1. |
static PP_Var Create(PepperPluginInstanceImpl* instance, |
const PPP_Class_Deprecated* ppp_class, |
void* ppp_class_data); |
- PepperPluginInstanceImpl* instance() const { return instance_; } |
+ // gin::NamedPropertyInterceptor |
+ virtual v8::Local<v8::Value> GetNamedProperty( |
+ v8::Isolate* isolate, |
+ const std::string& property) OVERRIDE; |
+ virtual void SetNamedProperty(v8::Isolate* isolate, |
+ const std::string& property, |
+ v8::Local<v8::Value> value) OVERRIDE; |
+ virtual std::vector<std::string> EnumerateNamedProperties( |
+ v8::Isolate* isolate) OVERRIDE; |
+ |
+ // gin::IndexedPropertyInterceptor |
+ virtual v8::Local<v8::Value> GetIndexedProperty(v8::Isolate* isolate, |
+ uint32_t index) OVERRIDE; |
+ virtual void SetIndexedProperty(v8::Isolate* isolate, |
+ uint32_t index, |
+ v8::Local<v8::Value> value) OVERRIDE; |
+ virtual std::vector<uint32_t> EnumerateIndexedProperties( |
+ v8::Isolate* isolate) OVERRIDE; |
const PPP_Class_Deprecated* ppp_class() { return ppp_class_; } |
- void* ppp_class_data() { |
- return ppp_class_data_; |
- }; |
- |
- NPObject* GetNPObject() const; |
- |
- // Returns true if the given var is an object implemented by the same plugin |
- // that owns the var object, and that the class matches. If it matches, |
- // returns true and places the class data into |*ppp_class_data| (which can |
- // optionally be NULL if no class data is desired). |
- static bool IsInstanceOf(NPObject* np_object, |
- const PPP_Class_Deprecated* ppp_class, |
- void** ppp_class_data); |
- |
- // Converts the given NPObject to the corresponding ObjectVar. |
- // |
- // The given NPObject must be one corresponding to a PluginObject or this |
- // will crash. If the object is a PluginObject but the plugin has gone |
- // away (the object could still be alive because of a reference from JS), |
- // then the return value will be NULL. |
- static PluginObject* FromNPObject(NPObject* object); |
- |
- // Allocates a plugin wrapper object and returns it as an NPObject. This is |
- // used internally only. |
- static NPObject* AllocateObjectWrapper(); |
+ void* ppp_class_data() { return ppp_class_data_; } |
- private: |
- struct NPObjectWrapper; |
+ // Called when the instance is destroyed. |
+ void InstanceDeleted(); |
- // This object must be created using the CreateObject function of the which |
- // will set up the correct NPObject. |
- // |
- // The NPObjectWrapper (an NPObject) should already have the reference |
- // incremented on it, and this class will take ownership of that reference. |
+ private: |
PluginObject(PepperPluginInstanceImpl* instance, |
- NPObjectWrapper* object_wrapper, |
const PPP_Class_Deprecated* ppp_class, |
void* ppp_class_data); |
- PepperPluginInstanceImpl* instance_; |
+ // gin::Wrappable |
+ virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
+ v8::Isolate* isolate) OVERRIDE; |
+ |
+ // Helper methods for Get/Set/Enumerate Named/Indexed properties. |
+ v8::Local<v8::Value> GetPropertyOrMethod(v8::Isolate* isolate, |
+ PP_Var identifier_var); |
+ void SetProperty(v8::Isolate* isolate, |
+ PP_Var identifier_var, |
+ v8::Handle<v8::Value> value); |
+ // Returns a pair with a vector of named properties and a vector of indexed |
+ // properties. |
+ std::pair<std::vector<std::string>, std::vector<uint32_t> > |
+ EnumerateProperties(v8::Isolate* isolate); |
- // Holds a pointer to the NPObject wrapper backing the var. This class |
- // derives from NPObject and we hold a reference to it, so it must be |
- // refcounted. When the type is not an object, this value will be NULL. |
- // |
- // We don't actually own this pointer, it's the NPObject that actually |
- // owns us. |
- NPObjectWrapper* object_wrapper_; |
+ void Call(const std::string& identifier, gin::Arguments* args); |
+ |
+ PepperPluginInstanceImpl* instance_; |
const PPP_Class_Deprecated* ppp_class_; |
void* ppp_class_data_; |
+ base::WeakPtrFactory<PluginObject> weak_factory_; |
+ |
DISALLOW_COPY_AND_ASSIGN(PluginObject); |
}; |