Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: content/browser/android/java/gin_java_bridge_dispatcher_host.cc

Issue 767453003: [Android] Fix a subtle issue in Java Bridge regarding interfaces removal (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698