Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / shell / android / shell_manager.cc
blobf7cfd63b49fa75f1e6f1165e3a502040e88b03bd
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.
5 #include "content/shell/android/shell_manager.h"
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"
19 using base::android::ScopedJavaLocalRef;
21 namespace {
23 struct GlobalState {
24 GlobalState() {}
25 base::android::ScopedJavaGlobalRef<jobject> j_shell_manager;
28 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER;
30 } // namespace
32 namespace content {
34 ScopedJavaLocalRef<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,
38 reinterpret_cast<intptr_t>(shell));
41 void RemoveShellView(jobject shell_view) {
42 JNIEnv* env = base::android::AttachCurrentThread();
43 jobject j_shell_manager = g_global_state.Get().j_shell_manager.obj();
44 Java_ShellManager_removeShell(env, j_shell_manager, shell_view);
47 // Register native methods
48 bool RegisterShellManager(JNIEnv* env) {
49 return RegisterNativesImpl(env);
52 static void Init(JNIEnv* env,
53 const JavaParamRef<jclass>& clazz,
54 const JavaParamRef<jobject>& obj) {
55 g_global_state.Get().j_shell_manager.Reset(obj);
58 void LaunchShell(JNIEnv* env,
59 const JavaParamRef<jclass>& clazz,
60 const JavaParamRef<jstring>& jurl) {
61 ShellBrowserContext* browserContext =
62 ShellContentBrowserClient::Get()->browser_context();
63 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
64 Shell::CreateNewWindow(browserContext,
65 url,
66 NULL,
67 gfx::Size());
70 } // namespace content