Index: content/browser/web_contents/web_contents_impl.cc |
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc |
index a19fcd9921d563c334e361a83b4689aad1dc658e..a095604ae464f0ee665ea305dce0df27622fb97e 100644 |
--- a/content/browser/web_contents/web_contents_impl.cc |
+++ b/content/browser/web_contents/web_contents_impl.cc |
@@ -2867,6 +2867,84 @@ void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, |
render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params); |
} |
+void WebContentsImpl::RunJavaScriptMessage( |
+ RenderFrameHost* rfh, |
+ const base::string16& message, |
+ const base::string16& default_prompt, |
+ const GURL& frame_url, |
+ JavaScriptMessageType javascript_message_type, |
+ IPC::Message* reply_msg, |
+ bool* did_suppress_message) { |
+ // Suppress JavaScript dialogs when requested. Also suppress messages when |
+ // showing an interstitial as it's shown over the previous page and we don't |
+ // want the hidden page's dialogs to interfere with the interstitial. |
+ bool suppress_this_message = |
+ static_cast<RenderFrameHostImpl*>(rfh)->is_swapped_out() || |
+ ShowingInterstitialPage() || |
+ !delegate_ || |
+ delegate_->ShouldSuppressDialogs() || |
+ !delegate_->GetJavaScriptDialogManager(); |
+ |
+ if (!suppress_this_message) { |
+ std::string accept_lang = GetContentClient()->browser()-> |
+ GetAcceptLangs(GetBrowserContext()); |
+ dialog_manager_ = delegate_->GetJavaScriptDialogManager(); |
+ dialog_manager_->RunJavaScriptDialog( |
+ this, |
+ frame_url.GetOrigin(), |
+ accept_lang, |
+ javascript_message_type, |
+ message, |
+ default_prompt, |
+ base::Bind(&WebContentsImpl::OnDialogClosed, |
+ base::Unretained(this), |
+ rfh, |
+ reply_msg), |
+ &suppress_this_message); |
+ } |
+ |
+ *did_suppress_message = suppress_this_message; |
+ |
+ if (suppress_this_message) { |
+ // If we are suppressing messages, just reply as if the user immediately |
+ // pressed "Cancel". |
+ OnDialogClosed(rfh, reply_msg, false, base::string16()); |
+ } |
+ |
+ // OnDialogClosed (two lines up) may have caused deletion of this object (see |
+ // http://crbug.com/288961 ). The only safe thing to do here is return. |
+} |
+ |
+void WebContentsImpl::RunBeforeUnloadConfirm( |
+ RenderFrameHost* rfh, |
+ const base::string16& message, |
+ bool is_reload, |
+ IPC::Message* reply_msg) { |
+ RenderFrameHostImpl* rfhi = static_cast<RenderFrameHostImpl*>(rfh); |
+ RenderViewHostImpl* rvhi = |
+ static_cast<RenderViewHostImpl*>(rfh->GetRenderViewHost()); |
+ if (delegate_) |
+ delegate_->WillRunBeforeUnloadConfirm(); |
+ |
+ bool suppress_this_message = |
+ rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT || |
+ !delegate_ || |
+ delegate_->ShouldSuppressDialogs() || |
+ !delegate_->GetJavaScriptDialogManager(); |
+ if (suppress_this_message) { |
+ // The reply must be sent to the RFH that sent the request. |
+ rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16()); |
+ return; |
+ } |
+ |
+ is_showing_before_unload_dialog_ = true; |
+ dialog_manager_ = delegate_->GetJavaScriptDialogManager(); |
+ dialog_manager_->RunBeforeUnloadDialog( |
+ this, message, is_reload, |
+ base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rfh, |
+ reply_msg)); |
+} |
+ |
WebContents* WebContentsImpl::GetAsWebContents() { |
return this; |
} |
@@ -3251,7 +3329,7 @@ void WebContentsImpl::RouteMessageEvent( |
Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params)); |
} |
-void WebContentsImpl::RunJavaScriptMessage( |
+void WebContentsImpl::RunJavaScriptMessageOBSOLETE( |
RenderViewHost* rvh, |
const base::string16& message, |
const base::string16& default_prompt, |
@@ -3280,7 +3358,7 @@ void WebContentsImpl::RunJavaScriptMessage( |
javascript_message_type, |
message, |
default_prompt, |
- base::Bind(&WebContentsImpl::OnDialogClosed, |
+ base::Bind(&WebContentsImpl::OnDialogClosedOBSOLETE, |
base::Unretained(this), |
rvh, |
reply_msg), |
@@ -3292,17 +3370,18 @@ 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()); |
+ OnDialogClosedOBSOLETE(rvh, reply_msg, false, base::string16()); |
} |
// OnDialogClosed (two lines up) may have caused deletion of this object (see |
// http://crbug.com/288961 ). The only safe thing to do here is return. |
} |
-void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh, |
- const base::string16& message, |
- bool is_reload, |
- IPC::Message* reply_msg) { |
+void WebContentsImpl::RunBeforeUnloadConfirmOBSOLETE( |
+ RenderViewHost* rvh, |
+ const base::string16& message, |
+ bool is_reload, |
+ IPC::Message* reply_msg) { |
RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh); |
if (delegate_) |
delegate_->WillRunBeforeUnloadConfirm(); |
@@ -3322,7 +3401,9 @@ void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh, |
dialog_manager_ = delegate_->GetJavaScriptDialogManager(); |
dialog_manager_->RunBeforeUnloadDialog( |
this, message, is_reload, |
- base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh, |
+ base::Bind(&WebContentsImpl::OnDialogClosedOBSOLETE, |
+ base::Unretained(this), |
+ rvh, |
reply_msg)); |
} |
@@ -3600,22 +3681,40 @@ bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { |
} |
#endif |
-void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh, |
+void WebContentsImpl::OnDialogClosedOBSOLETE(RenderViewHost* rvh, |
+ IPC::Message* reply_msg, |
+ bool success, |
+ const base::string16& user_input) { |
+ 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()); |
+ controller_.DiscardNonCommittedEntries(); |
+ |
+ FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
+ BeforeUnloadDialogCancelled()); |
+ } |
+ is_showing_before_unload_dialog_ = false; |
+ static_cast<RenderViewHostImpl*>(rvh)-> |
+ JavaScriptDialogClosed(reply_msg, success, user_input); |
+} |
+ |
+void WebContentsImpl::OnDialogClosed(RenderFrameHost* rfh, |
IPC::Message* reply_msg, |
bool success, |
const base::string16& user_input) { |
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()); |
+ DidStopLoading(rfh); |
controller_.DiscardNonCommittedEntries(); |
FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
BeforeUnloadDialogCancelled()); |
} |
is_showing_before_unload_dialog_ = false; |
- static_cast<RenderViewHostImpl*>( |
- rvh)->JavaScriptDialogClosed(reply_msg, success, user_input); |
+ static_cast<RenderFrameHostImpl*>(rfh)-> |
+ JavaScriptDialogClosed(reply_msg, success, user_input); |
} |
void WebContentsImpl::SetEncoding(const std::string& encoding) { |