OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.AlertDialog; | 8 import android.app.AlertDialog; |
9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.ContextWrapper; |
10 import android.content.DialogInterface; | 11 import android.content.DialogInterface; |
11 import android.util.Log; | 12 import android.util.Log; |
12 import android.view.Gravity; | 13 import android.view.Gravity; |
13 import android.view.KeyEvent; | 14 import android.view.KeyEvent; |
14 import android.view.Surface; | 15 import android.view.Surface; |
15 import android.view.SurfaceHolder; | 16 import android.view.SurfaceHolder; |
16 import android.view.SurfaceView; | 17 import android.view.SurfaceView; |
17 import android.view.View; | 18 import android.view.View; |
18 import android.view.ViewGroup; | 19 import android.view.ViewGroup; |
19 import android.widget.FrameLayout; | 20 import android.widget.FrameLayout; |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 public boolean isPlaying() { | 371 public boolean isPlaying() { |
371 return mNativeContentVideoView != 0 && nativeIsPlaying(mNativeContentVid
eoView); | 372 return mNativeContentVideoView != 0 && nativeIsPlaying(mNativeContentVid
eoView); |
372 } | 373 } |
373 | 374 |
374 @CalledByNative | 375 @CalledByNative |
375 private static ContentVideoView createContentVideoView( | 376 private static ContentVideoView createContentVideoView( |
376 Context context, long nativeContentVideoView, ContentVideoViewClient
client, | 377 Context context, long nativeContentVideoView, ContentVideoViewClient
client, |
377 boolean legacy) { | 378 boolean legacy) { |
378 ThreadUtils.assertOnUiThread(); | 379 ThreadUtils.assertOnUiThread(); |
379 // The context needs be Activity to create the ContentVideoView correctl
y. | 380 // The context needs be Activity to create the ContentVideoView correctl
y. |
380 if (!(context instanceof Activity)) { | 381 if (!isActivityContext(context)) { |
381 Log.w(TAG, "Wrong type of context, can't create fullscreen video"); | 382 Log.e(TAG, "Wrong type of context, can't create fullscreen video"); |
382 return null; | 383 return null; |
383 } | 384 } |
384 ContentVideoView videoView = null; | 385 ContentVideoView videoView = null; |
385 if (legacy) { | 386 if (legacy) { |
386 videoView = new ContentVideoViewLegacy(context, nativeContentVideoVi
ew, client); | 387 videoView = new ContentVideoViewLegacy(context, nativeContentVideoVi
ew, client); |
387 } else { | 388 } else { |
388 videoView = new ContentVideoView(context, nativeContentVideoView, cl
ient); | 389 videoView = new ContentVideoView(context, nativeContentVideoView, cl
ient); |
389 } | 390 } |
390 | 391 |
391 if (videoView.getContentVideoViewClient().onShowCustomView(videoView)) { | 392 if (videoView.getContentVideoViewClient().onShowCustomView(videoView)) { |
392 return videoView; | 393 return videoView; |
393 } | 394 } |
394 return null; | 395 return null; |
395 } | 396 } |
396 | 397 |
| 398 private static boolean isActivityContext(Context context) { |
| 399 // Only retrieve the base context if the supplied context is a ContextWr
apper but not |
| 400 // an Activity, given that Activity is already a subclass of ContextWrap
per. |
| 401 if (context instanceof ContextWrapper && !(context instanceof Activity))
{ |
| 402 context = ((ContextWrapper) context).getBaseContext(); |
| 403 } |
| 404 return context instanceof Activity; |
| 405 } |
| 406 |
397 public void removeSurfaceView() { | 407 public void removeSurfaceView() { |
398 removeView(mVideoSurfaceView); | 408 removeView(mVideoSurfaceView); |
399 removeView(mProgressView); | 409 removeView(mProgressView); |
400 mVideoSurfaceView = null; | 410 mVideoSurfaceView = null; |
401 mProgressView = null; | 411 mProgressView = null; |
402 } | 412 } |
403 | 413 |
404 public void exitFullscreen(boolean relaseMediaPlayer) { | 414 public void exitFullscreen(boolean relaseMediaPlayer) { |
405 destroyContentVideoView(false); | 415 destroyContentVideoView(false); |
406 if (mNativeContentVideoView != 0) { | 416 if (mNativeContentVideoView != 0) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 private native int nativeGetDurationInMilliSeconds(long nativeContentVideoVi
ew); | 484 private native int nativeGetDurationInMilliSeconds(long nativeContentVideoVi
ew); |
475 private native void nativeRequestMediaMetadata(long nativeContentVideoView); | 485 private native void nativeRequestMediaMetadata(long nativeContentVideoView); |
476 private native int nativeGetVideoWidth(long nativeContentVideoView); | 486 private native int nativeGetVideoWidth(long nativeContentVideoView); |
477 private native int nativeGetVideoHeight(long nativeContentVideoView); | 487 private native int nativeGetVideoHeight(long nativeContentVideoView); |
478 private native boolean nativeIsPlaying(long nativeContentVideoView); | 488 private native boolean nativeIsPlaying(long nativeContentVideoView); |
479 private native void nativePause(long nativeContentVideoView); | 489 private native void nativePause(long nativeContentVideoView); |
480 private native void nativePlay(long nativeContentVideoView); | 490 private native void nativePlay(long nativeContentVideoView); |
481 private native void nativeSeekTo(long nativeContentVideoView, int msec); | 491 private native void nativeSeekTo(long nativeContentVideoView, int msec); |
482 private native void nativeSetSurface(long nativeContentVideoView, Surface su
rface); | 492 private native void nativeSetSurface(long nativeContentVideoView, Surface su
rface); |
483 } | 493 } |
OLD | NEW |