Delay set picture if necessary

 Normally this wouldn't happen as a new picture should come after
 webcore has initialized. However, now that a view state can be loaded,
 setting a new picture needs to be delayed until after everything has
 initialized.

Change-Id: I823bc17eb939eab0436d7a398ebcbe849c0fb945
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 9e61ecf..a68ca60 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -6503,6 +6503,8 @@
     // arrow key events, not trackball events, from one child to the next
     private boolean mMapTrackballToArrowKeys = true;
 
+    private DrawData mDelaySetPicture;
+
     public void setMapTrackballToArrowKeys(boolean setMap) {
         checkThread();
         mMapTrackballToArrowKeys = setMap;
@@ -7912,7 +7914,8 @@
                 // after WebView's destroy() is called, skip handling messages.
                 return;
             }
-            if (mBlockWebkitViewMessages) {
+            if (mBlockWebkitViewMessages
+                    && msg.what != WEBCORE_INITIALIZED_MSG_ID) {
                 // Blocking messages from webkit
                 return;
             }
@@ -8060,6 +8063,10 @@
                             BrowserFrame.DRAWABLEDIR, mContext);
                     AssetManager am = mContext.getAssets();
                     nativeCreate(msg.arg1, drawableDir, am);
+                    if (mDelaySetPicture != null) {
+                        setNewPicture(mDelaySetPicture);
+                        mDelaySetPicture = null;
+                    }
                     break;
                 case UPDATE_TEXTFIELD_TEXT_MSG_ID:
                     // Make sure that the textfield is currently focused
@@ -8371,6 +8378,15 @@
     }
 
     void setNewPicture(final WebViewCore.DrawData draw) {
+        if (mNativeClass == 0) {
+            if (mDelaySetPicture != null) {
+                throw new IllegalStateException(
+                        "Tried to setNewPicture with a delay picture already set! (memory leak)");
+            }
+            // Not initialized yet, delay set
+            mDelaySetPicture = draw;
+            return;
+        }
         WebViewCore.ViewState viewState = draw.mViewState;
         boolean isPictureAfterFirstLayout = viewState != null;
         setBaseLayer(draw.mBaseLayer, draw.mInvalRegion,