It is possible that we may get a call from WebCore that the first layout has
completed before we've successfully syncd the webview dimensions from Java to
native and in this case, we end up syncing a height of 0 to WebKit. This causes
hit detection to fail, as WebKit thinks we have a 0-height visible area. This
patch fixes this scenario by syncing the height of the webview back to WebKit
in the case that the first layout comes back before we've sent our dimensions.

Fix for b/2449863

Change-Id: Id72c37b17411f3409edc7104d83ca5ffd17ab09b
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index 71f69fe..b339015 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -2191,7 +2191,14 @@
                              );
                 }
                 data.mWidth = Math.round(webViewWidth / data.mScale);
-                data.mHeight = mCurrentViewHeight * data.mWidth / viewportWidth;
+                // We may get a call here when mCurrentViewHeight == 0 if webcore completes the
+                // first layout before we sync our webview dimensions to it. In that case, we
+                // request the real height of the webview. This is not a perfect solution as we
+                // are calling a WebView method from the WebCore thread. But this is preferable
+                // to syncing an incorrect height.
+                data.mHeight = mCurrentViewHeight == 0 ?
+                        Math.round(mWebView.getViewHeight() / data.mScale)
+                        : mCurrentViewHeight * data.mWidth / viewportWidth;
                 data.mTextWrapWidth = Math.round(webViewWidth
                         / mRestoreState.mTextWrapScale);
                 data.mIgnoreHeight = false;