| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/android/feedback/screenshot_task.h" | 5 #include "chrome/browser/android/feedback/screenshot_task.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 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/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "jni/ScreenshotTask_jni.h" | 13 #include "jni/ScreenshotTask_jni.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "ui/android/window_android.h" | 15 #include "ui/android/window_android.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
| 17 #include "ui/snapshot/snapshot.h" | 17 #include "ui/snapshot/snapshot.h" |
| 18 | 18 |
| 19 using base::android::AttachCurrentThread; | 19 using base::android::AttachCurrentThread; |
| 20 using base::android::JavaParamRef; | 20 using base::android::JavaParamRef; |
| 21 using base::android::JavaRef; |
| 21 using base::android::ScopedJavaGlobalRef; | 22 using base::android::ScopedJavaGlobalRef; |
| 22 using ui::WindowAndroid; | 23 using ui::WindowAndroid; |
| 23 | 24 |
| 24 namespace chrome { | 25 namespace chrome { |
| 25 namespace android { | 26 namespace android { |
| 26 | 27 |
| 27 bool RegisterScreenshotTask(JNIEnv* env) { | 28 bool RegisterScreenshotTask(JNIEnv* env) { |
| 28 return RegisterNativesImpl(env); | 29 return RegisterNativesImpl(env); |
| 29 } | 30 } |
| 30 | 31 |
| 31 void SnapshotCallback(JNIEnv* env, | 32 void SnapshotCallback(JNIEnv* env, |
| 32 base::android::ScopedJavaGlobalRef<jobject>* callback, | 33 const JavaRef<jobject>& callback, |
| 33 scoped_refptr<base::RefCountedBytes> png_data) { | 34 scoped_refptr<base::RefCountedBytes> png_data) { |
| 34 jbyteArray jbytes = nullptr; | 35 jbyteArray jbytes = nullptr; |
| 35 if (png_data.get()) { | 36 if (png_data.get()) { |
| 36 size_t size = png_data->size(); | 37 size_t size = png_data->size(); |
| 37 jbytes = env->NewByteArray(size); | 38 jbytes = env->NewByteArray(size); |
| 38 env->SetByteArrayRegion(jbytes, 0, size, (jbyte*) png_data->front()); | 39 env->SetByteArrayRegion(jbytes, 0, size, (jbyte*) png_data->front()); |
| 39 } | 40 } |
| 40 Java_ScreenshotTask_notifySnapshotFinished(env, | 41 Java_ScreenshotTask_notifySnapshotFinished(env, callback, jbytes); |
| 41 callback->obj(), | |
| 42 jbytes); | |
| 43 } | 42 } |
| 44 | 43 |
| 45 void GrabWindowSnapshotAsync(JNIEnv* env, | 44 void GrabWindowSnapshotAsync(JNIEnv* env, |
| 46 const JavaParamRef<jclass>& clazz, | 45 const JavaParamRef<jclass>& clazz, |
| 47 const JavaParamRef<jobject>& jcallback, | 46 const JavaParamRef<jobject>& jcallback, |
| 48 jlong native_window_android, | 47 jlong native_window_android, |
| 49 jint window_width, | 48 jint window_width, |
| 50 jint window_height) { | 49 jint window_height) { |
| 51 WindowAndroid* window_android = reinterpret_cast<WindowAndroid*>( | 50 WindowAndroid* window_android = reinterpret_cast<WindowAndroid*>( |
| 52 native_window_android); | 51 native_window_android); |
| 53 gfx::Rect window_bounds(window_width, window_height); | 52 gfx::Rect window_bounds(window_width, window_height); |
| 54 ui::GrabWindowSnapshotAsync( | 53 ui::GrabWindowSnapshotAsync( |
| 55 window_android, | 54 window_android, window_bounds, base::ThreadTaskRunnerHandle::Get(), |
| 56 window_bounds, | 55 base::Bind(&SnapshotCallback, env, |
| 57 base::ThreadTaskRunnerHandle::Get(), | 56 ScopedJavaGlobalRef<jobject>(env, jcallback))); |
| 58 base::Bind(&SnapshotCallback, | |
| 59 env, | |
| 60 base::Owned(new ScopedJavaGlobalRef<jobject>(env, | |
| 61 jcallback)))); | |
| 62 } | 57 } |
| 63 | 58 |
| 64 } // namespace android | 59 } // namespace android |
| 65 } // namespace chrome | 60 } // namespace chrome |
| OLD | NEW |