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

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

Issue 606113005: Move RenderViewHost swap out state to RenderFrameHost. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix review suggestions Created 6 years, 2 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>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 namespace content { 50 namespace content {
51 51
52 class MediaWebContentsObserver; 52 class MediaWebContentsObserver;
53 class ChildProcessSecurityPolicyImpl; 53 class ChildProcessSecurityPolicyImpl;
54 class PageState; 54 class PageState;
55 class RenderWidgetHostDelegate; 55 class RenderWidgetHostDelegate;
56 class SessionStorageNamespace; 56 class SessionStorageNamespace;
57 class SessionStorageNamespaceImpl; 57 class SessionStorageNamespaceImpl;
58 class TestRenderViewHost; 58 class TestRenderViewHost;
59 class TimeoutMonitor;
60 struct FileChooserParams; 59 struct FileChooserParams;
61 60
62 #if defined(COMPILER_MSVC) 61 #if defined(COMPILER_MSVC)
63 // RenderViewHostImpl is the bottom of a diamond-shaped hierarchy, 62 // RenderViewHostImpl is the bottom of a diamond-shaped hierarchy,
64 // with RenderWidgetHost at the root. VS warns when methods from the 63 // with RenderWidgetHost at the root. VS warns when methods from the
65 // root are overridden in only one of the base classes and not both 64 // root are overridden in only one of the base classes and not both
66 // (in this case, RenderWidgetHostImpl provides implementations of 65 // (in this case, RenderWidgetHostImpl provides implementations of
67 // many of the methods). This is a silly warning when dealing with 66 // many of the methods). This is a silly warning when dealing with
68 // pure virtual methods that only have a single implementation in the 67 // pure virtual methods that only have a single implementation in the
69 // hierarchy above this class, and is safe to ignore in this case. 68 // hierarchy above this class, and is safe to ignore in this case.
(...skipping 12 matching lines...) Expand all
82 // 81 //
83 // Right now, the concept of page navigation (both top level and frame) exists 82 // Right now, the concept of page navigation (both top level and frame) exists
84 // in the WebContentsImpl still, so if you instantiate one of these elsewhere, 83 // in the WebContentsImpl still, so if you instantiate one of these elsewhere,
85 // you will not be able to traverse pages back and forward. We need to determine 84 // you will not be able to traverse pages back and forward. We need to determine
86 // if we want to bring that and other functionality down into this object so it 85 // if we want to bring that and other functionality down into this object so it
87 // can be shared by others. 86 // can be shared by others.
88 class CONTENT_EXPORT RenderViewHostImpl 87 class CONTENT_EXPORT RenderViewHostImpl
89 : public RenderViewHost, 88 : public RenderViewHost,
90 public RenderWidgetHostImpl { 89 public RenderWidgetHostImpl {
91 public: 90 public:
92 // Keeps track of the state of the RenderViewHostImpl, particularly with
93 // respect to swap out.
94 enum RenderViewHostImplState {
95 // The standard state for a RVH handling the communication with a
96 // RenderView.
97 STATE_DEFAULT = 0,
98 // The RVH is waiting for the CloseACK from the RenderView.
99 STATE_WAITING_FOR_CLOSE,
100 // The RVH has not received the SwapOutACK yet, but the new page has
101 // committed in a different RVH. The number of active views of the RVH
102 // SiteInstanceImpl is not zero. Upon reception of the SwapOutACK, the RVH
103 // will be swapped out.
104 STATE_PENDING_SWAP_OUT,
105 // The RVH has not received the SwapOutACK yet, but the new page has
106 // committed in a different RVH. The number of active views of the RVH
107 // SiteInstanceImpl is zero. Upon reception of the SwapOutACK, the RVH will
108 // be shutdown.
109 STATE_PENDING_SHUTDOWN,
110 // The RVH is swapped out, and it is being used as a placeholder to allow
111 // for cross-process communication.
112 STATE_SWAPPED_OUT,
113 };
114 // Helper function to determine whether the RVH state should contribute to the
115 // number of active views of a SiteInstance or not.
116 static bool IsRVHStateActive(RenderViewHostImplState rvh_state);
117
118 // Convenience function, just like RenderViewHost::FromID. 91 // Convenience function, just like RenderViewHost::FromID.
119 static RenderViewHostImpl* FromID(int render_process_id, int render_view_id); 92 static RenderViewHostImpl* FromID(int render_process_id, int render_view_id);
120 93
121 // |routing_id| could be a valid route id, or it could be MSG_ROUTING_NONE, in 94 // |routing_id| could be a valid route id, or it could be MSG_ROUTING_NONE, in
122 // which case RenderWidgetHost will create a new one. |swapped_out| indicates 95 // which case RenderWidgetHost will create a new one. |swapped_out| indicates
123 // whether the view should initially be swapped out (e.g., for an opener 96 // whether the view should initially be swapped out (e.g., for an opener
124 // frame being rendered by another process). |hidden| indicates whether the 97 // frame being rendered by another process). |hidden| indicates whether the
125 // view is initially hidden or visible. 98 // view is initially hidden or visible.
126 // 99 //
127 // The |session_storage_namespace| parameter allows multiple render views and 100 // The |session_storage_namespace| parameter allows multiple render views and
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 const blink::WebMediaPlayerAction& action) OVERRIDE; 152 const blink::WebMediaPlayerAction& action) OVERRIDE;
180 virtual void ExecutePluginActionAtLocation( 153 virtual void ExecutePluginActionAtLocation(
181 const gfx::Point& location, 154 const gfx::Point& location,
182 const blink::WebPluginAction& action) OVERRIDE; 155 const blink::WebPluginAction& action) OVERRIDE;
183 virtual void ExitFullscreen() OVERRIDE; 156 virtual void ExitFullscreen() OVERRIDE;
184 virtual void FilesSelectedInChooser( 157 virtual void FilesSelectedInChooser(
185 const std::vector<ui::SelectedFileInfo>& files, 158 const std::vector<ui::SelectedFileInfo>& files,
186 FileChooserParams::Mode permissions) OVERRIDE; 159 FileChooserParams::Mode permissions) OVERRIDE;
187 virtual RenderViewHostDelegate* GetDelegate() const OVERRIDE; 160 virtual RenderViewHostDelegate* GetDelegate() const OVERRIDE;
188 virtual int GetEnabledBindings() const OVERRIDE; 161 virtual int GetEnabledBindings() const OVERRIDE;
189 virtual SiteInstance* GetSiteInstance() const OVERRIDE; 162 virtual SiteInstanceImpl* GetSiteInstance() const OVERRIDE;
190 virtual bool IsRenderViewLive() const OVERRIDE; 163 virtual bool IsRenderViewLive() const OVERRIDE;
191 virtual void NotifyMoveOrResizeStarted() OVERRIDE; 164 virtual void NotifyMoveOrResizeStarted() OVERRIDE;
192 virtual void SetWebUIProperty(const std::string& name, 165 virtual void SetWebUIProperty(const std::string& name,
193 const std::string& value) OVERRIDE; 166 const std::string& value) OVERRIDE;
194 virtual void Zoom(PageZoom zoom) OVERRIDE; 167 virtual void Zoom(PageZoom zoom) OVERRIDE;
195 virtual void SyncRendererPrefs() OVERRIDE; 168 virtual void SyncRendererPrefs() OVERRIDE;
196 virtual WebPreferences GetWebkitPreferences() OVERRIDE; 169 virtual WebPreferences GetWebkitPreferences() OVERRIDE;
197 virtual void UpdateWebkitPreferences( 170 virtual void UpdateWebkitPreferences(
198 const WebPreferences& prefs) OVERRIDE; 171 const WebPreferences& prefs) OVERRIDE;
199 virtual void OnWebkitPreferencesChanged() OVERRIDE; 172 virtual void OnWebkitPreferencesChanged() OVERRIDE;
(...skipping 29 matching lines...) Expand all
229 int32 max_page_id, 202 int32 max_page_id,
230 bool window_was_created_with_opener); 203 bool window_was_created_with_opener);
231 204
232 base::TerminationStatus render_view_termination_status() const { 205 base::TerminationStatus render_view_termination_status() const {
233 return render_view_termination_status_; 206 return render_view_termination_status_;
234 } 207 }
235 208
236 // Returns the content specific prefs for this RenderViewHost. 209 // Returns the content specific prefs for this RenderViewHost.
237 WebPreferences ComputeWebkitPrefs(const GURL& url); 210 WebPreferences ComputeWebkitPrefs(const GURL& url);
238 211
239 // Whether this RenderViewHost has been swapped out to be displayed by a 212 // Tracks whether this RenderViewHost is in an active state (rather than
240 // different process. 213 // pending swap out, pending deletion, or swapped out), according to its main
241 bool IsSwappedOut() const { return rvh_state_ == STATE_SWAPPED_OUT; } 214 // frame RenderFrameHost.
215 bool is_active() const { return is_active_; }
216 void set_is_active(bool is_active) { is_active_ = is_active; }
242 217
243 // The current state of this RVH. 218 // Tracks whether this RenderViewHost is swapped out, according to its main
244 RenderViewHostImplState rvh_state() const { return rvh_state_; } 219 // frame RenderFrameHost.
220 void set_is_swapped_out(bool is_swapped_out) {
221 is_swapped_out_ = is_swapped_out;
222 }
245 223
246 // Tells the renderer that this RenderView will soon be swapped out, and thus 224 // Tells the renderer that this RenderView will soon be swapped out, and thus
247 // not to create any new modal dialogs until it happens. This must be done 225 // not to create any new modal dialogs until it happens. This must be done
248 // separately so that the PageGroupLoadDeferrers of any current dialogs are no 226 // separately so that the PageGroupLoadDeferrers of any current dialogs are no
249 // longer on the stack when we attempt to swap it out. 227 // longer on the stack when we attempt to swap it out.
250 void SuppressDialogsUntilSwapOut(); 228 void SuppressDialogsUntilSwapOut();
251 229
252 // Called when either the SwapOut request has been acknowledged or has timed
253 // out.
254 void OnSwappedOut(bool timed_out);
255
256 // Set |this| as pending shutdown. |on_swap_out| will be called
257 // when the SwapOutACK is received, or when the unload timer times out.
258 void SetPendingShutdown(const base::Closure& on_swap_out);
259
260 // Close the page ignoring whether it has unload events registers. 230 // Close the page ignoring whether it has unload events registers.
261 // This is called after the beforeunload and unload events have fired 231 // This is called after the beforeunload and unload events have fired
262 // and the user has agreed to continue with closing the page. 232 // and the user has agreed to continue with closing the page.
263 void ClosePageIgnoringUnloadEvents(); 233 void ClosePageIgnoringUnloadEvents();
264 234
265 // Tells the renderer view to focus the first (last if reverse is true) node. 235 // Tells the renderer view to focus the first (last if reverse is true) node.
266 void SetInitialFocus(bool reverse); 236 void SetInitialFocus(bool reverse);
267 237
268 // Get html data by serializing all frames of current page with lists 238 // Get html data by serializing all frames of current page with lists
269 // which contain all resource links that have local copy. 239 // which contain all resource links that have local copy.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 #if defined(ENABLE_BROWSER_CDMS) 293 #if defined(ENABLE_BROWSER_CDMS)
324 MediaWebContentsObserver* media_web_contents_observer() { 294 MediaWebContentsObserver* media_web_contents_observer() {
325 return media_web_contents_observer_.get(); 295 return media_web_contents_observer_.get();
326 } 296 }
327 #endif 297 #endif
328 298
329 int main_frame_routing_id() const { 299 int main_frame_routing_id() const {
330 return main_frame_routing_id_; 300 return main_frame_routing_id_;
331 } 301 }
332 302
333 bool is_waiting_for_beforeunload_ack() {
334 return is_waiting_for_beforeunload_ack_;
335 }
336
337 // Whether the RVH is waiting for the unload ack from the renderer.
338 bool IsWaitingForUnloadACK() const;
339
340 void OnTextSurroundingSelectionResponse(const base::string16& content, 303 void OnTextSurroundingSelectionResponse(const base::string16& content,
341 size_t start_offset, 304 size_t start_offset,
342 size_t end_offset); 305 size_t end_offset);
343 306
344 // Update the FrameTree to use this RenderViewHost's main frame 307 // Update the FrameTree to use this RenderViewHost's main frame
345 // RenderFrameHost. Called when the RenderViewHost is committed. 308 // RenderFrameHost. Called when the RenderViewHost is committed.
346 // 309 //
347 // TODO(ajwong): Remove once RenderViewHost no longer owns the main frame 310 // TODO(ajwong): Remove once RenderViewHost no longer owns the main frame
348 // RenderFrameHost. 311 // RenderFrameHost.
349 void AttachToFrameTree(); 312 void AttachToFrameTree();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 friend class RenderFrameHostImpl; 381 friend class RenderFrameHostImpl;
419 friend class TestRenderViewHost; 382 friend class TestRenderViewHost;
420 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, BasicRenderFrameHost); 383 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, BasicRenderFrameHost);
421 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, RoutingIdSane); 384 FRIEND_TEST_ALL_PREFIXES(RenderViewHostTest, RoutingIdSane);
422 385
423 // TODO(creis): Move to a private namespace on RenderFrameHostImpl. 386 // TODO(creis): Move to a private namespace on RenderFrameHostImpl.
424 // Delay to wait on closing the WebContents for a beforeunload/unload handler 387 // Delay to wait on closing the WebContents for a beforeunload/unload handler
425 // to fire. 388 // to fire.
426 static const int kUnloadTimeoutMS; 389 static const int kUnloadTimeoutMS;
427 390
428 // Updates the state of this RenderViewHost and clears any waiting state
429 // that is no longer relevant.
430 void SetState(RenderViewHostImplState rvh_state);
431
432 bool CanAccessFilesOfPageState(const PageState& state) const; 391 bool CanAccessFilesOfPageState(const PageState& state) const;
433 392
434 // The number of RenderFrameHosts which have a reference to this RVH. 393 // The number of RenderFrameHosts which have a reference to this RVH.
435 int frames_ref_count_; 394 int frames_ref_count_;
436 395
437 // Our delegate, which wants to know about changes in the RenderView. 396 // Our delegate, which wants to know about changes in the RenderView.
438 RenderViewHostDelegate* delegate_; 397 RenderViewHostDelegate* delegate_;
439 398
440 // The SiteInstance associated with this RenderViewHost. All pages drawn 399 // The SiteInstance associated with this RenderViewHost. All pages drawn
441 // in this RenderViewHost are part of this SiteInstance. Should not change 400 // in this RenderViewHost are part of this SiteInstance. Cannot change
442 // over time. 401 // over time.
443 scoped_refptr<SiteInstanceImpl> instance_; 402 scoped_refptr<SiteInstanceImpl> instance_;
444 403
445 // true if we are currently waiting for a response for drag context 404 // true if we are currently waiting for a response for drag context
446 // information. 405 // information.
447 bool waiting_for_drag_context_response_; 406 bool waiting_for_drag_context_response_;
448 407
449 // A bitwise OR of bindings types that have been enabled for this RenderView. 408 // A bitwise OR of bindings types that have been enabled for this RenderView.
450 // See BindingsPolicy for details. 409 // See BindingsPolicy for details.
451 int enabled_bindings_; 410 int enabled_bindings_;
452 411
453 // The most recent page ID we've heard from the renderer process. This is 412 // The most recent page ID we've heard from the renderer process. This is
454 // used as context when other session history related IPCs arrive. 413 // used as context when other session history related IPCs arrive.
455 // TODO(creis): Allocate this in WebContents/NavigationController instead. 414 // TODO(creis): Allocate this in WebContents/NavigationController instead.
456 int32 page_id_; 415 int32 page_id_;
457 416
458 // The current state of this RVH. 417 // Tracks whether this RenderViewHost is in an active state. False if the
459 // TODO(nasko): Move to RenderFrameHost, as this is per-frame state. 418 // main frame is pending swap out, pending deletion, or swapped out, because
460 RenderViewHostImplState rvh_state_; 419 // it is not visible to the user in any of these cases.
420 bool is_active_;
421
422 // Tracks whether the main frame RenderFrameHost is swapped out. Unlike
423 // is_active_, this is false when the frame is pending swap out or deletion.
424 // TODO(creis): Remove this when we no longer use swappedout://.
425 // See http://crbug.com/357747.
426 bool is_swapped_out_;
461 427
462 // Routing ID for the main frame's RenderFrameHost. 428 // Routing ID for the main frame's RenderFrameHost.
463 int main_frame_routing_id_; 429 int main_frame_routing_id_;
464 430
465 // If we were asked to RunModal, then this will hold the reply_msg that we 431 // If we were asked to RunModal, then this will hold the reply_msg that we
466 // must return to the renderer to unblock it. 432 // must return to the renderer to unblock it.
467 IPC::Message* run_modal_reply_msg_; 433 IPC::Message* run_modal_reply_msg_;
468 // This will hold the routing id of the RenderView that opened us. 434 // This will hold the routing id of the RenderView that opened us.
469 int run_modal_opener_id_; 435 int run_modal_opener_id_;
470 436
471 // Set to true when there is a pending ViewMsg_ShouldClose message. This 437 // Set to true when waiting for a ViewHostMsg_ClosePageACK.
472 // ensures we don't spam the renderer with multiple beforeunload requests. 438 // TODO(creis): Move to RenderFrameHost and RenderWidgetHost.
473 // When either this value or IsWaitingForUnloadACK is true, the value of 439 // See http://crbug.com/418265.
474 // unload_ack_is_for_cross_site_transition_ indicates whether this is for a 440 bool is_waiting_for_close_ack_;
475 // cross-site transition or a tab close attempt.
476 // TODO(clamy): Remove this boolean and add one more state to the state
477 // machine.
478 // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
479 bool is_waiting_for_beforeunload_ack_;
480
481 // Valid only when is_waiting_for_beforeunload_ack_ or
482 // IsWaitingForUnloadACK is true. This tells us if the unload request
483 // is for closing the entire tab ( = false), or only this RenderViewHost in
484 // the case of a cross-site transition ( = true).
485 // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
486 bool unload_ack_is_for_cross_site_transition_;
487 441
488 // True if the render view can be shut down suddenly. 442 // True if the render view can be shut down suddenly.
489 bool sudden_termination_allowed_; 443 bool sudden_termination_allowed_;
490 444
491 // The termination status of the last render view that terminated. 445 // The termination status of the last render view that terminated.
492 base::TerminationStatus render_view_termination_status_; 446 base::TerminationStatus render_view_termination_status_;
493 447
494 // Set to true if we requested the on screen keyboard to be displayed. 448 // Set to true if we requested the on screen keyboard to be displayed.
495 bool virtual_keyboard_requested_; 449 bool virtual_keyboard_requested_;
496 450
497 #if defined(ENABLE_BROWSER_CDMS) 451 #if defined(ENABLE_BROWSER_CDMS)
498 // Manages all the media player and CDM managers and forwards IPCs to them. 452 // Manages all the media player and CDM managers and forwards IPCs to them.
499 scoped_ptr<MediaWebContentsObserver> media_web_contents_observer_; 453 scoped_ptr<MediaWebContentsObserver> media_web_contents_observer_;
500 #endif 454 #endif
501 455
502 // Used to swap out or shutdown this RVH when the unload event is taking too
503 // long to execute, depending on the number of active views in the
504 // SiteInstance.
505 // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
506 scoped_ptr<TimeoutMonitor> unload_event_monitor_timeout_;
507
508 // Called after receiving the SwapOutACK when the RVH is in state pending
509 // shutdown. Also called if the unload timer times out.
510 // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
511 base::Closure pending_shutdown_on_swap_out_;
512
513 // True if the current focused element is editable. 456 // True if the current focused element is editable.
514 bool is_focused_element_editable_; 457 bool is_focused_element_editable_;
515 458
516 // This is updated every time UpdateWebkitPreferences is called. That method 459 // This is updated every time UpdateWebkitPreferences is called. That method
517 // is in turn called when any of the settings change that the WebPreferences 460 // is in turn called when any of the settings change that the WebPreferences
518 // values depend on. 461 // values depend on.
519 scoped_ptr<WebPreferences> web_preferences_; 462 scoped_ptr<WebPreferences> web_preferences_;
520 463
521 bool updating_web_preferences_; 464 bool updating_web_preferences_;
522 465
523 base::WeakPtrFactory<RenderViewHostImpl> weak_factory_; 466 base::WeakPtrFactory<RenderViewHostImpl> weak_factory_;
524 467
525 DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl); 468 DISALLOW_COPY_AND_ASSIGN(RenderViewHostImpl);
526 }; 469 };
527 470
528 #if defined(COMPILER_MSVC) 471 #if defined(COMPILER_MSVC)
529 #pragma warning(pop) 472 #pragma warning(pop)
530 #endif 473 #endif
531 474
532 } // namespace content 475 } // namespace content
533 476
534 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_ 477 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_delegate.h ('k') | content/browser/renderer_host/render_view_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698