Fix window.open()/window.close() regression by disabling window.close() until a message comes back
from the Browser thread saying that it's OK to allow javascript close calls.

ISSUE=http://crbug.com/4007
Review URL: http://codereview.chromium.org/12691

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6165 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 48a0e36b8..e571ace 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -162,7 +162,8 @@
     decrement_shared_popup_at_destruction_(false),
     greasemonkey_enabled_(false),
     waiting_for_create_window_ack_(false),
-    form_field_autofill_request_id_(0) {
+    form_field_autofill_request_id_(0),
+    popup_notification_visible_(false)  {
   resource_dispatcher_ = new ResourceDispatcher(this);
 #ifdef CHROME_PERSONALIZATION
   personalization_ = Personalization::CreateRendererPersonalization();
@@ -387,6 +388,9 @@
                         OnDisassociateFromPopupCount)
     IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions,
                         OnReceivedAutofillSuggestions)
+    IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisiblityChanged,
+                        OnPopupNotificationVisiblityChanged)
+
     // Have the super handle all other messages.
     IPC_MESSAGE_UNHANDLED(RenderWidget::OnMessageReceived(message))
   IPC_END_MESSAGE_MAP()
@@ -1692,6 +1696,10 @@
                                         default_suggestion_index);
 }
 
+void RenderView::OnPopupNotificationVisiblityChanged(bool visible) {
+  popup_notification_visible_ = visible;
+}
+
 void RenderView::ShowModalHTMLDialog(const GURL& url, int width, int height,
                                      const std::string& json_arguments,
                                      std::string* json_retval) {
@@ -1765,6 +1773,10 @@
   if (shared_popup_counter_->data > kMaximumNumberOfUnacknowledgedPopups)
     return NULL;
 
+  // This window can't be closed from a window.close() call until we receive a
+  // message from the Browser process explicitly allowing it.
+  popup_notification_visible_ = true;
+
   int32 routing_id = MSG_ROUTING_NONE;
   HANDLE modal_dialog_event = NULL;
   bool result = RenderThread::current()->Send(
@@ -1896,6 +1908,11 @@
       WasOpenedByUserGestureHelper()));
 }
 
+void RenderView::CloseWidgetSoon(WebWidget* webwidget) {
+  if (popup_notification_visible_ == false)
+    RenderWidget::CloseWidgetSoon(webwidget);
+}
+
 void RenderView::RunModal(WebWidget* webwidget) {
   DCHECK(did_show_) << "should already have shown the view";