// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chromecast/browser/android/cast_window_manager.h" #include #include "base/android/jni_android.h" #include "base/android/jni_string.h" #include "base/android/scoped_java_ref.h" #include "base/bind.h" #include "base/lazy_instance.h" #include "base/prefs/pref_service.h" #include "chromecast/base/pref_names.h" #include "chromecast/browser/android/cast_window_android.h" #include "chromecast/browser/cast_browser_context.h" #include "chromecast/browser/cast_browser_main_parts.h" #include "chromecast/browser/cast_browser_process.h" #include "chromecast/browser/cast_content_browser_client.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/web_contents.h" #include "ipc/ipc_channel.h" #include "jni/CastWindowManager_jni.h" #include "url/gurl.h" namespace { base::LazyInstance > g_window_manager = LAZY_INSTANCE_INITIALIZER; } // namespace namespace chromecast { namespace shell { base::android::ScopedJavaLocalRef CreateCastWindowView(CastWindowAndroid* shell) { JNIEnv* env = base::android::AttachCurrentThread(); jobject j_window_manager = g_window_manager.Get().obj(); return Java_CastWindowManager_createCastWindow(env, j_window_manager); } void CloseCastWindowView(jobject shell_wrapper) { JNIEnv* env = base::android::AttachCurrentThread(); jobject j_window_manager = g_window_manager.Get().obj(); Java_CastWindowManager_closeCastWindow(env, j_window_manager, shell_wrapper); } // Register native methods bool RegisterCastWindowManager(JNIEnv* env) { return RegisterNativesImpl(env); } void Init(JNIEnv* env, jclass clazz, jobject obj) { g_window_manager.Get().Reset( base::android::ScopedJavaLocalRef(env, obj)); } jlong LaunchCastWindow(JNIEnv* env, jclass clazz, jstring jurl) { GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); return reinterpret_cast( CastWindowAndroid::CreateNewWindow( CastBrowserProcess::GetInstance()->browser_context(), url)); } void StopCastWindow(JNIEnv* env, jclass clazz, jlong nativeCastWindow, jboolean gracefully) { CastWindowAndroid* window = reinterpret_cast(nativeCastWindow); DCHECK(window); if (gracefully) window->Close(); else window->Destroy(); } void EnableDevTools(JNIEnv* env, jclass clazz, jboolean enable) { DCHECK_CURRENTLY_ON(content::BrowserThread::UI); CastBrowserProcess::GetInstance()->pref_service()->SetBoolean( prefs::kEnableRemoteDebugging, enable); } } // namespace shell } // namespace chromecast