OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromecast/browser/android/cast_content_window_android.h" | 5 #include "chromecast/browser/android/cast_content_window_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "chromecast/base/metrics/cast_metrics_helper.h" | |
11 #include "content/public/browser/render_view_host.h" | |
12 #include "content/public/browser/render_widget_host.h" | |
13 #include "content/public/browser/render_widget_host_view.h" | |
14 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
15 #include "content/public/common/renderer_preferences.h" | 11 #include "content/public/common/renderer_preferences.h" |
16 #include "ipc/ipc_message.h" | |
17 #include "jni/CastContentWindowAndroid_jni.h" | 12 #include "jni/CastContentWindowAndroid_jni.h" |
18 #include "ui/display/display.h" | 13 #include "ui/display/display.h" |
19 #include "ui/display/screen.h" | 14 #include "ui/display/screen.h" |
20 #include "ui/events/keycodes/keyboard_code_conversion_android.h" | 15 #include "ui/events/keycodes/keyboard_code_conversion_android.h" |
21 | 16 |
22 namespace chromecast { | 17 namespace chromecast { |
23 namespace shell { | 18 namespace shell { |
24 | 19 |
25 namespace { | 20 namespace { |
26 base::android::ScopedJavaLocalRef<jobject> CreateJavaWindow( | 21 base::android::ScopedJavaLocalRef<jobject> CreateJavaWindow( |
(...skipping 10 matching lines...) Expand all Loading... |
37 | 32 |
38 // static | 33 // static |
39 std::unique_ptr<CastContentWindow> CastContentWindow::Create( | 34 std::unique_ptr<CastContentWindow> CastContentWindow::Create( |
40 CastContentWindow::Delegate* delegate) { | 35 CastContentWindow::Delegate* delegate) { |
41 return base::WrapUnique(new CastContentWindowAndroid(delegate)); | 36 return base::WrapUnique(new CastContentWindowAndroid(delegate)); |
42 } | 37 } |
43 | 38 |
44 CastContentWindowAndroid::CastContentWindowAndroid( | 39 CastContentWindowAndroid::CastContentWindowAndroid( |
45 CastContentWindow::Delegate* delegate) | 40 CastContentWindow::Delegate* delegate) |
46 : delegate_(delegate), | 41 : delegate_(delegate), |
47 transparent_(false), | |
48 java_window_(CreateJavaWindow(reinterpret_cast<jlong>(this))) { | 42 java_window_(CreateJavaWindow(reinterpret_cast<jlong>(this))) { |
49 DCHECK(delegate_); | 43 DCHECK(delegate_); |
50 } | 44 } |
51 | 45 |
52 CastContentWindowAndroid::~CastContentWindowAndroid() { | 46 CastContentWindowAndroid::~CastContentWindowAndroid() { |
53 JNIEnv* env = base::android::AttachCurrentThread(); | 47 JNIEnv* env = base::android::AttachCurrentThread(); |
54 Java_CastContentWindowAndroid_onNativeDestroyed(env, java_window_.obj()); | 48 Java_CastContentWindowAndroid_onNativeDestroyed(env, java_window_.obj()); |
55 } | 49 } |
56 | 50 |
57 void CastContentWindowAndroid::SetTransparent() { | 51 void CastContentWindowAndroid::SetTransparent() {} |
58 transparent_ = true; | |
59 } | |
60 | 52 |
61 void CastContentWindowAndroid::ShowWebContents( | 53 void CastContentWindowAndroid::ShowWebContents( |
62 content::WebContents* web_contents, | 54 content::WebContents* web_contents, |
63 CastWindowManager* window_manager) { | 55 CastWindowManager* window_manager) { |
64 DCHECK(window_manager); | 56 DCHECK(window_manager); |
65 JNIEnv* env = base::android::AttachCurrentThread(); | 57 JNIEnv* env = base::android::AttachCurrentThread(); |
66 base::android::ScopedJavaLocalRef<jobject> java_web_contents = | 58 base::android::ScopedJavaLocalRef<jobject> java_web_contents = |
67 web_contents->GetJavaWebContents(); | 59 web_contents->GetJavaWebContents(); |
68 | 60 |
69 Java_CastContentWindowAndroid_showWebContents(env, java_window_.obj(), | 61 Java_CastContentWindowAndroid_showWebContents(env, java_window_.obj(), |
70 java_web_contents.obj()); | 62 java_web_contents.obj()); |
71 } | 63 } |
72 | 64 |
73 std::unique_ptr<content::WebContents> | |
74 CastContentWindowAndroid::CreateWebContents( | |
75 content::BrowserContext* browser_context, | |
76 scoped_refptr<content::SiteInstance> site_instance) { | |
77 CHECK(display::Screen::GetScreen()); | |
78 gfx::Size display_size = | |
79 display::Screen::GetScreen()->GetPrimaryDisplay().size(); | |
80 | |
81 content::WebContents::CreateParams create_params(browser_context, nullptr); | |
82 create_params.routing_id = MSG_ROUTING_NONE; | |
83 create_params.initial_size = display_size; | |
84 create_params.site_instance = site_instance; | |
85 std::unique_ptr<content::WebContents> web_contents( | |
86 content::WebContents::Create(create_params)); | |
87 | |
88 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs(); | |
89 prefs->use_video_overlay_for_embedded_encrypted_video = true; | |
90 web_contents->GetRenderViewHost()->SyncRendererPrefs(); | |
91 | |
92 content::WebContentsObserver::Observe(web_contents.get()); | |
93 return web_contents; | |
94 } | |
95 | |
96 void CastContentWindowAndroid::DidFirstVisuallyNonEmptyPaint() { | |
97 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint(); | |
98 } | |
99 | |
100 void CastContentWindowAndroid::MediaStartedPlaying( | |
101 const MediaPlayerInfo& media_info, | |
102 const MediaPlayerId& id) { | |
103 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay(); | |
104 } | |
105 | |
106 void CastContentWindowAndroid::MediaStoppedPlaying( | |
107 const MediaPlayerInfo& media_info, | |
108 const MediaPlayerId& id) { | |
109 metrics::CastMetricsHelper::GetInstance()->LogMediaPause(); | |
110 } | |
111 | |
112 void CastContentWindowAndroid::RenderViewCreated( | |
113 content::RenderViewHost* render_view_host) { | |
114 content::RenderWidgetHostView* view = | |
115 render_view_host->GetWidget()->GetView(); | |
116 if (view) { | |
117 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT | |
118 : SK_ColorBLACK); | |
119 } | |
120 } | |
121 | |
122 void CastContentWindowAndroid::OnActivityStopped( | 65 void CastContentWindowAndroid::OnActivityStopped( |
123 JNIEnv* env, | 66 JNIEnv* env, |
124 const base::android::JavaParamRef<jobject>& jcaller) { | 67 const base::android::JavaParamRef<jobject>& jcaller) { |
125 delegate_->OnWindowDestroyed(); | 68 delegate_->OnWindowDestroyed(); |
126 } | 69 } |
127 | 70 |
128 void CastContentWindowAndroid::OnKeyDown( | 71 void CastContentWindowAndroid::OnKeyDown( |
129 JNIEnv* env, | 72 JNIEnv* env, |
130 const base::android::JavaParamRef<jobject>& jcaller, | 73 const base::android::JavaParamRef<jobject>& jcaller, |
131 int keycode) { | 74 int keycode) { |
132 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, | 75 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, |
133 ui::KeyboardCodeFromAndroidKeyCode(keycode), | 76 ui::KeyboardCodeFromAndroidKeyCode(keycode), |
134 ui::EF_NONE); | 77 ui::EF_NONE); |
135 delegate_->OnKeyEvent(key_event); | 78 delegate_->OnKeyEvent(key_event); |
136 } | 79 } |
137 | 80 |
138 } // namespace shell | 81 } // namespace shell |
139 } // namespace chromecast | 82 } // namespace chromecast |
OLD | NEW |