Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/renderer_host/render_view_host.h" | 5 #include "chrome/browser/renderer_host/render_view_host.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 instance_(instance), | 101 instance_(instance), |
| 102 delegate_(delegate), | 102 delegate_(delegate), |
| 103 waiting_for_drag_context_response_(false), | 103 waiting_for_drag_context_response_(false), |
| 104 enabled_bindings_(0), | 104 enabled_bindings_(0), |
| 105 pending_request_id_(0), | 105 pending_request_id_(0), |
| 106 modal_dialog_count_(0), | 106 modal_dialog_count_(0), |
| 107 navigations_suspended_(false), | 107 navigations_suspended_(false), |
| 108 suspended_nav_message_(NULL), | 108 suspended_nav_message_(NULL), |
| 109 run_modal_reply_msg_(NULL), | 109 run_modal_reply_msg_(NULL), |
| 110 is_waiting_for_unload_ack_(false), | 110 is_waiting_for_unload_ack_(false), |
| 111 unload_ack_is_for_cross_site_transition_(false), | |
| 111 are_javascript_messages_suppressed_(false), | 112 are_javascript_messages_suppressed_(false), |
| 112 sudden_termination_allowed_(false), | 113 sudden_termination_allowed_(false), |
| 113 in_inspect_element_mode_(false) { | 114 in_inspect_element_mode_(false) { |
| 114 DCHECK(instance_); | 115 DCHECK(instance_); |
| 115 DCHECK(delegate_); | 116 DCHECK(delegate_); |
| 116 if (modal_dialog_event == NULL) | 117 if (modal_dialog_event == NULL) |
| 117 modal_dialog_event = new base::WaitableEvent(true, false); | 118 modal_dialog_event = new base::WaitableEvent(true, false); |
| 118 | 119 |
| 119 modal_dialog_event_.reset(modal_dialog_event); | 120 modal_dialog_event_.reset(modal_dialog_event); |
| 120 | 121 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 DCHECK(navigations_suspended_ != suspend); | 294 DCHECK(navigations_suspended_ != suspend); |
| 294 | 295 |
| 295 navigations_suspended_ = suspend; | 296 navigations_suspended_ = suspend; |
| 296 if (!suspend && suspended_nav_message_.get()) { | 297 if (!suspend && suspended_nav_message_.get()) { |
| 297 // There's a navigation message waiting to be sent. Now that we're not | 298 // There's a navigation message waiting to be sent. Now that we're not |
| 298 // suspended anymore, resume navigation by sending it. | 299 // suspended anymore, resume navigation by sending it. |
| 299 Send(suspended_nav_message_.release()); | 300 Send(suspended_nav_message_.release()); |
| 300 } | 301 } |
| 301 } | 302 } |
| 302 | 303 |
| 303 void RenderViewHost::FirePageBeforeUnload() { | 304 void RenderViewHost::FirePageBeforeUnload(bool for_cross_site_transition) { |
| 304 if (!IsRenderViewLive()) { | 305 if (!IsRenderViewLive()) { |
| 305 // This RenderViewHost doesn't have a live renderer, so just skip running | 306 // This RenderViewHost doesn't have a live renderer, so just skip running |
| 306 // the onbeforeunload handler. | 307 // the onbeforeunload handler. |
| 308 is_waiting_for_unload_ack_ = true; // Prevent check in OnMsgShouldCloseACK. | |
| 309 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition; | |
| 307 OnMsgShouldCloseACK(true); | 310 OnMsgShouldCloseACK(true); |
| 308 return; | 311 return; |
| 309 } | 312 } |
| 310 | 313 |
| 311 // This may be called more than once (if the user clicks the tab close button | 314 // This may be called more than once (if the user clicks the tab close button |
| 312 // several times, or if she clicks the tab close button then the browser close | 315 // several times, or if she clicks the tab close button then the browser close |
| 313 // button), so this test makes sure we only send the message once. | 316 // button), and we only send the message once. |
| 314 if (!is_waiting_for_unload_ack_) { | 317 if (is_waiting_for_unload_ack_) { |
| 318 // Some of our close messages could be for the tab, others for cross-site | |
| 319 // transitions. We always want to think it's for closing the tab if any | |
| 320 // of the messages were, since otherwise it might be impossible to close | |
| 321 // (if there was a cross-site "close" request pending when the user clicked | |
| 322 // the close button). We want to keep the "for cross site" flag only if | |
| 323 // both the old and the new ones are also for cross site. | |
| 324 unload_ack_is_for_cross_site_transition_ = | |
|
darin (slow to review)
2009/07/25 00:25:11
nit: could use &&= to shorten this up.
| |
| 325 unload_ack_is_for_cross_site_transition_ && for_cross_site_transition; | |
| 326 } else { | |
| 315 // Start the hang monitor in case the renderer hangs in the beforeunload | 327 // Start the hang monitor in case the renderer hangs in the beforeunload |
| 316 // handler. | 328 // handler. |
| 317 is_waiting_for_unload_ack_ = true; | 329 is_waiting_for_unload_ack_ = true; |
| 330 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition; | |
| 318 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); | 331 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); |
| 319 Send(new ViewMsg_ShouldClose(routing_id())); | 332 Send(new ViewMsg_ShouldClose(routing_id())); |
| 320 } | 333 } |
| 321 } | 334 } |
| 322 | 335 |
| 323 void RenderViewHost::ClosePage(bool for_cross_site_transition, | 336 void RenderViewHost::ClosePage(bool for_cross_site_transition, |
| 324 int new_render_process_host_id, | 337 int new_render_process_host_id, |
| 325 int new_request_id) { | 338 int new_request_id) { |
| 326 // Start the hang monitor in case the renderer hangs in the unload handler. | 339 // Start the hang monitor in case the renderer hangs in the unload handler. |
| 327 is_waiting_for_unload_ack_ = true; | 340 is_waiting_for_unload_ack_ = true; |
| (...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1432 save_delegate->OnReceivedSerializedHtmlData(frame_url, data, status); | 1445 save_delegate->OnReceivedSerializedHtmlData(frame_url, data, status); |
| 1433 } | 1446 } |
| 1434 | 1447 |
| 1435 void RenderViewHost::OnMsgShouldCloseACK(bool proceed) { | 1448 void RenderViewHost::OnMsgShouldCloseACK(bool proceed) { |
| 1436 StopHangMonitorTimeout(); | 1449 StopHangMonitorTimeout(); |
| 1437 DCHECK(is_waiting_for_unload_ack_); | 1450 DCHECK(is_waiting_for_unload_ack_); |
| 1438 is_waiting_for_unload_ack_ = false; | 1451 is_waiting_for_unload_ack_ = false; |
| 1439 | 1452 |
| 1440 RenderViewHostDelegate::RendererManagement* management_delegate = | 1453 RenderViewHostDelegate::RendererManagement* management_delegate = |
| 1441 delegate_->GetRendererManagementDelegate(); | 1454 delegate_->GetRendererManagementDelegate(); |
| 1442 if (management_delegate) | 1455 if (management_delegate) { |
| 1443 management_delegate->ShouldClosePage(proceed); | 1456 management_delegate->ShouldClosePage( |
| 1457 unload_ack_is_for_cross_site_transition_, proceed); | |
| 1458 } | |
| 1444 } | 1459 } |
| 1445 | 1460 |
| 1446 void RenderViewHost::OnQueryFormFieldAutofill(const std::wstring& field_name, | 1461 void RenderViewHost::OnQueryFormFieldAutofill(const std::wstring& field_name, |
| 1447 const std::wstring& user_text, | 1462 const std::wstring& user_text, |
| 1448 int64 node_id, | 1463 int64 node_id, |
| 1449 int request_id) { | 1464 int request_id) { |
| 1450 RenderViewHostDelegate::Autofill* autofill_delegate = | 1465 RenderViewHostDelegate::Autofill* autofill_delegate = |
| 1451 delegate_->GetAutofillDelegate(); | 1466 delegate_->GetAutofillDelegate(); |
| 1452 if (autofill_delegate) { | 1467 if (autofill_delegate) { |
| 1453 autofill_delegate->GetAutofillSuggestions(field_name, user_text, | 1468 autofill_delegate->GetAutofillSuggestions(field_name, user_text, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1576 | 1591 |
| 1577 void RenderViewHost::SignalModalDialogEvent() { | 1592 void RenderViewHost::SignalModalDialogEvent() { |
| 1578 if (modal_dialog_count_++ == 0) | 1593 if (modal_dialog_count_++ == 0) |
| 1579 modal_dialog_event_->Signal(); | 1594 modal_dialog_event_->Signal(); |
| 1580 } | 1595 } |
| 1581 | 1596 |
| 1582 void RenderViewHost::ResetModalDialogEvent() { | 1597 void RenderViewHost::ResetModalDialogEvent() { |
| 1583 if (--modal_dialog_count_ == 0) | 1598 if (--modal_dialog_count_ == 0) |
| 1584 modal_dialog_event_->Reset(); | 1599 modal_dialog_event_->Reset(); |
| 1585 } | 1600 } |
| OLD | NEW |