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"
24 class GinJavaBridgeValueConverter
;
26 class GinJavaBridgeObject
: public gin::Wrappable
<GinJavaBridgeObject
>,
27 public gin::NamedPropertyInterceptor
{
29 static gin::WrapperInfo kWrapperInfo
;
31 GinJavaBridgeDispatcher::ObjectID
object_id() const { return object_id_
; }
34 virtual gin::ObjectTemplateBuilder
GetObjectTemplateBuilder(
35 v8::Isolate
* isolate
) OVERRIDE
;
37 // gin::NamedPropertyInterceptor
38 virtual v8::Local
<v8::Value
> GetNamedProperty(
39 v8::Isolate
* isolate
, const std::string
& property
) OVERRIDE
;
40 virtual std::vector
<std::string
> EnumerateNamedProperties(
41 v8::Isolate
* isolate
) OVERRIDE
;
43 static GinJavaBridgeObject
* InjectNamed(
44 blink::WebFrame
* frame
,
45 const base::WeakPtr
<GinJavaBridgeDispatcher
>& dispatcher
,
46 const std::string
& object_name
,
47 GinJavaBridgeDispatcher::ObjectID object_id
);
48 static GinJavaBridgeObject
* InjectAnonymous(
49 const base::WeakPtr
<GinJavaBridgeDispatcher
>& dispatcher
,
50 GinJavaBridgeDispatcher::ObjectID object_id
);
53 GinJavaBridgeObject(v8::Isolate
* isolate
,
54 const base::WeakPtr
<GinJavaBridgeDispatcher
>& dispatcher
,
55 GinJavaBridgeDispatcher::ObjectID object_id
);
56 virtual ~GinJavaBridgeObject();
58 v8::Handle
<v8::Value
> InvokeMethod(const std::string
& name
,
59 gin::Arguments
* args
);
61 base::WeakPtr
<GinJavaBridgeDispatcher
> dispatcher_
;
62 GinJavaBridgeDispatcher::ObjectID object_id_
;
63 scoped_ptr
<GinJavaBridgeValueConverter
> converter_
;
64 std::map
<std::string
, bool> known_methods_
;
66 DISALLOW_COPY_AND_ASSIGN(GinJavaBridgeObject
);
69 } // namespace content
71 #endif // CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_OBJECT_H_