1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_PEPPER_PLUGIN_OBJECT_H_
6 #define CONTENT_RENDERER_PEPPER_PLUGIN_OBJECT_H_
10 #include "base/basictypes.h"
13 struct PPP_Class_Deprecated;
14 typedef struct NPObject NPObject;
15 typedef struct _NPVariant NPVariant;
19 class PepperPluginInstanceImpl;
21 // A PluginObject is a JS-accessible object implemented by the plugin.
23 // In contrast, a var of type PP_VARTYPE_OBJECT is a reference to a JS object,
24 // which might be implemented by the plugin (here) or by the JS engine.
27 virtual ~PluginObject();
29 // Allocates a new PluginObject and returns it as a PP_Var with a
31 static PP_Var Create(PepperPluginInstanceImpl* instance,
32 const PPP_Class_Deprecated* ppp_class,
33 void* ppp_class_data);
35 PepperPluginInstanceImpl* instance() const { return instance_; }
37 const PPP_Class_Deprecated* ppp_class() { return ppp_class_; }
38 void* ppp_class_data() { return ppp_class_data_; };
40 NPObject* GetNPObject() const;
42 // Returns true if the given var is an object implemented by the same plugin
43 // that owns the var object, and that the class matches. If it matches,
44 // returns true and places the class data into |*ppp_class_data| (which can
45 // optionally be NULL if no class data is desired).
46 static bool IsInstanceOf(NPObject* np_object,
47 const PPP_Class_Deprecated* ppp_class,
48 void** ppp_class_data);
50 // Converts the given NPObject to the corresponding ObjectVar.
52 // The given NPObject must be one corresponding to a PluginObject or this
53 // will crash. If the object is a PluginObject but the plugin has gone
54 // away (the object could still be alive because of a reference from JS),
55 // then the return value will be NULL.
56 static PluginObject* FromNPObject(NPObject* object);
58 // Allocates a plugin wrapper object and returns it as an NPObject. This is
59 // used internally only.
60 static NPObject* AllocateObjectWrapper();
63 struct NPObjectWrapper;
65 // This object must be created using the CreateObject function of the which
66 // will set up the correct NPObject.
68 // The NPObjectWrapper (an NPObject) should already have the reference
69 // incremented on it, and this class will take ownership of that reference.
70 PluginObject(PepperPluginInstanceImpl* instance,
71 NPObjectWrapper* object_wrapper,
72 const PPP_Class_Deprecated* ppp_class,
73 void* ppp_class_data);
75 PepperPluginInstanceImpl* instance_;
77 // Holds a pointer to the NPObject wrapper backing the var. This class
78 // derives from NPObject and we hold a reference to it, so it must be
79 // refcounted. When the type is not an object, this value will be NULL.
81 // We don't actually own this pointer, it's the NPObject that actually
83 NPObjectWrapper* object_wrapper_;
85 const PPP_Class_Deprecated* ppp_class_;
86 void* ppp_class_data_;
88 DISALLOW_COPY_AND_ASSIGN(PluginObject);
91 } // namespace content
93 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_OBJECT_H_