1 // Copyright 2014 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_JAVA_GIN_JAVA_BRIDGE_OBJECT_H_
6 #define CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_OBJECT_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "content/renderer/java/gin_java_bridge_dispatcher.h"
13 #include "gin/handle.h"
14 #include "gin/interceptor.h"
15 #include "gin/object_template_builder.h"
16 #include "gin/wrappable.h"
17 #include "v8/include/v8-util.h"
25 class GinJavaBridgeValueConverter
;
27 class GinJavaBridgeObject
: public gin::Wrappable
<GinJavaBridgeObject
>,
28 public gin::NamedPropertyInterceptor
{
30 static gin::WrapperInfo kWrapperInfo
;
32 GinJavaBridgeDispatcher::ObjectID
object_id() const { return object_id_
; }
35 gin::ObjectTemplateBuilder
GetObjectTemplateBuilder(
36 v8::Isolate
* isolate
) override
;
38 // gin::NamedPropertyInterceptor
39 v8::Local
<v8::Value
> GetNamedProperty(v8::Isolate
* isolate
,
40 const std::string
& property
) override
;
41 std::vector
<std::string
> EnumerateNamedProperties(
42 v8::Isolate
* isolate
) override
;
44 static GinJavaBridgeObject
* InjectNamed(
45 blink::WebFrame
* frame
,
46 const base::WeakPtr
<GinJavaBridgeDispatcher
>& dispatcher
,
47 const std::string
& object_name
,
48 GinJavaBridgeDispatcher::ObjectID object_id
);
49 static GinJavaBridgeObject
* InjectAnonymous(
50 const base::WeakPtr
<GinJavaBridgeDispatcher
>& dispatcher
,
51 GinJavaBridgeDispatcher::ObjectID object_id
);
54 GinJavaBridgeObject(v8::Isolate
* isolate
,
55 const base::WeakPtr
<GinJavaBridgeDispatcher
>& dispatcher
,
56 GinJavaBridgeDispatcher::ObjectID object_id
);
57 ~GinJavaBridgeObject() override
;
59 v8::Local
<v8::FunctionTemplate
> GetFunctionTemplate(v8::Isolate
* isolate
,
60 const std::string
& name
);
61 v8::Handle
<v8::Value
> InvokeMethod(const std::string
& name
,
62 gin::Arguments
* args
);
64 base::WeakPtr
<GinJavaBridgeDispatcher
> dispatcher_
;
65 GinJavaBridgeDispatcher::ObjectID object_id_
;
66 scoped_ptr
<GinJavaBridgeValueConverter
> converter_
;
67 std::map
<std::string
, bool> known_methods_
;
68 v8::StdPersistentValueMap
<std::string
, v8::FunctionTemplate
> template_cache_
;
70 DISALLOW_COPY_AND_ASSIGN(GinJavaBridgeObject
);
73 } // namespace content
75 #endif // CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_OBJECT_H_