Chromium Code Reviews

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 255543009: Ensure that modal dialogs from subframes can be cleaned up correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't store a possibly deleted RFH Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 3050 matching lines...)
3061 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); 3061 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3062 dialog_manager_->RunJavaScriptDialog( 3062 dialog_manager_->RunJavaScriptDialog(
3063 this, 3063 this,
3064 frame_url.GetOrigin(), 3064 frame_url.GetOrigin(),
3065 accept_lang, 3065 accept_lang,
3066 javascript_message_type, 3066 javascript_message_type,
3067 message, 3067 message,
3068 default_prompt, 3068 default_prompt,
3069 base::Bind(&WebContentsImpl::OnDialogClosed, 3069 base::Bind(&WebContentsImpl::OnDialogClosed,
3070 base::Unretained(this), 3070 base::Unretained(this),
3071 rfh, 3071 rfh->GetProcess()->GetID(),
3072 rfh->GetRoutingID(),
3072 reply_msg, 3073 reply_msg,
3073 false), 3074 false),
3074 &suppress_this_message); 3075 &suppress_this_message);
3075 } 3076 }
3076 3077
3077 if (suppress_this_message) { 3078 if (suppress_this_message) {
3078 // If we are suppressing messages, just reply as if the user immediately 3079 // If we are suppressing messages, just reply as if the user immediately
3079 // pressed "Cancel", passing true to |dialog_was_suppressed|. 3080 // pressed "Cancel", passing true to |dialog_was_suppressed|.
3080 OnDialogClosed(rfh, reply_msg, true, false, base::string16()); 3081 OnDialogClosed(rfh->GetProcess()->GetID(), rfh->GetRoutingID(), reply_msg,
3082 true, false, base::string16());
3081 } 3083 }
3082 3084
3083 // OnDialogClosed (two lines up) may have caused deletion of this object (see 3085 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3084 // http://crbug.com/288961 ). The only safe thing to do here is return. 3086 // http://crbug.com/288961 ). The only safe thing to do here is return.
3085 } 3087 }
3086 3088
3087 void WebContentsImpl::RunBeforeUnloadConfirm( 3089 void WebContentsImpl::RunBeforeUnloadConfirm(
3088 RenderFrameHost* rfh, 3090 RenderFrameHost* rfh,
3089 const base::string16& message, 3091 const base::string16& message,
3090 bool is_reload, 3092 bool is_reload,
(...skipping 12 matching lines...)
3103 if (suppress_this_message) { 3105 if (suppress_this_message) {
3104 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true); 3106 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3105 return; 3107 return;
3106 } 3108 }
3107 3109
3108 is_showing_before_unload_dialog_ = true; 3110 is_showing_before_unload_dialog_ = true;
3109 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); 3111 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3110 dialog_manager_->RunBeforeUnloadDialog( 3112 dialog_manager_->RunBeforeUnloadDialog(
3111 this, message, is_reload, 3113 this, message, is_reload,
3112 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), 3114 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
3113 rfh, reply_msg, false)); 3115 rfh->GetProcess()->GetID(), rfh->GetRoutingID(), reply_msg,
3116 false));
3114 } 3117 }
3115 3118
3116 WebContents* WebContentsImpl::GetAsWebContents() { 3119 WebContents* WebContentsImpl::GetAsWebContents() {
3117 return this; 3120 return this;
3118 } 3121 }
3119 3122
3120 bool WebContentsImpl::IsNeverVisible() { 3123 bool WebContentsImpl::IsNeverVisible() {
3121 if (!delegate_) 3124 if (!delegate_)
3122 return false; 3125 return false;
3123 return delegate_->IsNeverVisible(this); 3126 return delegate_->IsNeverVisible(this);
(...skipping 653 matching lines...)
3777 return web_contents_android->GetJavaObject(); 3780 return web_contents_android->GetJavaObject();
3778 } 3781 }
3779 3782
3780 bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { 3783 bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3781 return CreateRenderViewForRenderManager(GetRenderViewHost(), 3784 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3782 MSG_ROUTING_NONE, 3785 MSG_ROUTING_NONE,
3783 NULL); 3786 NULL);
3784 } 3787 }
3785 #endif 3788 #endif
3786 3789
3787 void WebContentsImpl::OnDialogClosed(RenderFrameHost* rfh, 3790 void WebContentsImpl::OnDialogClosed(int render_process_id,
3791 int render_frame_id,
3788 IPC::Message* reply_msg, 3792 IPC::Message* reply_msg,
3789 bool dialog_was_suppressed, 3793 bool dialog_was_suppressed,
3790 bool success, 3794 bool success,
3791 const base::string16& user_input) { 3795 const base::string16& user_input) {
3796 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
3797 render_frame_id);
3792 last_dialog_suppressed_ = dialog_was_suppressed; 3798 last_dialog_suppressed_ = dialog_was_suppressed;
3793 3799
3794 if (is_showing_before_unload_dialog_ && !success) { 3800 if (is_showing_before_unload_dialog_ && !success) {
3795 // If a beforeunload dialog is canceled, we need to stop the throbber from 3801 // If a beforeunload dialog is canceled, we need to stop the throbber from
3796 // spinning, since we forced it to start spinning in Navigate. 3802 // spinning, since we forced it to start spinning in Navigate.
3797 DidStopLoading(rfh); 3803 if (rfh)
3804 DidStopLoading(rfh);
3798 controller_.DiscardNonCommittedEntries(); 3805 controller_.DiscardNonCommittedEntries();
3799 3806
3800 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 3807 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3801 BeforeUnloadDialogCancelled()); 3808 BeforeUnloadDialogCancelled());
3802 } 3809 }
3803 3810
3804 is_showing_before_unload_dialog_ = false; 3811 is_showing_before_unload_dialog_ = false;
3805 static_cast<RenderFrameHostImpl*>(rfh)->JavaScriptDialogClosed( 3812 if (rfh) {
3806 reply_msg, success, user_input, dialog_was_suppressed); 3813 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
3814 dialog_was_suppressed);
3815 }
3807 } 3816 }
3808 3817
3809 void WebContentsImpl::SetEncoding(const std::string& encoding) { 3818 void WebContentsImpl::SetEncoding(const std::string& encoding) {
3810 encoding_ = GetContentClient()->browser()-> 3819 encoding_ = GetContentClient()->browser()->
3811 GetCanonicalEncodingNameByAliasName(encoding); 3820 GetCanonicalEncodingNameByAliasName(encoding);
3812 } 3821 }
3813 3822
3814 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { 3823 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
3815 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh); 3824 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
3816 // Can be NULL during tests. 3825 // Can be NULL during tests.
(...skipping 64 matching lines...)
3881 3890
3882 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { 3891 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3883 if (!delegate_) 3892 if (!delegate_)
3884 return; 3893 return;
3885 const gfx::Size new_size = GetPreferredSize(); 3894 const gfx::Size new_size = GetPreferredSize();
3886 if (new_size != old_size) 3895 if (new_size != old_size)
3887 delegate_->UpdatePreferredSize(this, new_size); 3896 delegate_->UpdatePreferredSize(this, new_size);
3888 } 3897 }
3889 3898
3890 } // namespace content 3899 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine