Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / content / browser / web_contents / web_contents_impl.cc
index 79cfa06..320538b 100644 (file)
@@ -2194,6 +2194,22 @@ void WebContentsImpl::DidCommitProvisionalLoad(
                                        render_view_host));
 }
 
+void WebContentsImpl::DidNavigateMainFramePreCommit(
+    const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
+  // Ensure fullscreen mode is exited before committing the navigation to a
+  // different page.  The next page will not start out assuming it is in
+  // fullscreen mode.
+  if (controller_.IsURLInPageNavigation(params.url,
+                                        params.was_within_same_page,
+                                        NAVIGATION_TYPE_UNKNOWN)) {
+    // No page change?  Then, the renderer and browser can remain in fullscreen.
+    return;
+  }
+  if (IsFullscreenForCurrentTab())
+    GetRenderViewHost()->ExitFullscreen();
+  DCHECK(!IsFullscreenForCurrentTab());
+}
+
 void WebContentsImpl::DidNavigateMainFramePostCommit(
     const LoadCommittedDetails& details,
     const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
@@ -3009,19 +3025,8 @@ void WebContentsImpl::Close(RenderViewHost* rvh) {
 }
 
 void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
-  // TODO(creis): Handle subframes that go fullscreen.
-  if (rfh->GetRenderViewHost() == GetRenderViewHost()) {
-    // Exit fullscreen mode before the current RVH is swapped out.  For numerous
-    // cases, there is no guarantee the renderer would/could initiate an exit.
-    // Example: http://crbug.com/347232
-    if (IsFullscreenForCurrentTab()) {
-      rfh->GetRenderViewHost()->ExitFullscreen();
-      DCHECK(!IsFullscreenForCurrentTab());
-    }
-
-    if (delegate_)
-      delegate_->SwappedOut(this);
-  }
+  if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
+    delegate_->SwappedOut(this);
 }
 
 void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
@@ -3220,7 +3225,8 @@ void WebContentsImpl::RunJavaScriptMessage(
         default_prompt,
         base::Bind(&WebContentsImpl::OnDialogClosed,
                    base::Unretained(this),
-                   rvh,
+                   rvh->GetProcess()->GetID(),
+                   rvh->GetRoutingID(),
                    reply_msg),
         &suppress_this_message);
   }
@@ -3230,7 +3236,8 @@ void WebContentsImpl::RunJavaScriptMessage(
   if (suppress_this_message) {
     // If we are suppressing messages, just reply as if the user immediately
     // pressed "Cancel".
-    OnDialogClosed(rvh, reply_msg, false, base::string16());
+    OnDialogClosed(rvh->GetProcess()->GetID(), rvh->GetRoutingID(), reply_msg,
+                   false, base::string16());
   }
 
   // OnDialogClosed (two lines up) may have caused deletion of this object (see
@@ -3260,8 +3267,8 @@ void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
   dialog_manager_ = delegate_->GetJavaScriptDialogManager();
   dialog_manager_->RunBeforeUnloadDialog(
       this, message, is_reload,
-      base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
-                 reply_msg));
+      base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
+                 rvh->GetProcess()->GetID(), rvh->GetRoutingID(), reply_msg));
 }
 
 bool WebContentsImpl::AddMessageToConsole(int32 level,
@@ -3538,22 +3545,30 @@ bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
 }
 #endif
 
-void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
+void WebContentsImpl::OnDialogClosed(int render_process_id,
+                                     int render_view_id,
                                      IPC::Message* reply_msg,
                                      bool success,
                                      const base::string16& user_input) {
+  RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(render_process_id,
+                                                       render_view_id);
   if (is_showing_before_unload_dialog_ && !success) {
     // If a beforeunload dialog is canceled, we need to stop the throbber from
     // spinning, since we forced it to start spinning in Navigate.
-    DidStopLoading(rvh->GetMainFrame());
+    if (rvh)
+      DidStopLoading(rvh->GetMainFrame());
     controller_.DiscardNonCommittedEntries();
 
     FOR_EACH_OBSERVER(WebContentsObserver, observers_,
                       BeforeUnloadDialogCancelled());
   }
   is_showing_before_unload_dialog_ = false;
-  static_cast<RenderViewHostImpl*>(
-      rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
+  if (rvh) {
+    rvh->JavaScriptDialogClosed(reply_msg, success, user_input);
+  } else {
+    // Don't leak the sync IPC reply if the RVH or process is gone.
+    delete reply_msg;
+  }
 }
 
 void WebContentsImpl::SetEncoding(const std::string& encoding) {