Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: chromecast/browser/android/cast_content_window_android.cc

Issue 2570623003: [Chromecast] Turn CastContentWindow into an abstract interface. (Closed)
Patch Set: Fix browser test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chromecast/browser/android/cast_content_window_android.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/android/scoped_java_ref.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"
15 #include "content/public/common/renderer_preferences.h"
16 #include "ipc/ipc_message.h"
17 #include "jni/CastContentWindowAndroid_jni.h"
18 #include "ui/display/display.h"
19 #include "ui/display/screen.h"
20 #include "ui/events/keycodes/keyboard_code_conversion_android.h"
21
22 namespace chromecast {
23 namespace shell {
24
25 namespace {
26 base::android::ScopedJavaLocalRef<jobject> CreateJavaWindow(
27 jlong nativeWindow) {
28 JNIEnv* env = base::android::AttachCurrentThread();
29 return Java_CastContentWindowAndroid_create(env, nativeWindow);
30 }
31 } // namespace
32
33 // static
34 bool CastContentWindowAndroid::RegisterJni(JNIEnv* env) {
35 return RegisterNativesImpl(env);
36 }
37
38 // static
39 std::unique_ptr<CastContentWindow> CastContentWindow::Create(
40 CastContentWindow::Delegate* delegate) {
41 return base::WrapUnique(new CastContentWindowAndroid(delegate));
42 }
43
44 CastContentWindowAndroid::CastContentWindowAndroid(
45 CastContentWindow::Delegate* delegate)
46 : delegate_(delegate),
47 transparent_(false),
48 java_window_(CreateJavaWindow(reinterpret_cast<jlong>(this))) {
49 DCHECK(delegate_);
50 }
51
52 CastContentWindowAndroid::~CastContentWindowAndroid() {
53 JNIEnv* env = base::android::AttachCurrentThread();
54 Java_CastContentWindowAndroid_onNativeDestroyed(env, java_window_.obj());
55 }
56
57 void CastContentWindowAndroid::SetTransparent() {
58 transparent_ = true;
59 }
60
61 void CastContentWindowAndroid::ShowWebContents(
62 content::WebContents* web_contents) {
63 JNIEnv* env = base::android::AttachCurrentThread();
64 base::android::ScopedJavaLocalRef<jobject> java_web_contents =
65 web_contents->GetJavaWebContents();
66
67 Java_CastContentWindowAndroid_showWebContents(env, java_window_.obj(),
68 java_web_contents.obj());
69 }
70
71 std::unique_ptr<content::WebContents>
72 CastContentWindowAndroid::CreateWebContents(
73 content::BrowserContext* browser_context) {
74 CHECK(display::Screen::GetScreen());
75 gfx::Size display_size =
76 display::Screen::GetScreen()->GetPrimaryDisplay().size();
77
78 content::WebContents::CreateParams create_params(browser_context, nullptr);
79 create_params.routing_id = MSG_ROUTING_NONE;
80 create_params.initial_size = display_size;
81 std::unique_ptr<content::WebContents> web_contents(
82 content::WebContents::Create(create_params));
83
84 content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs();
85 prefs->use_video_overlay_for_embedded_encrypted_video = true;
86 web_contents->GetRenderViewHost()->SyncRendererPrefs();
87
88 content::WebContentsObserver::Observe(web_contents.get());
89 return web_contents;
90 }
91
92 void CastContentWindowAndroid::DidFirstVisuallyNonEmptyPaint() {
93 metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint();
94 }
95
96 void CastContentWindowAndroid::MediaStartedPlaying(
97 const MediaPlayerInfo& media_info,
98 const MediaPlayerId& id) {
99 metrics::CastMetricsHelper::GetInstance()->LogMediaPlay();
100 }
101
102 void CastContentWindowAndroid::MediaStoppedPlaying(
103 const MediaPlayerInfo& media_info,
104 const MediaPlayerId& id) {
105 metrics::CastMetricsHelper::GetInstance()->LogMediaPause();
106 }
107
108 void CastContentWindowAndroid::RenderViewCreated(
109 content::RenderViewHost* render_view_host) {
110 content::RenderWidgetHostView* view =
111 render_view_host->GetWidget()->GetView();
112 if (view) {
113 view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT
114 : SK_ColorBLACK);
115 }
116 }
117
118 void CastContentWindowAndroid::OnActivityStopped(
119 JNIEnv* env,
120 const base::android::JavaParamRef<jobject>& jcaller) {
121 delegate_->OnWindowDestroyed();
122 }
123
124 void CastContentWindowAndroid::OnKeyDown(
125 JNIEnv* env,
126 const base::android::JavaParamRef<jobject>& jcaller,
127 int keycode) {
128 ui::KeyEvent key_event(ui::ET_KEY_PRESSED,
129 ui::KeyboardCodeFromAndroidKeyCode(keycode),
130 ui::EF_NONE);
131 delegate_->OnKeyEvent(key_event);
132 }
133
134 } // namespace shell
135 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/browser/android/cast_content_window_android.h ('k') | chromecast/browser/android/cast_metrics_helper_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698