Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chromecast / browser / android / cast_window_manager.cc
blobc4e2f1274eaf582c7b61d2bf4e5771bb192f56eb
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"
7 #include <jni.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/base/pref_names.h"
16 #include "chromecast/browser/android/cast_window_android.h"
17 #include "chromecast/browser/cast_browser_context.h"
18 #include "chromecast/browser/cast_browser_main_parts.h"
19 #include "chromecast/browser/cast_browser_process.h"
20 #include "chromecast/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"
27 namespace {
29 base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >
30 g_window_manager = LAZY_INSTANCE_INITIALIZER;
32 } // namespace
34 namespace chromecast {
35 namespace shell {
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,
56 const JavaParamRef<jclass>& clazz,
57 const JavaParamRef<jobject>& obj) {
58 g_window_manager.Get().Reset(
59 base::android::ScopedJavaLocalRef<jobject>(env, obj));
62 jlong LaunchCastWindow(JNIEnv* env,
63 const JavaParamRef<jclass>& clazz,
64 const JavaParamRef<jstring>& jurl) {
65 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl));
66 return reinterpret_cast<jlong>(
67 CastWindowAndroid::CreateNewWindow(
68 CastBrowserProcess::GetInstance()->browser_context(),
69 url));
72 void StopCastWindow(JNIEnv* env,
73 const JavaParamRef<jclass>& clazz,
74 jlong nativeCastWindow,
75 jboolean gracefully) {
76 CastWindowAndroid* window =
77 reinterpret_cast<CastWindowAndroid*>(nativeCastWindow);
78 DCHECK(window);
79 if (gracefully)
80 window->Close();
81 else
82 window->Destroy();
85 void EnableDevTools(JNIEnv* env,
86 const JavaParamRef<jclass>& clazz,
87 jboolean enable) {
88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
89 CastBrowserProcess::GetInstance()->pref_service()->SetBoolean(
90 prefs::kEnableRemoteDebugging, enable);
93 } // namespace shell
94 } // namespace chromecast