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

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: Add WasSwappedOut message for clean exit. Created 9 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
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 is_swapped_out_(false),
103 run_modal_reply_msg_(NULL), 104 run_modal_reply_msg_(NULL),
104 is_waiting_for_beforeunload_ack_(false), 105 is_waiting_for_beforeunload_ack_(false),
105 is_waiting_for_unload_ack_(false), 106 is_waiting_for_unload_ack_(false),
106 unload_ack_is_for_cross_site_transition_(false), 107 unload_ack_is_for_cross_site_transition_(false),
107 are_javascript_messages_suppressed_(false), 108 are_javascript_messages_suppressed_(false),
108 sudden_termination_allowed_(false), 109 sudden_termination_allowed_(false),
109 session_storage_namespace_(session_storage), 110 session_storage_namespace_(session_storage),
110 is_extension_process_(false), 111 is_extension_process_(false),
111 save_accessibility_tree_for_testing_(false), 112 save_accessibility_tree_for_testing_(false),
112 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING) { 113 render_view_termination_status_(base::TERMINATION_STATUS_STILL_RUNNING) {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 Navigate(params); 257 Navigate(params);
257 } 258 }
258 259
259 void RenderViewHost::SetNavigationsSuspended(bool suspend) { 260 void RenderViewHost::SetNavigationsSuspended(bool suspend) {
260 // This should only be called to toggle the state. 261 // This should only be called to toggle the state.
261 DCHECK(navigations_suspended_ != suspend); 262 DCHECK(navigations_suspended_ != suspend);
262 263
263 navigations_suspended_ = suspend; 264 navigations_suspended_ = suspend;
264 if (!suspend && suspended_nav_message_.get()) { 265 if (!suspend && suspended_nav_message_.get()) {
265 // There's a navigation message waiting to be sent. Now that we're not 266 // There's a navigation message waiting to be sent. Now that we're not
266 // suspended anymore, resume navigation by sending it. 267 // suspended anymore, resume navigation by sending it. If we were swapped
268 // out, we should also stop filtering out the IPC messages now.
269 is_swapped_out_ = false;
267 Send(suspended_nav_message_.release()); 270 Send(suspended_nav_message_.release());
268 } 271 }
269 } 272 }
270 273
274 void RenderViewHost::CancelSuspendedNavigations() {
275 // Clear any state if a pending navigation is canceled or pre-empted.
276 if (suspended_nav_message_.get())
277 suspended_nav_message_.reset();
278 navigations_suspended_ = false;
279 }
280
271 void RenderViewHost::FirePageBeforeUnload(bool for_cross_site_transition) { 281 void RenderViewHost::FirePageBeforeUnload(bool for_cross_site_transition) {
272 if (!IsRenderViewLive()) { 282 if (!IsRenderViewLive()) {
273 // This RenderViewHost doesn't have a live renderer, so just skip running 283 // This RenderViewHost doesn't have a live renderer, so just skip running
274 // the onbeforeunload handler. 284 // the onbeforeunload handler.
275 is_waiting_for_beforeunload_ack_ = true; // Checked by OnMsgShouldCloseACK. 285 is_waiting_for_beforeunload_ack_ = true; // Checked by OnMsgShouldCloseACK.
276 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition; 286 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition;
277 OnMsgShouldCloseACK(true); 287 OnMsgShouldCloseACK(true);
278 return; 288 return;
279 } 289 }
280 290
(...skipping 12 matching lines...) Expand all
293 } else { 303 } else {
294 // Start the hang monitor in case the renderer hangs in the beforeunload 304 // Start the hang monitor in case the renderer hangs in the beforeunload
295 // handler. 305 // handler.
296 is_waiting_for_beforeunload_ack_ = true; 306 is_waiting_for_beforeunload_ack_ = true;
297 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition; 307 unload_ack_is_for_cross_site_transition_ = for_cross_site_transition;
298 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 308 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
299 Send(new ViewMsg_ShouldClose(routing_id())); 309 Send(new ViewMsg_ShouldClose(routing_id()));
300 } 310 }
301 } 311 }
302 312
303 void RenderViewHost::ClosePage(bool for_cross_site_transition, 313 void RenderViewHost::SwapOut(int new_render_process_host_id,
304 int new_render_process_host_id, 314 int new_request_id) {
305 int new_request_id) { 315 // Start filtering IPC messages to avoid confusing the delegate. This will
306 // This will be set back to false in OnClosePageACK, just before we close the 316 // prevent any dialogs from appearing during unload handlers, but we've
307 // tab or replace it with a pending RVH. There are some cases (such as 204 317 // already decided to silence them in crbug.com/68780. We will set it back
308 // errors) where we'll continue to show this RVH. 318 // to false in SetNavigationsSuspended if we swap back in.
319 is_swapped_out_ = true;
320
321 // This will be set back to false in OnSwapOutACK, just before we replace
322 // this RVH with the pending RVH.
309 is_waiting_for_unload_ack_ = true; 323 is_waiting_for_unload_ack_ = true;
310 // Start the hang monitor in case the renderer hangs in the unload handler. 324 // Start the hang monitor in case the renderer hangs in the unload handler.
311 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS)); 325 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
312 326
313 ViewMsg_ClosePage_Params params; 327 ViewMsg_SwapOut_Params params;
314 params.closing_process_id = process()->id(); 328 params.closing_process_id = process()->id();
315 params.closing_route_id = routing_id(); 329 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; 330 params.new_render_process_host_id = new_render_process_host_id;
318 params.new_request_id = new_request_id; 331 params.new_request_id = new_request_id;
319 if (IsRenderViewLive()) { 332 if (IsRenderViewLive()) {
333 Send(new ViewMsg_SwapOut(routing_id(), params));
334 } else {
335 // This RenderViewHost doesn't have a live renderer, so just skip the unload
336 // event. We must notify the ResourceDispatcherHost on the IO thread,
337 // which we will do through the RenderProcessHost's widget helper.
338 process()->CrossSiteSwapOutACK(params);
339 }
340 }
341
342 void RenderViewHost::OnSwapOutACK() {
343 // Stop the hang monitor now that the unload handler has finished.
344 StopHangMonitorTimeout();
345 is_waiting_for_unload_ack_ = false;
346 }
347
348 void RenderViewHost::ClosePage() {
349 // Start the hang monitor in case the renderer hangs in the unload handler.
350 is_waiting_for_unload_ack_ = true;
351 StartHangMonitorTimeout(TimeDelta::FromMilliseconds(kUnloadTimeoutMS));
352
353 if (IsRenderViewLive()) {
354 // TODO(creis): Should this be moved to Shutdown? It may not be called for
355 // RenderViewHosts that have been swapped out.
320 NotificationService::current()->Notify( 356 NotificationService::current()->Notify(
321 NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW, 357 NotificationType::RENDER_VIEW_HOST_WILL_CLOSE_RENDER_VIEW,
322 Source<RenderViewHost>(this), 358 Source<RenderViewHost>(this),
323 NotificationService::NoDetails()); 359 NotificationService::NoDetails());
324 360
325 Send(new ViewMsg_ClosePage(routing_id(), params)); 361 Send(new ViewMsg_ClosePage(routing_id()));
326 } else { 362 } else {
327 // This RenderViewHost doesn't have a live renderer, so just skip closing 363 // 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, 364 // 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(); 365 ClosePageIgnoringUnloadEvents();
343 } 366 }
344 } 367 }
345 368
346 void RenderViewHost::ClosePageIgnoringUnloadEvents() { 369 void RenderViewHost::ClosePageIgnoringUnloadEvents() {
347 StopHangMonitorTimeout(); 370 StopHangMonitorTimeout();
348 is_waiting_for_beforeunload_ack_ = false; 371 is_waiting_for_beforeunload_ack_ = false;
349 is_waiting_for_unload_ack_ = false; 372 is_waiting_for_unload_ack_ = false;
350 373
351 sudden_termination_allowed_ = true; 374 sudden_termination_allowed_ = true;
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnMsgUpdateTargetURL) 769 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateTargetURL, OnMsgUpdateTargetURL)
747 IPC_MESSAGE_HANDLER(ViewHostMsg_Snapshot, OnMsgScreenshot) 770 IPC_MESSAGE_HANDLER(ViewHostMsg_Snapshot, OnMsgScreenshot)
748 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateInspectorSetting, 771 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateInspectorSetting,
749 OnUpdateInspectorSetting) 772 OnUpdateInspectorSetting)
750 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnMsgClose) 773 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnMsgClose)
751 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnMsgRequestMove) 774 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnMsgRequestMove)
752 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartLoading, OnMsgDidStartLoading) 775 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartLoading, OnMsgDidStartLoading)
753 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStopLoading, OnMsgDidStopLoading) 776 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStopLoading, OnMsgDidStopLoading)
754 IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeLoadProgress, 777 IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeLoadProgress,
755 OnMsgDidChangeLoadProgress) 778 OnMsgDidChangeLoadProgress)
779 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
780 OnMsgDidStartProvisionalLoadForFrame)
781 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
782 OnMsgDidRedirectProvisionalLoad)
783 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
784 OnMsgDidFailProvisionalLoadWithError)
785 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
786 OnMsgDidLoadResourceFromMemoryCache)
787 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
788 OnMsgDidDisplayInsecureContent)
789 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
790 OnMsgDidRunInsecureContent)
791 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
792 OnMsgDocumentLoadedInFrame)
793 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnMsgDidFinishLoad)
794 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
795 OnMsgUpdateContentRestrictions)
756 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentAvailableInMainFrame, 796 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentAvailableInMainFrame,
757 OnMsgDocumentAvailableInMainFrame) 797 OnMsgDocumentAvailableInMainFrame)
758 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentOnLoadCompletedInMainFrame, 798 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentOnLoadCompletedInMainFrame,
759 OnMsgDocumentOnLoadCompletedInMainFrame) 799 OnMsgDocumentOnLoadCompletedInMainFrame)
760 IPC_MESSAGE_HANDLER(ViewHostMsg_ContextMenu, OnMsgContextMenu) 800 IPC_MESSAGE_HANDLER(ViewHostMsg_ContextMenu, OnMsgContextMenu)
761 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenURL, OnMsgOpenURL) 801 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenURL, OnMsgOpenURL)
762 IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange, 802 IPC_MESSAGE_HANDLER(ViewHostMsg_DidContentsPreferredSizeChange,
763 OnMsgDidContentsPreferredSizeChange) 803 OnMsgDidContentsPreferredSizeChange)
764 IPC_MESSAGE_HANDLER(ViewHostMsg_DomOperationResponse, 804 IPC_MESSAGE_HANDLER(ViewHostMsg_DomOperationResponse,
765 OnMsgDomOperationResponse) 805 OnMsgDomOperationResponse)
766 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnMsgWebUISend) 806 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnMsgWebUISend)
767 IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardMessageToExternalHost, 807 IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardMessageToExternalHost,
768 OnMsgForwardMessageToExternalHost) 808 OnMsgForwardMessageToExternalHost)
769 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnMsgSetTooltipText) 809 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnMsgSetTooltipText)
770 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunJavaScriptMessage, 810 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunJavaScriptMessage,
771 OnMsgRunJavaScriptMessage) 811 OnMsgRunJavaScriptMessage)
772 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunBeforeUnloadConfirm, 812 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_RunBeforeUnloadConfirm,
773 OnMsgRunBeforeUnloadConfirm) 813 OnMsgRunBeforeUnloadConfirm)
774 IPC_MESSAGE_HANDLER(DragHostMsg_StartDragging, OnMsgStartDragging) 814 IPC_MESSAGE_HANDLER(DragHostMsg_StartDragging, OnMsgStartDragging)
775 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor) 815 IPC_MESSAGE_HANDLER(DragHostMsg_UpdateDragCursor, OnUpdateDragCursor)
776 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) 816 IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus)
777 IPC_MESSAGE_HANDLER(ViewHostMsg_AddMessageToConsole, OnAddMessageToConsole) 817 IPC_MESSAGE_HANDLER(ViewHostMsg_AddMessageToConsole, OnAddMessageToConsole)
778 IPC_MESSAGE_HANDLER(ViewHostMsg_ShouldClose_ACK, OnMsgShouldCloseACK) 818 IPC_MESSAGE_HANDLER(ViewHostMsg_ShouldClose_ACK, OnMsgShouldCloseACK)
819 IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK, OnMsgClosePageACK)
779 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnMsgSelectionChanged) 820 IPC_MESSAGE_HANDLER(ViewHostMsg_SelectionChanged, OnMsgSelectionChanged)
780 IPC_MESSAGE_HANDLER(ViewHostMsg_AccessibilityNotifications, 821 IPC_MESSAGE_HANDLER(ViewHostMsg_AccessibilityNotifications,
781 OnAccessibilityNotifications) 822 OnAccessibilityNotifications)
782 IPC_MESSAGE_HANDLER(ViewHostMsg_OnCSSInserted, OnCSSInserted) 823 IPC_MESSAGE_HANDLER(ViewHostMsg_OnCSSInserted, OnCSSInserted)
783 IPC_MESSAGE_HANDLER(ViewHostMsg_ContentBlocked, OnContentBlocked) 824 IPC_MESSAGE_HANDLER(ViewHostMsg_ContentBlocked, OnContentBlocked)
784 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) 825 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
785 IPC_MESSAGE_HANDLER(ViewHostMsg_WebDatabaseAccessed, OnWebDatabaseAccessed) 826 IPC_MESSAGE_HANDLER(ViewHostMsg_WebDatabaseAccessed, OnWebDatabaseAccessed)
786 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnMsgFocusedNodeChanged) 827 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnMsgFocusedNodeChanged)
787 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) 828 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
788 IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptEvalResponse, OnScriptEvalResponse) 829 IPC_MESSAGE_HANDLER(ViewHostMsg_ScriptEvalResponse, OnScriptEvalResponse)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 866 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
826 if (!view) 867 if (!view)
827 return; 868 return;
828 869
829 view->CreateNewWindow(route_id, params); 870 view->CreateNewWindow(route_id, params);
830 } 871 }
831 872
832 void RenderViewHost::CreateNewWidget(int route_id, 873 void RenderViewHost::CreateNewWidget(int route_id,
833 WebKit::WebPopupType popup_type) { 874 WebKit::WebPopupType popup_type) {
834 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 875 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
835 if (view) 876 if (view && !is_swapped_out_)
Matt Perry 2011/04/28 22:48:20 rather than adding these checks in every message h
Charlie Reis 2011/04/29 17:53:53 That's a great idea-- thanks. Now there's only a
836 view->CreateNewWidget(route_id, popup_type); 877 view->CreateNewWidget(route_id, popup_type);
837 } 878 }
838 879
839 void RenderViewHost::CreateNewFullscreenWidget(int route_id) { 880 void RenderViewHost::CreateNewFullscreenWidget(int route_id) {
840 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 881 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
841 if (view) 882 if (view && !is_swapped_out_)
842 view->CreateNewFullscreenWidget(route_id); 883 view->CreateNewFullscreenWidget(route_id);
843 } 884 }
844 885
845 void RenderViewHost::OnMsgShowView(int route_id, 886 void RenderViewHost::OnMsgShowView(int route_id,
846 WindowOpenDisposition disposition, 887 WindowOpenDisposition disposition,
847 const gfx::Rect& initial_pos, 888 const gfx::Rect& initial_pos,
848 bool user_gesture) { 889 bool user_gesture) {
849 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 890 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
850 if (view) { 891 if (view) {
851 view->ShowCreatedWindow(route_id, disposition, initial_pos, user_gesture); 892 if (!is_swapped_out_)
893 view->ShowCreatedWindow(route_id, disposition, initial_pos, user_gesture);
852 Send(new ViewMsg_Move_ACK(route_id)); 894 Send(new ViewMsg_Move_ACK(route_id));
853 } 895 }
854 } 896 }
855 897
856 void RenderViewHost::OnMsgShowWidget(int route_id, 898 void RenderViewHost::OnMsgShowWidget(int route_id,
857 const gfx::Rect& initial_pos) { 899 const gfx::Rect& initial_pos) {
858 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 900 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
859 if (view) { 901 if (view) {
860 view->ShowCreatedWidget(route_id, initial_pos); 902 if (!is_swapped_out_)
903 view->ShowCreatedWidget(route_id, initial_pos);
861 Send(new ViewMsg_Move_ACK(route_id)); 904 Send(new ViewMsg_Move_ACK(route_id));
862 } 905 }
863 } 906 }
864 907
865 void RenderViewHost::OnMsgShowFullscreenWidget(int route_id) { 908 void RenderViewHost::OnMsgShowFullscreenWidget(int route_id) {
866 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 909 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
867 if (view) { 910 if (view) {
868 view->ShowCreatedFullscreenWidget(route_id); 911 if (!is_swapped_out_)
912 view->ShowCreatedFullscreenWidget(route_id);
869 Send(new ViewMsg_Move_ACK(route_id)); 913 Send(new ViewMsg_Move_ACK(route_id));
870 } 914 }
871 } 915 }
872 916
873 void RenderViewHost::OnMsgRunModal(IPC::Message* reply_msg) { 917 void RenderViewHost::OnMsgRunModal(IPC::Message* reply_msg) {
874 DCHECK(!run_modal_reply_msg_); 918 DCHECK(!run_modal_reply_msg_);
875 run_modal_reply_msg_ = reply_msg; 919 run_modal_reply_msg_ = reply_msg;
876 920
877 // TODO(darin): Bug 1107929: Need to inform our delegate to show this view in 921 // TODO(darin): Bug 1107929: Need to inform our delegate to show this view in
878 // an app-modal fashion. 922 // an app-modal fashion.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 } 981 }
938 982
939 // If we're waiting for an unload ack from this renderer and we receive a 983 // If we're waiting for an unload ack from this renderer and we receive a
940 // Navigate message, then the renderer was navigating before it received the 984 // Navigate message, then the renderer was navigating before it received the
941 // unload request. It will either respond to the unload request soon or our 985 // unload request. It will either respond to the unload request soon or our
942 // timer will expire. Either way, we should ignore this message, because we 986 // timer will expire. Either way, we should ignore this message, because we
943 // have already committed to closing this renderer. 987 // have already committed to closing this renderer.
944 if (is_waiting_for_unload_ack_) 988 if (is_waiting_for_unload_ack_)
945 return; 989 return;
946 990
991 // If this RVH has been swapped out, ignore the navigation.
992 if (is_swapped_out_)
993 return;
994
947 const int renderer_id = process()->id(); 995 const int renderer_id = process()->id();
948 ChildProcessSecurityPolicy* policy = 996 ChildProcessSecurityPolicy* policy =
949 ChildProcessSecurityPolicy::GetInstance(); 997 ChildProcessSecurityPolicy::GetInstance();
950 // Without this check, an evil renderer can trick the browser into creating 998 // Without this check, an evil renderer can trick the browser into creating
951 // a navigation entry for a banned URL. If the user clicks the back button 999 // a navigation entry for a banned URL. If the user clicks the back button
952 // followed by the forward button (or clicks reload, or round-trips through 1000 // followed by the forward button (or clicks reload, or round-trips through
953 // session restore, etc), we'll think that the browser commanded the 1001 // session restore, etc), we'll think that the browser commanded the
954 // renderer to load the URL and grant the renderer the privileges to request 1002 // renderer to load the URL and grant the renderer the privileges to request
955 // the URL. To prevent this attack, we block the renderer from inserting 1003 // the URL. To prevent this attack, we block the renderer from inserting
956 // banned URLs into the navigation controller in the first place. 1004 // banned URLs into the navigation controller in the first place.
957 FilterURL(policy, renderer_id, &validated_params.url); 1005 FilterURL(policy, renderer_id, &validated_params.url);
958 FilterURL(policy, renderer_id, &validated_params.referrer); 1006 FilterURL(policy, renderer_id, &validated_params.referrer);
959 for (std::vector<GURL>::iterator it(validated_params.redirects.begin()); 1007 for (std::vector<GURL>::iterator it(validated_params.redirects.begin());
960 it != validated_params.redirects.end(); ++it) { 1008 it != validated_params.redirects.end(); ++it) {
961 FilterURL(policy, renderer_id, &(*it)); 1009 FilterURL(policy, renderer_id, &(*it));
962 } 1010 }
963 FilterURL(policy, renderer_id, &validated_params.searchable_form_url); 1011 FilterURL(policy, renderer_id, &validated_params.searchable_form_url);
964 FilterURL(policy, renderer_id, &validated_params.password_form.origin); 1012 FilterURL(policy, renderer_id, &validated_params.password_form.origin);
965 FilterURL(policy, renderer_id, &validated_params.password_form.action); 1013 FilterURL(policy, renderer_id, &validated_params.password_form.action);
966 1014
967 delegate_->DidNavigate(this, validated_params); 1015 delegate_->DidNavigate(this, validated_params);
968 } 1016 }
969 1017
970 void RenderViewHost::OnMsgUpdateState(int32 page_id, 1018 void RenderViewHost::OnMsgUpdateState(int32 page_id,
971 const std::string& state) { 1019 const std::string& state) {
1020 // We allow UpdateState messages even from swapped out renderers.
972 delegate_->UpdateState(this, page_id, state); 1021 delegate_->UpdateState(this, page_id, state);
973 } 1022 }
974 1023
975 void RenderViewHost::OnMsgUpdateTitle(int32 page_id, 1024 void RenderViewHost::OnMsgUpdateTitle(int32 page_id,
976 const std::wstring& title) { 1025 const std::wstring& title) {
1026 if (is_swapped_out_)
1027 return;
1028
977 if (title.length() > content::kMaxTitleChars) { 1029 if (title.length() > content::kMaxTitleChars) {
978 NOTREACHED() << "Renderer sent too many characters in title."; 1030 NOTREACHED() << "Renderer sent too many characters in title.";
979 return; 1031 return;
980 } 1032 }
981 delegate_->UpdateTitle(this, page_id, title); 1033 delegate_->UpdateTitle(this, page_id, title);
982 } 1034 }
983 1035
984 void RenderViewHost::OnMsgUpdateEncoding(const std::string& encoding_name) { 1036 void RenderViewHost::OnMsgUpdateEncoding(const std::string& encoding_name) {
985 delegate_->UpdateEncoding(this, encoding_name); 1037 if (!is_swapped_out_)
1038 delegate_->UpdateEncoding(this, encoding_name);
986 } 1039 }
987 1040
988 void RenderViewHost::OnMsgUpdateTargetURL(int32 page_id, 1041 void RenderViewHost::OnMsgUpdateTargetURL(int32 page_id,
989 const GURL& url) { 1042 const GURL& url) {
990 delegate_->UpdateTargetURL(page_id, url); 1043 if (!is_swapped_out_)
1044 delegate_->UpdateTargetURL(page_id, url);
991 1045
992 // Send a notification back to the renderer that we are ready to 1046 // Send a notification back to the renderer that we are ready to
993 // receive more target urls. 1047 // receive more target urls.
994 Send(new ViewMsg_UpdateTargetURL_ACK(routing_id())); 1048 Send(new ViewMsg_UpdateTargetURL_ACK(routing_id()));
995 } 1049 }
996 1050
997 void RenderViewHost::OnMsgScreenshot(const SkBitmap& bitmap) { 1051 void RenderViewHost::OnMsgScreenshot(const SkBitmap& bitmap) {
998 NotificationService::current()->Notify( 1052 NotificationService::current()->Notify(
999 NotificationType::TAB_SNAPSHOT_TAKEN, 1053 NotificationType::TAB_SNAPSHOT_TAKEN,
1000 Source<RenderViewHost>(this), 1054 Source<RenderViewHost>(this),
1001 Details<const SkBitmap>(&bitmap)); 1055 Details<const SkBitmap>(&bitmap));
1002 } 1056 }
1003 1057
1004 void RenderViewHost::OnUpdateInspectorSetting( 1058 void RenderViewHost::OnUpdateInspectorSetting(
1005 const std::string& key, const std::string& value) { 1059 const std::string& key, const std::string& value) {
1006 delegate_->UpdateInspectorSetting(key, value); 1060 if (!is_swapped_out_)
1061 delegate_->UpdateInspectorSetting(key, value);
1007 } 1062 }
1008 1063
1009 void RenderViewHost::OnMsgClose() { 1064 void RenderViewHost::OnMsgClose() {
1010 // If the renderer is telling us to close, it has already run the unload 1065 // If the renderer is telling us to close, it has already run the unload
1011 // events, and we can take the fast path. 1066 // events, and we can take the fast path. We allow this even from swapped
1067 // out renderers.
1012 ClosePageIgnoringUnloadEvents(); 1068 ClosePageIgnoringUnloadEvents();
1013 } 1069 }
1014 1070
1015 void RenderViewHost::OnMsgRequestMove(const gfx::Rect& pos) { 1071 void RenderViewHost::OnMsgRequestMove(const gfx::Rect& pos) {
1016 delegate_->RequestMove(pos); 1072 if (!is_swapped_out_)
1073 delegate_->RequestMove(pos);
1017 Send(new ViewMsg_Move_ACK(routing_id())); 1074 Send(new ViewMsg_Move_ACK(routing_id()));
1018 } 1075 }
1019 1076
1020 void RenderViewHost::OnMsgDidStartLoading() { 1077 void RenderViewHost::OnMsgDidStartLoading() {
1021 delegate_->DidStartLoading(); 1078 if (!is_swapped_out_)
1079 delegate_->DidStartLoading();
1022 } 1080 }
1023 1081
1024 void RenderViewHost::OnMsgDidStopLoading() { 1082 void RenderViewHost::OnMsgDidStopLoading() {
1025 delegate_->DidStopLoading(); 1083 if (!is_swapped_out_)
1084 delegate_->DidStopLoading();
1026 } 1085 }
1027 1086
1028 void RenderViewHost::OnMsgDidChangeLoadProgress(double load_progress) { 1087 void RenderViewHost::OnMsgDidChangeLoadProgress(double load_progress) {
1029 delegate_->DidChangeLoadProgress(load_progress); 1088 if (!is_swapped_out_)
1089 delegate_->DidChangeLoadProgress(load_progress);
1090 }
1091
1092 void RenderViewHost::OnMsgDidStartProvisionalLoadForFrame(int64 frame_id,
1093 bool is_main_frame,
1094 const GURL& url) {
1095 if (!is_swapped_out_)
1096 delegate_->DidStartProvisionalLoadForFrame(frame_id, is_main_frame, url);
1097 }
1098
1099 void RenderViewHost::OnMsgDidRedirectProvisionalLoad(int32 page_id,
1100 const GURL& source_url,
1101 const GURL& target_url) {
1102 if (!is_swapped_out_)
1103 delegate_->DidRedirectProvisionalLoad(page_id, source_url, target_url);
1104 }
1105
1106 void RenderViewHost::OnMsgDidFailProvisionalLoadWithError(
1107 int64 frame_id,
1108 bool is_main_frame,
1109 int error_code,
1110 const GURL& url,
1111 bool showing_repost_interstitial) {
1112 if (!is_swapped_out_) {
1113 delegate_->DidFailProvisionalLoadWithError(frame_id, is_main_frame,
1114 error_code, url,
1115 showing_repost_interstitial);
1116 }
1117 }
1118
1119 void RenderViewHost::OnMsgDidLoadResourceFromMemoryCache(
1120 const GURL& url,
1121 const std::string& security_info) {
1122 if (!is_swapped_out_)
1123 delegate_->DidLoadResourceFromMemoryCache(url, security_info);
1124 }
1125
1126 void RenderViewHost::OnMsgDidDisplayInsecureContent() {
1127 if (!is_swapped_out_)
1128 delegate_->DidDisplayInsecureContent();
1129 }
1130
1131 void RenderViewHost::OnMsgDidRunInsecureContent(
1132 const std::string& security_origin, const GURL& target_url) {
1133 if (!is_swapped_out_)
1134 delegate_->DidRunInsecureContent(security_origin, target_url);
1135 }
1136
1137 void RenderViewHost::OnMsgDocumentLoadedInFrame(int64 frame_id) {
1138 if (!is_swapped_out_)
1139 delegate_->DocumentLoadedInFrame(frame_id);
1140 }
1141
1142 void RenderViewHost::OnMsgDidFinishLoad(int64 frame_id) {
1143 if (!is_swapped_out_)
1144 delegate_->DidFinishLoad(frame_id);
1145 }
1146
1147 void RenderViewHost::OnMsgUpdateContentRestrictions(int restrictions) {
1148 if (!is_swapped_out_)
1149 delegate_->UpdateContentRestrictions(restrictions);
1030 } 1150 }
1031 1151
1032 void RenderViewHost::OnMsgDocumentAvailableInMainFrame() { 1152 void RenderViewHost::OnMsgDocumentAvailableInMainFrame() {
1033 delegate_->DocumentAvailableInMainFrame(this); 1153 if (!is_swapped_out_)
1154 delegate_->DocumentAvailableInMainFrame(this);
1034 } 1155 }
1035 1156
1036 void RenderViewHost::OnMsgDocumentOnLoadCompletedInMainFrame(int32 page_id) { 1157 void RenderViewHost::OnMsgDocumentOnLoadCompletedInMainFrame(int32 page_id) {
1037 delegate_->DocumentOnLoadCompletedInMainFrame(this, page_id); 1158 if (!is_swapped_out_)
1159 delegate_->DocumentOnLoadCompletedInMainFrame(this, page_id);
1038 } 1160 }
1039 1161
1040 void RenderViewHost::OnMsgContextMenu(const ContextMenuParams& params) { 1162 void RenderViewHost::OnMsgContextMenu(const ContextMenuParams& params) {
1041 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 1163 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1042 if (!view) 1164 if (!view || is_swapped_out_)
1043 return; 1165 return;
1044 1166
1045 // Validate the URLs in |params|. If the renderer can't request the URLs 1167 // Validate the URLs in |params|. If the renderer can't request the URLs
1046 // directly, don't show them in the context menu. 1168 // directly, don't show them in the context menu.
1047 ContextMenuParams validated_params(params); 1169 ContextMenuParams validated_params(params);
1048 int renderer_id = process()->id(); 1170 int renderer_id = process()->id();
1049 ChildProcessSecurityPolicy* policy = 1171 ChildProcessSecurityPolicy* policy =
1050 ChildProcessSecurityPolicy::GetInstance(); 1172 ChildProcessSecurityPolicy::GetInstance();
1051 1173
1052 // We don't validate |unfiltered_link_url| so that this field can be used 1174 // We don't validate |unfiltered_link_url| so that this field can be used
1053 // when users want to copy the original link URL. 1175 // when users want to copy the original link URL.
1054 FilterURL(policy, renderer_id, &validated_params.link_url); 1176 FilterURL(policy, renderer_id, &validated_params.link_url);
1055 FilterURL(policy, renderer_id, &validated_params.src_url); 1177 FilterURL(policy, renderer_id, &validated_params.src_url);
1056 FilterURL(policy, renderer_id, &validated_params.page_url); 1178 FilterURL(policy, renderer_id, &validated_params.page_url);
1057 FilterURL(policy, renderer_id, &validated_params.frame_url); 1179 FilterURL(policy, renderer_id, &validated_params.frame_url);
1058 1180
1059 view->ShowContextMenu(validated_params); 1181 view->ShowContextMenu(validated_params);
1060 } 1182 }
1061 1183
1062 void RenderViewHost::OnMsgOpenURL(const GURL& url, 1184 void RenderViewHost::OnMsgOpenURL(const GURL& url,
1063 const GURL& referrer, 1185 const GURL& referrer,
1064 WindowOpenDisposition disposition) { 1186 WindowOpenDisposition disposition) {
1187 if (is_swapped_out_)
1188 return;
1189
1065 GURL validated_url(url); 1190 GURL validated_url(url);
1066 FilterURL(ChildProcessSecurityPolicy::GetInstance(), 1191 FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1067 process()->id(), &validated_url); 1192 process()->id(), &validated_url);
1068 1193
1069 delegate_->RequestOpenURL(validated_url, referrer, disposition); 1194 delegate_->RequestOpenURL(validated_url, referrer, disposition);
1070 } 1195 }
1071 1196
1072 void RenderViewHost::OnMsgDidContentsPreferredSizeChange( 1197 void RenderViewHost::OnMsgDidContentsPreferredSizeChange(
1073 const gfx::Size& new_size) { 1198 const gfx::Size& new_size) {
1074 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 1199 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1075 if (!view) 1200 if (!view || is_swapped_out_)
1076 return; 1201 return;
1077 view->UpdatePreferredSize(new_size); 1202 view->UpdatePreferredSize(new_size);
1078 } 1203 }
1079 1204
1080 void RenderViewHost::OnMsgDomOperationResponse( 1205 void RenderViewHost::OnMsgDomOperationResponse(
1081 const std::string& json_string, int automation_id) { 1206 const std::string& json_string, int automation_id) {
1207 // We allow this even when swapped out.
1082 delegate_->DomOperationResponse(json_string, automation_id); 1208 delegate_->DomOperationResponse(json_string, automation_id);
1083 1209
1084 // We also fire a notification for more loosely-coupled use cases. 1210 // We also fire a notification for more loosely-coupled use cases.
1085 DomOperationNotificationDetails details(json_string, automation_id); 1211 DomOperationNotificationDetails details(json_string, automation_id);
1086 NotificationService::current()->Notify( 1212 NotificationService::current()->Notify(
1087 NotificationType::DOM_OPERATION_RESPONSE, Source<RenderViewHost>(this), 1213 NotificationType::DOM_OPERATION_RESPONSE, Source<RenderViewHost>(this),
1088 Details<DomOperationNotificationDetails>(&details)); 1214 Details<DomOperationNotificationDetails>(&details));
1089 } 1215 }
1090 1216
1091 void RenderViewHost::OnMsgWebUISend( 1217 void RenderViewHost::OnMsgWebUISend(
1092 const GURL& source_url, const std::string& message, 1218 const GURL& source_url, const std::string& message,
1093 const std::string& content) { 1219 const std::string& content) {
1094 if (!ChildProcessSecurityPolicy::GetInstance()-> 1220 if (!ChildProcessSecurityPolicy::GetInstance()->
1095 HasWebUIBindings(process()->id())) { 1221 HasWebUIBindings(process()->id())) {
1096 NOTREACHED() << "Blocked unauthorized use of WebUIBindings."; 1222 NOTREACHED() << "Blocked unauthorized use of WebUIBindings.";
1097 return; 1223 return;
1098 } 1224 }
1099 1225
1100 scoped_ptr<Value> value; 1226 scoped_ptr<Value> value;
1101 if (!content.empty()) { 1227 if (!content.empty()) {
1102 value.reset(base::JSONReader::Read(content, false)); 1228 value.reset(base::JSONReader::Read(content, false));
1103 if (!value.get() || !value->IsType(Value::TYPE_LIST)) { 1229 if (!value.get() || !value->IsType(Value::TYPE_LIST)) {
1104 // The page sent us something that we didn't understand. 1230 // The page sent us something that we didn't understand.
1105 // This probably indicates a programming error. 1231 // This probably indicates a programming error.
1106 NOTREACHED() << "Invalid JSON argument in OnMsgWebUISend."; 1232 NOTREACHED() << "Invalid JSON argument in OnMsgWebUISend.";
1107 return; 1233 return;
1108 } 1234 }
1109 } 1235 }
1110 1236
1237 if (is_swapped_out_)
1238 return;
1239
1111 ExtensionHostMsg_DomMessage_Params params; 1240 ExtensionHostMsg_DomMessage_Params params;
1112 params.name = message; 1241 params.name = message;
1113 if (value.get()) 1242 if (value.get())
1114 params.arguments.Swap(static_cast<ListValue*>(value.get())); 1243 params.arguments.Swap(static_cast<ListValue*>(value.get()));
1115 params.source_url = source_url; 1244 params.source_url = source_url;
1116 // WebUI doesn't use these values yet. 1245 // WebUI doesn't use these values yet.
1117 // TODO(aa): When WebUI is ported to ExtensionFunctionDispatcher, send real 1246 // TODO(aa): When WebUI is ported to ExtensionFunctionDispatcher, send real
1118 // values here. 1247 // values here.
1119 params.request_id = -1; 1248 params.request_id = -1;
1120 params.has_callback = false; 1249 params.has_callback = false;
1121 params.user_gesture = false; 1250 params.user_gesture = false;
1122 delegate_->ProcessWebUIMessage(params); 1251 delegate_->ProcessWebUIMessage(params);
1123 } 1252 }
1124 1253
1125 void RenderViewHost::OnMsgForwardMessageToExternalHost( 1254 void RenderViewHost::OnMsgForwardMessageToExternalHost(
1126 const std::string& message, const std::string& origin, 1255 const std::string& message, const std::string& origin,
1127 const std::string& target) { 1256 const std::string& target) {
1128 delegate_->ProcessExternalHostMessage(message, origin, target); 1257 if (!is_swapped_out_)
1258 delegate_->ProcessExternalHostMessage(message, origin, target);
1129 } 1259 }
1130 1260
1131 void RenderViewHost::DisassociateFromPopupCount() { 1261 void RenderViewHost::DisassociateFromPopupCount() {
1132 Send(new ViewMsg_DisassociateFromPopupCount(routing_id())); 1262 Send(new ViewMsg_DisassociateFromPopupCount(routing_id()));
1133 } 1263 }
1134 1264
1135 void RenderViewHost::OnMsgSetTooltipText( 1265 void RenderViewHost::OnMsgSetTooltipText(
1136 const std::wstring& tooltip_text, 1266 const std::wstring& tooltip_text,
1137 WebTextDirection text_direction_hint) { 1267 WebTextDirection text_direction_hint) {
1268 if (is_swapped_out_)
1269 return;
1270
1138 // First, add directionality marks around tooltip text if necessary. 1271 // First, add directionality marks around tooltip text if necessary.
1139 // A naive solution would be to simply always wrap the text. However, on 1272 // A naive solution would be to simply always wrap the text. However, on
1140 // windows, Unicode directional embedding characters can't be displayed on 1273 // windows, Unicode directional embedding characters can't be displayed on
1141 // systems that lack RTL fonts and are instead displayed as empty squares. 1274 // systems that lack RTL fonts and are instead displayed as empty squares.
1142 // 1275 //
1143 // To get around this we only wrap the string when we deem it necessary i.e. 1276 // To get around this we only wrap the string when we deem it necessary i.e.
1144 // when the locale direction is different than the tooltip direction hint. 1277 // when the locale direction is different than the tooltip direction hint.
1145 // 1278 //
1146 // Currently, we use element's directionality as the tooltip direction hint. 1279 // Currently, we use element's directionality as the tooltip direction hint.
1147 // An alternate solution would be to set the overall directionality based on 1280 // An alternate solution would be to set the overall directionality based on
(...skipping 10 matching lines...) Expand all
1158 !base::i18n::IsRTL()) { 1291 !base::i18n::IsRTL()) {
1159 // Force the tooltip to have RTL directionality. 1292 // Force the tooltip to have RTL directionality.
1160 base::i18n::WrapStringWithRTLFormatting(&wrapped_tooltip_text); 1293 base::i18n::WrapStringWithRTLFormatting(&wrapped_tooltip_text);
1161 } 1294 }
1162 } 1295 }
1163 if (view()) 1296 if (view())
1164 view()->SetTooltipText(UTF16ToWide(wrapped_tooltip_text)); 1297 view()->SetTooltipText(UTF16ToWide(wrapped_tooltip_text));
1165 } 1298 }
1166 1299
1167 void RenderViewHost::OnMsgSelectionChanged(const std::string& text) { 1300 void RenderViewHost::OnMsgSelectionChanged(const std::string& text) {
1168 if (view()) 1301 if (view() && !is_swapped_out_)
1169 view()->SelectionChanged(text); 1302 view()->SelectionChanged(text);
1170 } 1303 }
1171 1304
1172 void RenderViewHost::OnMsgRunJavaScriptMessage( 1305 void RenderViewHost::OnMsgRunJavaScriptMessage(
1173 const std::wstring& message, 1306 const std::wstring& message,
1174 const std::wstring& default_prompt, 1307 const std::wstring& default_prompt,
1175 const GURL& frame_url, 1308 const GURL& frame_url,
1176 const int flags, 1309 const int flags,
1177 IPC::Message* reply_msg) { 1310 IPC::Message* reply_msg) {
1178 // While a JS message dialog is showing, tabs in the same process shouldn't 1311 // While a JS message dialog is showing, tabs in the same process shouldn't
1179 // process input events. 1312 // process input events.
1180 process()->set_ignore_input_events(true); 1313 process()->set_ignore_input_events(true);
1181 StopHangMonitorTimeout(); 1314 StopHangMonitorTimeout();
1182 delegate_->RunJavaScriptMessage(message, default_prompt, frame_url, flags, 1315 delegate_->RunJavaScriptMessage(this, message, default_prompt, frame_url,
1183 reply_msg, 1316 flags, reply_msg,
1184 &are_javascript_messages_suppressed_); 1317 &are_javascript_messages_suppressed_);
1185 } 1318 }
1186 1319
1187 void RenderViewHost::OnMsgRunBeforeUnloadConfirm(const GURL& frame_url, 1320 void RenderViewHost::OnMsgRunBeforeUnloadConfirm(const GURL& frame_url,
1188 const std::wstring& message, 1321 const std::wstring& message,
1189 IPC::Message* reply_msg) { 1322 IPC::Message* reply_msg) {
1190 // While a JS before unload dialog is showing, tabs in the same process 1323 // While a JS before unload dialog is showing, tabs in the same process
1191 // shouldn't process input events. 1324 // shouldn't process input events.
1192 process()->set_ignore_input_events(true); 1325 process()->set_ignore_input_events(true);
1193 StopHangMonitorTimeout(); 1326 StopHangMonitorTimeout();
1194 delegate_->RunBeforeUnloadConfirm(message, reply_msg); 1327 delegate_->RunBeforeUnloadConfirm(this, message, reply_msg);
1195 } 1328 }
1196 1329
1197 void RenderViewHost::MediaPlayerActionAt(const gfx::Point& location, 1330 void RenderViewHost::MediaPlayerActionAt(const gfx::Point& location,
1198 const WebMediaPlayerAction& action) { 1331 const WebMediaPlayerAction& action) {
1199 // TODO(ajwong): Which thread should run this? Does it matter? 1332 // TODO(ajwong): Which thread should run this? Does it matter?
1200 Send(new ViewMsg_MediaPlayerActionAt(routing_id(), location, action)); 1333 Send(new ViewMsg_MediaPlayerActionAt(routing_id(), location, action));
1201 } 1334 }
1202 1335
1203 void RenderViewHost::ContextMenuClosed( 1336 void RenderViewHost::ContextMenuClosed(
1204 const webkit_glue::CustomContextMenuContext& custom_context) { 1337 const webkit_glue::CustomContextMenuContext& custom_context) {
1205 Send(new ViewMsg_ContextMenuClosed(routing_id(), custom_context)); 1338 Send(new ViewMsg_ContextMenuClosed(routing_id(), custom_context));
1206 } 1339 }
1207 1340
1208 void RenderViewHost::OnMsgStartDragging( 1341 void RenderViewHost::OnMsgStartDragging(
1209 const WebDropData& drop_data, 1342 const WebDropData& drop_data,
1210 WebDragOperationsMask drag_operations_mask, 1343 WebDragOperationsMask drag_operations_mask,
1211 const SkBitmap& image, 1344 const SkBitmap& image,
1212 const gfx::Point& image_offset) { 1345 const gfx::Point& image_offset) {
1213 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 1346 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1214 if (view) 1347 if (view && !is_swapped_out_)
1215 view->StartDragging(drop_data, drag_operations_mask, image, image_offset); 1348 view->StartDragging(drop_data, drag_operations_mask, image, image_offset);
1216 } 1349 }
1217 1350
1218 void RenderViewHost::OnUpdateDragCursor(WebDragOperation current_op) { 1351 void RenderViewHost::OnUpdateDragCursor(WebDragOperation current_op) {
1219 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 1352 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1220 if (view) 1353 if (view && !is_swapped_out_)
1221 view->UpdateDragCursor(current_op); 1354 view->UpdateDragCursor(current_op);
1222 } 1355 }
1223 1356
1224 void RenderViewHost::OnTakeFocus(bool reverse) { 1357 void RenderViewHost::OnTakeFocus(bool reverse) {
1225 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 1358 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1226 if (view) 1359 if (view && !is_swapped_out_)
1227 view->TakeFocus(reverse); 1360 view->TakeFocus(reverse);
1228 } 1361 }
1229 1362
1230 void RenderViewHost::OnAddMessageToConsole(int32 level, 1363 void RenderViewHost::OnAddMessageToConsole(int32 level,
1231 const std::wstring& message, 1364 const std::wstring& message,
1232 int32 line_no, 1365 int32 line_no,
1233 const std::wstring& source_id) { 1366 const std::wstring& source_id) {
1367 if (is_swapped_out_)
1368 return;
1369
1234 // Pass through log level only on WebUI pages to limit console spew. 1370 // Pass through log level only on WebUI pages to limit console spew.
1235 int32 resolved_level = 1371 int32 resolved_level =
1236 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ? level : 0; 1372 BindingsPolicy::is_web_ui_enabled(enabled_bindings_) ? level : 0;
1237 1373
1238 logging::LogMessage("CONSOLE", line_no, resolved_level).stream() << "\"" << 1374 logging::LogMessage("CONSOLE", line_no, resolved_level).stream() << "\"" <<
1239 message << "\", source: " << source_id << " (" << line_no << ")"; 1375 message << "\", source: " << source_id << " (" << line_no << ")";
1240 } 1376 }
1241 1377
1242 void RenderViewHost::AddObserver(RenderViewHostObserver* observer) { 1378 void RenderViewHost::AddObserver(RenderViewHostObserver* observer) {
1243 observers_.AddObserver(observer); 1379 observers_.AddObserver(observer);
(...skipping 10 matching lines...) Expand all
1254 } 1390 }
1255 1391
1256 void RenderViewHost::UnhandledKeyboardEvent( 1392 void RenderViewHost::UnhandledKeyboardEvent(
1257 const NativeWebKeyboardEvent& event) { 1393 const NativeWebKeyboardEvent& event) {
1258 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 1394 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1259 if (view) 1395 if (view)
1260 view->HandleKeyboardEvent(event); 1396 view->HandleKeyboardEvent(event);
1261 } 1397 }
1262 1398
1263 void RenderViewHost::OnUserGesture() { 1399 void RenderViewHost::OnUserGesture() {
1264 delegate_->OnUserGesture(); 1400 if (is_swapped_out_)
1401 delegate_->OnUserGesture();
1265 } 1402 }
1266 1403
1267 void RenderViewHost::GetAllSavableResourceLinksForCurrentPage( 1404 void RenderViewHost::GetAllSavableResourceLinksForCurrentPage(
1268 const GURL& page_url) { 1405 const GURL& page_url) {
1269 Send(new ViewMsg_GetAllSavableResourceLinksForCurrentPage(routing_id(), 1406 Send(new ViewMsg_GetAllSavableResourceLinksForCurrentPage(routing_id(),
1270 page_url)); 1407 page_url));
1271 } 1408 }
1272 1409
1273 void RenderViewHost::GetSerializedHtmlDataForCurrentPageWithLocalLinks( 1410 void RenderViewHost::GetSerializedHtmlDataForCurrentPageWithLocalLinks(
1274 const std::vector<GURL>& links, 1411 const std::vector<GURL>& links,
1275 const std::vector<FilePath>& local_paths, 1412 const std::vector<FilePath>& local_paths,
1276 const FilePath& local_directory_name) { 1413 const FilePath& local_directory_name) {
1277 Send(new ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks( 1414 Send(new ViewMsg_GetSerializedHtmlDataForCurrentPageWithLocalLinks(
1278 routing_id(), links, local_paths, local_directory_name)); 1415 routing_id(), links, local_paths, local_directory_name));
1279 } 1416 }
1280 1417
1281 void RenderViewHost::OnMsgShouldCloseACK(bool proceed) { 1418 void RenderViewHost::OnMsgShouldCloseACK(bool proceed) {
1282 StopHangMonitorTimeout(); 1419 StopHangMonitorTimeout();
1283 // If this renderer navigated while the beforeunload request was in flight, we 1420 // If this renderer navigated while the beforeunload request was in flight, we
1284 // may have cleared this state in OnMsgNavigate, in which case we can ignore 1421 // may have cleared this state in OnMsgNavigate, in which case we can ignore
1285 // this message. 1422 // this message.
1286 if (!is_waiting_for_beforeunload_ack_) 1423 if (!is_waiting_for_beforeunload_ack_ || is_swapped_out_)
1287 return; 1424 return;
1288 1425
1289 is_waiting_for_beforeunload_ack_ = false; 1426 is_waiting_for_beforeunload_ack_ = false;
1290 1427
1291 RenderViewHostDelegate::RendererManagement* management_delegate = 1428 RenderViewHostDelegate::RendererManagement* management_delegate =
1292 delegate_->GetRendererManagementDelegate(); 1429 delegate_->GetRendererManagementDelegate();
1293 if (management_delegate) { 1430 if (management_delegate) {
1294 management_delegate->ShouldClosePage( 1431 management_delegate->ShouldClosePage(
1295 unload_ack_is_for_cross_site_transition_, proceed); 1432 unload_ack_is_for_cross_site_transition_, proceed);
1296 } 1433 }
1297 } 1434 }
1298 1435
1436 void RenderViewHost::OnMsgClosePageACK() {
1437 // We allow this even while swapped out.
1438 ClosePageIgnoringUnloadEvents();
1439 }
1440
1299 void RenderViewHost::WindowMoveOrResizeStarted() { 1441 void RenderViewHost::WindowMoveOrResizeStarted() {
1300 Send(new ViewMsg_MoveOrResizeStarted(routing_id())); 1442 Send(new ViewMsg_MoveOrResizeStarted(routing_id()));
1301 } 1443 }
1302 1444
1303 void RenderViewHost::NotifyRendererUnresponsive() { 1445 void RenderViewHost::NotifyRendererUnresponsive() {
1304 delegate_->RendererUnresponsive( 1446 delegate_->RendererUnresponsive(
1305 this, is_waiting_for_beforeunload_ack_ || is_waiting_for_unload_ack_); 1447 this, is_waiting_for_beforeunload_ack_ || is_waiting_for_unload_ack_);
1306 } 1448 }
1307 1449
1308 void RenderViewHost::NotifyRendererResponsive() { 1450 void RenderViewHost::NotifyRendererResponsive() {
1309 delegate_->RendererResponsive(this); 1451 delegate_->RendererResponsive(this);
1310 } 1452 }
1311 1453
1312 void RenderViewHost::OnMsgFocusedNodeChanged(bool is_editable_node) { 1454 void RenderViewHost::OnMsgFocusedNodeChanged(bool is_editable_node) {
1313 delegate_->FocusedNodeChanged(is_editable_node); 1455 if (!is_swapped_out_)
1456 delegate_->FocusedNodeChanged(is_editable_node);
1314 } 1457 }
1315 1458
1316 void RenderViewHost::OnMsgFocus() { 1459 void RenderViewHost::OnMsgFocus() {
1317 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 1460 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1318 if (view) 1461 if (view && !is_swapped_out_)
1319 view->Activate(); 1462 view->Activate();
1320 } 1463 }
1321 1464
1322 void RenderViewHost::OnMsgBlur() { 1465 void RenderViewHost::OnMsgBlur() {
1323 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 1466 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1324 if (view) 1467 if (view && !is_swapped_out_)
1325 view->Deactivate(); 1468 view->Deactivate();
1326 } 1469 }
1327 1470
1328 void RenderViewHost::ForwardMouseEvent( 1471 void RenderViewHost::ForwardMouseEvent(
1329 const WebKit::WebMouseEvent& mouse_event) { 1472 const WebKit::WebMouseEvent& mouse_event) {
1330 1473
1331 // We make a copy of the mouse event because 1474 // We make a copy of the mouse event because
1332 // RenderWidgetHost::ForwardMouseEvent will delete |mouse_event|. 1475 // RenderWidgetHost::ForwardMouseEvent will delete |mouse_event|.
1333 WebKit::WebMouseEvent event_copy(mouse_event); 1476 WebKit::WebMouseEvent event_copy(mouse_event);
1334 RenderWidgetHost::ForwardMouseEvent(event_copy); 1477 RenderWidgetHost::ForwardMouseEvent(event_copy);
(...skipping 18 matching lines...) Expand all
1353 view->HandleMouseUp(); 1496 view->HandleMouseUp();
1354 default: 1497 default:
1355 // For now, we don't care about the rest. 1498 // For now, we don't care about the rest.
1356 break; 1499 break;
1357 } 1500 }
1358 } 1501 }
1359 } 1502 }
1360 1503
1361 void RenderViewHost::OnMouseActivate() { 1504 void RenderViewHost::OnMouseActivate() {
1362 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 1505 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1363 if (view) 1506 if (view && !is_swapped_out_)
1364 view->HandleMouseActivate(); 1507 view->HandleMouseActivate();
1365 } 1508 }
1366 1509
1367 void RenderViewHost::ForwardKeyboardEvent( 1510 void RenderViewHost::ForwardKeyboardEvent(
1368 const NativeWebKeyboardEvent& key_event) { 1511 const NativeWebKeyboardEvent& key_event) {
1369 if (ignore_input_events()) { 1512 if (ignore_input_events()) {
1370 if (key_event.type == WebInputEvent::RawKeyDown) 1513 if (key_event.type == WebInputEvent::RawKeyDown)
1371 delegate_->OnIgnoredUIEvent(); 1514 delegate_->OnIgnoredUIEvent();
1372 return; 1515 return;
1373 } 1516 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 *url = GURL(); 1614 *url = GURL();
1472 } 1615 }
1473 } 1616 }
1474 1617
1475 void RenderViewHost::JavaScriptStressTestControl(int cmd, int param) { 1618 void RenderViewHost::JavaScriptStressTestControl(int cmd, int param) {
1476 Send(new ViewMsg_JavaScriptStressTestControl(routing_id(), cmd, param)); 1619 Send(new ViewMsg_JavaScriptStressTestControl(routing_id(), cmd, param));
1477 } 1620 }
1478 1621
1479 void RenderViewHost::OnAccessibilityNotifications( 1622 void RenderViewHost::OnAccessibilityNotifications(
1480 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) { 1623 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) {
1481 if (view()) 1624 if (view() && !is_swapped_out_)
1482 view()->OnAccessibilityNotifications(params); 1625 view()->OnAccessibilityNotifications(params);
1483 1626
1484 if (!params.empty()) { 1627 if (!params.empty()) {
1485 for (unsigned i = 0; i < params.size(); i++) { 1628 for (unsigned i = 0; i < params.size(); i++) {
1486 const ViewHostMsg_AccessibilityNotification_Params& param = params[i]; 1629 const ViewHostMsg_AccessibilityNotification_Params& param = params[i];
1487 1630
1488 if (param.notification_type == 1631 if (param.notification_type ==
1489 ViewHostMsg_AccessibilityNotification_Type:: 1632 ViewHostMsg_AccessibilityNotification_Type::
1490 NOTIFICATION_TYPE_LOAD_COMPLETE) { 1633 NOTIFICATION_TYPE_LOAD_COMPLETE) {
1491 // TODO(ctguil): Remove when mac processes OnAccessibilityNotifications. 1634 // TODO(ctguil): Remove when mac processes OnAccessibilityNotifications.
1492 if (view()) 1635 if (view())
1493 view()->UpdateAccessibilityTree(param.acc_obj); 1636 view()->UpdateAccessibilityTree(param.acc_obj);
1494 1637
1495 if (save_accessibility_tree_for_testing_) 1638 if (save_accessibility_tree_for_testing_)
1496 accessibility_tree_ = param.acc_obj; 1639 accessibility_tree_ = param.acc_obj;
1497 } 1640 }
1498 } 1641 }
1499 1642
1500 NotificationService::current()->Notify( 1643 NotificationService::current()->Notify(
1501 NotificationType::RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED, 1644 NotificationType::RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED,
1502 Source<RenderViewHost>(this), 1645 Source<RenderViewHost>(this),
1503 NotificationService::NoDetails()); 1646 NotificationService::NoDetails());
1504 } 1647 }
1505 1648
1506 AccessibilityNotificationsAck(); 1649 AccessibilityNotificationsAck();
1507 } 1650 }
1508 1651
1509 void RenderViewHost::OnCSSInserted() { 1652 void RenderViewHost::OnCSSInserted() {
1510 delegate_->DidInsertCSS(); 1653 if (!is_swapped_out_)
1654 delegate_->DidInsertCSS();
1511 } 1655 }
1512 1656
1513 void RenderViewHost::OnContentBlocked(ContentSettingsType type, 1657 void RenderViewHost::OnContentBlocked(ContentSettingsType type,
1514 const std::string& resource_identifier) { 1658 const std::string& resource_identifier) {
1515 RenderViewHostDelegate::ContentSettings* content_settings_delegate = 1659 RenderViewHostDelegate::ContentSettings* content_settings_delegate =
1516 delegate_->GetContentSettingsDelegate(); 1660 delegate_->GetContentSettingsDelegate();
1517 if (content_settings_delegate) 1661 if (content_settings_delegate && !is_swapped_out_)
1518 content_settings_delegate->OnContentBlocked(type, resource_identifier); 1662 content_settings_delegate->OnContentBlocked(type, resource_identifier);
1519 } 1663 }
1520 1664
1521 void RenderViewHost::OnAppCacheAccessed(const GURL& manifest_url, 1665 void RenderViewHost::OnAppCacheAccessed(const GURL& manifest_url,
1522 bool blocked_by_policy) { 1666 bool blocked_by_policy) {
1523 RenderViewHostDelegate::ContentSettings* content_settings_delegate = 1667 RenderViewHostDelegate::ContentSettings* content_settings_delegate =
1524 delegate_->GetContentSettingsDelegate(); 1668 delegate_->GetContentSettingsDelegate();
1525 if (content_settings_delegate) 1669 if (content_settings_delegate && !is_swapped_out_)
1526 content_settings_delegate->OnAppCacheAccessed(manifest_url, 1670 content_settings_delegate->OnAppCacheAccessed(manifest_url,
1527 blocked_by_policy); 1671 blocked_by_policy);
1528 } 1672 }
1529 1673
1530 void RenderViewHost::OnWebDatabaseAccessed(const GURL& url, 1674 void RenderViewHost::OnWebDatabaseAccessed(const GURL& url,
1531 const string16& name, 1675 const string16& name,
1532 const string16& display_name, 1676 const string16& display_name,
1533 unsigned long estimated_size, 1677 unsigned long estimated_size,
1534 bool blocked_by_policy) { 1678 bool blocked_by_policy) {
1535 RenderViewHostDelegate::ContentSettings* content_settings_delegate = 1679 RenderViewHostDelegate::ContentSettings* content_settings_delegate =
1536 delegate_->GetContentSettingsDelegate(); 1680 delegate_->GetContentSettingsDelegate();
1537 if (content_settings_delegate) 1681 if (content_settings_delegate && !is_swapped_out_)
1538 content_settings_delegate->OnWebDatabaseAccessed( 1682 content_settings_delegate->OnWebDatabaseAccessed(
1539 url, name, display_name, estimated_size, blocked_by_policy); 1683 url, name, display_name, estimated_size, blocked_by_policy);
1540 } 1684 }
1541 1685
1542 void RenderViewHost::OnUpdateZoomLimits(int minimum_percent, 1686 void RenderViewHost::OnUpdateZoomLimits(int minimum_percent,
1543 int maximum_percent, 1687 int maximum_percent,
1544 bool remember) { 1688 bool remember) {
1545 delegate_->UpdateZoomLimits(minimum_percent, maximum_percent, remember); 1689 if (!is_swapped_out_)
1690 delegate_->UpdateZoomLimits(minimum_percent, maximum_percent, remember);
1546 } 1691 }
1547 1692
1548 void RenderViewHost::OnScriptEvalResponse(int id, const ListValue& result) { 1693 void RenderViewHost::OnScriptEvalResponse(int id, const ListValue& result) {
1549 Value* result_value; 1694 Value* result_value;
1550 if (!result.Get(0, &result_value)) { 1695 if (!result.Get(0, &result_value)) {
1551 // Programming error or rogue renderer. 1696 // Programming error or rogue renderer.
1552 NOTREACHED() << "Got bad arguments for OnScriptEvalResponse"; 1697 NOTREACHED() << "Got bad arguments for OnScriptEvalResponse";
1553 return; 1698 return;
1554 } 1699 }
1700 if (is_swapped_out_)
1701 return;
1702
1555 std::pair<int, Value*> details(id, result_value); 1703 std::pair<int, Value*> details(id, result_value);
1556 NotificationService::current()->Notify( 1704 NotificationService::current()->Notify(
1557 NotificationType::EXECUTE_JAVASCRIPT_RESULT, 1705 NotificationType::EXECUTE_JAVASCRIPT_RESULT,
1558 Source<RenderViewHost>(this), 1706 Source<RenderViewHost>(this),
1559 Details<std::pair<int, Value*> >(&details)); 1707 Details<std::pair<int, Value*> >(&details));
1560 } 1708 }
1561 1709
1562 #if defined(OS_MACOSX) 1710 #if defined(OS_MACOSX)
1563 void RenderViewHost::OnMsgShowPopup( 1711 void RenderViewHost::OnMsgShowPopup(
1564 const ViewHostMsg_ShowPopup_Params& params) { 1712 const ViewHostMsg_ShowPopup_Params& params) {
1565 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate(); 1713 RenderViewHostDelegate::View* view = delegate_->GetViewDelegate();
1566 if (view) { 1714 if (view && !is_swapped_out_) {
1567 view->ShowPopupMenu(params.bounds, 1715 view->ShowPopupMenu(params.bounds,
1568 params.item_height, 1716 params.item_height,
1569 params.item_font_size, 1717 params.item_font_size,
1570 params.selected_item, 1718 params.selected_item,
1571 params.popup_items, 1719 params.popup_items,
1572 params.right_aligned); 1720 params.right_aligned);
1573 } 1721 }
1574 } 1722 }
1575 #endif 1723 #endif
1576 1724
(...skipping 11 matching lines...) Expand all
1588 LOG(DFATAL) << "Invalid checked state " << checked_state; 1736 LOG(DFATAL) << "Invalid checked state " << checked_state;
1589 return; 1737 return;
1590 } 1738 }
1591 1739
1592 CommandState state; 1740 CommandState state;
1593 state.is_enabled = is_enabled; 1741 state.is_enabled = is_enabled;
1594 state.checked_state = 1742 state.checked_state =
1595 static_cast<RenderViewCommandCheckedState>(checked_state); 1743 static_cast<RenderViewCommandCheckedState>(checked_state);
1596 command_states_[static_cast<RenderViewCommand>(command)] = state; 1744 command_states_[static_cast<RenderViewCommand>(command)] = state;
1597 } 1745 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698