This source file includes following definitions.
- allow_object_contents_inspection_
- AddNamedObject
- SetRetainedObjectSet
- RemoveNamedObject
- OnGetChannelHandle
- RenderFrameCreated
- RenderFrameDeleted
- DocumentAvailableInMainFrame
- JavaBoundObjectCreated
- JavaBoundObjectDestroyed
- SetAllowObjectContentsInspection
#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
#include "base/android/jni_android.h"
#include "base/android/jni_helper.h"
#include "base/android/scoped_java_ref.h"
#include "base/bind.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "content/browser/renderer_host/java/java_bound_object.h"
#include "content/browser/renderer_host/java/java_bridge_dispatcher_host.h"
#include "content/common/android/hash_set.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "third_party/WebKit/public/web/WebBindings.h"
namespace content {
JavaBridgeDispatcherHostManager::JavaBridgeDispatcherHostManager(
WebContents* web_contents)
: WebContentsObserver(web_contents),
allow_object_contents_inspection_(true) {
}
JavaBridgeDispatcherHostManager::~JavaBridgeDispatcherHostManager() {
for (ObjectMap::iterator iter = objects_.begin(); iter != objects_.end();
++iter) {
blink::WebBindings::releaseObject(iter->second);
}
DCHECK_EQ(0U, instances_.size());
}
void JavaBridgeDispatcherHostManager::AddNamedObject(const base::string16& name,
NPObject* object) {
blink::WebBindings::retainObject(object);
objects_[name] = object;
for (InstanceMap::iterator iter = instances_.begin();
iter != instances_.end(); ++iter) {
iter->second->AddNamedObject(name, object);
}
}
void JavaBridgeDispatcherHostManager::SetRetainedObjectSet(
const JavaObjectWeakGlobalRef& retained_object_set) {
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jobject> new_retained_object_set =
retained_object_set.get(env);
base::android::ScopedJavaLocalRef<jobject> current_retained_object_set =
retained_object_set_.get(env);
if (!env->IsSameObject(new_retained_object_set.obj(),
current_retained_object_set.obj())) {
DCHECK(current_retained_object_set.is_null());
retained_object_set_ = retained_object_set;
}
}
void JavaBridgeDispatcherHostManager::RemoveNamedObject(
const base::string16& name) {
ObjectMap::iterator iter = objects_.find(name);
if (iter == objects_.end()) {
return;
}
blink::WebBindings::releaseObject(iter->second);
objects_.erase(iter);
for (InstanceMap::iterator iter = instances_.begin();
iter != instances_.end(); ++iter) {
iter->second->RemoveNamedObject(name);
}
}
void JavaBridgeDispatcherHostManager::OnGetChannelHandle(
RenderFrameHost* render_frame_host, IPC::Message* reply_msg) {
instances_[render_frame_host]->OnGetChannelHandle(reply_msg);
}
void JavaBridgeDispatcherHostManager::RenderFrameCreated(
RenderFrameHost* render_frame_host) {
scoped_refptr<JavaBridgeDispatcherHost> instance =
new JavaBridgeDispatcherHost(render_frame_host);
for (ObjectMap::const_iterator iter = objects_.begin();
iter != objects_.end(); ++iter) {
instance->AddNamedObject(iter->first, iter->second);
}
instances_[render_frame_host] = instance;
}
void JavaBridgeDispatcherHostManager::RenderFrameDeleted(
RenderFrameHost* render_frame_host) {
if (!instances_.count(render_frame_host))
return;
instances_[render_frame_host]->RenderFrameDeleted();
instances_.erase(render_frame_host);
}
void JavaBridgeDispatcherHostManager::DocumentAvailableInMainFrame() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jobject> retained_object_set =
retained_object_set_.get(env);
if (!retained_object_set.is_null()) {
JNI_Java_HashSet_clear(env, retained_object_set);
ObjectMap::iterator it = objects_.begin();
for (; it != objects_.end(); ++it) {
JNI_Java_HashSet_add(env, retained_object_set,
JavaBoundObject::GetJavaObject(it->second));
}
}
}
void JavaBridgeDispatcherHostManager::JavaBoundObjectCreated(
const base::android::JavaRef<jobject>& object) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jobject> retained_object_set =
retained_object_set_.get(env);
if (!retained_object_set.is_null()) {
JNI_Java_HashSet_add(env, retained_object_set, object);
}
}
void JavaBridgeDispatcherHostManager::JavaBoundObjectDestroyed(
const base::android::JavaRef<jobject>& object) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jobject> retained_object_set =
retained_object_set_.get(env);
if (!retained_object_set.is_null()) {
JNI_Java_HashSet_remove(env, retained_object_set, object);
}
}
void JavaBridgeDispatcherHostManager::SetAllowObjectContentsInspection(
bool allow) {
allow_object_contents_inspection_ = allow;
}
}