Exclude TrayIMETest.PerformActionOnDetailedView under valgrind, where it crashes.
[chromium-blink-merge.git] / ui / android / window_android.cc
blob0106ba1829895a6e97f9c48e7d71b50c784ba35f
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/android/window_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h"
10 #include "base/android/jni_weak_ref.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "jni/WindowAndroid_jni.h"
13 #include "ui/android/window_android_compositor.h"
14 #include "ui/android/window_android_observer.h"
16 namespace ui {
18 using base::android::AttachCurrentThread;
19 using base::android::ScopedJavaLocalRef;
21 WindowAndroid::WindowAndroid(JNIEnv* env, jobject obj) : compositor_(NULL) {
22 java_window_.Reset(env, obj);
25 void WindowAndroid::Destroy(JNIEnv* env, jobject obj) {
26 delete this;
29 ScopedJavaLocalRef<jobject> WindowAndroid::GetJavaObject() {
30 return base::android::ScopedJavaLocalRef<jobject>(java_window_);
33 bool WindowAndroid::RegisterWindowAndroid(JNIEnv* env) {
34 return RegisterNativesImpl(env);
37 WindowAndroid::~WindowAndroid() {
38 DCHECK(!compositor_);
41 void WindowAndroid::OnCompositingDidCommit() {
42 FOR_EACH_OBSERVER(WindowAndroidObserver,
43 observer_list_,
44 OnCompositingDidCommit());
47 void WindowAndroid::AddObserver(WindowAndroidObserver* observer) {
48 if (!observer_list_.HasObserver(observer))
49 observer_list_.AddObserver(observer);
52 void WindowAndroid::RemoveObserver(WindowAndroidObserver* observer) {
53 observer_list_.RemoveObserver(observer);
56 void WindowAndroid::AttachCompositor(WindowAndroidCompositor* compositor) {
57 if (compositor_ && compositor != compositor_)
58 DetachCompositor();
60 compositor_ = compositor;
61 FOR_EACH_OBSERVER(WindowAndroidObserver,
62 observer_list_,
63 OnAttachCompositor());
66 void WindowAndroid::DetachCompositor() {
67 compositor_ = NULL;
68 FOR_EACH_OBSERVER(WindowAndroidObserver,
69 observer_list_,
70 OnDetachCompositor());
71 observer_list_.Clear();
74 void WindowAndroid::RequestVSyncUpdate() {
75 JNIEnv* env = AttachCurrentThread();
76 Java_WindowAndroid_requestVSyncUpdate(env, GetJavaObject().obj());
79 void WindowAndroid::SetNeedsAnimate() {
80 if (compositor_)
81 compositor_->SetNeedsAnimate();
84 void WindowAndroid::Animate(base::TimeTicks begin_frame_time) {
85 FOR_EACH_OBSERVER(
86 WindowAndroidObserver, observer_list_, OnAnimate(begin_frame_time));
89 void WindowAndroid::OnVSync(JNIEnv* env,
90 jobject obj,
91 jlong time_micros,
92 jlong period_micros) {
93 base::TimeTicks frame_time(base::TimeTicks::FromInternalValue(time_micros));
94 base::TimeDelta vsync_period(
95 base::TimeDelta::FromMicroseconds(period_micros));
96 FOR_EACH_OBSERVER(
97 WindowAndroidObserver,
98 observer_list_,
99 OnVSync(frame_time, vsync_period));
100 if (compositor_)
101 compositor_->OnVSync(frame_time, vsync_period);
104 void WindowAndroid::OnVisibilityChanged(JNIEnv* env,
105 jobject obj,
106 bool visible) {
107 FOR_EACH_OBSERVER(WindowAndroidObserver, observer_list_,
108 OnRootWindowVisibilityChanged(visible));
111 void WindowAndroid::OnActivityStopped(JNIEnv* env, jobject obj) {
112 FOR_EACH_OBSERVER(WindowAndroidObserver, observer_list_, OnActivityStopped());
115 void WindowAndroid::OnActivityStarted(JNIEnv* env, jobject obj) {
116 FOR_EACH_OBSERVER(WindowAndroidObserver, observer_list_, OnActivityStarted());
119 bool WindowAndroid::HasPermission(const std::string& permission) {
120 JNIEnv* env = AttachCurrentThread();
121 return Java_WindowAndroid_hasPermission(
122 env,
123 GetJavaObject().obj(),
124 base::android::ConvertUTF8ToJavaString(env, permission).obj());
127 bool WindowAndroid::CanRequestPermission(const std::string& permission) {
128 JNIEnv* env = AttachCurrentThread();
129 return Java_WindowAndroid_canRequestPermission(
130 env,
131 GetJavaObject().obj(),
132 base::android::ConvertUTF8ToJavaString(env, permission).obj());
135 // ----------------------------------------------------------------------------
136 // Native JNI methods
137 // ----------------------------------------------------------------------------
139 jlong Init(JNIEnv* env, jobject obj) {
140 WindowAndroid* window = new WindowAndroid(env, obj);
141 return reinterpret_cast<intptr_t>(window);
144 } // namespace ui