OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_OBJECT_H_ | |
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_OBJECT_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 | |
12 struct PP_Var; | |
13 struct PPP_Class_Deprecated; | |
14 typedef struct NPObject NPObject; | |
15 typedef struct _NPVariant NPVariant; | |
16 | |
17 namespace pepper { | |
18 | |
19 class PluginModule; | |
20 | |
21 class PluginObject { | |
22 public: | |
23 virtual ~PluginObject(); | |
24 | |
25 // Allocates a new PluginObject and returns it as a PP_Var with a | |
26 // refcount of 1. | |
27 static PP_Var Create(PluginModule* module, | |
28 const PPP_Class_Deprecated* ppp_class, | |
29 void* ppp_class_data); | |
30 | |
31 PluginModule* module() const { return module_; } | |
32 | |
33 const PPP_Class_Deprecated* ppp_class() { return ppp_class_; } | |
34 void* ppp_class_data() { return ppp_class_data_; }; | |
35 | |
36 NPObject* GetNPObject() const; | |
37 | |
38 // Returns true if the given var is an object implemented by the same plugin | |
39 // that owns the var object, and that the class matches. If it matches, | |
40 // returns true and places the class data into |*ppp_class_data| (which can | |
41 // optionally be NULL if no class data is desired). | |
42 static bool IsInstanceOf(NPObject* np_object, | |
43 const PPP_Class_Deprecated* ppp_class, | |
44 void** ppp_class_data); | |
45 | |
46 // Converts the given NPObject to the corresponding ObjectVar. | |
47 // | |
48 // The given NPObject must be one corresponding to a PluginObject or this | |
49 // will crash. If the object is a PluginObject but the plugin has gone | |
50 // away (the object could still be alive because of a reference from JS), | |
51 // then the return value will be NULL. | |
52 static PluginObject* FromNPObject(NPObject* object); | |
53 | |
54 // Allocates a plugin wrapper object and returns it as an NPObject. This is | |
55 // used internally only. | |
56 static NPObject* AllocateObjectWrapper(); | |
57 | |
58 private: | |
59 struct NPObjectWrapper; | |
60 | |
61 // This object must be created using the CreateObject function of the which | |
62 // will set up the correct NPObject. | |
63 // | |
64 // The NPObjectWrapper (an NPObject) should already have the reference | |
65 // incremented on it, and this class will take ownership of that reference. | |
66 PluginObject(PluginModule* module, | |
67 NPObjectWrapper* object_wrapper, | |
68 const PPP_Class_Deprecated* ppp_class, | |
69 void* ppp_class_data); | |
70 | |
71 PluginModule* module_; | |
72 | |
73 // Holds a pointer to the NPObject wrapper backing the var. This class | |
74 // derives from NPObject and we hold a reference to it, so it must be | |
75 // refcounted. When the type is not an object, this value will be NULL. | |
76 // | |
77 // We don't actually own this pointer, it's the NPObject that actually | |
78 // owns us. | |
79 NPObjectWrapper* object_wrapper_; | |
80 | |
81 const PPP_Class_Deprecated* ppp_class_; | |
82 void* ppp_class_data_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(PluginObject); | |
85 }; | |
86 | |
87 } // namespace pepper | |
88 | |
89 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_PLUGIN_OBJECT_H_ | |
OLD | NEW |