| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" | 5 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/android/java_handler_thread.h" | 7 #include "base/android/java_handler_thread.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 return; | 203 return; |
| 204 | 204 |
| 205 // |name| may come from |named_objects_|. Make a copy of name so that if | 205 // |name| may come from |named_objects_|. Make a copy of name so that if |
| 206 // |name| is from |named_objects_| it'll be valid after the remove below. | 206 // |name| is from |named_objects_| it'll be valid after the remove below. |
| 207 const std::string copied_name(name); | 207 const std::string copied_name(name); |
| 208 | 208 |
| 209 scoped_refptr<GinJavaBoundObject> object(*objects_.Lookup(iter->second)); | 209 scoped_refptr<GinJavaBoundObject> object(*objects_.Lookup(iter->second)); |
| 210 named_objects_.erase(iter); | 210 named_objects_.erase(iter); |
| 211 object->RemoveName(); | 211 object->RemoveName(); |
| 212 | 212 |
| 213 // Not erasing from the objects map, as we can still receive method | 213 // As the object isn't going to be removed from the JavaScript side until the |
| 214 // invocation requests for this object, and they should work until the | 214 // next page reload, calls to it must still work, thus we should continue to |
| 215 // java object is gone. | 215 // hold it. All the transient objects and removed named objects will be purged |
| 216 if (!object->IsNamed()) { | 216 // during the cleansing caused by DocumentAvailableInMainFrame event. |
| 217 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 218 base::android::ScopedJavaLocalRef<jobject> retained_object_set = | |
| 219 retained_object_set_.get(env); | |
| 220 if (!retained_object_set.is_null()) { | |
| 221 JNI_Java_HashSet_remove( | |
| 222 env, retained_object_set, object->GetLocalRef(env)); | |
| 223 } | |
| 224 } | |
| 225 | 217 |
| 226 web_contents()->SendToAllFrames( | 218 web_contents()->SendToAllFrames( |
| 227 new GinJavaBridgeMsg_RemoveNamedObject(MSG_ROUTING_NONE, copied_name)); | 219 new GinJavaBridgeMsg_RemoveNamedObject(MSG_ROUTING_NONE, copied_name)); |
| 228 } | 220 } |
| 229 | 221 |
| 230 void GinJavaBridgeDispatcherHost::SetAllowObjectContentsInspection(bool allow) { | 222 void GinJavaBridgeDispatcherHost::SetAllowObjectContentsInspection(bool allow) { |
| 231 allow_object_contents_inspection_ = allow; | 223 allow_object_contents_inspection_ = allow; |
| 232 } | 224 } |
| 233 | 225 |
| 234 void GinJavaBridgeDispatcherHost::DocumentAvailableInMainFrame() { | 226 void GinJavaBridgeDispatcherHost::DocumentAvailableInMainFrame() { |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 pending_replies_.erase(it); | 555 pending_replies_.erase(it); |
| 564 return reply_msg; | 556 return reply_msg; |
| 565 } | 557 } |
| 566 | 558 |
| 567 bool GinJavaBridgeDispatcherHost::HasPendingReply( | 559 bool GinJavaBridgeDispatcherHost::HasPendingReply( |
| 568 RenderFrameHost* render_frame_host) const { | 560 RenderFrameHost* render_frame_host) const { |
| 569 return pending_replies_.find(render_frame_host) != pending_replies_.end(); | 561 return pending_replies_.find(render_frame_host) != pending_replies_.end(); |
| 570 } | 562 } |
| 571 | 563 |
| 572 } // namespace content | 564 } // namespace content |
| OLD | NEW |