| Index: chrome/android/testshell/tab_manager.cc
|
| diff --git a/content/shell/android/shell_manager.cc b/chrome/android/testshell/tab_manager.cc
|
| similarity index 50%
|
| copy from content/shell/android/shell_manager.cc
|
| copy to chrome/android/testshell/tab_manager.cc
|
| index a7b6b263b25615e9c5307cded799bfe974496c03..97ccbe1bcff95621c6424df1b995945040acb826 100644
|
| --- a/content/shell/android/shell_manager.cc
|
| +++ b/chrome/android/testshell/tab_manager.cc
|
| @@ -2,36 +2,27 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "content/shell/android/shell_manager.h"
|
| +#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 "base/memory/scoped_ptr.h"
|
| -#include "content/shell/shell.h"
|
| -#include "content/shell/shell_browser_context.h"
|
| -#include "content/shell/shell_content_browser_client.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 "content/public/browser/web_contents.h"
|
| -#include "content/shell/shell.h"
|
| -#include "googleurl/src/gurl.h"
|
| -#include "jni/ShellManager_jni.h"
|
| +#include "jni/TabManager_jni.h"
|
| #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h"
|
| -#include "ui/gfx/size.h"
|
|
|
| #include <android/native_window_jni.h>
|
|
|
| using base::android::ScopedJavaLocalRef;
|
| -using content::Compositor;
|
| -using content::DrawDelegate;
|
|
|
| namespace {
|
|
|
| struct GlobalState {
|
| - base::android::ScopedJavaGlobalRef<jobject> j_obj;
|
| scoped_ptr<content::Compositor> compositor;
|
| scoped_ptr<WebKit::WebLayer> root_layer;
|
| };
|
| @@ -43,50 +34,43 @@ content::Compositor* GetCompositor() {
|
| }
|
|
|
| static void SurfacePresented(
|
| - const DrawDelegate::SurfacePresentedCallback& callback,
|
| + const content::DrawDelegate::SurfacePresentedCallback& callback,
|
| uint32 sync_point) {
|
| callback.Run(sync_point);
|
| }
|
|
|
| +void DummyCallback(uint32) { }
|
| +
|
| static void SurfaceUpdated(
|
| uint64 texture,
|
| content::RenderWidgetHostView* view,
|
| - const DrawDelegate::SurfacePresentedCallback& callback) {
|
| + const content::DrawDelegate::SurfacePresentedCallback& callback) {
|
| GetCompositor()->OnSurfaceUpdated(base::Bind(
|
| &SurfacePresented, callback));
|
| }
|
|
|
| -} // anonymous namespace
|
| -
|
| -namespace content {
|
| +} // anonymous namespace
|
|
|
| -jobject CreateShellView() {
|
| - JNIEnv* env = base::android::AttachCurrentThread();
|
| - 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());
|
| - }
|
| - return Java_ShellManager_createShell(
|
| - env, g_global_state.Get().j_obj.obj()).Release();
|
| -}
|
| +namespace chrome {
|
|
|
| // Register native methods
|
| -bool RegisterShellManager(JNIEnv* env) {
|
| +bool RegisterTabManager(JNIEnv* env) {
|
| return RegisterNativesImpl(env);
|
| }
|
|
|
| static void Init(JNIEnv* env, jclass clazz, jobject obj) {
|
| - g_global_state.Get().j_obj.Reset(
|
| - base::android::ScopedJavaLocalRef<jobject>(env, obj));
|
| - DrawDelegate::SurfaceUpdatedCallback cb = base::Bind(
|
| + content::DrawDelegate::SurfaceUpdatedCallback cb = base::Bind(
|
| &SurfaceUpdated);
|
| - DrawDelegate::GetInstance()->SetUpdateCallback(cb);
|
| + content::DrawDelegate::GetInstance()->SetUpdateCallback(cb);
|
| + if (!GetCompositor()) {
|
| + content::Compositor::Initialize();
|
| + g_global_state.Get().compositor.reset(content::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) {
|
| +static void SurfaceCreated(JNIEnv* env, jclass clazz, jobject jsurface) {
|
| ANativeWindow* native_window = ANativeWindow_fromSurface(env, jsurface);
|
| if (native_window) {
|
| GetCompositor()->SetWindowSurface(native_window);
|
| @@ -102,29 +86,23 @@ static void SurfaceDestroyed(JNIEnv* env, jclass clazz) {
|
| static void SurfaceSetSize(
|
| JNIEnv* env, jclass clazz, jint width, jint height) {
|
| gfx::Size size = gfx::Size(width, height);
|
| - DrawDelegate::GetInstance()->SetBounds(size);
|
| + content::DrawDelegate::GetInstance()->SetBounds(size);
|
| GetCompositor()->SetWindowBounds(size);
|
| }
|
|
|
| -void LaunchShell(JNIEnv* env, jclass clazz, jstring jurl) {
|
| - ShellBrowserContext* browserContext =
|
| - static_cast<ShellContentBrowserClient*>(
|
| - GetContentClient()->browser())->browser_context();
|
| - GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
|
| - Shell::CreateNewWindow(browserContext,
|
| - url,
|
| - NULL,
|
| - MSG_ROUTING_NONE,
|
| - NULL);
|
| +static void ShowTab(JNIEnv* env, jclass clazz, jint jtab) {
|
| + if (!GetCompositor())
|
| + return;
|
| + TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab);
|
| + g_global_state.Get().root_layer->addChild(tab->tab_layer());
|
| + GetCompositor()->OnSurfaceUpdated(base::Bind(&DummyCallback));
|
| }
|
|
|
| -void ShellAttachLayer(WebKit::WebLayer* layer) {
|
| - g_global_state.Get().root_layer->addChild(layer);
|
| -}
|
| -
|
| -
|
| -void ShellRemoveLayer(WebKit::WebLayer* layer) {
|
| - layer->removeFromParent();
|
| +static void HideTab(JNIEnv* env, jclass clazz, jint jtab) {
|
| + if (!GetCompositor())
|
| + return;
|
| + TabBaseAndroidImpl* tab = reinterpret_cast<TabBaseAndroidImpl*>(jtab);
|
| + tab->tab_layer()->removeFromParent();
|
| }
|
|
|
| -} // namespace content
|
| +} // namespace chrome
|
|
|