OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BRIDGE_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BRIDGE_DISPATCHER_HOST_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BRIDGE_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BRIDGE_DISPATCHER_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
| 11 #include "content/browser/renderer_host/render_view_host_observer.h" |
11 | 12 |
12 class JavaBridgeChannelHost; | 13 class NPChannelBase; |
13 class RenderViewHost; | 14 class RenderViewHost; |
| 15 class RouteIDGenerator; |
14 struct NPObject; | 16 struct NPObject; |
| 17 struct NPVariant_Param; |
| 18 struct _NPVariant; |
| 19 typedef _NPVariant NPVariant; |
15 | 20 |
16 // This class handles injecting Java objects into a single RenderView. The Java | 21 // This class handles injecting Java objects into a single RenderView. The Java |
17 // object itself lives on the browser's WEBKIT thread, while a proxy object is | 22 // object itself lives on the browser's WEBKIT thread, while a proxy object is |
18 // created in the renderer. An instance of this class exists for each | 23 // created in the renderer. An instance of this class exists for each |
19 // RenderViewHost. | 24 // RenderViewHost. |
20 class JavaBridgeDispatcherHost : | 25 class JavaBridgeDispatcherHost : |
| 26 public RenderViewHostObserver, |
21 public base::RefCountedThreadSafe<JavaBridgeDispatcherHost> { | 27 public base::RefCountedThreadSafe<JavaBridgeDispatcherHost> { |
22 public: | 28 public: |
23 // We hold a weak pointer to the RenderViewhost. It must outlive this object. | 29 // We hold a weak pointer to the RenderViewhost. It must outlive this object. |
24 JavaBridgeDispatcherHost(RenderViewHost* render_view_host); | 30 JavaBridgeDispatcherHost(RenderViewHost* render_view_host); |
25 | 31 |
26 // Injects |object| into the main frame of the corresponding RenderView. A | 32 // Injects |object| into the main frame of the corresponding RenderView. A |
27 // proxy object is created in the renderer and when the main frame's window | 33 // proxy object is created in the renderer and when the main frame's window |
28 // object is next cleared, this proxy object is bound to the window object | 34 // object is next cleared, this proxy object is bound to the window object |
29 // using |name|. The proxy object remains bound until the next time the | 35 // using |name|. The proxy object remains bound until the next time the |
30 // window object is cleared after a call to RemoveNamedObject() or | 36 // window object is cleared after a call to RemoveNamedObject() or |
31 // AddNamedObject() with the same name. The proxy object proxies calls back | 37 // AddNamedObject() with the same name. The proxy object proxies calls back |
32 // to |object|, which is manipulated on the WEBKIT thread. This class holds a | 38 // to |object|, which is manipulated on the WEBKIT thread. This class holds a |
33 // reference to |object| for the time that the proxy object is bound to the | 39 // reference to |object| for the time that the proxy object is bound to the |
34 // window object. | 40 // window object. |
35 void AddNamedObject(const string16& name, NPObject* object); | 41 void AddNamedObject(const string16& name, NPObject* object); |
36 void RemoveNamedObject(const string16& name); | 42 void RemoveNamedObject(const string16& name); |
37 | 43 |
| 44 // RenderViewHostObserver override: |
| 45 // The IPC macros require this to be public. |
| 46 virtual bool Send(IPC::Message* msg) OVERRIDE; |
| 47 |
38 private: | 48 private: |
39 friend class base::RefCountedThreadSafe<JavaBridgeDispatcherHost>; | 49 friend class base::RefCountedThreadSafe<JavaBridgeDispatcherHost>; |
40 ~JavaBridgeDispatcherHost(); | 50 ~JavaBridgeDispatcherHost(); |
41 | 51 |
42 void DoAddNamedObject(const string16& name, NPObject* object); | 52 // RenderViewHostObserver override: |
43 void EnsureChannelIsSetUp(); | 53 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
44 | 54 |
45 RenderViewHost* render_view_host_; | 55 // Message handlers |
46 scoped_refptr<JavaBridgeChannelHost> channel_; | 56 void OnGetChannelHandle(IPC::Message* reply_msg); |
| 57 |
| 58 void GetChannelHandle(IPC::Message* reply_msg); |
| 59 void CreateNPVariantParam(NPObject* object, NPVariant_Param* param); |
| 60 void CreateObjectStub(NPObject* object, int route_id); |
| 61 |
| 62 scoped_refptr<RouteIDGenerator> route_id_generator_; |
| 63 scoped_refptr<NPChannelBase> channel_; |
47 | 64 |
48 DISALLOW_COPY_AND_ASSIGN(JavaBridgeDispatcherHost); | 65 DISALLOW_COPY_AND_ASSIGN(JavaBridgeDispatcherHost); |
49 }; | 66 }; |
50 | 67 |
51 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BRIDGE_DISPATCHER_HOST_H_ | 68 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BRIDGE_DISPATCHER_HOST_H_ |
OLD | NEW |