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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chromecast/browser/android/cast_content_window_android.cc
diff --git a/chromecast/browser/android/cast_content_window_android.cc b/chromecast/browser/android/cast_content_window_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7c22d2c0f76c4f84a5b119244ca8b450e6faa7e7
--- /dev/null
+++ b/chromecast/browser/android/cast_content_window_android.cc
@@ -0,0 +1,135 @@
+// Copyright 2016 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_content_window_android.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/memory/ptr_util.h"
+#include "chromecast/base/metrics/cast_metrics_helper.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host.h"
+#include "content/public/browser/render_widget_host_view.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/common/renderer_preferences.h"
+#include "ipc/ipc_message.h"
+#include "jni/CastContentWindowAndroid_jni.h"
+#include "ui/display/display.h"
+#include "ui/display/screen.h"
+#include "ui/events/keycodes/keyboard_code_conversion_android.h"
+
+namespace chromecast {
+namespace shell {
+
+namespace {
+base::android::ScopedJavaLocalRef<jobject> CreateJavaWindow(
+ jlong nativeWindow) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ return Java_CastContentWindowAndroid_create(env, nativeWindow);
+}
+} // namespace
+
+// static
+bool CastContentWindowAndroid::RegisterJni(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+// static
+std::unique_ptr<CastContentWindow> CastContentWindow::Create(
+ CastContentWindow::Delegate* delegate) {
+ return base::WrapUnique(new CastContentWindowAndroid(delegate));
+}
+
+CastContentWindowAndroid::CastContentWindowAndroid(
+ CastContentWindow::Delegate* delegate)
+ : delegate_(delegate),
+ transparent_(false),
+ java_window_(CreateJavaWindow(reinterpret_cast<jlong>(this))) {
+ DCHECK(delegate_);
+}
+
+CastContentWindowAndroid::~CastContentWindowAndroid() {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ Java_CastContentWindowAndroid_onNativeDestroyed(env, java_window_.obj());
+}
+
+void CastContentWindowAndroid::SetTransparent() {
+ transparent_ = true;
+}
+
+void CastContentWindowAndroid::ShowWebContents(
+ content::WebContents* web_contents) {
+ JNIEnv* env = base::android::AttachCurrentThread();
+ base::android::ScopedJavaLocalRef<jobject> java_web_contents =
+ web_contents->GetJavaWebContents();
+
+ Java_CastContentWindowAndroid_showWebContents(env, java_window_.obj(),
+ java_web_contents.obj());
+}
+
+std::unique_ptr<content::WebContents>
+CastContentWindowAndroid::CreateWebContents(
+ content::BrowserContext* browser_context) {
+ CHECK(display::Screen::GetScreen());
+ gfx::Size display_size =
+ display::Screen::GetScreen()->GetPrimaryDisplay().size();
+
+ content::WebContents::CreateParams create_params(browser_context, nullptr);
+ create_params.routing_id = MSG_ROUTING_NONE;
+ create_params.initial_size = display_size;
+ std::unique_ptr<content::WebContents> web_contents(
+ content::WebContents::Create(create_params));
+
+ content::RendererPreferences* prefs = web_contents->GetMutableRendererPrefs();
+ prefs->use_video_overlay_for_embedded_encrypted_video = true;
+ web_contents->GetRenderViewHost()->SyncRendererPrefs();
+
+ content::WebContentsObserver::Observe(web_contents.get());
+ return web_contents;
+}
+
+void CastContentWindowAndroid::DidFirstVisuallyNonEmptyPaint() {
+ metrics::CastMetricsHelper::GetInstance()->LogTimeToFirstPaint();
+}
+
+void CastContentWindowAndroid::MediaStartedPlaying(
+ const MediaPlayerInfo& media_info,
+ const MediaPlayerId& id) {
+ metrics::CastMetricsHelper::GetInstance()->LogMediaPlay();
+}
+
+void CastContentWindowAndroid::MediaStoppedPlaying(
+ const MediaPlayerInfo& media_info,
+ const MediaPlayerId& id) {
+ metrics::CastMetricsHelper::GetInstance()->LogMediaPause();
+}
+
+void CastContentWindowAndroid::RenderViewCreated(
+ content::RenderViewHost* render_view_host) {
+ content::RenderWidgetHostView* view =
+ render_view_host->GetWidget()->GetView();
+ if (view) {
+ view->SetBackgroundColor(transparent_ ? SK_ColorTRANSPARENT
+ : SK_ColorBLACK);
+ }
+}
+
+void CastContentWindowAndroid::OnActivityStopped(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& jcaller) {
+ delegate_->OnWindowDestroyed();
+}
+
+void CastContentWindowAndroid::OnKeyDown(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& jcaller,
+ int keycode) {
+ ui::KeyEvent key_event(ui::ET_KEY_PRESSED,
+ ui::KeyboardCodeFromAndroidKeyCode(keycode),
+ ui::EF_NONE);
+ delegate_->OnKeyEvent(key_event);
+}
+
+} // namespace shell
+} // namespace chromecast
« 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