| 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_MANAGER_H
_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BRIDGE_DISPATCHER_HOST_MANAGER_H
_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BRIDGE_DISPATCHER_HOST_MANAGER_H
_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BRIDGE_DISPATCHER_HOST_MANAGER_H
_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/android/jni_weak_ref.h" | 10 #include "base/android/jni_weak_ref.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 class JavaBridgeDispatcherHost; | 21 class JavaBridgeDispatcherHost; |
| 22 class RenderFrameHost; | 22 class RenderFrameHost; |
| 23 | 23 |
| 24 // This class handles injecting Java objects into all of the RenderFrames | 24 // This class handles injecting Java objects into all of the RenderFrames |
| 25 // associated with a WebContents. It manages a set of JavaBridgeDispatcherHost | 25 // associated with a WebContents. It manages a set of JavaBridgeDispatcherHost |
| 26 // objects, one per RenderFrameHost. | 26 // objects, one per RenderFrameHost. |
| 27 class JavaBridgeDispatcherHostManager | 27 class JavaBridgeDispatcherHostManager |
| 28 : public WebContentsObserver, | 28 : public WebContentsObserver, |
| 29 public base::SupportsWeakPtr<JavaBridgeDispatcherHostManager> { | 29 public base::SupportsWeakPtr<JavaBridgeDispatcherHostManager> { |
| 30 public: | 30 public: |
| 31 explicit JavaBridgeDispatcherHostManager(WebContents* web_contents); | 31 JavaBridgeDispatcherHostManager(WebContents* web_contents, |
| 32 jobject retained_object_set); |
| 32 virtual ~JavaBridgeDispatcherHostManager(); | 33 virtual ~JavaBridgeDispatcherHostManager(); |
| 33 | 34 |
| 34 // These methods add or remove the object to each JavaBridgeDispatcherHost. | 35 // These methods add or remove the object to each JavaBridgeDispatcherHost. |
| 35 // Each one holds a reference to the NPObject while the object is bound to | 36 // Each one holds a reference to the NPObject while the object is bound to |
| 36 // the corresponding RenderFrame. See JavaBridgeDispatcherHost for details. | 37 // the corresponding RenderFrame. See JavaBridgeDispatcherHost for details. |
| 37 void AddNamedObject(const base::string16& name, NPObject* object); | 38 void AddNamedObject(const base::string16& name, NPObject* object); |
| 38 void RemoveNamedObject(const base::string16& name); | 39 void RemoveNamedObject(const base::string16& name); |
| 39 | 40 |
| 40 void OnGetChannelHandle(RenderFrameHost* render_frame_host, | |
| 41 IPC::Message* reply_msg); | |
| 42 | |
| 43 // Every time a JavaBoundObject backed by a real Java object is | |
| 44 // created/destroyed, we insert/remove a strong ref to that Java object into | |
| 45 // this set so that it doesn't get garbage collected while it's still | |
| 46 // potentially in use. Although the set is managed native side, it's owned | |
| 47 // and defined in Java so that pushing refs into it does not create new GC | |
| 48 // roots that would prevent ContentViewCore from being garbage collected. | |
| 49 void SetRetainedObjectSet(const JavaObjectWeakGlobalRef& retained_object_set); | |
| 50 | |
| 51 // WebContentsObserver overrides | 41 // WebContentsObserver overrides |
| 52 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) OVERRIDE; | 42 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) OVERRIDE; |
| 53 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE; | 43 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) OVERRIDE; |
| 54 virtual void DocumentAvailableInMainFrame() OVERRIDE; | 44 virtual void DocumentAvailableInMainFrame() OVERRIDE; |
| 45 virtual bool OnMessageReceived(RenderFrameHost* render_frame_host, |
| 46 const IPC::Message& message) OVERRIDE; |
| 55 | 47 |
| 56 void JavaBoundObjectCreated(const base::android::JavaRef<jobject>& object); | 48 void JavaBoundObjectCreated(const base::android::JavaRef<jobject>& object); |
| 57 void JavaBoundObjectDestroyed(const base::android::JavaRef<jobject>& object); | 49 void JavaBoundObjectDestroyed(const base::android::JavaRef<jobject>& object); |
| 58 | 50 |
| 59 bool GetAllowObjectContentsInspection() const { | 51 bool GetAllowObjectContentsInspection() const { |
| 60 return allow_object_contents_inspection_; | 52 return allow_object_contents_inspection_; |
| 61 } | 53 } |
| 62 void SetAllowObjectContentsInspection(bool allow); | 54 void SetAllowObjectContentsInspection(bool allow); |
| 63 | 55 |
| 64 private: | 56 private: |
| 57 void OnGetChannelHandle(IPC::Message* reply_msg); |
| 58 |
| 65 typedef std::map<RenderFrameHost*, scoped_refptr<JavaBridgeDispatcherHost> > | 59 typedef std::map<RenderFrameHost*, scoped_refptr<JavaBridgeDispatcherHost> > |
| 66 InstanceMap; | 60 InstanceMap; |
| 67 InstanceMap instances_; | 61 InstanceMap instances_; |
| 68 typedef std::map<base::string16, NPObject*> ObjectMap; | 62 typedef std::map<base::string16, NPObject*> ObjectMap; |
| 69 ObjectMap objects_; | 63 ObjectMap objects_; |
| 64 // Every time a JavaBoundObject backed by a real Java object is |
| 65 // created/destroyed, we insert/remove a strong ref to that Java object into |
| 66 // this set so that it doesn't get garbage collected while it's still |
| 67 // potentially in use. Although the set is managed native side, it's owned |
| 68 // and defined in Java so that pushing refs into it does not create new GC |
| 69 // roots that would prevent ContentViewCore from being garbage collected. |
| 70 JavaObjectWeakGlobalRef retained_object_set_; | 70 JavaObjectWeakGlobalRef retained_object_set_; |
| 71 bool allow_object_contents_inspection_; | 71 bool allow_object_contents_inspection_; |
| 72 RenderFrameHost* render_frame_host_message_source_; |
| 72 | 73 |
| 73 DISALLOW_COPY_AND_ASSIGN(JavaBridgeDispatcherHostManager); | 74 DISALLOW_COPY_AND_ASSIGN(JavaBridgeDispatcherHostManager); |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 } // namespace content | 77 } // namespace content |
| 77 | 78 |
| 78 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BRIDGE_DISPATCHER_HOST_MANAGE
R_H_ | 79 #endif // CONTENT_BROWSER_RENDERER_HOST_JAVA_JAVA_BRIDGE_DISPATCHER_HOST_MANAGE
R_H_ |
| OLD | NEW |