Index: content/shell/browser/shell_views.cc |
diff --git a/content/shell/browser/shell_views.cc b/content/shell/browser/shell_views.cc |
index 1c6a1f9dd430db68ca07c3e69623c632bd5c3046..bcd9ec2fa8de3e01c6a3a65d012f0d5327bdf65d 100644 |
--- a/content/shell/browser/shell_views.cc |
+++ b/content/shell/browser/shell_views.cc |
@@ -31,7 +31,6 @@ |
#include "ui/views/controls/webview/webview.h" |
#include "ui/views/layout/fill_layout.h" |
#include "ui/views/layout/grid_layout.h" |
-#include "ui/views/test/desktop_test_views_delegate.h" |
#include "ui/views/view.h" |
#include "ui/views/widget/widget.h" |
#include "ui/views/widget/widget_delegate.h" |
@@ -39,9 +38,11 @@ |
#if defined(OS_CHROMEOS) |
#include "chromeos/dbus/dbus_thread_manager.h" |
#include "device/bluetooth/dbus/bluez_dbus_manager.h" |
+#endif |
+#if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
#include "ui/aura/test/test_screen.h" |
#include "ui/wm/test/wm_test_helper.h" |
-#else // !defined(OS_CHROMEOS) |
+#else // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
#include "ui/views/widget/desktop_aura/desktop_screen.h" |
#endif |
@@ -50,10 +51,71 @@ |
#include <io.h> |
#endif |
+#if defined(OS_ANDROID) |
+#include "base/android/scoped_java_ref.h" |
+#include "base/run_loop.h" |
+#include "jni/Shell_jni.h" |
+#include "ui/aura/client/aura_constants.h" |
+#include "ui/views/test/test_views_delegate.h" |
+#include "ui/views/widget/android/native_widget_android.h" |
+#include "ui/views/widget/native_widget_aura.h" |
+#else |
+#include "ui/views/test/desktop_test_views_delegate.h" |
+#endif |
+ |
+#if defined(OS_ANDROID) |
+using base::android::AttachCurrentThread; |
+#endif |
+ |
namespace content { |
namespace { |
+ |
+struct GlobalState { |
+ GlobalState() {} |
+ base::android::ScopedJavaGlobalRef<jobject> j_shell; |
+}; |
+ |
+base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; |
+ |
// ViewDelegate implementation for aura content shell |
+#if defined(OS_ANDROID) |
+class ShellViewsDelegateAura : public views::TestViewsDelegate { |
+ public: |
+ ShellViewsDelegateAura() : use_transparent_windows_(false) { |
+ } |
+ |
+ ~ShellViewsDelegateAura() override {} |
+ |
+ void SetUseTransparentWindows(bool transparent) { |
+ use_transparent_windows_ = transparent; |
+ } |
+ |
+ void OnBeforeWidgetInit( |
+ views::Widget::InitParams* params, |
+ views::internal::NativeWidgetDelegate* delegate) { |
+ #if !defined(OS_CHROMEOS) |
+ // If we already have a native_widget, we don't have to try to come |
+ // up with one. |
+ if (params->native_widget) |
+ return; |
+ |
+ if (params->parent && |
+ params->type != views::Widget::InitParams::TYPE_MENU && |
+ params->type != views::Widget::InitParams::TYPE_TOOLTIP) { |
+ params->native_widget = new views::NativeWidgetAura(delegate); |
+ } else { |
+ params->native_widget = new views::NativeWidgetAndroid(delegate); |
+ } |
+ #endif |
+ } |
+ |
+ private: |
+ bool use_transparent_windows_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegateAura); |
+}; |
+#else |
class ShellViewsDelegateAura : public views::DesktopTestViewsDelegate { |
public: |
ShellViewsDelegateAura() : use_transparent_windows_(false) { |
@@ -70,6 +132,7 @@ class ShellViewsDelegateAura : public views::DesktopTestViewsDelegate { |
DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegateAura); |
}; |
+#endif |
// Model for the "Debug" menu |
class ContextMenuModel : public ui::SimpleMenuModel, |
@@ -310,6 +373,8 @@ class ShellWindowDelegateView : public views::WidgetDelegateView, |
GURL url(text); |
if (!url.has_scheme()) { |
url = GURL(std::string("http://") + std::string(text)); |
+ if (url.is_empty() || !url.is_valid()) |
+ return false; |
url_entry_->SetText(base::ASCIIToUTF16(url.spec())); |
} |
shell_->LoadURL(url); |
@@ -399,14 +464,14 @@ class ShellWindowDelegateView : public views::WidgetDelegateView, |
} // namespace |
-#if defined(OS_CHROMEOS) |
+#if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
wm::WMTestHelper* Shell::wm_test_helper_ = NULL; |
gfx::Screen* Shell::test_screen_ = NULL; |
#endif |
views::ViewsDelegate* Shell::views_delegate_ = NULL; |
-// static |
void Shell::PlatformInitialize(const gfx::Size& default_window_size) { |
+ LOG(ERROR) << "auraclank: Shell::PlatformInitialize"; |
#if defined(OS_WIN) |
_setmode(_fileno(stdout), _O_BINARY); |
_setmode(_fileno(stderr), _O_BINARY); |
@@ -417,10 +482,21 @@ void Shell::PlatformInitialize(const gfx::Size& default_window_size) { |
chromeos::DBusThreadManager::Get()->GetSystemBus(), |
chromeos::DBusThreadManager::Get()->IsUsingStub( |
chromeos::DBusClientBundle::BLUETOOTH)); |
+#endif |
+#if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
+// TODO(mfomitchev): We can either use wm_test_helper_ here and have that instantiate |
+// the host, or we can use the views delegate (which seems like a better approach). |
+ // TODO(mfomitchev): We should pick the screen we use on Android. |
+ // If we use screen_android, we shouldn't do this. |
test_screen_ = aura::TestScreen::Create(gfx::Size()); |
gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_); |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ jobject j_shell = g_global_state.Get().j_shell.obj(); |
+ jobject j_activity = Java_Shell_getActivity(env, j_shell).obj(); |
wm_test_helper_ = new wm::WMTestHelper(default_window_size, |
GetContextFactory()); |
+ wm_test_helper_->host()->window()->SetProperty( |
+ aura::client::kActivityForRootWindow, j_activity); |
#else |
gfx::Screen::SetScreenInstance( |
gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); |
@@ -429,7 +505,7 @@ void Shell::PlatformInitialize(const gfx::Size& default_window_size) { |
} |
void Shell::PlatformExit() { |
-#if defined(OS_CHROMEOS) |
+#if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
delete wm_test_helper_; |
wm_test_helper_ = NULL; |
@@ -448,9 +524,6 @@ void Shell::PlatformExit() { |
aura::Env::DeleteInstance(); |
} |
-void Shell::PlatformCleanUp() { |
-} |
- |
void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { |
if (headless_) |
return; |
@@ -480,6 +553,7 @@ void Shell::PlatformSetIsLoading(bool loading) { |
} |
void Shell::PlatformCreateWindow(int width, int height) { |
+ LOG(ERROR) << "auraclank: Shell::PlatformCreateWindow"; |
if (headless_) { |
content_size_ = gfx::Size(width, height); |
if (!platform_) |
@@ -488,7 +562,9 @@ void Shell::PlatformCreateWindow(int width, int height) { |
platform_->ResizeWindow(content_size_); |
return; |
} |
-#if defined(OS_CHROMEOS) |
+ |
+#if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
+ wm_test_helper_->Init(); |
window_widget_ = views::Widget::CreateWindowWithContextAndBounds( |
new ShellWindowDelegateView(this), |
wm_test_helper_->GetDefaultParent(NULL, NULL, gfx::Rect()), |
@@ -506,10 +582,23 @@ void Shell::PlatformCreateWindow(int width, int height) { |
window_ = window_widget_->GetNativeWindow(); |
// Call ShowRootWindow on RootWindow created by WMTestHelper without |
// which XWindow owned by RootWindow doesn't get mapped. |
+//TODO(mfomitchev) |
window_->GetHost()->Show(); |
window_widget_->Show(); |
+ |
+ |
} |
+#if defined(OS_ANDROID) |
+// aura::EnvObserver: |
+void Shell::OnHostInitialized(aura::WindowTreeHost* host) { |
+ LOG(ERROR) << "auraclank: Shell::OnHostInitialized!"; |
+// quit_closure_.Run(); |
+ aura::Env::GetInstance()->RemoveObserver(this); |
+} |
+#endif |
+ |
+ |
void Shell::PlatformSetContents() { |
if (headless_) { |
CHECK(platform_); |
@@ -560,4 +649,30 @@ bool Shell::PlatformHandleContextMenu( |
return true; |
} |
+#if defined(OS_ANDROID) |
+// static |
+bool Shell::Register(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+ |
+// static |
+void CloseShell( |
+ JNIEnv* env, const JavaParamRef<jclass>& clazz, jlong shellPtr) { |
+ Shell* shell = reinterpret_cast<Shell*>(shellPtr); |
+ shell->Close(); |
+} |
+ |
+static void Init(JNIEnv* env, |
+ const JavaParamRef<jclass>& clazz, |
+ const JavaParamRef<jobject>& obj) { |
+ g_global_state.Get().j_shell.Reset(obj); |
+} |
+ |
+void Shell::PlatformCleanUp() { |
+ JNIEnv* env = AttachCurrentThread(); |
+ Java_Shell_onNativeDestroyed(env, g_global_state.Get().j_shell.obj()); |
+} |
+#endif |
+ |
+ |
} // namespace content |