Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1140)

Unified Diff: ui/gfx/android/window_android.cc

Issue 10916160: Upstreaming SelectFileDialog for Android (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Yaron's nits Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/android/window_android.cc
diff --git a/ui/gfx/android/window_android.cc b/ui/gfx/android/window_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2fde3aa2d35fb672a2c9c1836c1a6b1aba5fad54
--- /dev/null
+++ b/ui/gfx/android/window_android.cc
@@ -0,0 +1,61 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "window_android.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_helper.h"
+#include "base/android/scoped_java_ref.h"
+#include "jni/NativeWindow_jni.h"
+
+namespace ui {
+
+using base::android::AttachCurrentThread;
+using base::android::ScopedJavaLocalRef;
+
+struct WindowAndroid::JavaObject {
+ jweak obj_;
+ ScopedJavaLocalRef<jobject> WindowAndroid(JNIEnv* env) {
sky 2012/09/13 16:24:04 Generally structs shouldn't have methods.
aurimas (slooooooooow) 2012/09/14 00:06:59 Done.
+ return GetRealObject(env, obj_);
+ }
+};
+
+WindowAndroid::WindowAndroid(JNIEnv* env, jobject obj) {
+ java_object_ = new JavaObject;
+ java_object_->obj_ = env->NewWeakGlobalRef(obj);
+}
+
+WindowAndroid::~WindowAndroid() {
+ if (java_object_->obj_) {
+ JNIEnv* env = AttachCurrentThread();
+ env->DeleteWeakGlobalRef(java_object_->obj_);
+ java_object_->obj_ = 0;
sky 2012/09/13 16:24:04 NULL
aurimas (slooooooooow) 2012/09/14 00:06:59 Done.
+ }
+ delete java_object_;
+}
+
+void WindowAndroid::Destroy(JNIEnv* env, jobject obj) {
+ delete this;
sky 2012/09/13 16:24:04 If this is the only way to delte 'this' then make
aurimas (slooooooooow) 2012/09/14 00:06:59 Done.
+}
+
+ScopedJavaLocalRef<jobject> WindowAndroid::GetJavaObject() {
+ JNIEnv* env = AttachCurrentThread();
+ return GetRealObject(env, java_object_->obj_);
+}
+
+bool WindowAndroid::RegisterWindowAndroid(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+
+// ----------------------------------------------------------------------------
+// Native JNI methods
+// ----------------------------------------------------------------------------
+
+jint Init(JNIEnv* env, jobject obj) {
+ WindowAndroid* window = new WindowAndroid(env, obj);
+ return reinterpret_cast<jint>(window);
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698