| 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_browser_process.h" | |
| 20 #include "chromecast/shell/browser/cast_content_browser_client.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" | |
| 25 #include "url/gurl.h" | |
| 26 | |
| 27 namespace { | |
| 28 | |
| 29 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> > | |
| 30 g_window_manager = LAZY_INSTANCE_INITIALIZER; | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 namespace chromecast { | |
| 35 namespace shell { | |
| 36 | |
| 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); | |
| 42 } | |
| 43 | |
| 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); | |
| 48 } | |
| 49 | |
| 50 // Register native methods | |
| 51 bool RegisterCastWindowManager(JNIEnv* env) { | |
| 52 return RegisterNativesImpl(env); | |
| 53 } | |
| 54 | |
| 55 void Init(JNIEnv* env, jclass clazz, jobject obj) { | |
| 56 g_window_manager.Get().Reset( | |
| 57 base::android::ScopedJavaLocalRef<jobject>(env, obj)); | |
| 58 } | |
| 59 | |
| 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(), | |
| 65 url)); | |
| 66 } | |
| 67 | |
| 68 void StopCastWindow(JNIEnv* env, jclass clazz, | |
| 69 jlong nativeCastWindow, jboolean gracefully) { | |
| 70 CastWindowAndroid* window = | |
| 71 reinterpret_cast<CastWindowAndroid*>(nativeCastWindow); | |
| 72 DCHECK(window); | |
| 73 if (gracefully) | |
| 74 window->Close(); | |
| 75 else | |
| 76 window->Destroy(); | |
| 77 } | |
| 78 | |
| 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 chromecast::ChromecastConfig::GetInstance()->pref_service()-> | |
| 84 SetInteger(prefs::kRemoteDebuggingPort, enable ? 1 : 0); | |
| 85 } | |
| 86 | |
| 87 } // namespace shell | |
| 88 } // namespace chromecast | |
| OLD | NEW |