- add sources.
[platform/framework/web/crosswalk.git] / src / content / shell / android / shell_manager.cc
1 // Copyright (c) 2012 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.
4
5 #include "content/shell/android/shell_manager.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/android/scoped_java_ref.h"
10 #include "base/bind.h"
11 #include "base/lazy_instance.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/shell/browser/shell.h"
14 #include "content/shell/browser/shell_browser_context.h"
15 #include "content/shell/browser/shell_content_browser_client.h"
16 #include "jni/ShellManager_jni.h"
17 #include "url/gurl.h"
18
19 using base::android::ScopedJavaLocalRef;
20
21 namespace {
22
23 struct GlobalState {
24   GlobalState() {}
25   base::android::ScopedJavaGlobalRef<jobject> j_shell_manager;
26 };
27
28 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER;
29
30 }  // namespace
31
32 namespace content {
33
34 jobject CreateShellView(Shell* shell) {
35   JNIEnv* env = base::android::AttachCurrentThread();
36   jobject j_shell_manager = g_global_state.Get().j_shell_manager.obj();
37   return Java_ShellManager_createShell(env, j_shell_manager).Release();
38 }
39
40 void CloseShellView(jobject shell_view) {
41   JNIEnv* env = base::android::AttachCurrentThread();
42   jobject j_shell_manager = g_global_state.Get().j_shell_manager.obj();
43   Java_ShellManager_closeShell(env, j_shell_manager, shell_view);
44 }
45
46 // Register native methods
47 bool RegisterShellManager(JNIEnv* env) {
48   return RegisterNativesImpl(env);
49 }
50
51 static void Init(JNIEnv* env, jclass clazz, jobject obj) {
52   g_global_state.Get().j_shell_manager.Reset(
53       base::android::ScopedJavaLocalRef<jobject>(env, obj));
54 }
55
56 void LaunchShell(JNIEnv* env, jclass clazz, jstring jurl) {
57   ShellBrowserContext* browserContext =
58       ShellContentBrowserClient::Get()->browser_context();
59   GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
60   Shell::CreateNewWindow(browserContext,
61                          url,
62                          NULL,
63                          MSG_ROUTING_NONE,
64                          gfx::Size());
65 }
66
67 }  // namespace content