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_DISPATCHER_H_
6 #define CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_DISPATCHER_H_
11 #include "base/id_map.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/values.h"
15 #include "content/common/android/gin_java_bridge_errors.h"
16 #include "content/public/renderer/render_frame_observer.h"
24 class GinJavaBridgeObject
;
26 // This class handles injecting Java objects into the main frame of a
27 // RenderView. The 'add' and 'remove' messages received from the browser
28 // process modify the entries in a map of 'pending' objects. These objects are
29 // bound to the window object of the main frame when that window object is next
30 // cleared. These objects remain bound until the window object is cleared
32 class GinJavaBridgeDispatcher
33 : public base::SupportsWeakPtr
<GinJavaBridgeDispatcher
>,
34 public RenderFrameObserver
{
36 // GinJavaBridgeObjects are managed by gin. An object gets destroyed
37 // when it is no more referenced from JS. As GinJavaBridgeObject reports
38 // deletion of self to GinJavaBridgeDispatcher, we would not have stale
40 typedef IDMap
<GinJavaBridgeObject
, IDMapExternalPointer
> ObjectMap
;
41 typedef ObjectMap::KeyType ObjectID
;
43 explicit GinJavaBridgeDispatcher(RenderFrame
* render_frame
);
44 virtual ~GinJavaBridgeDispatcher();
46 // RenderFrameObserver override:
47 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
48 virtual void DidClearWindowObject() OVERRIDE
;
50 void GetJavaMethods(ObjectID object_id
, std::set
<std::string
>* methods
);
51 bool HasJavaMethod(ObjectID object_id
, const std::string
& method_name
);
52 scoped_ptr
<base::Value
> InvokeJavaMethod(ObjectID object_id
,
53 const std::string
& method_name
,
54 const base::ListValue
& arguments
,
55 GinJavaBridgeError
* error
);
56 GinJavaBridgeObject
* GetObject(ObjectID object_id
);
57 void OnGinJavaBridgeObjectDeleted(ObjectID object_id
);
60 void OnAddNamedObject(const std::string
& name
,
62 void OnRemoveNamedObject(const std::string
& name
);
63 void OnSetAllowObjectContentsInspection(bool allow
);
65 typedef std::map
<std::string
, ObjectID
> NamedObjectMap
;
66 NamedObjectMap named_objects_
;
68 bool inside_did_clear_window_object_
;
70 DISALLOW_COPY_AND_ASSIGN(GinJavaBridgeDispatcher
);
73 } // namespace content
75 #endif // CONTENT_RENDERER_JAVA_GIN_JAVA_BRIDGE_DISPATCHER_H_