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.
5 #include "chromecast/browser/android/cast_window_manager.h"
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 "base/prefs/pref_service.h"
15 #include "chromecast/browser/android/cast_window_android.h"
16 #include "chromecast/browser/cast_browser_context.h"
17 #include "chromecast/browser/cast_browser_main_parts.h"
18 #include "chromecast/browser/cast_browser_process.h"
19 #include "chromecast/browser/cast_content_browser_client.h"
20 #include "chromecast/common/pref_names.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "content/public/browser/web_contents.h"
23 #include "ipc/ipc_channel.h"
24 #include "jni/CastWindowManager_jni.h"
29 base::LazyInstance
<base::android::ScopedJavaGlobalRef
<jobject
> >
30 g_window_manager
= LAZY_INSTANCE_INITIALIZER
;
34 namespace chromecast
{
37 base::android::ScopedJavaLocalRef
<jobject
>
38 CreateCastWindowView(CastWindowAndroid
* shell
) {
39 JNIEnv
* env
= base::android::AttachCurrentThread();
40 jobject j_window_manager
= g_window_manager
.Get().obj();
41 return Java_CastWindowManager_createCastWindow(env
, j_window_manager
);
44 void CloseCastWindowView(jobject shell_wrapper
) {
45 JNIEnv
* env
= base::android::AttachCurrentThread();
46 jobject j_window_manager
= g_window_manager
.Get().obj();
47 Java_CastWindowManager_closeCastWindow(env
, j_window_manager
, shell_wrapper
);
50 // Register native methods
51 bool RegisterCastWindowManager(JNIEnv
* env
) {
52 return RegisterNativesImpl(env
);
55 void Init(JNIEnv
* env
, jclass clazz
, jobject obj
) {
56 g_window_manager
.Get().Reset(
57 base::android::ScopedJavaLocalRef
<jobject
>(env
, obj
));
60 jlong
LaunchCastWindow(JNIEnv
* env
, jclass clazz
, jstring jurl
) {
61 GURL
url(base::android::ConvertJavaStringToUTF8(env
, jurl
));
62 return reinterpret_cast<jlong
>(
63 CastWindowAndroid::CreateNewWindow(
64 CastBrowserProcess::GetInstance()->browser_context(),
68 void StopCastWindow(JNIEnv
* env
, jclass clazz
,
69 jlong nativeCastWindow
, jboolean gracefully
) {
70 CastWindowAndroid
* window
=
71 reinterpret_cast<CastWindowAndroid
*>(nativeCastWindow
);
79 void EnableDevTools(JNIEnv
* env
, jclass clazz
, jboolean enable
) {
80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI
);
81 // The specific port value doesn't matter since Android uses Unix domain
82 // sockets, only whether or not it is zero.
83 CastBrowserProcess::GetInstance()->pref_service()->
84 SetInteger(prefs::kRemoteDebuggingPort
, enable
? 1 : 0);
88 } // namespace chromecast