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

Unified Diff: ui/platform_window/android/platform_window_android.cc

Issue 1455793005: Adding a way to associate Android Activities with PlatformWindowAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@auraclank_upstream_native_widget
Patch Set: Making the new property "owned" property. Created 5 years 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
« no previous file with comments | « ui/platform_window/android/platform_window_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/platform_window/android/platform_window_android.cc
diff --git a/ui/platform_window/android/platform_window_android.cc b/ui/platform_window/android/platform_window_android.cc
index 0cfdc6bf8504e06f67ff6fd03f1ec7e036572ff3..63eaabbff80224e6aede9ecf3b0dafc79dc1bc7c 100644
--- a/ui/platform_window/android/platform_window_android.cc
+++ b/ui/platform_window/android/platform_window_android.cc
@@ -52,6 +52,12 @@ bool PlatformWindowAndroid::Register(JNIEnv* env) {
return RegisterNativesImpl(env);
}
+//static
+PlatformWindowAndroid* PlatformWindowAndroid::From(
+ PlatformWindow* platform_window) {
+ return static_cast<PlatformWindowAndroid*>(platform_window);
+}
+
PlatformWindowAndroid::PlatformWindowAndroid(PlatformWindowDelegate* delegate)
: delegate_(delegate),
window_(NULL),
@@ -70,6 +76,25 @@ PlatformWindowAndroid::~PlatformWindowAndroid() {
}
}
+void PlatformWindowAndroid::AttachToActivity(
+ JNIEnv* env,
+ const base::android::JavaRef<jobject>& activity) {
+ DCHECK(!IsAttachedToActivity());
+ DCHECK(!activity.is_null());
+ base::android::ScopedJavaLocalRef<jobject> jpwa =
+ Java_PlatformWindowAndroid_createForActivity(
+ env,
+ activity.obj(),
+ reinterpret_cast<jlong>(this),
+ reinterpret_cast<jlong>(&platform_ime_controller_));
+ java_platform_window_android_ = JavaObjectWeakGlobalRef(env, jpwa.obj());
+}
+
+bool PlatformWindowAndroid::IsAttachedToActivity() const {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ return !java_platform_window_android_.get(env).is_null();
+}
+
void PlatformWindowAndroid::Destroy(JNIEnv* env, jobject obj) {
delegate_->OnClosed();
}
@@ -154,14 +179,7 @@ void PlatformWindowAndroid::ReleaseWindow() {
// PlatformWindowAndroid, PlatformWindow implementation:
void PlatformWindowAndroid::Show() {
- if (!java_platform_window_android_.is_empty())
- return;
- JNIEnv* env = base::android::AttachCurrentThread();
- java_platform_window_android_ = JavaObjectWeakGlobalRef(
- env, Java_PlatformWindowAndroid_createForActivity(
- env, base::android::GetApplicationContext(),
- reinterpret_cast<jlong>(this),
- reinterpret_cast<jlong>(&platform_ime_controller_)).obj());
+ DCHECK(IsAttachedToActivity());
}
void PlatformWindowAndroid::Hide() {
« no previous file with comments | « ui/platform_window/android/platform_window_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698