Chromium Code Reviews| Index: chrome/android/testshell/tab_manager.cc |
| diff --git a/chrome/android/testshell/tab_manager.cc b/chrome/android/testshell/tab_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1e3404afcc576e462d29488d03bee5d25855b477 |
| --- /dev/null |
| +++ b/chrome/android/testshell/tab_manager.cc |
| @@ -0,0 +1,114 @@ |
| +// 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 "chrome/android/testshell/tab_manager.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_string.h" |
| +#include "base/android/scoped_java_ref.h" |
| +#include "base/bind.h" |
| +#include "base/lazy_instance.h" |
| +#include "chrome/browser/android/tab_base_android_impl.h" |
| +#include "content/public/browser/android/compositor.h" |
| +#include "content/public/browser/android/draw_delegate.h" |
| +#include "jni/TabManager_jni.h" |
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" |
| + |
| +#include <android/native_window_jni.h> |
| + |
| +using base::android::ScopedJavaLocalRef; |
| +using content::Compositor; |
| +using content::DrawDelegate; |
| + |
| +namespace { |
| + |
| +struct GlobalState { |
| + base::android::ScopedJavaGlobalRef<jobject> jobj_; |
|
Jay Civelli
2012/09/24 22:43:08
No "_" for struct members, it should be:
base::an
David Trainor- moved to gerrit
2012/09/24 23:39:57
Done.
|
| + scoped_ptr<content::Compositor> compositor_; |
|
Jay Civelli
2012/09/24 22:43:08
Nit: no need for fully qualified name, you are "us
David Trainor- moved to gerrit
2012/09/24 23:39:57
Done.
|
| + scoped_ptr<WebKit::WebLayer> root_layer_; |
| +}; |
| + |
| +base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; |
| + |
| +content::Compositor* GetCompositor() { |
| + return g_global_state.Get().compositor_.get(); |
| +} |
| + |
| +static void SurfacePresented( |
| + const content::DrawDelegate::SurfacePresentedCallback& callback, |
| + uint32 sync_point) { |
| + callback.Run(sync_point); |
| +} |
| + |
| +void DummyCallback(uint32) { } |
| + |
| +static void SurfaceUpdated( |
| + uint64 texture, |
| + content::RenderWidgetHostView* view, |
| + const content::DrawDelegate::SurfacePresentedCallback& callback) { |
| + GetCompositor()->OnSurfaceUpdated(base::Bind( |
| + &SurfacePresented, callback)); |
| +} |
| + |
| +} // anonymous namespace |
| + |
| +namespace chrome { |
| + |
| +// Register native methods |
| +bool RegisterTabManager(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +static void Init(JNIEnv* env, jclass clazz, jobject obj) { |
| + g_global_state.Get().jobj_.Reset( |
|
Jay Civelli
2012/09/24 22:43:08
I don't understand why we need a GlobalRef on that
David Trainor- moved to gerrit
2012/09/24 23:39:57
After refactoring I think I don't need this at all
|
| + base::android::ScopedJavaLocalRef<jobject>(env, obj)); |
|
Jay Civelli
2012/09/24 22:43:08
Nit: no need for the full qualified name, you are
David Trainor- moved to gerrit
2012/09/24 23:39:57
Done.
|
| + content::DrawDelegate::SurfaceUpdatedCallback cb = base::Bind( |
| + &SurfaceUpdated); |
| + content::DrawDelegate::GetInstance()->SetUpdateCallback(cb); |
| + if (!GetCompositor()) { |
| + Compositor::Initialize(); |
| + g_global_state.Get().compositor_.reset(Compositor::Create()); |
| + DCHECK(!g_global_state.Get().root_layer_.get()); |
| + g_global_state.Get().root_layer_.reset(WebKit::WebLayer::create()); |
| + } |
| +} |
| + |
| +static void SurfaceCreated( |
| + JNIEnv* env, jclass clazz, jobject jsurface) { |
|
Jay Civelli
2012/09/24 22:43:08
Doesn't that fit on the prev line?
David Trainor- moved to gerrit
2012/09/24 23:39:57
Done.
|
| + ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface); |
| + if (native_window) { |
| + GetCompositor()->SetWindowSurface(native_window); |
| + ANativeWindow_release(native_window); |
| + GetCompositor()->SetRootLayer(g_global_state.Get().root_layer_.get()); |
| + } |
| +} |
| + |
| +static void SurfaceDestroyed(JNIEnv* env, jclass clazz) { |
| + GetCompositor()->SetWindowSurface(NULL); |
| +} |
| + |
| +static void SurfaceSetSize( |
| + JNIEnv* env, jclass clazz, jint width, jint height) { |
| + gfx::Size size = gfx::Size(width, height); |
| + content::DrawDelegate::GetInstance()->SetBounds(size); |
| + GetCompositor()->SetWindowBounds(size); |
| +} |
| + |
| +static void ShowTab( |
| + JNIEnv* env, jclass clazz, jint jtab) { |
|
Jay Civelli
2012/09/24 22:43:08
Nit: Should fit on previous line, right?
David Trainor- moved to gerrit
2012/09/24 23:39:57
Done.
|
| + if (!GetCompositor()) return; |
|
Jay Civelli
2012/09/24 22:43:08
C++ style code says return should be on next line.
David Trainor- moved to gerrit
2012/09/24 23:39:57
Done.
|
| + TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab); |
| + g_global_state.Get().root_layer_->addChild(tab->tab_layer()); |
| + GetCompositor()->OnSurfaceUpdated(base::Bind(&DummyCallback)); |
| +} |
| + |
| +static void HideTab( |
| + JNIEnv* env, jclass clazz, jint jtab) { |
|
Jay Civelli
2012/09/24 22:43:08
Nit: Would fit on prev line.
David Trainor- moved to gerrit
2012/09/24 23:39:57
Done.
|
| + if (!GetCompositor()) return; |
| + TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab); |
| + tab->tab_layer()->removeFromParent(); |
| +} |
| + |
| +} // namespace chrome |