4f640b88cea70c6ab4ebd14b0a9a92aa4c4eef94
[platform/framework/web/crosswalk.git] / src / content / renderer / pepper / plugin_object.h
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 CONTENT_RENDERER_PEPPER_PLUGIN_OBJECT_H_
6 #define CONTENT_RENDERER_PEPPER_PLUGIN_OBJECT_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "gin/interceptor.h"
13 #include "gin/wrappable.h"
14 #include "ppapi/c/pp_var.h"
15
16 struct PPP_Class_Deprecated;
17
18 namespace gin {
19   class Arguments;
20 }  // namespace gin
21
22 namespace content {
23
24 class PepperPluginInstanceImpl;
25
26 // A PluginObject is a JS-accessible object implemented by the plugin.
27 //
28 // In contrast, a var of type PP_VARTYPE_OBJECT is a reference to a JS object,
29 // which might be implemented by the plugin (here) or by the JS engine.
30 class PluginObject : public gin::Wrappable<PluginObject>,
31                      public gin::NamedPropertyInterceptor {
32  public:
33   static gin::WrapperInfo kWrapperInfo;
34
35   virtual ~PluginObject();
36
37   // Returns the PluginObject which is contained in the given v8 object, or NULL
38   // if the object isn't backed by a PluginObject.
39   static PluginObject* FromV8Object(v8::Isolate* isolate,
40                                     v8::Handle<v8::Object> v8_object);
41
42   // Allocates a new PluginObject and returns it as a PP_Var with a
43   // refcount of 1.
44   static PP_Var Create(PepperPluginInstanceImpl* instance,
45                        const PPP_Class_Deprecated* ppp_class,
46                        void* ppp_class_data);
47
48   // gin::NamedPropertyInterceptor
49   virtual v8::Local<v8::Value> GetNamedProperty(
50       v8::Isolate* isolate,
51       const std::string& property) OVERRIDE;
52   virtual std::vector<std::string> EnumerateNamedProperties(
53       v8::Isolate* isolate) OVERRIDE;
54
55   const PPP_Class_Deprecated* ppp_class() { return ppp_class_; }
56   void* ppp_class_data() { return ppp_class_data_; }
57
58   // Called when the instance is destroyed.
59   void InstanceDeleted();
60
61  private:
62   PluginObject(PepperPluginInstanceImpl* instance,
63                const PPP_Class_Deprecated* ppp_class,
64                void* ppp_class_data);
65
66   // gin::Wrappable
67   virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
68       v8::Isolate* isolate) OVERRIDE;
69
70   // Helper method to get named properties.
71   v8::Local<v8::Value> GetPropertyOrMethod(v8::Isolate* isolate,
72                                            PP_Var identifier_var);
73
74   void Call(const std::string& identifier, gin::Arguments* args);
75
76   PepperPluginInstanceImpl* instance_;
77
78   const PPP_Class_Deprecated* ppp_class_;
79   void* ppp_class_data_;
80
81   base::WeakPtrFactory<PluginObject> weak_factory_;
82
83   DISALLOW_COPY_AND_ASSIGN(PluginObject);
84 };
85
86 }  // namespace content
87
88 #endif  // CONTENT_RENDERER_PEPPER_PLUGIN_OBJECT_H_