- add sources.
[platform/framework/web/crosswalk.git] / src / content / renderer / java / java_bridge_dispatcher.h
1 // Copyright (c) 2012 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_JAVA_JAVA_BRIDGE_DISPATCHER_H_
6 #define CONTENT_RENDERER_JAVA_JAVA_BRIDGE_DISPATCHER_H_
7
8 #include <map>
9
10 #include "base/memory/ref_counted.h"
11 #include "content/public/renderer/render_view_observer.h"
12 #include "ipc/ipc_channel_handle.h"
13 #include "third_party/npapi/bindings/npruntime.h"
14
15 namespace content {
16 class JavaBridgeChannel;
17 struct NPVariant_Param;
18
19 // This class handles injecting Java objects into the main frame of a
20 // RenderView. The 'add' and 'remove' messages received from the browser
21 // process modify the entries in a map of 'pending' objects. These objects are
22 // bound to the window object of the main frame when that window object is next
23 // cleared. These objects remain bound until the window object is cleared
24 // again.
25 class JavaBridgeDispatcher : public RenderViewObserver {
26  public:
27   JavaBridgeDispatcher(RenderView* render_view);
28   virtual ~JavaBridgeDispatcher();
29
30  private:
31   // RenderViewObserver override:
32   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
33   virtual void DidClearWindowObject(WebKit::WebFrame* frame) OVERRIDE;
34
35   // Message handlers
36   void OnAddNamedObject(const string16& name,
37                         const NPVariant_Param& variant_param);
38   void OnRemoveNamedObject(const string16& name);
39
40   void EnsureChannelIsSetUp();
41
42   // Objects that will be bound to the window when the window object is next
43   // cleared. We hold a ref to these.
44   typedef std::map<string16, NPVariant> ObjectMap;
45   ObjectMap objects_;
46   scoped_refptr<JavaBridgeChannel> channel_;
47 };
48
49 }  // namespace content
50
51 #endif  // CONTENT_RENDERER_JAVA_JAVA_BRIDGE_DISPATCHER_H_