Don't force ended when full screen video is returned manually.

issue: 3102273
Change-Id: Id9983a229e103dd255b280638979712873117d10
diff --git a/core/java/android/webkit/HTML5VideoViewProxy.java b/core/java/android/webkit/HTML5VideoViewProxy.java
index eda2e72..6769563 100644
--- a/core/java/android/webkit/HTML5VideoViewProxy.java
+++ b/core/java/android/webkit/HTML5VideoViewProxy.java
@@ -72,6 +72,7 @@
     private static final int PREPARED          = 200;
     private static final int ENDED             = 201;
     private static final int POSTER_FETCHED    = 202;
+    private static final int PAUSED            = 203;
 
     private static final String COOKIE = "Cookie";
 
@@ -118,6 +119,7 @@
         }
         // The spec says the timer should fire every 250 ms or less.
         private static final int TIMEUPDATE_PERIOD = 250;  // ms
+        static boolean isVideoSelfEnded = false;
 
         private static final WebChromeClient.CustomViewCallback mCallback =
             new WebChromeClient.CustomViewCallback() {
@@ -132,7 +134,11 @@
                     if (mVideoView.isPlaying()) {
                         mVideoView.stopPlayback();
                     }
-                    mCurrentProxy.dispatchOnEnded();
+                    if (isVideoSelfEnded)
+                        mCurrentProxy.dispatchOnEnded();
+                    else
+                        mCurrentProxy.dispatchOnPaused();
+                    isVideoSelfEnded = false;
                     mCurrentProxy = null;
                     mLayout.removeView(mVideoView);
                     mVideoView = null;
@@ -249,7 +255,8 @@
         // The video ended by itself, so we need to
         // send a message to the UI thread to dismiss
         // the video view and to return to the WebView.
-        sendMessage(obtainMessage(ENDED));
+        // arg1 == 1 means the video ends by itself.
+        sendMessage(obtainMessage(ENDED, 1, 0));
     }
 
     // MediaPlayer.OnErrorListener
@@ -263,6 +270,11 @@
         mWebCoreHandler.sendMessage(msg);
     }
 
+    public void dispatchOnPaused() {
+      Message msg = Message.obtain(mWebCoreHandler, PAUSED);
+      mWebCoreHandler.sendMessage(msg);
+    }
+
     public void onTimeupdate() {
         sendMessage(obtainMessage(TIMEUPDATE));
     }
@@ -291,6 +303,8 @@
                 break;
             }
             case ENDED:
+                if (msg.arg1 == 1)
+                    VideoPlayer.isVideoSelfEnded = true;
             case ERROR: {
                 WebChromeClient client = mWebView.getWebChromeClient();
                 if (client != null) {
@@ -476,6 +490,9 @@
                     case ENDED:
                         nativeOnEnded(mNativePointer);
                         break;
+                    case PAUSED:
+                        nativeOnPaused(mNativePointer);
+                        break;
                     case POSTER_FETCHED:
                         Bitmap poster = (Bitmap) msg.obj;
                         nativeOnPosterFetched(poster, mNativePointer);
@@ -584,6 +601,7 @@
 
     private native void nativeOnPrepared(int duration, int width, int height, int nativePointer);
     private native void nativeOnEnded(int nativePointer);
+    private native void nativeOnPaused(int nativePointer);
     private native void nativeOnPosterFetched(Bitmap poster, int nativePointer);
     private native void nativeOnTimeupdate(int position, int nativePointer);
 }