Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #include "chrome/browser/android/swipe_refresh_handler.h" | |
| 6 | |
| 7 #include "jni/SwipeRefreshHandler_jni.h" | |
| 8 | |
| 9 using base::android::AttachCurrentThread; | |
| 10 using base::android::JavaParamRef; | |
| 11 using base::android::JavaRef; | |
| 12 using base::android::ScopedJavaLocalRef; | |
| 13 | |
| 14 SwipeRefreshHandler::SwipeRefreshHandler(JNIEnv* env, | |
| 15 const JavaRef<jobject>& obj) | |
| 16 : java_ref_(env, obj) {} | |
| 17 | |
| 18 bool SwipeRefreshHandler::PullStart() { | |
| 19 JNIEnv* env = AttachCurrentThread(); | |
| 20 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 21 if (!obj.is_null()) { | |
| 22 return Java_SwipeRefreshHandler_start(env, obj); | |
| 23 } | |
| 24 return false; | |
| 25 } | |
| 26 | |
| 27 void SwipeRefreshHandler::PullUpdate(float delta) { | |
| 28 JNIEnv* env = AttachCurrentThread(); | |
| 29 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 30 if (!obj.is_null()) { | |
| 31 Java_SwipeRefreshHandler_pull(env, obj, delta); | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 void SwipeRefreshHandler::PullRelease(bool allow_refresh) { | |
| 36 JNIEnv* env = AttachCurrentThread(); | |
| 37 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 38 if (!obj.is_null()) { | |
| 39 Java_SwipeRefreshHandler_release(env, obj, allow_refresh); | |
| 40 } | |
| 41 } | |
| 42 | |
| 43 void SwipeRefreshHandler::PullReset() { | |
| 44 JNIEnv* env = AttachCurrentThread(); | |
| 45 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | |
| 46 if (!obj.is_null()) { | |
| 47 Java_SwipeRefreshHandler_reset(env, obj); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | |
| 52 SwipeRefreshHandler* swipe_refresh_handler = | |
| 53 new SwipeRefreshHandler(env, obj); | |
| 54 return reinterpret_cast<intptr_t>(swipe_refresh_handler); | |
|
Jinsuk Kim
2016/11/25 01:49:18
Alternatively, you can set the created object to W
rlanday
2016/11/28 19:42:01
This seems potentially problematic to me; inside T
Jinsuk Kim
2016/11/28 23:06:40
YOu can add the api to native WebContents/WebConte
| |
| 55 } | |
| 56 | |
| 57 void SwipeRefreshHandler::Destroy(JNIEnv* env, | |
| 58 const JavaParamRef<jobject>& obj) { | |
| 59 delete this; | |
|
Jinsuk Kim
2016/11/25 01:49:18
With the refactoring I think this object better be
rlanday
2016/11/28 19:42:01
This seems weird to me; I think the native SwipeRe
Jinsuk Kim
2016/11/28 23:06:40
You don't have to worry about the destruction orde
| |
| 60 } | |
| 61 | |
| 62 // static | |
| 63 bool SwipeRefreshHandler::RegisterSwipeRefreshHandler(JNIEnv* env) { | |
| 64 return RegisterNativesImpl(env); | |
| 65 } | |
| OLD | NEW |