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