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"
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 #include "v8/include/v8-util.h"
17 struct PPP_Class_Deprecated
;
25 class PepperPluginInstanceImpl
;
27 // A PluginObject is a JS-accessible object implemented by the plugin.
29 // In contrast, a var of type PP_VARTYPE_OBJECT is a reference to a JS object,
30 // which might be implemented by the plugin (here) or by the JS engine.
31 class PluginObject
: public gin::Wrappable
<PluginObject
>,
32 public gin::NamedPropertyInterceptor
{
34 static gin::WrapperInfo kWrapperInfo
;
36 ~PluginObject() override
;
38 // Returns the PluginObject which is contained in the given v8 object, or NULL
39 // if the object isn't backed by a PluginObject.
40 static PluginObject
* FromV8Object(v8::Isolate
* isolate
,
41 v8::Handle
<v8::Object
> v8_object
);
43 // Allocates a new PluginObject and returns it as a PP_Var with a
45 static PP_Var
Create(PepperPluginInstanceImpl
* instance
,
46 const PPP_Class_Deprecated
* ppp_class
,
47 void* ppp_class_data
);
49 // gin::NamedPropertyInterceptor
50 v8::Local
<v8::Value
> GetNamedProperty(v8::Isolate
* isolate
,
51 const std::string
& property
) override
;
52 bool SetNamedProperty(v8::Isolate
* isolate
,
53 const std::string
& property
,
54 v8::Local
<v8::Value
> value
) override
;
55 std::vector
<std::string
> EnumerateNamedProperties(
56 v8::Isolate
* isolate
) override
;
58 const PPP_Class_Deprecated
* ppp_class() { return ppp_class_
; }
59 void* ppp_class_data() { return ppp_class_data_
; }
61 // Called when the instance is destroyed.
62 void InstanceDeleted();
65 PluginObject(PepperPluginInstanceImpl
* instance
,
66 const PPP_Class_Deprecated
* ppp_class
,
67 void* ppp_class_data
);
70 gin::ObjectTemplateBuilder
GetObjectTemplateBuilder(
71 v8::Isolate
* isolate
) override
;
73 // Helper method to get named properties.
74 v8::Local
<v8::Value
> GetPropertyOrMethod(v8::Isolate
* isolate
,
75 PP_Var identifier_var
);
77 void Call(const std::string
& identifier
, gin::Arguments
* args
);
79 v8::Local
<v8::FunctionTemplate
> GetFunctionTemplate(v8::Isolate
* isolate
,
80 const std::string
& name
);
82 PepperPluginInstanceImpl
* instance_
;
84 const PPP_Class_Deprecated
* ppp_class_
;
85 void* ppp_class_data_
;
87 v8::StdPersistentValueMap
<std::string
, v8::FunctionTemplate
> template_cache_
;
89 base::WeakPtrFactory
<PluginObject
> weak_factory_
;
91 DISALLOW_COPY_AND_ASSIGN(PluginObject
);
94 } // namespace content
96 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_OBJECT_H_