1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/android/view_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_helper.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "jni/ViewAndroid_jni.h"
11 #include "ui/android/window_android.h"
15 using base::android::AttachCurrentThread
;
16 using base::android::ScopedJavaLocalRef
;
18 ViewAndroid::ViewAndroid(JNIEnv
* env
, jobject obj
, WindowAndroid
* window
)
19 : weak_java_view_(env
, obj
),
20 window_android_(window
) {}
22 void ViewAndroid::Destroy(JNIEnv
* env
, jobject obj
) {
23 DCHECK(obj
&& env
->IsSameObject(weak_java_view_
.get(env
).obj(), obj
));
27 ScopedJavaLocalRef
<jobject
> ViewAndroid::GetJavaObject() {
28 // It is mandatory to explicitly call destroy() before releasing the java
29 // side object. This could be changed in future by adding CleanupReference
30 // based destruct path;
31 return weak_java_view_
.get(AttachCurrentThread());
34 WindowAndroid
* ViewAndroid::GetWindowAndroid() {
35 return window_android_
;
38 bool ViewAndroid::RegisterViewAndroid(JNIEnv
* env
) {
39 return RegisterNativesImpl(env
);
42 ViewAndroid::~ViewAndroid() {
45 jint
Init(JNIEnv
* env
, jobject obj
, jint window
) {
46 ViewAndroid
* view
= new ViewAndroid(
47 env
, obj
, reinterpret_cast<ui::WindowAndroid
*>(window
));
48 return reinterpret_cast<jint
>(view
);