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

Side by Side Diff: content/browser/renderer_host/render_view_host_impl.h

Issue 180993003: Revert "Revert 249676 "Have the unload event execute in background on cr..."" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed an error in the swap out logic Created 6 years, 10 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
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 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h"
12 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/process/kill.h" 16 #include "base/process/kill.h"
16 #include "content/browser/renderer_host/render_widget_host_impl.h" 17 #include "content/browser/renderer_host/render_widget_host_impl.h"
17 #include "content/browser/site_instance_impl.h" 18 #include "content/browser/site_instance_impl.h"
18 #include "content/common/drag_event_source_info.h" 19 #include "content/common/drag_event_source_info.h"
19 #include "content/public/browser/notification_observer.h" 20 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
21 #include "content/public/common/javascript_message_type.h" 22 #include "content/public/common/javascript_message_type.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 namespace content { 59 namespace content {
59 60
60 class BrowserMediaPlayerManager; 61 class BrowserMediaPlayerManager;
61 class ChildProcessSecurityPolicyImpl; 62 class ChildProcessSecurityPolicyImpl;
62 class CrossSiteTransferringRequest; 63 class CrossSiteTransferringRequest;
63 class PageState; 64 class PageState;
64 class RenderWidgetHostDelegate; 65 class RenderWidgetHostDelegate;
65 class SessionStorageNamespace; 66 class SessionStorageNamespace;
66 class SessionStorageNamespaceImpl; 67 class SessionStorageNamespaceImpl;
67 class TestRenderViewHost; 68 class TestRenderViewHost;
69 class TimeoutMonitor;
68 struct FileChooserParams; 70 struct FileChooserParams;
69 struct Referrer; 71 struct Referrer;
70 struct ShowDesktopNotificationHostMsgParams; 72 struct ShowDesktopNotificationHostMsgParams;
71 73
72 #if defined(COMPILER_MSVC) 74 #if defined(COMPILER_MSVC)
73 // RenderViewHostImpl is the bottom of a diamond-shaped hierarchy, 75 // RenderViewHostImpl is the bottom of a diamond-shaped hierarchy,
74 // with RenderWidgetHost at the root. VS warns when methods from the 76 // with RenderWidgetHost at the root. VS warns when methods from the
75 // root are overridden in only one of the base classes and not both 77 // root are overridden in only one of the base classes and not both
76 // (in this case, RenderWidgetHostImpl provides implementations of 78 // (in this case, RenderWidgetHostImpl provides implementations of
77 // many of the methods). This is a silly warning when dealing with 79 // many of the methods). This is a silly warning when dealing with
(...skipping 14 matching lines...) Expand all
92 // 94 //
93 // Right now, the concept of page navigation (both top level and frame) exists 95 // Right now, the concept of page navigation (both top level and frame) exists
94 // in the WebContentsImpl still, so if you instantiate one of these elsewhere, 96 // in the WebContentsImpl still, so if you instantiate one of these elsewhere,
95 // you will not be able to traverse pages back and forward. We need to determine 97 // you will not be able to traverse pages back and forward. We need to determine
96 // if we want to bring that and other functionality down into this object so it 98 // if we want to bring that and other functionality down into this object so it
97 // can be shared by others. 99 // can be shared by others.
98 class CONTENT_EXPORT RenderViewHostImpl 100 class CONTENT_EXPORT RenderViewHostImpl
99 : public RenderViewHost, 101 : public RenderViewHost,
100 public RenderWidgetHostImpl { 102 public RenderWidgetHostImpl {
101 public: 103 public:
104 // Keeps track of the state of the RenderViewHostImpl, particularly with
105 // respect to swap out.
106 enum RenderViewHostImplState {
107 // The standard state for a RVH handling the communication with a
108 // RenderView.
109 STATE_DEFAULT = 0,
110 // The RVH has sent the SwapOut request to the renderer, but has not
111 // received the SwapOutACK yet. The new page has not been committed yet
112 // either.
113 STATE_WAITING_FOR_UNLOAD_ACK,
114 // The RVH received the SwapOutACK from the RenderView, but the new page has
115 // not been committed yet.
116 STATE_WAITING_FOR_COMMIT,
117 // The RVH is waiting for the CloseACK from the RenderView.
118 STATE_WAITING_FOR_CLOSE,
119 // The RVH has not received the SwapOutACK yet, but the new page has
120 // committed in a different RVH. The number of active views of the RVH
121 // SiteInstanceImpl is not zero. Upon reception of the SwapOutACK, the RVH
122 // will be swapped out.
123 STATE_PENDING_SWAP_OUT,
124 // The RVH has not received the SwapOutACK yet, but the new page has
125 // committed in a different RVH. The number of active views of the RVH
126 // SiteInstanceImpl is zero. Upon reception of the SwapOutACK, the RVH will
127 // be shutdown.
128 STATE_PENDING_SHUTDOWN,
129 // The RVH is swapped out, and it is being used as a placeholder to allow
130 // for cross-process communication.
131 STATE_SWAPPED_OUT,
132 };
133 // Helper function to determine whether the RVH state should contribute to the
134 // number of active views of a SiteInstance or not.
135 static bool IsRVHStateActive(RenderViewHostImplState rvh_state);
136
102 // Convenience function, just like RenderViewHost::FromID. 137 // Convenience function, just like RenderViewHost::FromID.
103 static RenderViewHostImpl* FromID(int render_process_id, int render_view_id); 138 static RenderViewHostImpl* FromID(int render_process_id, int render_view_id);
104 139
105 // |routing_id| could be a valid route id, or it could be MSG_ROUTING_NONE, in 140 // |routing_id| could be a valid route id, or it could be MSG_ROUTING_NONE, in
106 // which case RenderWidgetHost will create a new one. |swapped_out| indicates 141 // which case RenderWidgetHost will create a new one. |swapped_out| indicates
107 // whether the view should initially be swapped out (e.g., for an opener 142 // whether the view should initially be swapped out (e.g., for an opener
108 // frame being rendered by another process). |hidden| indicates whether the 143 // frame being rendered by another process). |hidden| indicates whether the
109 // view is initially hidden or visible. 144 // view is initially hidden or visible.
110 // 145 //
111 // The |session_storage_namespace| parameter allows multiple render views and 146 // The |session_storage_namespace| parameter allows multiple render views and
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 308
274 // Whether the initial empty page of this view has been accessed by another 309 // Whether the initial empty page of this view has been accessed by another
275 // page, making it unsafe to show the pending URL. Always false after the 310 // page, making it unsafe to show the pending URL. Always false after the
276 // first commit. 311 // first commit.
277 bool has_accessed_initial_document() { 312 bool has_accessed_initial_document() {
278 return has_accessed_initial_document_; 313 return has_accessed_initial_document_;
279 } 314 }
280 315
281 // Whether this RenderViewHost has been swapped out to be displayed by a 316 // Whether this RenderViewHost has been swapped out to be displayed by a
282 // different process. 317 // different process.
283 bool is_swapped_out() const { return is_swapped_out_; } 318 bool IsSwappedOut() const { return rvh_state_ == STATE_SWAPPED_OUT; }
319
320 // The current state of this RVH.
321 RenderViewHostImplState rvh_state() const { return rvh_state_; }
284 322
285 // Called on the pending RenderViewHost when the network response is ready to 323 // Called on the pending RenderViewHost when the network response is ready to
286 // commit. We should ensure that the old RenderViewHost runs its unload 324 // commit. We should ensure that the old RenderViewHost runs its unload
287 // handler and determine whether a transfer to a different RenderViewHost is 325 // handler and determine whether a transfer to a different RenderViewHost is
288 // needed. 326 // needed.
289 void OnCrossSiteResponse( 327 void OnCrossSiteResponse(
290 const GlobalRequestID& global_request_id, 328 const GlobalRequestID& global_request_id,
291 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request, 329 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request,
292 const std::vector<GURL>& transfer_url_chain, 330 const std::vector<GURL>& transfer_url_chain,
293 const Referrer& referrer, 331 const Referrer& referrer,
(...skipping 12 matching lines...) Expand all
306 // a blank document. The renderer should preserve the Frame object until it 344 // a blank document. The renderer should preserve the Frame object until it
307 // exits, in case we come back. The renderer can exit if it has no other 345 // exits, in case we come back. The renderer can exit if it has no other
308 // active RenderViews, but not until WasSwappedOut is called (when it is no 346 // active RenderViews, but not until WasSwappedOut is called (when it is no
309 // longer visible). 347 // longer visible).
310 void SwapOut(); 348 void SwapOut();
311 349
312 // Called when either the SwapOut request has been acknowledged or has timed 350 // Called when either the SwapOut request has been acknowledged or has timed
313 // out. 351 // out.
314 void OnSwappedOut(bool timed_out); 352 void OnSwappedOut(bool timed_out);
315 353
316 // Called to notify the renderer that it has been visibly swapped out and 354 // Called when the RenderFrameHostManager has swapped in a new
317 // replaced by another RenderViewHost, after an earlier call to SwapOut. 355 // RenderFrameHost. Should |this| RVH switch to the pending shutdown state,
318 // It is now safe for the process to exit if there are no other active 356 // |pending_delete_on_swap_out| will be executed upon reception of the
319 // RenderViews. 357 // SwapOutACK, or when the unload timer times out.
320 void WasSwappedOut(); 358 void WasSwappedOut(const base::Closure& pending_delete_on_swap_out);
359
360 // Set |this| as pending shutdown. |on_swap_out| will be called
361 // when the SwapOutACK is received, or when the unload timer times out.
362 void SetPendingShutdown(const base::Closure& on_swap_out);
321 363
322 // Close the page ignoring whether it has unload events registers. 364 // Close the page ignoring whether it has unload events registers.
323 // This is called after the beforeunload and unload events have fired 365 // This is called after the beforeunload and unload events have fired
324 // and the user has agreed to continue with closing the page. 366 // and the user has agreed to continue with closing the page.
325 void ClosePageIgnoringUnloadEvents(); 367 void ClosePageIgnoringUnloadEvents();
326 368
327 // Returns whether this RenderViewHost has an outstanding cross-site request. 369 // Returns whether this RenderViewHost has an outstanding cross-site request.
328 // Cleared when we hear the response and start to swap out the old 370 // Cleared when we hear the response and start to swap out the old
329 // RenderViewHost, or if we hear a commit here without a network request. 371 // RenderViewHost, or if we hear a commit here without a network request.
330 bool HasPendingCrossSiteRequest(); 372 bool HasPendingCrossSiteRequest();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 const base::Closure& callback); 483 const base::Closure& callback);
442 void SetAccessibilityLoadCompleteCallbackForTesting( 484 void SetAccessibilityLoadCompleteCallbackForTesting(
443 const base::Closure& callback); 485 const base::Closure& callback);
444 void SetAccessibilityOtherCallbackForTesting( 486 void SetAccessibilityOtherCallbackForTesting(
445 const base::Closure& callback); 487 const base::Closure& callback);
446 488
447 bool is_waiting_for_beforeunload_ack() { 489 bool is_waiting_for_beforeunload_ack() {
448 return is_waiting_for_beforeunload_ack_; 490 return is_waiting_for_beforeunload_ack_;
449 } 491 }
450 492
451 bool is_waiting_for_unload_ack() { 493 // Whether the RVH is waiting for the unload ack from the renderer.
452 return is_waiting_for_unload_ack_; 494 bool IsWaitingForUnloadACK() const;
453 }
454 495
455 // Update the FrameTree to use this RenderViewHost's main frame 496 // Update the FrameTree to use this RenderViewHost's main frame
456 // RenderFrameHost. Called when the RenderViewHost is committed. 497 // RenderFrameHost. Called when the RenderViewHost is committed.
457 // 498 //
458 // TODO(ajwong): Remove once RenderViewHost no longer owns the main frame 499 // TODO(ajwong): Remove once RenderViewHost no longer owns the main frame
459 // RenderFrameHost. 500 // RenderFrameHost.
460 void AttachToFrameTree(); 501 void AttachToFrameTree();
461 502
462 // The following IPC handlers are public so RenderFrameHost can call them, 503 // The following IPC handlers are public so RenderFrameHost can call them,
463 // while we transition the code to not use RenderViewHost. 504 // while we transition the code to not use RenderViewHost.
464 // 505 //
465 // TODO(nasko): Remove those methods once we are done moving navigation 506 // TODO(nasko): Remove those methods once we are done moving navigation
466 // into RenderFrameHost. 507 // into RenderFrameHost.
467 void OnDidStartProvisionalLoadForFrame(int parent_routing_id, 508 void OnDidStartProvisionalLoadForFrame(int parent_routing_id,
468 bool main_frame, 509 bool main_frame,
469 const GURL& url); 510 const GURL& url);
470 511
512 // Increases the refcounting on this RVH. This is done by the FrameTree on
513 // creation of a RenderFrameHost.
514 void increment_ref_count() { ++frames_ref_count_; }
515
516 // Decreases the refcounting on this RVH. This is done by the FrameTree on
517 // destruction of a RenderFrameHost.
518 void decrement_ref_count() { --frames_ref_count_; }
519
520 // Returns the refcount on this RVH, that is the number of RenderFrameHosts
521 // currently using it.
522 int ref_count() { return frames_ref_count_; }
523
471 // NOTE: Do not add functions that just send an IPC message that are called in 524 // NOTE: Do not add functions that just send an IPC message that are called in
472 // one or two places. Have the caller send the IPC message directly (unless 525 // one or two places. Have the caller send the IPC message directly (unless
473 // the caller places are in different platforms, in which case it's better 526 // the caller places are in different platforms, in which case it's better
474 // to keep them consistent). 527 // to keep them consistent).
475 528
476 protected: 529 protected:
477 // RenderWidgetHost protected overrides. 530 // RenderWidgetHost protected overrides.
478 virtual void OnUserGesture() OVERRIDE; 531 virtual void OnUserGesture() OVERRIDE;
479 virtual void NotifyRendererUnresponsive() OVERRIDE; 532 virtual void NotifyRendererUnresponsive() OVERRIDE;
480 virtual void NotifyRendererResponsive() OVERRIDE; 533 virtual void NotifyRendererResponsive() OVERRIDE;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 628
576 private: 629 private:
577 // TODO(nasko): Temporarily friend RenderFrameHostImpl, so we don't duplicate 630 // TODO(nasko): Temporarily friend RenderFrameHostImpl, so we don't duplicate
578 // utility functions and state needed in both classes, while we move frame 631 // utility functions and state needed in both classes, while we move frame
579 // specific code away from this class. 632 // specific code away from this class.
580 friend class RenderFrameHostImpl; 633 friend class RenderFrameHostImpl;
581 friend class TestRenderViewHost; 634 friend class TestRenderViewHost;
582 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, BasicRenderFrameHost); 635 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, BasicRenderFrameHost);
583 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, RoutingIdSane); 636 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, RoutingIdSane);
584 637
585 // Sets whether this RenderViewHost is swapped out in favor of another, 638 // Updates the state of this RenderViewHost and clears any waiting state
586 // and clears any waiting state that is no longer relevant. 639 // that is no longer relevant.
587 void SetSwappedOut(bool is_swapped_out); 640 void SetState(RenderViewHostImplState rvh_state);
588 641
589 bool CanAccessFilesOfPageState(const PageState& state) const; 642 bool CanAccessFilesOfPageState(const PageState& state) const;
590 643
644 // The number of RenderFrameHosts which have a reference to this RVH.
645 int frames_ref_count_;
646
591 // Our delegate, which wants to know about changes in the RenderView. 647 // Our delegate, which wants to know about changes in the RenderView.
592 RenderViewHostDelegate* delegate_; 648 RenderViewHostDelegate* delegate_;
593 649
594 // The SiteInstance associated with this RenderViewHost. All pages drawn 650 // The SiteInstance associated with this RenderViewHost. All pages drawn
595 // in this RenderViewHost are part of this SiteInstance. Should not change 651 // in this RenderViewHost are part of this SiteInstance. Should not change
596 // over time. 652 // over time.
597 scoped_refptr<SiteInstanceImpl> instance_; 653 scoped_refptr<SiteInstanceImpl> instance_;
598 654
599 // true if we are currently waiting for a response for drag context 655 // true if we are currently waiting for a response for drag context
600 // information. 656 // information.
(...skipping 14 matching lines...) Expand all
615 // navigation, because WebContentsImpl will destroy the pending RVH and create 671 // navigation, because WebContentsImpl will destroy the pending RVH and create
616 // a new one if a second navigation occurs. 672 // a new one if a second navigation occurs.
617 scoped_ptr<ViewMsg_Navigate_Params> suspended_nav_params_; 673 scoped_ptr<ViewMsg_Navigate_Params> suspended_nav_params_;
618 674
619 // Whether the initial empty page of this view has been accessed by another 675 // Whether the initial empty page of this view has been accessed by another
620 // page, making it unsafe to show the pending URL. Usually false unless 676 // page, making it unsafe to show the pending URL. Usually false unless
621 // another window tries to modify the blank page. Always false after the 677 // another window tries to modify the blank page. Always false after the
622 // first commit. 678 // first commit.
623 bool has_accessed_initial_document_; 679 bool has_accessed_initial_document_;
624 680
625 // Whether this RenderViewHost is currently swapped out, such that the view is 681 // The current state of this RVH.
626 // being rendered by another process. 682 RenderViewHostImplState rvh_state_;
627 bool is_swapped_out_;
628 683
629 // Routing ID for the main frame's RenderFrameHost. 684 // Routing ID for the main frame's RenderFrameHost.
630 int main_frame_routing_id_; 685 int main_frame_routing_id_;
631 686
632 // Set to true when there is a pending ViewMsg_ShouldClose message. This 687 // Set to true when there is a pending ViewMsg_ShouldClose message. This
633 // ensures we don't spam the renderer with multiple beforeunload requests. 688 // ensures we don't spam the renderer with multiple beforeunload requests.
634 // When either this value or is_waiting_for_unload_ack_ is true, the value of 689 // When either this value or IsWaitingForUnloadACK is true, the value of
635 // unload_ack_is_for_cross_site_transition_ indicates whether this is for a 690 // unload_ack_is_for_cross_site_transition_ indicates whether this is for a
636 // cross-site transition or a tab close attempt. 691 // cross-site transition or a tab close attempt.
692 // TODO(clamy): Remove this boolean and add one more state to the state
693 // machine.
637 bool is_waiting_for_beforeunload_ack_; 694 bool is_waiting_for_beforeunload_ack_;
638 695
639 // Set to true when there is a pending ViewMsg_Close message. Also see
640 // is_waiting_for_beforeunload_ack_, unload_ack_is_for_cross_site_transition_.
641 bool is_waiting_for_unload_ack_;
642
643 // Set to true when waiting for ViewHostMsg_SwapOut_ACK has timed out.
644 bool has_timed_out_on_unload_;
645
646 // Valid only when is_waiting_for_beforeunload_ack_ or 696 // Valid only when is_waiting_for_beforeunload_ack_ or
647 // is_waiting_for_unload_ack_ is true. This tells us if the unload request 697 // IsWaitingForUnloadACK is true. This tells us if the unload request
648 // is for closing the entire tab ( = false), or only this RenderViewHost in 698 // is for closing the entire tab ( = false), or only this RenderViewHost in
649 // the case of a cross-site transition ( = true). 699 // the case of a cross-site transition ( = true).
650 bool unload_ack_is_for_cross_site_transition_; 700 bool unload_ack_is_for_cross_site_transition_;
651 701
652 bool are_javascript_messages_suppressed_; 702 bool are_javascript_messages_suppressed_;
653 703
654 // The mapping of pending javascript calls created by 704 // The mapping of pending javascript calls created by
655 // ExecuteJavascriptInWebFrameCallbackResult and their corresponding 705 // ExecuteJavascriptInWebFrameCallbackResult and their corresponding
656 // callbacks. 706 // callbacks.
657 std::map<int, JavascriptResultCallback> javascript_callbacks_; 707 std::map<int, JavascriptResultCallback> javascript_callbacks_;
(...skipping 14 matching lines...) Expand all
672 base::TimeTicks send_should_close_start_time_; 722 base::TimeTicks send_should_close_start_time_;
673 723
674 // Set to true if we requested the on screen keyboard to be displayed. 724 // Set to true if we requested the on screen keyboard to be displayed.
675 bool virtual_keyboard_requested_; 725 bool virtual_keyboard_requested_;
676 726
677 #if defined(OS_ANDROID) 727 #if defined(OS_ANDROID)
678 // Manages all the android mediaplayer objects and handling IPCs for video. 728 // Manages all the android mediaplayer objects and handling IPCs for video.
679 scoped_ptr<BrowserMediaPlayerManager> media_player_manager_; 729 scoped_ptr<BrowserMediaPlayerManager> media_player_manager_;
680 #endif 730 #endif
681 731
732 // Used to swap out or shutdown this RVH when the unload event is taking too
733 // long to execute, depending on the number of active views in the
734 // SiteInstance.
735 scoped_ptr<TimeoutMonitor> unload_event_monitor_timeout_;
736
737 // Called after receiving the SwapOutACK when the RVH is in state pending
738 // shutdown. Also called if the unload timer times out.
739 base::Closure pending_shutdown_on_swap_out_;
740
741 base::WeakPtrFactory<RenderViewHostImpl> weak_factory_;
742
682 DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl); 743 DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl);
683 }; 744 };
684 745
685 #if defined(COMPILER_MSVC) 746 #if defined(COMPILER_MSVC)
686 #pragma warning(pop) 747 #pragma warning(pop)
687 #endif 748 #endif
688 749
689 } // namespace content 750 } // namespace content
690 751
691 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_ 752 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698