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 #include "content/browser/renderer_host/render_view_host_observer.h" |
12 | 12 |
13 class NPChannelBase; | 13 class NPChannelBase; |
14 class RenderViewHost; | 14 class RenderViewHost; |
15 class RouteIDGenerator; | 15 class RouteIDGenerator; |
16 struct NPObject; | 16 struct NPObject; |
17 struct NPVariant_Param; | 17 struct NPVariant_Param; |
18 struct _NPVariant; | 18 struct _NPVariant; |
19 typedef _NPVariant NPVariant; | 19 typedef _NPVariant NPVariant; |
20 | 20 |
21 // 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 |
22 // object itself lives on the browser's WEBKIT thread, while a proxy object is | 22 // object itself lives on the browser's JAVA_BRIDGE thread, while a proxy |
23 // created in the renderer. An instance of this class exists for each | 23 // object is created in the renderer. An instance of this class exists for each |
24 // RenderViewHost. | 24 // RenderViewHost. |
25 class JavaBridgeDispatcherHost : | 25 class JavaBridgeDispatcherHost : |
26 public RenderViewHostObserver, | 26 public RenderViewHostObserver, |
27 public base::RefCountedThreadSafe<JavaBridgeDispatcherHost> { | 27 public base::RefCountedThreadSafe<JavaBridgeDispatcherHost> { |
28 public: | 28 public: |
29 // 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. |
30 JavaBridgeDispatcherHost(RenderViewHost* render_view_host); | 30 JavaBridgeDispatcherHost(RenderViewHost* render_view_host); |
31 | 31 |
32 // Injects |object| into the main frame of the corresponding RenderView. A | 32 // Injects |object| into the main frame of the corresponding RenderView. A |
33 // 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 |
34 // 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 |
35 // 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 |
36 // window object is cleared after a call to RemoveNamedObject() or | 36 // window object is cleared after a call to RemoveNamedObject() or |
37 // AddNamedObject() with the same name. The proxy object proxies calls back | 37 // AddNamedObject() with the same name. The proxy object proxies calls back |
38 // to |object|, which is manipulated on the WEBKIT thread. This class holds a | 38 // to |object|, which is manipulated on the JAVA_BRIDGE thread. This class |
39 // reference to |object| for the time that the proxy object is bound to the | 39 // holds a reference to |object| for the time that the proxy object is bound |
40 // window object. | 40 // to the window object. |
41 void AddNamedObject(const string16& name, NPObject* object); | 41 void AddNamedObject(const string16& name, NPObject* object); |
42 void RemoveNamedObject(const string16& name); | 42 void RemoveNamedObject(const string16& name); |
43 | 43 |
44 // RenderViewHostObserver override: | 44 // RenderViewHostObserver override: |
45 // The IPC macros require this to be public. | 45 // The IPC macros require this to be public. |
46 virtual bool Send(IPC::Message* msg) OVERRIDE; | 46 virtual bool Send(IPC::Message* msg) OVERRIDE; |
47 | 47 |
48 private: | 48 private: |
49 friend class base::RefCountedThreadSafe<JavaBridgeDispatcherHost>; | 49 friend class base::RefCountedThreadSafe<JavaBridgeDispatcherHost>; |
50 ~JavaBridgeDispatcherHost(); | 50 ~JavaBridgeDispatcherHost(); |
51 | 51 |
52 // RenderViewHostObserver override: | 52 // RenderViewHostObserver override: |
53 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 53 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
54 | 54 |
55 // Message handlers | 55 // Message handlers |
56 void OnGetChannelHandle(IPC::Message* reply_msg); | 56 void OnGetChannelHandle(IPC::Message* reply_msg); |
57 | 57 |
58 void GetChannelHandle(IPC::Message* reply_msg); | 58 void GetChannelHandle(IPC::Message* reply_msg); |
59 void CreateNPVariantParam(NPObject* object, NPVariant_Param* param); | 59 void CreateNPVariantParam(NPObject* object, NPVariant_Param* param); |
60 void CreateObjectStub(NPObject* object, int route_id); | 60 void CreateObjectStub(NPObject* object, int route_id); |
61 | 61 |
62 scoped_refptr<NPChannelBase> channel_; | 62 scoped_refptr<NPChannelBase> channel_; |
63 bool is_renderer_initialized_; | 63 bool is_renderer_initialized_; |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(JavaBridgeDispatcherHost); | 65 DISALLOW_COPY_AND_ASSIGN(JavaBridgeDispatcherHost); |
66 }; | 66 }; |
67 | 67 |
68 #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 |