Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(618)

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

Issue 256233002: Ensure that modal dialogs from subframes can be cleaned up correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory leak. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | 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 3062 matching lines...) Expand 10 before | Expand all | Expand 10 after
3073 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); 3073 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3074 dialog_manager_->RunJavaScriptDialog( 3074 dialog_manager_->RunJavaScriptDialog(
3075 this, 3075 this,
3076 frame_url.GetOrigin(), 3076 frame_url.GetOrigin(),
3077 accept_lang, 3077 accept_lang,
3078 javascript_message_type, 3078 javascript_message_type,
3079 message, 3079 message,
3080 default_prompt, 3080 default_prompt,
3081 base::Bind(&WebContentsImpl::OnDialogClosed, 3081 base::Bind(&WebContentsImpl::OnDialogClosed,
3082 base::Unretained(this), 3082 base::Unretained(this),
3083 rfh, 3083 rfh->GetProcess()->GetID(),
3084 rfh->GetRoutingID(),
3084 reply_msg, 3085 reply_msg,
3085 false), 3086 false),
3086 &suppress_this_message); 3087 &suppress_this_message);
3087 } 3088 }
3088 3089
3089 if (suppress_this_message) { 3090 if (suppress_this_message) {
3090 // If we are suppressing messages, just reply as if the user immediately 3091 // If we are suppressing messages, just reply as if the user immediately
3091 // pressed "Cancel", passing true to |dialog_was_suppressed|. 3092 // pressed "Cancel", passing true to |dialog_was_suppressed|.
3092 OnDialogClosed(rfh, reply_msg, true, false, base::string16()); 3093 OnDialogClosed(rfh->GetProcess()->GetID(), rfh->GetRoutingID(), reply_msg,
3094 true, false, base::string16());
3093 } 3095 }
3094 3096
3095 // OnDialogClosed (two lines up) may have caused deletion of this object (see 3097 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3096 // http://crbug.com/288961 ). The only safe thing to do here is return. 3098 // http://crbug.com/288961 ). The only safe thing to do here is return.
3097 } 3099 }
3098 3100
3099 void WebContentsImpl::RunBeforeUnloadConfirm( 3101 void WebContentsImpl::RunBeforeUnloadConfirm(
3100 RenderFrameHost* rfh, 3102 RenderFrameHost* rfh,
3101 const base::string16& message, 3103 const base::string16& message,
3102 bool is_reload, 3104 bool is_reload,
(...skipping 12 matching lines...) Expand all
3115 if (suppress_this_message) { 3117 if (suppress_this_message) {
3116 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true); 3118 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3117 return; 3119 return;
3118 } 3120 }
3119 3121
3120 is_showing_before_unload_dialog_ = true; 3122 is_showing_before_unload_dialog_ = true;
3121 dialog_manager_ = delegate_->GetJavaScriptDialogManager(); 3123 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3122 dialog_manager_->RunBeforeUnloadDialog( 3124 dialog_manager_->RunBeforeUnloadDialog(
3123 this, message, is_reload, 3125 this, message, is_reload,
3124 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), 3126 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
3125 rfh, reply_msg, false)); 3127 rfh->GetProcess()->GetID(), rfh->GetRoutingID(), reply_msg,
3128 false));
3126 } 3129 }
3127 3130
3128 WebContents* WebContentsImpl::GetAsWebContents() { 3131 WebContents* WebContentsImpl::GetAsWebContents() {
3129 return this; 3132 return this;
3130 } 3133 }
3131 3134
3132 bool WebContentsImpl::IsNeverVisible() { 3135 bool WebContentsImpl::IsNeverVisible() {
3133 if (!delegate_) 3136 if (!delegate_)
3134 return false; 3137 return false;
3135 return delegate_->IsNeverVisible(this); 3138 return delegate_->IsNeverVisible(this);
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
3789 return web_contents_android->GetJavaObject(); 3792 return web_contents_android->GetJavaObject();
3790 } 3793 }
3791 3794
3792 bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { 3795 bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3793 return CreateRenderViewForRenderManager(GetRenderViewHost(), 3796 return CreateRenderViewForRenderManager(GetRenderViewHost(),
3794 MSG_ROUTING_NONE, 3797 MSG_ROUTING_NONE,
3795 NULL); 3798 NULL);
3796 } 3799 }
3797 #endif 3800 #endif
3798 3801
3799 void WebContentsImpl::OnDialogClosed(RenderFrameHost* rfh, 3802 void WebContentsImpl::OnDialogClosed(int render_process_id,
3803 int render_frame_id,
3800 IPC::Message* reply_msg, 3804 IPC::Message* reply_msg,
3801 bool dialog_was_suppressed, 3805 bool dialog_was_suppressed,
3802 bool success, 3806 bool success,
3803 const base::string16& user_input) { 3807 const base::string16& user_input) {
3808 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
3809 render_frame_id);
3804 last_dialog_suppressed_ = dialog_was_suppressed; 3810 last_dialog_suppressed_ = dialog_was_suppressed;
3805 3811
3806 if (is_showing_before_unload_dialog_ && !success) { 3812 if (is_showing_before_unload_dialog_ && !success) {
3807 // If a beforeunload dialog is canceled, we need to stop the throbber from 3813 // If a beforeunload dialog is canceled, we need to stop the throbber from
3808 // spinning, since we forced it to start spinning in Navigate. 3814 // spinning, since we forced it to start spinning in Navigate.
3809 DidStopLoading(rfh); 3815 if (rfh)
3816 DidStopLoading(rfh);
3810 controller_.DiscardNonCommittedEntries(); 3817 controller_.DiscardNonCommittedEntries();
3811 3818
3812 FOR_EACH_OBSERVER(WebContentsObserver, observers_, 3819 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3813 BeforeUnloadDialogCancelled()); 3820 BeforeUnloadDialogCancelled());
3814 } 3821 }
3815 3822
3816 is_showing_before_unload_dialog_ = false; 3823 is_showing_before_unload_dialog_ = false;
3817 static_cast<RenderFrameHostImpl*>(rfh)->JavaScriptDialogClosed( 3824 if (rfh) {
3818 reply_msg, success, user_input, dialog_was_suppressed); 3825 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
3826 dialog_was_suppressed);
3827 } else {
3828 // Don't leak the sync IPC reply if the RFH or process is gone.
3829 delete reply_msg;
3830 }
3819 } 3831 }
3820 3832
3821 void WebContentsImpl::SetEncoding(const std::string& encoding) { 3833 void WebContentsImpl::SetEncoding(const std::string& encoding) {
3822 encoding_ = GetContentClient()->browser()-> 3834 encoding_ = GetContentClient()->browser()->
3823 GetCanonicalEncodingNameByAliasName(encoding); 3835 GetCanonicalEncodingNameByAliasName(encoding);
3824 } 3836 }
3825 3837
3826 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { 3838 void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
3827 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh); 3839 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
3828 // Can be NULL during tests. 3840 // Can be NULL during tests.
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
3893 3905
3894 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { 3906 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3895 if (!delegate_) 3907 if (!delegate_)
3896 return; 3908 return;
3897 const gfx::Size new_size = GetPreferredSize(); 3909 const gfx::Size new_size = GetPreferredSize();
3898 if (new_size != old_size) 3910 if (new_size != old_size)
3899 delegate_->UpdatePreferredSize(this, new_size); 3911 delegate_->UpdatePreferredSize(this, new_size);
3900 } 3912 }
3901 3913
3902 } // namespace content 3914 } // 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
This is Rietveld 408576698