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

Side by Side Diff: content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.cc

Issue 18570003: Move Renderer-side NPObject owner tracking to JavaBridgeChannel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move some comment cleanup to crrev.com/17428003 Created 7 years, 5 months 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 | Annotate | Revision Log
OLDNEW
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 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager .h" 5 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager .h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_helper.h" 8 #include "base/android/jni_helper.h"
9 #include "base/android/scoped_java_ref.h" 9 #include "base/android/scoped_java_ref.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "content/browser/renderer_host/java/java_bound_object.h" 13 #include "content/browser/renderer_host/java/java_bound_object.h"
14 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host.h" 14 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host.h"
15 #include "content/common/android/hash_set.h" 15 #include "content/common/android/hash_set.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "third_party/WebKit/public/web/WebBindings.h" 17 #include "third_party/WebKit/public/web/WebBindings.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 JavaBridgeDispatcherHostManager::JavaBridgeDispatcherHostManager( 21 JavaBridgeDispatcherHostManager::JavaBridgeDispatcherHostManager(
22 WebContents* web_contents) 22 WebContents* web_contents)
23 : WebContentsObserver(web_contents) { 23 : WebContentsObserver(web_contents),
24 object_owner_id_(new struct _NPP) {
25 // Register a dummy owner Id for JavaBoundObject instances.
26 WebKit::WebBindings::registerObjectOwner(object_owner_id_.get());
24 } 27 }
25 28
26 JavaBridgeDispatcherHostManager::~JavaBridgeDispatcherHostManager() { 29 JavaBridgeDispatcherHostManager::~JavaBridgeDispatcherHostManager() {
27 for (ObjectMap::iterator iter = objects_.begin(); iter != objects_.end(); 30 for (ObjectMap::iterator iter = objects_.begin(); iter != objects_.end();
28 ++iter) { 31 ++iter) {
29 WebKit::WebBindings::releaseObject(iter->second); 32 WebKit::WebBindings::releaseObject(iter->second);
30 } 33 }
31 DCHECK_EQ(0U, instances_.size()); 34 DCHECK_EQ(0U, instances_.size());
35
36 WebKit::WebBindings::unregisterObjectOwner(object_owner_id_.get());
32 } 37 }
33 38
34 void JavaBridgeDispatcherHostManager::AddNamedObject(const string16& name, 39 void JavaBridgeDispatcherHostManager::AddNamedObject(const string16& name,
35 NPObject* object) { 40 NPObject* object) {
36 // Record this object in a map so that we can add it into RenderViewHosts 41 // Record this object in a map so that we can add it into RenderViewHosts
37 // created later. The JavaBridgeDispatcherHost instances will take a 42 // created later. The JavaBridgeDispatcherHost instances will take a
38 // reference to the object, but we take one too, because this method can be 43 // reference to the object, but we take one too, because this method can be
39 // called before there are any such instances. 44 // called before there are any such instances.
40 WebKit::WebBindings::retainObject(object); 45 WebKit::WebBindings::retainObject(object);
41 objects_[name] = object; 46 objects_[name] = object;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 152
148 JNIEnv* env = base::android::AttachCurrentThread(); 153 JNIEnv* env = base::android::AttachCurrentThread();
149 base::android::ScopedJavaLocalRef<jobject> retained_object_set = 154 base::android::ScopedJavaLocalRef<jobject> retained_object_set =
150 retained_object_set_.get(env); 155 retained_object_set_.get(env);
151 if (!retained_object_set.is_null()) { 156 if (!retained_object_set.is_null()) {
152 JNI_Java_HashSet_remove(env, retained_object_set, object); 157 JNI_Java_HashSet_remove(env, retained_object_set, object);
153 } 158 }
154 } 159 }
155 160
156 } // namespace content 161 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698