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

Side by Side Diff: content/browser/renderer_host/render_view_host.cc

Issue 6319001: Support window.opener after a process swap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comments. Created 9 years, 8 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/renderer_host/render_view_host.h" 5 #include "content/browser/renderer_host/render_view_host.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 RenderViewHost::RenderViewHost(SiteInstance* instance, 91 RenderViewHost::RenderViewHost(SiteInstance* instance,
92 RenderViewHostDelegate* delegate, 92 RenderViewHostDelegate* delegate,
93 int routing_id, 93 int routing_id,
94 SessionStorageNamespace* session_storage) 94 SessionStorageNamespace* session_storage)
95 : RenderWidgetHost(instance->GetProcess(), routing_id), 95 : RenderWidgetHost(instance->GetProcess(), routing_id),
96 instance_(instance), 96 instance_(instance),
97 delegate_(delegate), 97 delegate_(delegate),
98 waiting_for_drag_context_response_(false), 98 waiting_for_drag_context_response_(false),
99 enabled_bindings_(0), 99 enabled_bindings_(0),
100 pending_request_id_(0), 100 pending_request_id_(-1),
101 navigations_suspended_(false), 101 navigations_suspended_(false),
102 suspended_nav_message_(NULL), 102 suspended_nav_message_(NULL),
103 run_modal_reply_msg_(NULL), 103 run_modal_reply_msg_(NULL),
104 is_waiting_for_beforeunload_ack_(false), 104 is_waiting_for_beforeunload_ack_(false),
105 is_waiting_for_unload_ack_(false), 105 is_waiting_for_unload_ack_(false),
106 unload_ack_is_for_cross_site_transition_(false), 106 unload_ack_is_for_cross_site_transition_(false),
107 are_javascript_messages_suppressed_(false), 107 are_javascript_messages_suppressed_(false),
108 sudden_termination_allowed_(false), 108 sudden_termination_allowed_(false),
109 session_storage_namespace_(session_storage), 109 session_storage_namespace_(session_storage),
110 is_extension_process_(false), 110 is_extension_process_(false),
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } else { 293 } else {
294 // Start the hang monitor in case the renderer hangs in the beforeunload 294 // Start the hang monitor in case the renderer hangs in the beforeunload
295 // handler. 295 // handler.
296 is_waiting_for_beforeunload_ack_ = true; 296 is_waiting_for_beforeunload_ack_ = true;
297 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition; 297 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition;
298 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 298 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
299 Send(new ViewMsg_ShouldClose(routing_id())); 299 Send(new ViewMsg_ShouldClose(routing_id()));
300 } 300 }
301 } 301 }
302 302
303 void RenderViewHost::ClosePage(bool for_cross_site_transition, 303 void RenderViewHost::SwapOut(int new_render_process_host_id,
304 int new_render_process_host_id, 304 int new_request_id) {
305 int new_request_id) { 305 // This will be set back to false in OnSwapOutACK, just before we replace
306 // This will be set back to false in OnClosePageACK, just before we close the 306 // this RVH with the pending RVH. Note there are some cases (such as 204
307 // tab or replace it with a pending RVH. There are some cases (such as 204 307 // responses) where we'll continue to show this RVH.
308 // errors) where we'll continue to show this RVH.
309 is_waiting_for_unload_ack_ = true; 308 is_waiting_for_unload_ack_ = true;
310 // Start the hang monitor in case the renderer hangs in the unload handler. 309 // Start the hang monitor in case the renderer hangs in the unload handler.
311 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 310 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
312 311
313 ViewMsg_ClosePage_Params params; 312 ViewMsg_SwapOut_Params params;
314 params.closing_process_id = process()->id(); 313 params.closing_process_id = process()->id();
315 params.closing_route_id = routing_id(); 314 params.closing_route_id = routing_id();
316 params.for_cross_site_transition = for_cross_site_transition;
317 params.new_render_process_host_id = new_render_process_host_id; 315 params.new_render_process_host_id = new_render_process_host_id;
318 params.new_request_id = new_request_id; 316 params.new_request_id = new_request_id;
319 if (IsRenderViewLive()) { 317 if (IsRenderViewLive()) {
318 Send(new ViewMsg_SwapOut(routing_id(), params));
319 } else {
320 // This RenderViewHost doesn't have a live renderer, so just skip the unload
321 // event. We must notify the ResourceDispatcherHost on the IO thread,
322 // which we will do through the RenderProcessHost's widget helper.
323 process()->CrossSiteSwapOutACK(params);
324 }
325 }
326
327 void RenderViewHost::OnSwapOutACK() {
328 // Stop the hang monitor now that the unload handler has finished.
329 StopHangMonitorTimeout();
330 is_waiting_for_unload_ack_ = false;
331 }
332
333 void RenderViewHost::ClosePage() {
334 // Start the hang monitor in case the renderer hangs in the unload handler.
335 is_waiting_for_unload_ack_ = true;
336 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
337
338 if (IsRenderViewLive()) {
339 // TODO(creis): Should this be moved to Shutdown? It may not be called for
340 // RenderViewHosts that have been swapped out.
320 NotificationService::current()->Notify( 341 NotificationService::current()->Notify(
321 NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, 342 NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
322 Source<RenderViewHost>(this), 343 Source<RenderViewHost>(this),
323 NotificationService::NoDetails()); 344 NotificationService::NoDetails());
324 345
325 Send(new ViewMsg_ClosePage(routing_id(), params)); 346 Send(new ViewMsg_ClosePage(routing_id()));
326 } else { 347 } else {
327 // This RenderViewHost doesn't have a live renderer, so just skip closing 348 // This RenderViewHost doesn't have a live renderer, so just skip the unload
328 // the page. We must notify the ResourceDispatcherHost on the IO thread, 349 // event and close the page.
329 // which we will do through the RenderProcessHost's widget helper.
330 process()->CrossSiteClosePageACK(params);
331 }
332 }
333
334 void RenderViewHost::OnClosePageACK(bool for_cross_site_transition) {
335 StopHangMonitorTimeout();
336 is_waiting_for_unload_ack_ = false;
337
338 // If this ClosePageACK is not for a cross-site transition, then it is for an
339 // attempt to close the tab. We have now finished the unload handler and can
340 // proceed with closing the tab.
341 if (!for_cross_site_transition) {
342 ClosePageIgnoringUnloadEvents(); 350 ClosePageIgnoringUnloadEvents();
343 } 351 }
344 } 352 }
345 353
346 void RenderViewHost::ClosePageIgnoringUnloadEvents() { 354 void RenderViewHost::ClosePageIgnoringUnloadEvents() {
347 StopHangMonitorTimeout(); 355 StopHangMonitorTimeout();
348 is_waiting_for_beforeunload_ack_ = false; 356 is_waiting_for_beforeunload_ack_ = false;
349 is_waiting_for_unload_ack_ = false; 357 is_waiting_for_unload_ack_ = false;
350 358
351 sudden_termination_allowed_ = true; 359 sudden_termination_allowed_ = true;
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnMsgSetTooltipText) 781 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnMsgSetTooltipText)
774 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunJavaScriptMessage, 782 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunJavaScriptMessage,
775 OnMsgRunJavaScriptMessage) 783 OnMsgRunJavaScriptMessage)
776 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunBeforeUnloadConfirm, 784 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunBeforeUnloadConfirm,
777 OnMsgRunBeforeUnloadConfirm) 785 OnMsgRunBeforeUnloadConfirm)
778 IPC_MESSAGE_HANDLER(DragHostMsg_StartDragging, OnMsgStartDragging) 786 IPC_MESSAGE_HANDLER(DragHostMsg_StartDragging, OnMsgStartDragging)
779 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) 787 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor)
780 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) 788 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus)
781 IPC_MESSAGE_HANDLER(ViewHostMsg_AddMessageToConsole, OnAddMessageToConsole) 789 IPC_MESSAGE_HANDLER(ViewHostMsg_AddMessageToConsole, OnAddMessageToConsole)
782 IPC_MESSAGE_HANDLER(ViewHostMsg_ShouldClose_ACK, OnMsgShouldCloseACK) 790 IPC_MESSAGE_HANDLER(ViewHostMsg_ShouldClose_ACK, OnMsgShouldCloseACK)
791 IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK, OnMsgClosePageACK)
783 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnMsgSelectionChanged) 792 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnMsgSelectionChanged)
784 IPC_MESSAGE_HANDLER(ViewHostMsg_AccessibilityNotifications, 793 IPC_MESSAGE_HANDLER(ViewHostMsg_AccessibilityNotifications,
785 OnAccessibilityNotifications) 794 OnAccessibilityNotifications)
786 IPC_MESSAGE_HANDLER(ViewHostMsg_OnCSSInserted, OnCSSInserted) 795 IPC_MESSAGE_HANDLER(ViewHostMsg_OnCSSInserted, OnCSSInserted)
787 IPC_MESSAGE_HANDLER(ViewHostMsg_ContentBlocked, OnContentBlocked) 796 IPC_MESSAGE_HANDLER(ViewHostMsg_ContentBlocked, OnContentBlocked)
788 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) 797 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
789 IPC_MESSAGE_HANDLER(ViewHostMsg_WebDatabaseAccessed, OnWebDatabaseAccessed) 798 IPC_MESSAGE_HANDLER(ViewHostMsg_WebDatabaseAccessed, OnWebDatabaseAccessed)
790 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnMsgFocusedNodeChanged) 799 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnMsgFocusedNodeChanged)
791 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) 800 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
792 IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptEvalResponse, OnScriptEvalResponse) 801 IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptEvalResponse, OnScriptEvalResponse)
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 is_waiting_for_beforeunload_ack_ = false; 1306 is_waiting_for_beforeunload_ack_ = false;
1298 1307
1299 RenderViewHostDelegate::RendererManagement* management_delegate = 1308 RenderViewHostDelegate::RendererManagement* management_delegate =
1300 delegate_->GetRendererManagementDelegate(); 1309 delegate_->GetRendererManagementDelegate();
1301 if (management_delegate) { 1310 if (management_delegate) {
1302 management_delegate->ShouldClosePage( 1311 management_delegate->ShouldClosePage(
1303 unload_ack_is_for_cross_site_transition_, proceed); 1312 unload_ack_is_for_cross_site_transition_, proceed);
1304 } 1313 }
1305 } 1314 }
1306 1315
1316 void RenderViewHost::OnMsgClosePageACK() {
1317 ClosePageIgnoringUnloadEvents();
1318 }
1319
1307 void RenderViewHost::WindowMoveOrResizeStarted() { 1320 void RenderViewHost::WindowMoveOrResizeStarted() {
1308 Send(new ViewMsg_MoveOrResizeStarted(routing_id())); 1321 Send(new ViewMsg_MoveOrResizeStarted(routing_id()));
1309 } 1322 }
1310 1323
1311 void RenderViewHost::NotifyRendererUnresponsive() { 1324 void RenderViewHost::NotifyRendererUnresponsive() {
1312 delegate_->RendererUnresponsive( 1325 delegate_->RendererUnresponsive(
1313 this, is_waiting_for_beforeunload_ack_ || is_waiting_for_unload_ack_); 1326 this, is_waiting_for_beforeunload_ack_ || is_waiting_for_unload_ack_);
1314 } 1327 }
1315 1328
1316 void RenderViewHost::NotifyRendererResponsive() { 1329 void RenderViewHost::NotifyRendererResponsive() {
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 LOG(DFATAL) << "Invalid checked state " << checked_state; 1609 LOG(DFATAL) << "Invalid checked state " << checked_state;
1597 return; 1610 return;
1598 } 1611 }
1599 1612
1600 CommandState state; 1613 CommandState state;
1601 state.is_enabled = is_enabled; 1614 state.is_enabled = is_enabled;
1602 state.checked_state = 1615 state.checked_state =
1603 static_cast<RenderViewCommandCheckedState>(checked_state); 1616 static_cast<RenderViewCommandCheckedState>(checked_state);
1604 command_states_[static_cast<RenderViewCommand>(command)] = state; 1617 command_states_[static_cast<RenderViewCommand>(command)] = state;
1605 } 1618 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698