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

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

Issue 2626863006: [Chromecast] Add CastWebContents (Closed)
Patch Set: [Chromecast] Add CastWebContents 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
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
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 JNIEnv* env = base::android::AttachCurrentThread(); 55 JNIEnv* env = base::android::AttachCurrentThread();
64 base::android::ScopedJavaLocalRef<jobject> java_web_contents = 56 base::android::ScopedJavaLocalRef<jobject> java_web_contents =
65 web_contents->GetJavaWebContents(); 57 web_contents->GetJavaWebContents();
66 58
67 Java_CastContentWindowAndroid_showWebContents(env, java_window_.obj(), 59 Java_CastContentWindowAndroid_showWebContents(env, java_window_.obj(),
68 java_web_contents.obj()); 60 java_web_contents.obj());
69 } 61 }
70 62
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( 63 void CastContentWindowAndroid::OnActivityStopped(
119 JNIEnv* env, 64 JNIEnv* env,
120 const base::android::JavaParamRef<jobject>& jcaller) { 65 const base::android::JavaParamRef<jobject>& jcaller) {
121 delegate_->OnWindowDestroyed(); 66 delegate_->OnWindowDestroyed();
122 } 67 }
123 68
124 void CastContentWindowAndroid::OnKeyDown( 69 void CastContentWindowAndroid::OnKeyDown(
125 JNIEnv* env, 70 JNIEnv* env,
126 const base::android::JavaParamRef<jobject>& jcaller, 71 const base::android::JavaParamRef<jobject>& jcaller,
127 int keycode) { 72 int keycode) {
128 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, 73 ui::KeyEvent key_event(ui::ET_KEY_PRESSED,
129 ui::KeyboardCodeFromAndroidKeyCode(keycode), 74 ui::KeyboardCodeFromAndroidKeyCode(keycode),
130 ui::EF_NONE); 75 ui::EF_NONE);
131 delegate_->OnKeyEvent(key_event); 76 delegate_->OnKeyEvent(key_event);
132 } 77 }
133 78
134 } // namespace shell 79 } // namespace shell
135 } // namespace chromecast 80 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698