Support cross-process window.close() messages.

BUG=99202
TEST=Call w.close() on a window that has opened but navigated cross-process.

Review URL: https://chromiumcodereview.appspot.com/10344028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135416 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index a8abbc6f1..2bdb987 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2398,6 +2398,16 @@
   }
 }
 
+void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
+  // Tell the active RenderViewHost to run unload handlers and close, as long
+  // as the request came from a RenderViewHost in the same BrowsingInstance.
+  // In most cases, we receive this from a swapped out RenderViewHost.
+  // It is possible to receive it from one that has just been swapped in,
+  // in which case we might as well deliver the message anyway.
+  if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
+    GetRenderViewHost()->ClosePage();
+}
+
 void WebContentsImpl::RunJavaScriptMessage(
     RenderViewHost* rvh,
     const string16& message,