Skip to content

Commit

Permalink
Fix ContentVideoView to support a ContextWrapper.
Browse files Browse the repository at this point in the history
BUG=400755

Review URL: https://codereview.chromium.org/440143002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287764 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
igsolla@chromium.org committed Aug 6, 2014
1 parent c616397 commit b3a4d2b
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.util.Log;
import android.view.Gravity;
Expand Down Expand Up @@ -377,8 +378,8 @@ private static ContentVideoView createContentVideoView(
boolean legacy) {
ThreadUtils.assertOnUiThread();
// The context needs be Activity to create the ContentVideoView correctly.
if (!(context instanceof Activity)) {
Log.w(TAG, "Wrong type of context, can't create fullscreen video");
if (!isActivityContext(context)) {
Log.e(TAG, "Wrong type of context, can't create fullscreen video");
return null;
}
ContentVideoView videoView = null;
Expand All @@ -394,6 +395,15 @@ private static ContentVideoView createContentVideoView(
return null;
}

private static boolean isActivityContext(Context context) {
// Only retrieve the base context if the supplied context is a ContextWrapper but not
// an Activity, given that Activity is already a subclass of ContextWrapper.
if (context instanceof ContextWrapper && !(context instanceof Activity)) {
context = ((ContextWrapper) context).getBaseContext();
}
return context instanceof Activity;
}

public void removeSurfaceView() {
removeView(mVideoSurfaceView);
removeView(mProgressView);
Expand Down

0 comments on commit b3a4d2b

Please sign in to comment.