OLD | NEW |
---|---|
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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 #include <utility> | 10 #include <utility> |
(...skipping 4345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4356 &suppress_this_message); | 4356 &suppress_this_message); |
4357 } | 4357 } |
4358 | 4358 |
4359 if (suppress_this_message) { | 4359 if (suppress_this_message) { |
4360 // If we are suppressing messages, just reply as if the user immediately | 4360 // If we are suppressing messages, just reply as if the user immediately |
4361 // pressed "Cancel", passing true to |dialog_was_suppressed|. | 4361 // pressed "Cancel", passing true to |dialog_was_suppressed|. |
4362 OnDialogClosed(render_frame_host->GetProcess()->GetID(), | 4362 OnDialogClosed(render_frame_host->GetProcess()->GetID(), |
4363 render_frame_host->GetRoutingID(), reply_msg, | 4363 render_frame_host->GetRoutingID(), reply_msg, |
4364 true, false, base::string16()); | 4364 true, false, base::string16()); |
4365 } | 4365 } |
4366 | |
4367 // OnDialogClosed (two lines up) may have caused deletion of this object (see | |
4368 // http://crbug.com/288961 ). The only safe thing to do here is return. | |
Charlie Reis
2017/05/03 21:33:46
Good find that this used to happen in RenderFrameH
Avi (use Gerrit)
2017/05/04 15:15:04
2017 me is super grateful to 2013 me for the hint.
| |
4369 } | 4366 } |
4370 | 4367 |
4371 void WebContentsImpl::RunBeforeUnloadConfirm( | 4368 void WebContentsImpl::RunBeforeUnloadConfirm( |
4372 RenderFrameHost* render_frame_host, | 4369 RenderFrameHost* render_frame_host, |
4373 bool is_reload, | 4370 bool is_reload, |
4374 IPC::Message* reply_msg) { | 4371 IPC::Message* reply_msg) { |
4375 RenderFrameHostImpl* rfhi = | 4372 RenderFrameHostImpl* rfhi = |
4376 static_cast<RenderFrameHostImpl*>(render_frame_host); | 4373 static_cast<RenderFrameHostImpl*>(render_frame_host); |
4377 if (delegate_) | 4374 if (delegate_) |
4378 delegate_->WillRunBeforeUnloadConfirm(); | 4375 delegate_->WillRunBeforeUnloadConfirm(); |
4379 | 4376 |
4380 bool suppress_this_message = | 4377 bool suppress_this_message = |
4381 !rfhi->is_active() || | 4378 !rfhi->is_active() || |
4382 ShowingInterstitialPage() || !delegate_ || | 4379 ShowingInterstitialPage() || !delegate_ || |
4383 delegate_->ShouldSuppressDialogs(this) || | 4380 delegate_->ShouldSuppressDialogs(this) || |
4384 !delegate_->GetJavaScriptDialogManager(this); | 4381 !delegate_->GetJavaScriptDialogManager(this); |
4385 if (suppress_this_message) { | 4382 if (suppress_this_message) { |
4386 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true); | 4383 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16()); |
4387 return; | 4384 return; |
4388 } | 4385 } |
4389 | 4386 |
4390 is_showing_before_unload_dialog_ = true; | 4387 is_showing_before_unload_dialog_ = true; |
4391 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); | 4388 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
4392 dialog_manager_->RunBeforeUnloadDialog( | 4389 dialog_manager_->RunBeforeUnloadDialog( |
4393 this, is_reload, | 4390 this, is_reload, |
4394 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), | 4391 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
4395 render_frame_host->GetProcess()->GetID(), | 4392 render_frame_host->GetProcess()->GetID(), |
4396 render_frame_host->GetRoutingID(), reply_msg, | 4393 render_frame_host->GetRoutingID(), reply_msg, |
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5262 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) { | 5259 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) { |
5263 rfh->frame_tree_node()->BeforeUnloadCanceled(); | 5260 rfh->frame_tree_node()->BeforeUnloadCanceled(); |
5264 controller_.DiscardNonCommittedEntries(); | 5261 controller_.DiscardNonCommittedEntries(); |
5265 } | 5262 } |
5266 | 5263 |
5267 for (auto& observer : observers_) | 5264 for (auto& observer : observers_) |
5268 observer.BeforeUnloadDialogCancelled(); | 5265 observer.BeforeUnloadDialogCancelled(); |
5269 } | 5266 } |
5270 | 5267 |
5271 if (rfh) { | 5268 if (rfh) { |
5272 rfh->JavaScriptDialogClosed(reply_msg, success, user_input, | 5269 rfh->JavaScriptDialogClosed(reply_msg, success, user_input); |
5273 dialog_was_suppressed); | |
5274 } else { | 5270 } else { |
5275 // Don't leak the sync IPC reply if the RFH or process is gone. | 5271 // Don't leak the sync IPC reply if the RFH or process is gone. |
5276 delete reply_msg; | 5272 delete reply_msg; |
5277 } | 5273 } |
5278 | 5274 |
5279 is_showing_javascript_dialog_ = false; | 5275 is_showing_javascript_dialog_ = false; |
5280 is_showing_before_unload_dialog_ = false; | 5276 is_showing_before_unload_dialog_ = false; |
5281 } | 5277 } |
5282 | 5278 |
5283 void WebContentsImpl::SetEncoding(const std::string& encoding) { | 5279 void WebContentsImpl::SetEncoding(const std::string& encoding) { |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5589 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); | 5585 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); |
5590 if (!render_view_host) | 5586 if (!render_view_host) |
5591 continue; | 5587 continue; |
5592 render_view_host_set.insert(render_view_host); | 5588 render_view_host_set.insert(render_view_host); |
5593 } | 5589 } |
5594 for (RenderViewHost* render_view_host : render_view_host_set) | 5590 for (RenderViewHost* render_view_host : render_view_host_set) |
5595 render_view_host->OnWebkitPreferencesChanged(); | 5591 render_view_host->OnWebkitPreferencesChanged(); |
5596 } | 5592 } |
5597 | 5593 |
5598 } // namespace content | 5594 } // namespace content |
OLD | NEW |