1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h"
16 #include "base/time/time.h"
17 #include "content/browser/accessibility/browser_accessibility_manager.h"
18 #include "content/browser/site_instance_impl.h"
19 #include "content/common/accessibility_mode_enums.h"
20 #include "content/common/content_export.h"
21 #include "content/common/frame_message_enums.h"
22 #include "content/common/frame_replication_state.h"
23 #include "content/common/mojo/service_registry_impl.h"
24 #include "content/common/navigation_params.h"
25 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/common/javascript_message_type.h"
27 #include "net/http/http_response_headers.h"
28 #include "third_party/WebKit/public/web/WebTextDirection.h"
29 #include "third_party/WebKit/public/web/WebTreeScopeType.h"
30 #include "ui/accessibility/ax_node_data.h"
31 #include "ui/base/page_transition_types.h"
33 #if defined(OS_ANDROID)
34 #include "content/browser/mojo/service_registry_android.h"
38 struct AccessibilityHostMsg_EventParams
;
39 struct AccessibilityHostMsg_FindInPageResultParams
;
40 struct AccessibilityHostMsg_LocationChangeParams
;
41 struct FrameHostMsg_DidFailProvisionalLoadWithError_Params
;
42 struct FrameHostMsg_OpenURL_Params
;
43 struct FrameMsg_TextTrackSettings_Params
;
44 #if defined(OS_MACOSX) || defined(OS_ANDROID)
45 struct FrameHostMsg_ShowPopup_Params
;
55 class CrossProcessFrameConnector
;
56 class CrossSiteTransferringRequest
;
60 class PermissionServiceContext
;
61 class RenderFrameHostDelegate
;
62 class RenderFrameProxyHost
;
63 class RenderProcessHost
;
64 class RenderViewHostImpl
;
65 class RenderWidgetHostDelegate
;
66 class RenderWidgetHostImpl
;
67 class RenderWidgetHostView
;
68 class ResourceRequestBody
;
71 struct ContextMenuParams
;
72 struct GlobalRequestID
;
74 struct ResourceResponse
;
76 // Flag arguments for RenderFrameHost creation.
77 enum CreateRenderFrameFlags
{
78 // The RFH will be initially placed on the swapped out hosts list.
79 CREATE_RF_SWAPPED_OUT
= 1 << 0,
80 // The new RenderFrame is being created for a navigation of the
82 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION
= 1 << 1,
83 // The RenderFrame is initially hidden.
84 CREATE_RF_HIDDEN
= 1 << 2,
85 // The RenderFrameHost will have a new RenderWidgetHost created and
86 // attached to it. This is used when the RenderFrameHost is in a different
87 // process from its parent frame.
88 CREATE_RF_NEEDS_RENDER_WIDGET_HOST
= 1 << 3
91 class CONTENT_EXPORT RenderFrameHostImpl
92 : public RenderFrameHost
,
93 public BrowserAccessibilityDelegate
{
95 typedef base::Callback
<void(const ui::AXTreeUpdate
&)>
96 AXTreeSnapshotCallback
;
98 // Keeps track of the state of the RenderFrameHostImpl, particularly with
99 // respect to swap out.
100 enum RenderFrameHostImplState
{
101 // The standard state for a RFH handling the communication with an active
104 // The RFH has not received the SwapOutACK yet, but the new page has
105 // committed in a different RFH. Upon reception of the SwapOutACK, the RFH
106 // will either enter STATE_SWAPPED_OUT (if it is a main frame and there are
107 // other active frames in its SiteInstance) or it will be deleted.
108 STATE_PENDING_SWAP_OUT
,
109 // The RFH is swapped out and stored inside a RenderFrameProxyHost, being
110 // used as a placeholder to allow cross-process communication. Only main
111 // frames can enter this state.
114 // Helper function to determine whether the RFH state should contribute to the
115 // number of active frames of a SiteInstance or not.
116 static bool IsRFHStateActive(RenderFrameHostImplState rfh_state
);
118 // An accessibility reset is only allowed to prevent very rare corner cases
119 // or race conditions where the browser and renderer get out of sync. If
120 // this happens more than this many times, kill the renderer.
121 static const int kMaxAccessibilityResets
= 5;
123 static RenderFrameHostImpl
* FromID(int process_id
, int routing_id
);
125 ~RenderFrameHostImpl() override
;
128 int GetRoutingID() override
;
129 SiteInstanceImpl
* GetSiteInstance() override
;
130 RenderProcessHost
* GetProcess() override
;
131 RenderFrameHost
* GetParent() override
;
132 const std::string
& GetFrameName() override
;
133 bool IsCrossProcessSubframe() override
;
134 GURL
GetLastCommittedURL() override
;
135 gfx::NativeView
GetNativeView() override
;
136 void AddMessageToConsole(ConsoleMessageLevel level
,
137 const std::string
& message
) override
;
138 void ExecuteJavaScript(const base::string16
& javascript
) override
;
139 void ExecuteJavaScript(const base::string16
& javascript
,
140 const JavaScriptResultCallback
& callback
) override
;
141 void ExecuteJavaScriptWithUserGestureForTests(
142 const base::string16
& javascript
) override
;
143 void ExecuteJavaScriptInIsolatedWorld(
144 const base::string16
& javascript
,
145 const JavaScriptResultCallback
& callback
,
146 int world_id
) override
;
147 void ActivateFindInPageResultForAccessibility(int request_id
) override
;
148 RenderViewHost
* GetRenderViewHost() override
;
149 ServiceRegistry
* GetServiceRegistry() override
;
150 blink::WebPageVisibilityState
GetVisibilityState() override
;
151 void InsertVisualStateCallback(
152 const VisualStateCallback
& callback
) override
;
153 bool IsRenderFrameLive() override
;
156 bool Send(IPC::Message
* msg
) override
;
159 bool OnMessageReceived(const IPC::Message
& msg
) override
;
161 // BrowserAccessibilityDelegate
162 void AccessibilitySetFocus(int acc_obj_id
) override
;
163 void AccessibilityDoDefaultAction(int acc_obj_id
) override
;
164 void AccessibilityShowContextMenu(int acc_obj_id
) override
;
165 void AccessibilityScrollToMakeVisible(int acc_obj_id
,
166 const gfx::Rect
& subfocus
) override
;
167 void AccessibilityScrollToPoint(int acc_obj_id
,
168 const gfx::Point
& point
) override
;
169 void AccessibilitySetScrollOffset(int acc_obj_id
,
170 const gfx::Point
& offset
) override
;
171 void AccessibilitySetTextSelection(int acc_obj_id
,
173 int end_offset
) override
;
174 void AccessibilitySetValue(int acc_obj_id
, const base::string16
& value
)
176 bool AccessibilityViewHasFocus() const override
;
177 gfx::Rect
AccessibilityGetViewBounds() const override
;
178 gfx::Point
AccessibilityOriginInScreen(
179 const gfx::Rect
& bounds
) const override
;
180 void AccessibilityHitTest(const gfx::Point
& point
) override
;
181 void AccessibilitySetAccessibilityFocus(int acc_obj_id
) override
;
182 void AccessibilityFatalError() override
;
183 gfx::AcceleratedWidget
AccessibilityGetAcceleratedWidget() override
;
184 gfx::NativeViewAccessible
AccessibilityGetNativeViewAccessible() override
;
185 BrowserAccessibilityManager
* AccessibilityGetChildFrame(
186 int accessibility_node_id
) override
;
187 void AccessibilityGetAllChildFrames(
188 std::vector
<BrowserAccessibilityManager
*>* child_frames
) override
;
189 BrowserAccessibility
* AccessibilityGetParentFrame() override
;
191 // Creates a RenderFrame in the renderer process. Only called for
192 // cross-process subframe navigations in --site-per-process.
193 bool CreateRenderFrame(int parent_routing_id
,
194 int previous_sibling_routing_id
,
195 int proxy_routing_id
);
197 // Tracks whether the RenderFrame for this RenderFrameHost has been created in
198 // the renderer process. This is currently only used for subframes.
199 // TODO(creis): Use this for main frames as well when RVH goes away.
200 void SetRenderFrameCreated(bool created
);
202 // Called for renderer-created windows to resume requests from this frame,
203 // after they are blocked in RenderWidgetHelper::CreateNewWindow.
206 int routing_id() const { return routing_id_
; }
207 void OnCreateChildFrame(int new_routing_id
,
208 blink::WebTreeScopeType scope
,
209 const std::string
& frame_name
,
210 blink::WebSandboxFlags sandbox_flags
);
212 RenderViewHostImpl
* render_view_host() { return render_view_host_
; }
213 RenderFrameHostDelegate
* delegate() { return delegate_
; }
214 FrameTreeNode
* frame_tree_node() { return frame_tree_node_
; }
216 // Returns this RenderFrameHost's loading state. This method is only used by
217 // FrameTreeNode. The proper way to check whether a frame is loading is to
218 // call FrameTreeNode::IsLoading.
219 bool is_loading() const { return is_loading_
; }
221 // This returns the RenderFrameHost's owned RenderWidgetHost if it has one,
222 // or else it returns nullptr.
223 // If the RenderFrameHost is the page's main frame, this returns instead a
224 // pointer to the RenderViewHost (which inherits RenderWidgetHost).
225 RenderWidgetHostImpl
* GetRenderWidgetHost();
227 // This returns the RenderWidgetHostView that can be used to control
228 // focus and visibility for this frame.
229 RenderWidgetHostView
* GetView();
231 // This function is called when this is a swapped out RenderFrameHost that
232 // lives in the same process as the parent frame. The
233 // |cross_process_frame_connector| allows the non-swapped-out
234 // RenderFrameHost for a frame to communicate with the parent process
235 // so that it may composite drawing data.
237 // Ownership is not transfered.
238 void set_cross_process_frame_connector(
239 CrossProcessFrameConnector
* cross_process_frame_connector
) {
240 cross_process_frame_connector_
= cross_process_frame_connector
;
243 void set_render_frame_proxy_host(RenderFrameProxyHost
* proxy
) {
244 render_frame_proxy_host_
= proxy
;
247 // Returns a bitwise OR of bindings types that have been enabled for this
248 // RenderFrameHostImpl's RenderView. See BindingsPolicy for details.
249 // TODO(creis): Make bindings frame-specific, to support cases like <webview>.
250 int GetEnabledBindings();
252 // Called on the pending RenderFrameHost when the network response is ready to
253 // commit. We should ensure that the old RenderFrameHost runs its unload
254 // handler and determine whether a transfer to a different RenderFrameHost is
256 void OnCrossSiteResponse(
257 const GlobalRequestID
& global_request_id
,
258 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request
,
259 const std::vector
<GURL
>& transfer_url_chain
,
260 const Referrer
& referrer
,
261 ui::PageTransition page_transition
,
262 bool should_replace_current_entry
);
264 // Tells the renderer that this RenderFrame is being swapped out for one in a
265 // different renderer process. It should run its unload handler and move to
266 // a blank document. If |proxy| is not null, it should also create a
267 // RenderFrameProxy to replace the RenderFrame and set it to |is_loading|
268 // state. The renderer should preserve the RenderFrameProxy object until it
269 // exits, in case we come back. The renderer can exit if it has no other
270 // active RenderFrames, but not until WasSwappedOut is called.
271 void SwapOut(RenderFrameProxyHost
* proxy
, bool is_loading
);
273 // Whether an ongoing navigation is waiting for a BeforeUnload ACK from the
274 // RenderFrame. Currently this only happens in cross-site navigations.
275 // PlzNavigate: this happens in every browser-initiated navigation that is not
277 bool is_waiting_for_beforeunload_ack() const {
278 return is_waiting_for_beforeunload_ack_
;
281 // Whether the RFH is waiting for an unload ACK from the renderer.
282 bool IsWaitingForUnloadACK() const;
284 // Called when either the SwapOut request has been acknowledged or has timed
288 // Whether this RenderFrameHost has been swapped out, such that the frame is
289 // now rendered by a RenderFrameHost in a different process.
290 bool is_swapped_out() const { return rfh_state_
== STATE_SWAPPED_OUT
; }
292 // The current state of this RFH.
293 RenderFrameHostImplState
rfh_state() const { return rfh_state_
; }
295 // Sends the given navigation message. Use this rather than sending it
296 // yourself since this does the internal bookkeeping described below. This
297 // function takes ownership of the provided message pointer.
299 // If a cross-site request is in progress, we may be suspended while waiting
300 // for the onbeforeunload handler, so this function might buffer the message
301 // rather than sending it.
302 void Navigate(const CommonNavigationParams
& common_params
,
303 const StartNavigationParams
& start_params
,
304 const RequestNavigationParams
& request_params
);
306 // Load the specified URL; this is a shortcut for Navigate().
307 void NavigateToURL(const GURL
& url
);
309 // Treat this prospective navigation as though it originated from the frame.
310 // Used, e.g., for a navigation request that originated from a RemoteFrame.
311 // |source_site_instance| is the SiteInstance of the frame that initiated the
313 // TODO(creis): Remove this method and have RenderFrameProxyHost call
314 // RequestOpenURL with its FrameTreeNode.
315 void OpenURL(const FrameHostMsg_OpenURL_Params
& params
,
316 SiteInstance
* source_site_instance
);
318 // Stop the load in progress.
321 // Returns whether navigation messages are currently suspended for this
322 // RenderFrameHost. Only true during a cross-site navigation, while waiting
323 // for the onbeforeunload handler.
324 bool are_navigations_suspended() const { return navigations_suspended_
; }
326 // Suspends (or unsuspends) any navigation messages from being sent from this
327 // RenderFrameHost. This is called when a pending RenderFrameHost is created
328 // for a cross-site navigation, because we must suspend any navigations until
329 // we hear back from the old renderer's onbeforeunload handler. Note that it
330 // is important that only one navigation event happen after calling this
331 // method with |suspend| equal to true. If |suspend| is false and there is a
332 // suspended_nav_message_, this will send the message. This function should
333 // only be called to toggle the state; callers should check
334 // are_navigations_suspended() first. If |suspend| is false, the time that the
335 // user decided the navigation should proceed should be passed as
337 void SetNavigationsSuspended(bool suspend
,
338 const base::TimeTicks
& proceed_time
);
340 // Clears any suspended navigation state after a cross-site navigation is
341 // canceled or suspended. This is important if we later return to this
343 void CancelSuspendedNavigations();
345 // Runs the beforeunload handler for this frame. |for_navigation| indicates
346 // whether this call is for the current frame during a cross-process
347 // navigation. False means we're closing the entire tab.
348 // PlzNavigate: this call happens on all browser-initiated navigations.
349 void DispatchBeforeUnload(bool for_navigation
);
351 // Returns true if a call to DispatchBeforeUnload will actually send the
352 // BeforeUnload IPC. This is the case if the current renderer is live and this
353 // frame is the main frame.
354 bool ShouldDispatchBeforeUnload();
356 // Set the frame's opener to null in the renderer process in response to an
357 // action in another renderer process.
360 // Deletes the current selection plus the specified number of characters
361 // before and after the selection or caret.
362 void ExtendSelectionAndDelete(size_t before
, size_t after
);
364 // Notifies the RenderFrame that the JavaScript message that was shown was
365 // closed by the user.
366 void JavaScriptDialogClosed(IPC::Message
* reply_msg
,
368 const base::string16
& user_input
,
369 bool dialog_was_suppressed
);
371 // Send a message to the renderer process to change the accessibility mode.
372 void SetAccessibilityMode(AccessibilityMode AccessibilityMode
);
374 // Request a one-time snapshot of the accessibility tree without changing
375 // the accessibility mode.
376 void RequestAXTreeSnapshot(AXTreeSnapshotCallback callback
);
378 // Turn on accessibility testing. The given callback will be run
379 // every time an accessibility notification is received from the
380 // renderer process, and the accessibility tree it sent can be
381 // retrieved using GetAXTreeForTesting().
382 void SetAccessibilityCallbackForTesting(
383 const base::Callback
<void(ui::AXEvent
, int)>& callback
);
385 // Send a message to the render process to change text track style settings.
386 void SetTextTrackSettings(const FrameMsg_TextTrackSettings_Params
& params
);
388 // Returns a snapshot of the accessibility tree received from the
389 // renderer as of the last time an accessibility notification was
391 const ui::AXTree
* GetAXTreeForTesting();
393 // Access the BrowserAccessibilityManager if it already exists.
394 BrowserAccessibilityManager
* browser_accessibility_manager() const {
395 return browser_accessibility_manager_
.get();
398 // If accessibility is enabled, get the BrowserAccessibilityManager for
399 // this frame, or create one if it doesn't exist yet, otherwise return
401 BrowserAccessibilityManager
* GetOrCreateBrowserAccessibilityManager();
403 void set_no_create_browser_accessibility_manager_for_testing(bool flag
) {
404 no_create_browser_accessibility_manager_for_testing_
= flag
;
408 void SetParentNativeViewAccessible(
409 gfx::NativeViewAccessible accessible_parent
);
410 gfx::NativeViewAccessible
GetParentNativeViewAccessible() const;
411 #elif defined(OS_MACOSX)
412 // Select popup menu related methods (for external popup menus).
413 void DidSelectPopupMenuItem(int selected_index
);
414 void DidCancelPopupMenu();
415 #elif defined(OS_ANDROID)
416 void DidSelectPopupMenuItems(const std::vector
<int>& selected_indices
);
417 void DidCancelPopupMenu();
420 // PlzNavigate: Indicates that a navigation is ready to commit and can be
421 // handled by this RenderFrame.
422 void CommitNavigation(ResourceResponse
* response
,
423 scoped_ptr
<StreamHandle
> body
,
424 const CommonNavigationParams
& common_params
,
425 const RequestNavigationParams
& request_params
);
428 // Indicates that a navigation failed and that this RenderFrame should display
430 void FailedNavigation(const CommonNavigationParams
& common_params
,
431 const RequestNavigationParams
& request_params
,
432 bool has_stale_copy_in_cache
,
435 // Sets up the Mojo connection between this instance and its associated render
436 // frame if it has not yet been set up.
437 void SetUpMojoIfNeeded();
439 // Tears down the browser-side state relating to the Mojo connection between
440 // this instance and its associated render frame.
441 void InvalidateMojoConnection();
443 // Returns whether the frame is focused. A frame is considered focused when it
444 // is the parent chain of the focused frame within the frame tree. In
445 // addition, its associated RenderWidgetHost has to be focused.
449 friend class RenderFrameHostFactory
;
451 // |flags| is a combination of CreateRenderFrameFlags.
452 // TODO(nasko): Remove dependency on RenderViewHost here. RenderProcessHost
453 // should be the abstraction needed here, but we need RenderViewHost to pass
454 // into WebContentsObserver::FrameDetached for now.
455 RenderFrameHostImpl(SiteInstance
* site_instance
,
456 RenderViewHostImpl
* render_view_host
,
457 RenderFrameHostDelegate
* delegate
,
458 RenderWidgetHostDelegate
* rwh_delegate
,
459 FrameTree
* frame_tree
,
460 FrameTreeNode
* frame_tree_node
,
465 friend class TestRenderFrameHost
;
466 friend class TestRenderViewHost
;
468 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest
, CrashSubframe
);
470 // IPC Message handlers.
471 void OnAddMessageToConsole(int32 level
,
472 const base::string16
& message
,
474 const base::string16
& source_id
);
476 void OnFrameFocused();
477 void OnOpenURL(const FrameHostMsg_OpenURL_Params
& params
);
478 void OnDocumentOnLoadCompleted(
479 FrameMsg_UILoadMetricsReportType::Value report_type
,
480 base::TimeTicks ui_timestamp
);
481 void OnDidStartProvisionalLoadForFrame(const GURL
& url
);
482 void OnDidFailProvisionalLoadWithError(
483 const FrameHostMsg_DidFailProvisionalLoadWithError_Params
& params
);
484 void OnDidFailLoadWithError(
487 const base::string16
& error_description
,
488 bool was_ignored_by_handler
);
489 void OnDidCommitProvisionalLoad(const IPC::Message
& msg
);
490 void OnDidDropNavigation();
491 void OnBeforeUnloadACK(
493 const base::TimeTicks
& renderer_before_unload_start_time
,
494 const base::TimeTicks
& renderer_before_unload_end_time
);
496 void OnRenderProcessGone(int status
, int error_code
);
497 void OnContextMenu(const ContextMenuParams
& params
);
498 void OnJavaScriptExecuteResponse(int id
, const base::ListValue
& result
);
499 void OnVisualStateResponse(uint64 id
);
500 void OnRunJavaScriptMessage(const base::string16
& message
,
501 const base::string16
& default_prompt
,
502 const GURL
& frame_url
,
503 JavaScriptMessageType type
,
504 IPC::Message
* reply_msg
);
505 void OnRunBeforeUnloadConfirm(const GURL
& frame_url
,
506 const base::string16
& message
,
508 IPC::Message
* reply_msg
);
509 void OnTextSurroundingSelectionResponse(const base::string16
& content
,
512 void OnDidAccessInitialDocument();
513 void OnDidDisownOpener();
514 void OnDidChangeName(const std::string
& name
);
515 void OnDidAssignPageId(int32 page_id
);
516 void OnDidChangeSandboxFlags(int32 frame_routing_id
,
517 blink::WebSandboxFlags flags
);
518 void OnUpdateTitle(const base::string16
& title
,
519 blink::WebTextDirection title_direction
);
520 void OnUpdateEncoding(const std::string
& encoding
);
521 void OnBeginNavigation(const CommonNavigationParams
& common_params
,
522 const BeginNavigationParams
& begin_params
,
523 scoped_refptr
<ResourceRequestBody
> body
);
524 void OnDispatchLoad();
525 void OnAccessibilityEvents(
526 const std::vector
<AccessibilityHostMsg_EventParams
>& params
,
528 void OnAccessibilityLocationChanges(
529 const std::vector
<AccessibilityHostMsg_LocationChangeParams
>& params
);
530 void OnAccessibilityFindInPageResult(
531 const AccessibilityHostMsg_FindInPageResultParams
& params
);
532 void OnAccessibilitySnapshotResponse(int callback_id
,
533 const ui::AXTreeUpdate
& snapshot
);
534 void OnToggleFullscreen(bool enter_fullscreen
);
535 void OnDidStartLoading(bool to_different_document
);
536 void OnDidStopLoading();
537 void OnDidChangeLoadProgress(double load_progress
);
539 #if defined(OS_MACOSX) || defined(OS_ANDROID)
540 void OnShowPopup(const FrameHostMsg_ShowPopup_Params
& params
);
544 // Registers Mojo services that this frame host makes available.
545 void RegisterMojoServices();
547 // Updates the state of this RenderFrameHost and clears any waiting state
548 // that is no longer relevant.
549 void SetState(RenderFrameHostImplState rfh_state
);
551 // Returns whether the given URL is allowed to commit in the current process.
552 // This is a more conservative check than RenderProcessHost::FilterURL, since
553 // it will be used to kill processes that commit unauthorized URLs.
554 bool CanCommitURL(const GURL
& url
);
556 // Update the the singleton FrameAccessibility instance with a map
557 // from accessibility node id to the frame routing id of a cross-process
559 void UpdateCrossProcessIframeAccessibility(
560 const std::map
<int32
, int>& node_to_frame_routing_id_map
);
562 // Update the the singleton FrameAccessibility instance with a map
563 // from accessibility node id to the browser plugin instance id of a
564 // guest WebContents.
565 void UpdateGuestFrameAccessibility(
566 const std::map
<int32
, int>& node_to_browser_plugin_instance_id_map
);
568 // Asserts that the given RenderFrameHostImpl is part of the same browser
569 // context (and crashes if not), then returns whether the given frame is
570 // part of the same site instance.
571 bool IsSameSiteInstance(RenderFrameHostImpl
* other_render_frame_host
);
573 // Informs the content client that geolocation permissions were used.
574 void DidUseGeolocationPermission();
576 void UpdatePermissionsForNavigation(
577 const CommonNavigationParams
& common_params
,
578 const RequestNavigationParams
& request_params
);
580 // For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
581 // refcount that calls Shutdown when it reaches zero. This allows each
582 // RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
583 // we have a RenderViewHost for each RenderFrameHost.
584 // TODO(creis): RenderViewHost will eventually go away and be replaced with
585 // some form of page context.
586 RenderViewHostImpl
* render_view_host_
;
588 RenderFrameHostDelegate
* delegate_
;
590 // The SiteInstance associated with this RenderFrameHost. All content drawn
591 // in this RenderFrameHost is part of this SiteInstance. Cannot change over
593 scoped_refptr
<SiteInstanceImpl
> site_instance_
;
595 // The renderer process this RenderFrameHost is associated with. It is
596 // equivalent to the result of site_instance_->GetProcess(), but that
597 // method has the side effect of creating the process if it doesn't exist.
598 // Cache a pointer to avoid unnecessary process creation.
599 RenderProcessHost
* process_
;
601 // |cross_process_frame_connector_| passes messages from an out-of-process
602 // child frame to the parent process for compositing.
604 // This is only non-NULL when this is the swapped out RenderFrameHost in
605 // the same site instance as this frame's parent.
607 // See the class comment above CrossProcessFrameConnector for more
610 // This will move to RenderFrameProxyHost when that class is created.
611 CrossProcessFrameConnector
* cross_process_frame_connector_
;
613 // The proxy created for this RenderFrameHost. It is used to send and receive
614 // IPC messages while in swapped out state.
615 // TODO(nasko): This can be removed once we don't have a swapped out state on
616 // RenderFrameHosts. See https://crbug.com/357747.
617 RenderFrameProxyHost
* render_frame_proxy_host_
;
619 // Reference to the whole frame tree that this RenderFrameHost belongs to.
620 // Allows this RenderFrameHost to add and remove nodes in response to
621 // messages from the renderer requesting DOM manipulation.
622 FrameTree
* frame_tree_
;
624 // The FrameTreeNode which this RenderFrameHostImpl is hosted in.
625 FrameTreeNode
* frame_tree_node_
;
627 // The mapping of pending JavaScript calls created by
628 // ExecuteJavaScript and their corresponding callbacks.
629 std::map
<int, JavaScriptResultCallback
> javascript_callbacks_
;
630 std::map
<uint64
, VisualStateCallback
> visual_state_callbacks_
;
632 // RenderFrameHosts that need management of the rendering and input events
633 // for their frame subtrees require RenderWidgetHosts. This typically
634 // means frames that are rendered in different processes from their parent
636 // TODO(kenrb): Later this will also be used on the top-level frame, when
637 // RenderFrameHost owns its RenderViewHost.
638 RenderWidgetHostImpl
* render_widget_host_
;
642 // The current state of this RenderFrameHost.
643 RenderFrameHostImplState rfh_state_
;
645 // Tracks whether the RenderFrame for this RenderFrameHost has been created in
646 // the renderer process. Currently only used for subframes.
647 // TODO(creis): Use this for main frames as well when RVH goes away.
648 bool render_frame_created_
;
650 // Whether we should buffer outgoing Navigate messages rather than sending
651 // them. This will be true when a RenderFrameHost is created for a cross-site
652 // request, until we hear back from the onbeforeunload handler of the old
654 bool navigations_suspended_
;
656 // Holds the parameters for a suspended navigation. This can only happen while
657 // this RFH is the pending RenderFrameHost of a RenderFrameHostManager. There
658 // will only ever be one suspended navigation, because RenderFrameHostManager
659 // will destroy the pending RenderFrameHost and create a new one if a second
660 // navigation occurs.
661 // PlzNavigate: unused as navigations are never suspended.
662 scoped_ptr
<NavigationParams
> suspended_nav_params_
;
664 // When the last BeforeUnload message was sent.
665 base::TimeTicks send_before_unload_start_time_
;
667 // Set to true when there is a pending FrameMsg_ShouldClose message. This
668 // ensures we don't spam the renderer with multiple beforeunload requests.
669 // When either this value or IsWaitingForUnloadACK is true, the value of
670 // unload_ack_is_for_cross_site_transition_ indicates whether this is for a
671 // cross-site transition or a tab close attempt.
672 // TODO(clamy): Remove this boolean and add one more state to the state
674 bool is_waiting_for_beforeunload_ack_
;
676 // Valid only when is_waiting_for_beforeunload_ack_ or
677 // IsWaitingForUnloadACK is true. This tells us if the unload request
678 // is for closing the entire tab ( = false), or only this RenderFrameHost in
679 // the case of a navigation ( = true). Currently only cross-site navigations
680 // require a beforeUnload/unload ACK.
681 // PlzNavigate: all navigations require a beforeUnload ACK.
682 bool unload_ack_is_for_navigation_
;
684 // Indicates whether this RenderFrameHost is in the process of loading a
689 // Used to track whether a commit is expected in this frame. Only used in
691 bool pending_commit_
;
693 // Used to swap out or shut down this RFH when the unload event is taking too
694 // long to execute, depending on the number of active frames in the
696 scoped_ptr
<TimeoutMonitor
> swapout_event_monitor_timeout_
;
698 scoped_ptr
<ServiceRegistryImpl
> service_registry_
;
700 #if defined(OS_ANDROID)
701 scoped_ptr
<ServiceRegistryAndroid
> service_registry_android_
;
704 // The object managing the accessibility tree for this frame.
705 scoped_ptr
<BrowserAccessibilityManager
> browser_accessibility_manager_
;
707 // This is nonzero if we sent an accessibility reset to the renderer and
708 // we're waiting for an IPC containing this reset token (sequentially
709 // assigned) and a complete replacement accessibility tree.
710 int accessibility_reset_token_
;
712 // A count of the number of times we needed to reset accessibility, so
713 // we don't keep trying to reset forever.
714 int accessibility_reset_count_
;
716 // The mapping from callback id to corresponding callback for pending
717 // accessibility tree snapshot calls created by RequestAXTreeSnapshot.
718 std::map
<int, AXTreeSnapshotCallback
> ax_tree_snapshot_callbacks_
;
720 // Callback when an event is received, for testing.
721 base::Callback
<void(ui::AXEvent
, int)> accessibility_testing_callback_
;
722 // The most recently received accessibility tree - for testing only.
723 scoped_ptr
<ui::AXTree
> ax_tree_for_testing_
;
724 // Flag to not create a BrowserAccessibilityManager, for testing. If one
725 // already exists it will still be used.
726 bool no_create_browser_accessibility_manager_for_testing_
;
728 // PlzNavigate: Owns the stream used in navigations to store the body of the
729 // response once it has started.
730 scoped_ptr
<StreamHandle
> stream_handle_
;
732 // Context shared for each PermissionService instance created for this RFH.
733 scoped_ptr
<PermissionServiceContext
> permission_service_context_
;
735 // The frame's Mojo Shell service.
736 scoped_ptr
<FrameMojoShell
> frame_mojo_shell_
;
738 // NOTE: This must be the last member.
739 base::WeakPtrFactory
<RenderFrameHostImpl
> weak_ptr_factory_
;
741 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl
);
744 } // namespace content
746 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_