OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 "chromecast/shell/browser/android/cast_window_manager.h" | |
6 | |
7 #include <jni.h> | |
8 | |
9 #include "base/android/jni_android.h" | |
10 #include "base/android/jni_string.h" | |
11 #include "base/android/scoped_java_ref.h" | |
12 #include "base/bind.h" | |
13 #include "base/lazy_instance.h" | |
14 #include "chromecast/common/chromecast_config.h" | |
15 #include "chromecast/common/pref_names.h" | |
16 #include "chromecast/shell/browser/android/cast_window_android.h" | |
17 #include "chromecast/shell/browser/cast_browser_context.h" | |
18 #include "chromecast/shell/browser/cast_browser_main_parts.h" | |
19 #include "chromecast/shell/browser/cast_content_browser_client.h" | |
20 #include "content/public/browser/browser_thread.h" | |
21 #include "content/public/browser/web_contents.h" | |
22 #include "ipc/ipc_channel.h" | |
23 #include "jni/CastWindowManager_jni.h" | |
24 #include "url/gurl.h" | |
25 | |
26 namespace { | |
27 | |
28 struct GlobalState { | |
29 base::android::ScopedJavaGlobalRef<jobject> j_window_manager; | |
30 }; | |
31 | |
32 base::LazyInstance<GlobalState> g_global_state = LAZY_INSTANCE_INITIALIZER; | |
Yaron
2014/08/20 18:11:02
why the extra wrapper struct?
gunsch
2014/08/21 22:31:28
Done.
| |
33 | |
34 content::BrowserContext* g_browser_context = NULL; | |
35 | |
36 } // namespace | |
37 | |
38 namespace chromecast { | |
39 namespace shell { | |
40 | |
41 void SetBrowserContextAndroid(content::BrowserContext* browser_context) { | |
42 g_browser_context = browser_context; | |
43 } | |
44 | |
45 base::android::ScopedJavaLocalRef<jobject> | |
46 CreateCastWindowView(CastWindowAndroid* shell) { | |
47 JNIEnv* env = base::android::AttachCurrentThread(); | |
48 jobject j_window_manager = g_global_state.Get().j_window_manager.obj(); | |
49 return Java_CastWindowManager_createCastWindow(env, j_window_manager); | |
50 } | |
51 | |
52 void CloseCastWindowView(jobject shell_wrapper) { | |
53 JNIEnv* env = base::android::AttachCurrentThread(); | |
54 jobject j_window_manager = g_global_state.Get().j_window_manager.obj(); | |
55 Java_CastWindowManager_closeCastWindow(env, j_window_manager, shell_wrapper); | |
56 } | |
57 | |
58 // Register native methods | |
59 bool RegisterCastWindowManager(JNIEnv* env) { | |
60 return RegisterNativesImpl(env); | |
61 } | |
62 | |
63 void Init(JNIEnv* env, jclass clazz, jobject obj) { | |
64 g_global_state.Get().j_window_manager.Reset( | |
65 base::android::ScopedJavaLocalRef<jobject>(env, obj)); | |
66 } | |
67 | |
68 jlong LaunchCastWindow(JNIEnv* env, jclass clazz, jstring jurl) { | |
69 DCHECK(g_browser_context); | |
70 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | |
71 return reinterpret_cast<jlong>( | |
72 CastWindowAndroid::CreateNewWindow(g_browser_context, url)); | |
73 } | |
74 | |
75 void StopCastWindow(JNIEnv* env, jclass clazz, jlong nativeCastWindow) { | |
76 CastWindowAndroid* window = | |
77 reinterpret_cast<CastWindowAndroid*>(nativeCastWindow); | |
78 DCHECK(window); | |
79 window->Close(); | |
80 } | |
81 | |
82 void EnableDevTools(JNIEnv* env, jclass clazz, jboolean enable) { | |
83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
84 // The specific port value doesn't matter since Android uses Unix domain | |
85 // sockets, only whether or not it is zero. | |
86 chromecast::ChromecastConfig::GetInstance()->pref_service()-> | |
87 SetInteger(prefs::kRemoteDebuggingPort, enable ? 1 : 0); | |
88 } | |
89 | |
90 } // namespace shell | |
91 } // namespace chromecast | |
OLD | NEW |