| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 new GinJavaBridgeMsg_AddNamedObject(MSG_ROUTING_NONE, name, object_id)); | 185 new GinJavaBridgeMsg_AddNamedObject(MSG_ROUTING_NONE, name, object_id)); |
| 186 } | 186 } |
| 187 | 187 |
| 188 void GinJavaBridgeDispatcherHost::RemoveNamedObject( | 188 void GinJavaBridgeDispatcherHost::RemoveNamedObject( |
| 189 const std::string& name) { | 189 const std::string& name) { |
| 190 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 190 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 191 NamedObjectMap::iterator iter = named_objects_.find(name); | 191 NamedObjectMap::iterator iter = named_objects_.find(name); |
| 192 if (iter == named_objects_.end()) | 192 if (iter == named_objects_.end()) |
| 193 return; | 193 return; |
| 194 | 194 |
| 195 // |name| may come from |named_objects_|. Make a copy of name so that if |
| 196 // |name| is from |named_objects_| it'll be valid after the remove below. |
| 197 const std::string copied_name(name); |
| 198 |
| 195 scoped_refptr<GinJavaBoundObject> object(*objects_.Lookup(iter->second)); | 199 scoped_refptr<GinJavaBoundObject> object(*objects_.Lookup(iter->second)); |
| 196 named_objects_.erase(iter); | 200 named_objects_.erase(iter); |
| 197 object->RemoveName(); | 201 object->RemoveName(); |
| 198 | 202 |
| 199 // Not erasing from the objects map, as we can still receive method | 203 // Not erasing from the objects map, as we can still receive method |
| 200 // invocation requests for this object, and they should work until the | 204 // invocation requests for this object, and they should work until the |
| 201 // java object is gone. | 205 // java object is gone. |
| 202 if (!object->IsNamed()) { | 206 if (!object->IsNamed()) { |
| 203 JNIEnv* env = base::android::AttachCurrentThread(); | 207 JNIEnv* env = base::android::AttachCurrentThread(); |
| 204 base::android::ScopedJavaLocalRef<jobject> retained_object_set = | 208 base::android::ScopedJavaLocalRef<jobject> retained_object_set = |
| 205 retained_object_set_.get(env); | 209 retained_object_set_.get(env); |
| 206 if (!retained_object_set.is_null()) { | 210 if (!retained_object_set.is_null()) { |
| 207 JNI_Java_HashSet_remove( | 211 JNI_Java_HashSet_remove( |
| 208 env, retained_object_set, object->GetLocalRef(env)); | 212 env, retained_object_set, object->GetLocalRef(env)); |
| 209 } | 213 } |
| 210 } | 214 } |
| 211 | 215 |
| 212 web_contents()->SendToAllFrames( | 216 web_contents()->SendToAllFrames( |
| 213 new GinJavaBridgeMsg_RemoveNamedObject(MSG_ROUTING_NONE, name)); | 217 new GinJavaBridgeMsg_RemoveNamedObject(MSG_ROUTING_NONE, copied_name)); |
| 214 } | 218 } |
| 215 | 219 |
| 216 void GinJavaBridgeDispatcherHost::SetAllowObjectContentsInspection(bool allow) { | 220 void GinJavaBridgeDispatcherHost::SetAllowObjectContentsInspection(bool allow) { |
| 217 allow_object_contents_inspection_ = allow; | 221 allow_object_contents_inspection_ = allow; |
| 218 } | 222 } |
| 219 | 223 |
| 220 void GinJavaBridgeDispatcherHost::DocumentAvailableInMainFrame() { | 224 void GinJavaBridgeDispatcherHost::DocumentAvailableInMainFrame() { |
| 221 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 225 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 222 // Called when the window object has been cleared in the main frame. | 226 // Called when the window object has been cleared in the main frame. |
| 223 // That means, all sub-frames have also been cleared, so only named | 227 // That means, all sub-frames have also been cleared, so only named |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 if (objects_.Lookup(object_id)) { | 521 if (objects_.Lookup(object_id)) { |
| 518 GinJavaBoundObject::ObjectMap::iterator iter(&objects_); | 522 GinJavaBoundObject::ObjectMap::iterator iter(&objects_); |
| 519 while (!iter.IsAtEnd() && iter.GetCurrentKey() != object_id) | 523 while (!iter.IsAtEnd() && iter.GetCurrentKey() != object_id) |
| 520 iter.Advance(); | 524 iter.Advance(); |
| 521 DCHECK(!iter.IsAtEnd()); | 525 DCHECK(!iter.IsAtEnd()); |
| 522 RemoveHolder(render_frame_host, iter, 1); | 526 RemoveHolder(render_frame_host, iter, 1); |
| 523 } | 527 } |
| 524 } | 528 } |
| 525 | 529 |
| 526 } // namespace content | 530 } // namespace content |
| OLD | NEW |