Defer window.close(), resizeTo() and moveTo() actions
by posting a task back to the message loop before notifying
the RenderWidgetHost to perform these operations.
Otherwise the JS code races with the browser to use the
modified window.

BUG=http://crbug.com/6377
BUG=http://crbug.com/6192

Cache a pending_window_rect on the render_view (moved from
prior CL where I had it on the chrome_client_impl).  This 
is a short lived cache, and not a complete solution.  It
fixes this case, where a JS script makes multiple operations
and expects the GetWindowSize() to be correct immedately
after having called SetWindowSize().  

BUG=http://crbug.com/835



Review URL: http://codereview.chromium.org/115030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15698 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/renderer/render_widget.h b/chrome/renderer/render_widget.h
index 62777e8f..660ccbbb 100644
--- a/chrome/renderer/render_widget.h
+++ b/chrome/renderer/render_widget.h
@@ -18,6 +18,7 @@
 #include "skia/ext/platform_canvas.h"
 #include "skia/include/SkBitmap.h"
 
+#include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
 #include "webkit/glue/webwidget_delegate.h"
 #include "webkit/glue/webcursor.h"
 
@@ -119,6 +120,8 @@
 
   void DoDeferredPaint();
   void DoDeferredScroll();
+  void DoDeferredClose();
+  void DoDeferredSetWindowRect(const WebKit::WebRect& pos);
 
   // This method is called immediately after PaintRect but before the
   // corresponding paint or scroll message is send to the widget host.
@@ -138,6 +141,7 @@
   void OnWasRestored(bool needs_repainting);
   void OnPaintRectAck();
   void OnScrollRectAck();
+  void OnRequestMoveAck();
   void OnHandleInputEvent(const IPC::Message& message);
   void OnMouseCaptureLost();
   void OnSetFocus(bool enable);
@@ -175,6 +179,14 @@
   // the focus on our own when the browser did not focus us.
   void ClearFocus();
 
+  // Set the pending window rect.
+  // Because the real render_widget is hosted in another process, there is
+  // a time period where we may have set a new window rect which has not yet
+  // been processed by the browser.  So we maintain a pending window rect
+  // size.  If JS code sets the WindowRect, and then immediately calls
+  // GetWindowRect() we'll use this pending window rect as the size.
+  void SetPendingWindowRect(const WebKit::WebRect& r);
+
   // Routing ID that allows us to communicate to the parent browser process
   // RenderWidgetHost. When MSG_ROUTING_NONE, no messages may be sent.
   int32 routing_id_;
@@ -280,6 +292,11 @@
   // A custom background for the widget.
   SkBitmap background_;
 
+  // While we are waiting for the browser to update window sizes,
+  // we track the pending size temporarily.
+  int pending_window_rect_count_;
+  WebKit::WebRect pending_window_rect_;
+
   DISALLOW_COPY_AND_ASSIGN(RenderWidget);
 };