1 // Copyright 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/base/android/window_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
9 #include "base/android/jni_helper.h"
10 #include "base/android/scoped_java_ref.h"
11 #include "jni/WindowAndroid_jni.h"
15 using base::android::AttachCurrentThread;
16 using base::android::ScopedJavaLocalRef;
18 WindowAndroid::WindowAndroid(JNIEnv* env, jobject obj)
19 : weak_java_window_(env, obj) {
22 void WindowAndroid::Destroy(JNIEnv* env, jobject obj) {
26 ScopedJavaLocalRef<jobject> WindowAndroid::GetJavaObject() {
27 return weak_java_window_.get(AttachCurrentThread());
30 bool WindowAndroid::RegisterWindowAndroid(JNIEnv* env) {
31 return RegisterNativesImpl(env);
34 WindowAndroid::~WindowAndroid() {
37 bool WindowAndroid::GrabSnapshot(
38 int content_x, int content_y, int width, int height,
39 std::vector<unsigned char>* png_representation) {
40 JNIEnv* env = AttachCurrentThread();
41 ScopedJavaLocalRef<jbyteArray> result =
42 Java_WindowAndroid_grabSnapshot(env, GetJavaObject().obj(),
43 content_x + content_offset_.x(),
44 content_y + content_offset_.y(),
48 base::android::JavaByteArrayToByteVector(
49 env, result.obj(), png_representation);
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 jint Init(JNIEnv* env, jobject obj) {
58 WindowAndroid* window = new WindowAndroid(env, obj);
59 return reinterpret_cast<jint>(window);