Merge "Query the native side to decide to play when going into full screen mode"
diff --git a/core/java/android/webkit/HTML5VideoFullScreen.java b/core/java/android/webkit/HTML5VideoFullScreen.java
index e1eff58..21364c1a 100644
--- a/core/java/android/webkit/HTML5VideoFullScreen.java
+++ b/core/java/android/webkit/HTML5VideoFullScreen.java
@@ -116,13 +116,12 @@
         return mVideoSurfaceView;
     }
 
-    HTML5VideoFullScreen(Context context, int videoLayerId, int position,
-            boolean autoStart) {
+    HTML5VideoFullScreen(Context context, int videoLayerId, int position) {
         mVideoSurfaceView = new VideoSurfaceView(context);
         mFullScreenMode = FULLSCREEN_OFF;
         mVideoWidth = 0;
         mVideoHeight = 0;
-        init(videoLayerId, position, autoStart);
+        init(videoLayerId, position);
     }
 
     private void setMediaController(MediaController m) {
@@ -186,11 +185,6 @@
         // after reading the MetaData
         if (mMediaController != null) {
             mMediaController.setEnabled(true);
-            // If paused , should show the controller for ever!
-            if (getAutostart())
-                mMediaController.show();
-            else
-                mMediaController.show(0);
         }
 
         if (mProgressView != null) {
@@ -201,6 +195,9 @@
         mVideoHeight = mp.getVideoHeight();
         // This will trigger the onMeasure to get the display size right.
         mVideoSurfaceView.getHolder().setFixedSize(mVideoWidth, mVideoHeight);
+        // Call into the native to ask for the state, if still in play mode,
+        // this will trigger the video to play.
+        mProxy.dispatchOnRestoreState();
     }
 
     public boolean fullScreenExited() {
diff --git a/core/java/android/webkit/HTML5VideoInline.java b/core/java/android/webkit/HTML5VideoInline.java
index fe5908e..2d5b263 100644
--- a/core/java/android/webkit/HTML5VideoInline.java
+++ b/core/java/android/webkit/HTML5VideoInline.java
@@ -34,9 +34,8 @@
         }
     }
 
-    HTML5VideoInline(int videoLayerId, int position,
-            boolean autoStart) {
-        init(videoLayerId, position, autoStart);
+    HTML5VideoInline(int videoLayerId, int position) {
+        init(videoLayerId, position);
         mTextureNames = null;
     }
 
diff --git a/core/java/android/webkit/HTML5VideoView.java b/core/java/android/webkit/HTML5VideoView.java
index 67660b8..1d8bda7 100644
--- a/core/java/android/webkit/HTML5VideoView.java
+++ b/core/java/android/webkit/HTML5VideoView.java
@@ -52,10 +52,6 @@
     // Switching between inline and full screen will also create a new instance.
     protected MediaPlayer mPlayer;
 
-    // This will be set up every time we create the Video View object.
-    // Set to true only when switching into full screen while playing
-    protected boolean mAutostart;
-
     // We need to save such info.
     protected Uri mUri;
     protected Map<String, String> mHeaders;
@@ -141,22 +137,17 @@
         }
     }
 
-    public boolean getAutostart() {
-        return mAutostart;
-    }
-
     public boolean getPauseDuringPreparing() {
         return mPauseDuringPreparing;
     }
 
     // Every time we start a new Video, we create a VideoView and a MediaPlayer
-    public void init(int videoLayerId, int position, boolean autoStart) {
+    public void init(int videoLayerId, int position) {
         mPlayer = new MediaPlayer();
         mCurrentState = STATE_INITIALIZED;
         mProxy = null;
         mVideoLayerId = videoLayerId;
         mSaveSeekTime = position;
-        mAutostart = autoStart;
         mTimer = null;
         mPauseDuringPreparing = false;
     }
diff --git a/core/java/android/webkit/HTML5VideoViewProxy.java b/core/java/android/webkit/HTML5VideoViewProxy.java
index d0237b5..7c2dc38 100644
--- a/core/java/android/webkit/HTML5VideoViewProxy.java
+++ b/core/java/android/webkit/HTML5VideoViewProxy.java
@@ -66,6 +66,7 @@
     private static final int POSTER_FETCHED    = 202;
     private static final int PAUSED            = 203;
     private static final int STOPFULLSCREEN    = 204;
+    private static final int RESTORESTATE      = 205;
 
     // Timer thread -> UI thread
     private static final int TIMEUPDATE = 300;
@@ -144,19 +145,16 @@
                 HTML5VideoViewProxy proxy, WebView webView) {
                 // Save the inline video info and inherit it in the full screen
                 int savePosition = 0;
-                boolean savedIsPlaying = false;
                 if (mHTML5VideoView != null) {
                     // If we are playing the same video, then it is better to
                     // save the current position.
                     if (layerId == mHTML5VideoView.getVideoLayerId()) {
                         savePosition = mHTML5VideoView.getCurrentPosition();
-                        savedIsPlaying = mHTML5VideoView.isPlaying();
                     }
-                    mHTML5VideoView.pauseAndDispatch(mCurrentProxy);
                     mHTML5VideoView.release();
                 }
                 mHTML5VideoView = new HTML5VideoFullScreen(proxy.getContext(),
-                        layerId, savePosition, savedIsPlaying);
+                        layerId, savePosition);
                 mCurrentProxy = proxy;
 
                 mHTML5VideoView.setVideoURI(url, mCurrentProxy);
@@ -192,7 +190,7 @@
                     mHTML5VideoView.release();
                 }
                 mCurrentProxy = proxy;
-                mHTML5VideoView = new HTML5VideoInline(videoLayerId, time, false);
+                mHTML5VideoView = new HTML5VideoInline(videoLayerId, time);
 
                 mHTML5VideoView.setVideoURI(url, mCurrentProxy);
                 mHTML5VideoView.prepareDataAndDisplayMode(proxy);
@@ -235,7 +233,7 @@
         }
 
         public static void onPrepared() {
-            if (!mHTML5VideoView.isFullScreenMode() || mHTML5VideoView.getAutostart()) {
+            if (!mHTML5VideoView.isFullScreenMode()) {
                 mHTML5VideoView.start();
             }
             if (mBaseLayer != 0) {
@@ -297,6 +295,11 @@
         mWebCoreHandler.sendMessage(msg);
     }
 
+    public void dispatchOnRestoreState() {
+        Message msg = Message.obtain(mWebCoreHandler, RESTORESTATE);
+        mWebCoreHandler.sendMessage(msg);
+    }
+
     public void onTimeupdate() {
         sendMessage(obtainMessage(TIMEUPDATE));
     }
@@ -569,6 +572,9 @@
                     case STOPFULLSCREEN:
                         nativeOnStopFullscreen(mNativePointer);
                         break;
+                    case RESTORESTATE:
+                        nativeOnRestoreState(mNativePointer);
+                        break;
                 }
             }
         };
@@ -696,6 +702,7 @@
     private native void nativeOnPosterFetched(Bitmap poster, int nativePointer);
     private native void nativeOnTimeupdate(int position, int nativePointer);
     private native void nativeOnStopFullscreen(int nativePointer);
+    private native void nativeOnRestoreState(int nativePointer);
     private native static boolean nativeSendSurfaceTexture(SurfaceTexture texture,
             int baseLayer, int videoLayerId, int textureName,
             int playerState);