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/image_downloader/image_downloader.mojom.h"
24 #include "content/common/mojo/service_registry_impl.h"
25 #include "content/common/navigation_params.h"
26 #include "content/public/browser/render_frame_host.h"
27 #include "content/public/common/javascript_message_type.h"
28 #include "net/http/http_response_headers.h"
29 #include "third_party/WebKit/public/web/WebTextDirection.h"
30 #include "third_party/WebKit/public/web/WebTreeScopeType.h"
31 #include "ui/accessibility/ax_node_data.h"
32 #include "ui/base/page_transition_types.h"
34 #if defined(OS_ANDROID)
35 #include "content/browser/mojo/service_registry_android.h"
39 struct AccessibilityHostMsg_EventParams
;
40 struct AccessibilityHostMsg_FindInPageResultParams
;
41 struct AccessibilityHostMsg_LocationChangeParams
;
42 struct FrameHostMsg_DidFailProvisionalLoadWithError_Params
;
43 struct FrameHostMsg_OpenURL_Params
;
44 struct FrameMsg_TextTrackSettings_Params
;
45 #if defined(OS_MACOSX) || defined(OS_ANDROID)
46 struct FrameHostMsg_ShowPopup_Params
;
56 class CrossProcessFrameConnector
;
57 class CrossSiteTransferringRequest
;
61 class NavigationHandleImpl
;
62 class PermissionServiceContext
;
63 class RenderFrameHostDelegate
;
64 class RenderFrameProxyHost
;
65 class RenderProcessHost
;
66 class RenderViewHostImpl
;
67 class RenderWidgetHostDelegate
;
68 class RenderWidgetHostImpl
;
69 class RenderWidgetHostView
;
70 class ResourceRequestBody
;
73 struct ContextMenuParams
;
74 struct GlobalRequestID
;
76 struct ResourceResponse
;
78 // Flag arguments for RenderFrameHost creation.
79 enum CreateRenderFrameFlags
{
80 // The RFH will be initially placed on the swapped out hosts list.
81 CREATE_RF_SWAPPED_OUT
= 1 << 0,
82 // The new RenderFrame is being created for a navigation of the
84 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION
= 1 << 1,
85 // The RenderFrame is initially hidden.
86 CREATE_RF_HIDDEN
= 1 << 2,
87 // The RenderFrameHost will have a new RenderWidgetHost created and
88 // attached to it. This is used when the RenderFrameHost is in a different
89 // process from its parent frame.
90 CREATE_RF_NEEDS_RENDER_WIDGET_HOST
= 1 << 3
93 class CONTENT_EXPORT RenderFrameHostImpl
94 : public RenderFrameHost
,
95 public BrowserAccessibilityDelegate
{
97 typedef base::Callback
<void(const ui::AXTreeUpdate
&)>
98 AXTreeSnapshotCallback
;
100 // Keeps track of the state of the RenderFrameHostImpl, particularly with
101 // respect to swap out.
102 enum RenderFrameHostImplState
{
103 // The standard state for a RFH handling the communication with an active
106 // The RFH has not received the SwapOutACK yet, but the new page has
107 // committed in a different RFH. Upon reception of the SwapOutACK, the RFH
108 // will either enter STATE_SWAPPED_OUT (if it is a main frame and there are
109 // other active frames in its SiteInstance) or it will be deleted.
110 STATE_PENDING_SWAP_OUT
,
111 // The RFH is swapped out and stored inside a RenderFrameProxyHost, being
112 // used as a placeholder to allow cross-process communication. Only main
113 // frames can enter this state.
116 // Helper function to determine whether the RFH state should contribute to the
117 // number of active frames of a SiteInstance or not.
118 static bool IsRFHStateActive(RenderFrameHostImplState rfh_state
);
120 // An accessibility reset is only allowed to prevent very rare corner cases
121 // or race conditions where the browser and renderer get out of sync. If
122 // this happens more than this many times, kill the renderer.
123 static const int kMaxAccessibilityResets
= 5;
125 static RenderFrameHostImpl
* FromID(int process_id
, int routing_id
);
127 ~RenderFrameHostImpl() override
;
130 int GetRoutingID() override
;
131 SiteInstanceImpl
* GetSiteInstance() override
;
132 RenderProcessHost
* GetProcess() override
;
133 RenderFrameHost
* GetParent() override
;
134 const std::string
& GetFrameName() override
;
135 bool IsCrossProcessSubframe() override
;
136 GURL
GetLastCommittedURL() override
;
137 gfx::NativeView
GetNativeView() override
;
138 void AddMessageToConsole(ConsoleMessageLevel level
,
139 const std::string
& message
) override
;
140 void ExecuteJavaScript(const base::string16
& javascript
) override
;
141 void ExecuteJavaScript(const base::string16
& javascript
,
142 const JavaScriptResultCallback
& callback
) override
;
143 void ExecuteJavaScriptForTests(const base::string16
& javascript
) override
;
144 void ExecuteJavaScriptForTests(
145 const base::string16
& javascript
,
146 const JavaScriptResultCallback
& callback
) override
;
147 void ExecuteJavaScriptWithUserGestureForTests(
148 const base::string16
& javascript
) override
;
149 void ExecuteJavaScriptInIsolatedWorld(
150 const base::string16
& javascript
,
151 const JavaScriptResultCallback
& callback
,
152 int world_id
) override
;
153 void ActivateFindInPageResultForAccessibility(int request_id
) override
;
154 RenderViewHost
* GetRenderViewHost() override
;
155 ServiceRegistry
* GetServiceRegistry() override
;
156 blink::WebPageVisibilityState
GetVisibilityState() override
;
157 void InsertVisualStateCallback(
158 const VisualStateCallback
& callback
) override
;
159 bool IsRenderFrameLive() override
;
162 bool Send(IPC::Message
* msg
) override
;
165 bool OnMessageReceived(const IPC::Message
& msg
) override
;
167 // BrowserAccessibilityDelegate
168 void AccessibilitySetFocus(int acc_obj_id
) override
;
169 void AccessibilityDoDefaultAction(int acc_obj_id
) override
;
170 void AccessibilityShowContextMenu(int acc_obj_id
) override
;
171 void AccessibilityScrollToMakeVisible(int acc_obj_id
,
172 const gfx::Rect
& subfocus
) override
;
173 void AccessibilityScrollToPoint(int acc_obj_id
,
174 const gfx::Point
& point
) override
;
175 void AccessibilitySetScrollOffset(int acc_obj_id
,
176 const gfx::Point
& offset
) override
;
177 void AccessibilitySetTextSelection(int acc_obj_id
,
179 int end_offset
) override
;
180 void AccessibilitySetValue(int acc_obj_id
, const base::string16
& value
)
182 bool AccessibilityViewHasFocus() const override
;
183 gfx::Rect
AccessibilityGetViewBounds() const override
;
184 gfx::Point
AccessibilityOriginInScreen(
185 const gfx::Rect
& bounds
) const override
;
186 void AccessibilityHitTest(const gfx::Point
& point
) override
;
187 void AccessibilitySetAccessibilityFocus(int acc_obj_id
) override
;
188 void AccessibilityFatalError() override
;
189 gfx::AcceleratedWidget
AccessibilityGetAcceleratedWidget() override
;
190 gfx::NativeViewAccessible
AccessibilityGetNativeViewAccessible() override
;
191 BrowserAccessibilityManager
* AccessibilityGetChildFrame(
192 int accessibility_node_id
) override
;
193 void AccessibilityGetAllChildFrames(
194 std::vector
<BrowserAccessibilityManager
*>* child_frames
) override
;
195 BrowserAccessibility
* AccessibilityGetParentFrame() override
;
197 // Creates a RenderFrame in the renderer process. Only called for
198 // cross-process subframe navigations in --site-per-process.
199 bool CreateRenderFrame(int parent_routing_id
,
200 int previous_sibling_routing_id
,
201 int proxy_routing_id
);
203 // Tracks whether the RenderFrame for this RenderFrameHost has been created in
204 // the renderer process. This is currently only used for subframes.
205 // TODO(creis): Use this for main frames as well when RVH goes away.
206 void SetRenderFrameCreated(bool created
);
208 // Called for renderer-created windows to resume requests from this frame,
209 // after they are blocked in RenderWidgetHelper::CreateNewWindow.
212 int routing_id() const { return routing_id_
; }
213 void OnCreateChildFrame(int new_routing_id
,
214 blink::WebTreeScopeType scope
,
215 const std::string
& frame_name
,
216 blink::WebSandboxFlags sandbox_flags
);
218 RenderViewHostImpl
* render_view_host() { return render_view_host_
; }
219 RenderFrameHostDelegate
* delegate() { return delegate_
; }
220 FrameTreeNode
* frame_tree_node() { return frame_tree_node_
; }
222 // Returns this RenderFrameHost's loading state. This method is only used by
223 // FrameTreeNode. The proper way to check whether a frame is loading is to
224 // call FrameTreeNode::IsLoading.
225 bool is_loading() const { return is_loading_
; }
227 // This returns the RenderFrameHost's owned RenderWidgetHost if it has one,
228 // or else it returns nullptr.
229 // If the RenderFrameHost is the page's main frame, this returns instead a
230 // pointer to the RenderViewHost (which inherits RenderWidgetHost).
231 RenderWidgetHostImpl
* GetRenderWidgetHost();
233 // This returns the RenderWidgetHostView that can be used to control
234 // focus and visibility for this frame.
235 RenderWidgetHostView
* GetView();
237 // This function is called when this is a swapped out RenderFrameHost that
238 // lives in the same process as the parent frame. The
239 // |cross_process_frame_connector| allows the non-swapped-out
240 // RenderFrameHost for a frame to communicate with the parent process
241 // so that it may composite drawing data.
243 // Ownership is not transfered.
244 void set_cross_process_frame_connector(
245 CrossProcessFrameConnector
* cross_process_frame_connector
) {
246 cross_process_frame_connector_
= cross_process_frame_connector
;
249 void set_render_frame_proxy_host(RenderFrameProxyHost
* proxy
) {
250 render_frame_proxy_host_
= proxy
;
253 // Returns a bitwise OR of bindings types that have been enabled for this
254 // RenderFrameHostImpl's RenderView. See BindingsPolicy for details.
255 // TODO(creis): Make bindings frame-specific, to support cases like <webview>.
256 int GetEnabledBindings();
258 NavigationHandleImpl
* navigation_handle() const {
259 return navigation_handle_
.get();
262 // Called when a new navigation starts in this RenderFrameHost. Ownership of
263 // |navigation_handle| is transferred.
264 // PlzNavigate: called when a navigation is ready to commit in this
266 void SetNavigationHandle(scoped_ptr
<NavigationHandleImpl
> navigation_handle
);
268 // Gives the ownership of |navigation_handle_| to the caller.
269 // This happens during transfer navigations, where it should be transferred
270 // from the RenderFrameHost that issued the initial request to the new
271 // RenderFrameHost that will issue the transferring request.
272 scoped_ptr
<NavigationHandleImpl
> PassNavigationHandleOwnership();
274 // Called on the pending RenderFrameHost when the network response is ready to
275 // commit. We should ensure that the old RenderFrameHost runs its unload
276 // handler and determine whether a transfer to a different RenderFrameHost is
278 void OnCrossSiteResponse(
279 const GlobalRequestID
& global_request_id
,
280 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request
,
281 const std::vector
<GURL
>& transfer_url_chain
,
282 const Referrer
& referrer
,
283 ui::PageTransition page_transition
,
284 bool should_replace_current_entry
);
286 // Tells the renderer that this RenderFrame is being swapped out for one in a
287 // different renderer process. It should run its unload handler and move to
288 // a blank document. If |proxy| is not null, it should also create a
289 // RenderFrameProxy to replace the RenderFrame and set it to |is_loading|
290 // state. The renderer should preserve the RenderFrameProxy object until it
291 // exits, in case we come back. The renderer can exit if it has no other
292 // active RenderFrames, but not until WasSwappedOut is called.
293 void SwapOut(RenderFrameProxyHost
* proxy
, bool is_loading
);
295 // Whether an ongoing navigation is waiting for a BeforeUnload ACK from the
296 // RenderFrame. Currently this only happens in cross-site navigations.
297 // PlzNavigate: this happens in every browser-initiated navigation that is not
299 bool is_waiting_for_beforeunload_ack() const {
300 return is_waiting_for_beforeunload_ack_
;
303 // Whether the RFH is waiting for an unload ACK from the renderer.
304 bool IsWaitingForUnloadACK() const;
306 // Called when either the SwapOut request has been acknowledged or has timed
310 // Whether this RenderFrameHost has been swapped out, such that the frame is
311 // now rendered by a RenderFrameHost in a different process.
312 bool is_swapped_out() const { return rfh_state_
== STATE_SWAPPED_OUT
; }
314 // The current state of this RFH.
315 RenderFrameHostImplState
rfh_state() const { return rfh_state_
; }
317 // Sends the given navigation message. Use this rather than sending it
318 // yourself since this does the internal bookkeeping described below. This
319 // function takes ownership of the provided message pointer.
321 // If a cross-site request is in progress, we may be suspended while waiting
322 // for the onbeforeunload handler, so this function might buffer the message
323 // rather than sending it.
324 void Navigate(const CommonNavigationParams
& common_params
,
325 const StartNavigationParams
& start_params
,
326 const RequestNavigationParams
& request_params
);
328 // Load the specified URL; this is a shortcut for Navigate().
329 void NavigateToURL(const GURL
& url
);
331 // Treat this prospective navigation as though it originated from the frame.
332 // Used, e.g., for a navigation request that originated from a RemoteFrame.
333 // |source_site_instance| is the SiteInstance of the frame that initiated the
335 // TODO(creis): Remove this method and have RenderFrameProxyHost call
336 // RequestOpenURL with its FrameTreeNode.
337 void OpenURL(const FrameHostMsg_OpenURL_Params
& params
,
338 SiteInstance
* source_site_instance
);
340 // Stop the load in progress.
343 // Returns whether navigation messages are currently suspended for this
344 // RenderFrameHost. Only true during a cross-site navigation, while waiting
345 // for the onbeforeunload handler.
346 bool are_navigations_suspended() const { return navigations_suspended_
; }
348 // Suspends (or unsuspends) any navigation messages from being sent from this
349 // RenderFrameHost. This is called when a pending RenderFrameHost is created
350 // for a cross-site navigation, because we must suspend any navigations until
351 // we hear back from the old renderer's onbeforeunload handler. Note that it
352 // is important that only one navigation event happen after calling this
353 // method with |suspend| equal to true. If |suspend| is false and there is a
354 // suspended_nav_message_, this will send the message. This function should
355 // only be called to toggle the state; callers should check
356 // are_navigations_suspended() first. If |suspend| is false, the time that the
357 // user decided the navigation should proceed should be passed as
359 void SetNavigationsSuspended(bool suspend
,
360 const base::TimeTicks
& proceed_time
);
362 // Clears any suspended navigation state after a cross-site navigation is
363 // canceled or suspended. This is important if we later return to this
365 void CancelSuspendedNavigations();
367 // Runs the beforeunload handler for this frame. |for_navigation| indicates
368 // whether this call is for the current frame during a cross-process
369 // navigation. False means we're closing the entire tab.
370 // PlzNavigate: this call happens on all browser-initiated navigations.
371 void DispatchBeforeUnload(bool for_navigation
);
373 // Returns true if a call to DispatchBeforeUnload will actually send the
374 // BeforeUnload IPC. This is the case if the current renderer is live and this
375 // frame is the main frame.
376 bool ShouldDispatchBeforeUnload();
378 // Set the frame's opener to null in the renderer process in response to an
379 // action in another renderer process.
382 // Deletes the current selection plus the specified number of characters
383 // before and after the selection or caret.
384 void ExtendSelectionAndDelete(size_t before
, size_t after
);
386 // Notifies the RenderFrame that the JavaScript message that was shown was
387 // closed by the user.
388 void JavaScriptDialogClosed(IPC::Message
* reply_msg
,
390 const base::string16
& user_input
,
391 bool dialog_was_suppressed
);
393 // Send a message to the renderer process to change the accessibility mode.
394 void SetAccessibilityMode(AccessibilityMode AccessibilityMode
);
396 // Request a one-time snapshot of the accessibility tree without changing
397 // the accessibility mode.
398 void RequestAXTreeSnapshot(AXTreeSnapshotCallback callback
);
400 // Resets the accessibility serializer in the renderer.
401 void AccessibilityReset();
403 // Turn on accessibility testing. The given callback will be run
404 // every time an accessibility notification is received from the
405 // renderer process, and the accessibility tree it sent can be
406 // retrieved using GetAXTreeForTesting().
407 void SetAccessibilityCallbackForTesting(
408 const base::Callback
<void(ui::AXEvent
, int)>& callback
);
410 // Send a message to the render process to change text track style settings.
411 void SetTextTrackSettings(const FrameMsg_TextTrackSettings_Params
& params
);
413 // Returns a snapshot of the accessibility tree received from the
414 // renderer as of the last time an accessibility notification was
416 const ui::AXTree
* GetAXTreeForTesting();
418 // Access the BrowserAccessibilityManager if it already exists.
419 BrowserAccessibilityManager
* browser_accessibility_manager() const {
420 return browser_accessibility_manager_
.get();
423 // If accessibility is enabled, get the BrowserAccessibilityManager for
424 // this frame, or create one if it doesn't exist yet, otherwise return
426 BrowserAccessibilityManager
* GetOrCreateBrowserAccessibilityManager();
428 void set_no_create_browser_accessibility_manager_for_testing(bool flag
) {
429 no_create_browser_accessibility_manager_for_testing_
= flag
;
433 void SetParentNativeViewAccessible(
434 gfx::NativeViewAccessible accessible_parent
);
435 gfx::NativeViewAccessible
GetParentNativeViewAccessible() const;
436 #elif defined(OS_MACOSX)
437 // Select popup menu related methods (for external popup menus).
438 void DidSelectPopupMenuItem(int selected_index
);
439 void DidCancelPopupMenu();
440 #elif defined(OS_ANDROID)
441 void DidSelectPopupMenuItems(const std::vector
<int>& selected_indices
);
442 void DidCancelPopupMenu();
445 // PlzNavigate: Indicates that a navigation is ready to commit and can be
446 // handled by this RenderFrame.
447 void CommitNavigation(ResourceResponse
* response
,
448 scoped_ptr
<StreamHandle
> body
,
449 const CommonNavigationParams
& common_params
,
450 const RequestNavigationParams
& request_params
);
453 // Indicates that a navigation failed and that this RenderFrame should display
455 void FailedNavigation(const CommonNavigationParams
& common_params
,
456 const RequestNavigationParams
& request_params
,
457 bool has_stale_copy_in_cache
,
460 // Sets up the Mojo connection between this instance and its associated render
461 // frame if it has not yet been set up.
462 void SetUpMojoIfNeeded();
464 // Tears down the browser-side state relating to the Mojo connection between
465 // this instance and its associated render frame.
466 void InvalidateMojoConnection();
468 // Returns whether the frame is focused. A frame is considered focused when it
469 // is the parent chain of the focused frame within the frame tree. In
470 // addition, its associated RenderWidgetHost has to be focused.
473 // Returns the Mojo ImageDownloader service.
474 const image_downloader::ImageDownloaderPtr
& GetMojoImageDownloader();
477 friend class RenderFrameHostFactory
;
479 // |flags| is a combination of CreateRenderFrameFlags.
480 // TODO(nasko): Remove dependency on RenderViewHost here. RenderProcessHost
481 // should be the abstraction needed here, but we need RenderViewHost to pass
482 // into WebContentsObserver::FrameDetached for now.
483 RenderFrameHostImpl(SiteInstance
* site_instance
,
484 RenderViewHostImpl
* render_view_host
,
485 RenderFrameHostDelegate
* delegate
,
486 RenderWidgetHostDelegate
* rwh_delegate
,
487 FrameTree
* frame_tree
,
488 FrameTreeNode
* frame_tree_node
,
493 friend class TestRenderFrameHost
;
494 friend class TestRenderViewHost
;
496 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest
, CrashSubframe
);
498 // IPC Message handlers.
499 void OnAddMessageToConsole(int32 level
,
500 const base::string16
& message
,
502 const base::string16
& source_id
);
504 void OnFrameFocused();
505 void OnOpenURL(const FrameHostMsg_OpenURL_Params
& params
);
506 void OnDocumentOnLoadCompleted(
507 FrameMsg_UILoadMetricsReportType::Value report_type
,
508 base::TimeTicks ui_timestamp
);
509 void OnDidStartProvisionalLoadForFrame(const GURL
& url
);
510 void OnDidFailProvisionalLoadWithError(
511 const FrameHostMsg_DidFailProvisionalLoadWithError_Params
& params
);
512 void OnDidFailLoadWithError(
515 const base::string16
& error_description
,
516 bool was_ignored_by_handler
);
517 void OnDidCommitProvisionalLoad(const IPC::Message
& msg
);
518 void OnDidDropNavigation();
519 void OnBeforeUnloadACK(
521 const base::TimeTicks
& renderer_before_unload_start_time
,
522 const base::TimeTicks
& renderer_before_unload_end_time
);
524 void OnRenderProcessGone(int status
, int error_code
);
525 void OnContextMenu(const ContextMenuParams
& params
);
526 void OnJavaScriptExecuteResponse(int id
, const base::ListValue
& result
);
527 void OnVisualStateResponse(uint64 id
);
528 void OnRunJavaScriptMessage(const base::string16
& message
,
529 const base::string16
& default_prompt
,
530 const GURL
& frame_url
,
531 JavaScriptMessageType type
,
532 IPC::Message
* reply_msg
);
533 void OnRunBeforeUnloadConfirm(const GURL
& frame_url
,
534 const base::string16
& message
,
536 IPC::Message
* reply_msg
);
537 void OnTextSurroundingSelectionResponse(const base::string16
& content
,
540 void OnDidAccessInitialDocument();
541 void OnDidDisownOpener();
542 void OnDidChangeName(const std::string
& name
);
543 void OnDidAssignPageId(int32 page_id
);
544 void OnDidChangeSandboxFlags(int32 frame_routing_id
,
545 blink::WebSandboxFlags flags
);
546 void OnUpdateTitle(const base::string16
& title
,
547 blink::WebTextDirection title_direction
);
548 void OnUpdateEncoding(const std::string
& encoding
);
549 void OnBeginNavigation(const CommonNavigationParams
& common_params
,
550 const BeginNavigationParams
& begin_params
,
551 scoped_refptr
<ResourceRequestBody
> body
);
552 void OnDispatchLoad();
553 void OnAccessibilityEvents(
554 const std::vector
<AccessibilityHostMsg_EventParams
>& params
,
556 void OnAccessibilityLocationChanges(
557 const std::vector
<AccessibilityHostMsg_LocationChangeParams
>& params
);
558 void OnAccessibilityFindInPageResult(
559 const AccessibilityHostMsg_FindInPageResultParams
& params
);
560 void OnAccessibilitySnapshotResponse(int callback_id
,
561 const ui::AXTreeUpdate
& snapshot
);
562 void OnToggleFullscreen(bool enter_fullscreen
);
563 void OnDidStartLoading(bool to_different_document
);
564 void OnDidStopLoading();
565 void OnDidChangeLoadProgress(double load_progress
);
567 #if defined(OS_MACOSX) || defined(OS_ANDROID)
568 void OnShowPopup(const FrameHostMsg_ShowPopup_Params
& params
);
572 // Registers Mojo services that this frame host makes available.
573 void RegisterMojoServices();
575 // Updates the state of this RenderFrameHost and clears any waiting state
576 // that is no longer relevant.
577 void SetState(RenderFrameHostImplState rfh_state
);
579 // Returns whether the given URL is allowed to commit in the current process.
580 // This is a more conservative check than RenderProcessHost::FilterURL, since
581 // it will be used to kill processes that commit unauthorized URLs.
582 bool CanCommitURL(const GURL
& url
);
584 // Update the the singleton FrameAccessibility instance with a map
585 // from accessibility node id to the frame routing id of a cross-process
587 void UpdateCrossProcessIframeAccessibility(
588 const std::map
<int32
, int>& node_to_frame_routing_id_map
);
590 // Update the the singleton FrameAccessibility instance with a map
591 // from accessibility node id to the browser plugin instance id of a
592 // guest WebContents.
593 void UpdateGuestFrameAccessibility(
594 const std::map
<int32
, int>& node_to_browser_plugin_instance_id_map
);
596 // Asserts that the given RenderFrameHostImpl is part of the same browser
597 // context (and crashes if not), then returns whether the given frame is
598 // part of the same site instance.
599 bool IsSameSiteInstance(RenderFrameHostImpl
* other_render_frame_host
);
601 // Informs the content client that geolocation permissions were used.
602 void DidUseGeolocationPermission();
604 void UpdatePermissionsForNavigation(
605 const CommonNavigationParams
& common_params
,
606 const RequestNavigationParams
& request_params
);
608 // Returns true if the ExecuteJavaScript() API can be used on this host.
609 bool CanExecuteJavaScript();
611 // For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
612 // refcount that calls Shutdown when it reaches zero. This allows each
613 // RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
614 // we have a RenderViewHost for each RenderFrameHost.
615 // TODO(creis): RenderViewHost will eventually go away and be replaced with
616 // some form of page context.
617 RenderViewHostImpl
* render_view_host_
;
619 RenderFrameHostDelegate
* delegate_
;
621 // The SiteInstance associated with this RenderFrameHost. All content drawn
622 // in this RenderFrameHost is part of this SiteInstance. Cannot change over
624 scoped_refptr
<SiteInstanceImpl
> site_instance_
;
626 // The renderer process this RenderFrameHost is associated with. It is
627 // equivalent to the result of site_instance_->GetProcess(), but that
628 // method has the side effect of creating the process if it doesn't exist.
629 // Cache a pointer to avoid unnecessary process creation.
630 RenderProcessHost
* process_
;
632 // |cross_process_frame_connector_| passes messages from an out-of-process
633 // child frame to the parent process for compositing.
635 // This is only non-NULL when this is the swapped out RenderFrameHost in
636 // the same site instance as this frame's parent.
638 // See the class comment above CrossProcessFrameConnector for more
641 // This will move to RenderFrameProxyHost when that class is created.
642 CrossProcessFrameConnector
* cross_process_frame_connector_
;
644 // The proxy created for this RenderFrameHost. It is used to send and receive
645 // IPC messages while in swapped out state.
646 // TODO(nasko): This can be removed once we don't have a swapped out state on
647 // RenderFrameHosts. See https://crbug.com/357747.
648 RenderFrameProxyHost
* render_frame_proxy_host_
;
650 // Reference to the whole frame tree that this RenderFrameHost belongs to.
651 // Allows this RenderFrameHost to add and remove nodes in response to
652 // messages from the renderer requesting DOM manipulation.
653 FrameTree
* frame_tree_
;
655 // The FrameTreeNode which this RenderFrameHostImpl is hosted in.
656 FrameTreeNode
* frame_tree_node_
;
658 // The mapping of pending JavaScript calls created by
659 // ExecuteJavaScript and their corresponding callbacks.
660 std::map
<int, JavaScriptResultCallback
> javascript_callbacks_
;
661 std::map
<uint64
, VisualStateCallback
> visual_state_callbacks_
;
663 // RenderFrameHosts that need management of the rendering and input events
664 // for their frame subtrees require RenderWidgetHosts. This typically
665 // means frames that are rendered in different processes from their parent
667 // TODO(kenrb): Later this will also be used on the top-level frame, when
668 // RenderFrameHost owns its RenderViewHost.
669 RenderWidgetHostImpl
* render_widget_host_
;
673 // The current state of this RenderFrameHost.
674 RenderFrameHostImplState rfh_state_
;
676 // Tracks whether the RenderFrame for this RenderFrameHost has been created in
677 // the renderer process. Currently only used for subframes.
678 // TODO(creis): Use this for main frames as well when RVH goes away.
679 bool render_frame_created_
;
681 // Whether we should buffer outgoing Navigate messages rather than sending
682 // them. This will be true when a RenderFrameHost is created for a cross-site
683 // request, until we hear back from the onbeforeunload handler of the old
685 bool navigations_suspended_
;
687 // Holds the parameters for a suspended navigation. This can only happen while
688 // this RFH is the pending RenderFrameHost of a RenderFrameHostManager. There
689 // will only ever be one suspended navigation, because RenderFrameHostManager
690 // will destroy the pending RenderFrameHost and create a new one if a second
691 // navigation occurs.
692 // PlzNavigate: unused as navigations are never suspended.
693 scoped_ptr
<NavigationParams
> suspended_nav_params_
;
695 // When the last BeforeUnload message was sent.
696 base::TimeTicks send_before_unload_start_time_
;
698 // Set to true when there is a pending FrameMsg_BeforeUnload message. This
699 // ensures we don't spam the renderer with multiple beforeunload requests.
700 // When either this value or IsWaitingForUnloadACK is true, the value of
701 // unload_ack_is_for_cross_site_transition_ indicates whether this is for a
702 // cross-site transition or a tab close attempt.
703 // TODO(clamy): Remove this boolean and add one more state to the state
705 bool is_waiting_for_beforeunload_ack_
;
707 // Valid only when is_waiting_for_beforeunload_ack_ or
708 // IsWaitingForUnloadACK is true. This tells us if the unload request
709 // is for closing the entire tab ( = false), or only this RenderFrameHost in
710 // the case of a navigation ( = true). Currently only cross-site navigations
711 // require a beforeUnload/unload ACK.
712 // PlzNavigate: all navigations require a beforeUnload ACK.
713 bool unload_ack_is_for_navigation_
;
715 // Indicates whether this RenderFrameHost is in the process of loading a
720 // Used to track whether a commit is expected in this frame. Only used in
722 bool pending_commit_
;
724 // Used to swap out or shut down this RFH when the unload event is taking too
725 // long to execute, depending on the number of active frames in the
727 scoped_ptr
<TimeoutMonitor
> swapout_event_monitor_timeout_
;
729 scoped_ptr
<ServiceRegistryImpl
> service_registry_
;
731 #if defined(OS_ANDROID)
732 scoped_ptr
<ServiceRegistryAndroid
> service_registry_android_
;
735 // The object managing the accessibility tree for this frame.
736 scoped_ptr
<BrowserAccessibilityManager
> browser_accessibility_manager_
;
738 // This is nonzero if we sent an accessibility reset to the renderer and
739 // we're waiting for an IPC containing this reset token (sequentially
740 // assigned) and a complete replacement accessibility tree.
741 int accessibility_reset_token_
;
743 // A count of the number of times we needed to reset accessibility, so
744 // we don't keep trying to reset forever.
745 int accessibility_reset_count_
;
747 // The mapping from callback id to corresponding callback for pending
748 // accessibility tree snapshot calls created by RequestAXTreeSnapshot.
749 std::map
<int, AXTreeSnapshotCallback
> ax_tree_snapshot_callbacks_
;
751 // Callback when an event is received, for testing.
752 base::Callback
<void(ui::AXEvent
, int)> accessibility_testing_callback_
;
753 // The most recently received accessibility tree - for testing only.
754 scoped_ptr
<ui::AXTree
> ax_tree_for_testing_
;
755 // Flag to not create a BrowserAccessibilityManager, for testing. If one
756 // already exists it will still be used.
757 bool no_create_browser_accessibility_manager_for_testing_
;
759 // PlzNavigate: Owns the stream used in navigations to store the body of the
760 // response once it has started.
761 scoped_ptr
<StreamHandle
> stream_handle_
;
763 // Context shared for each PermissionService instance created for this RFH.
764 scoped_ptr
<PermissionServiceContext
> permission_service_context_
;
766 // The frame's Mojo Shell service.
767 scoped_ptr
<FrameMojoShell
> frame_mojo_shell_
;
769 // Holder of Mojo connection with ImageDownloader service in RenderFrame.
770 image_downloader::ImageDownloaderPtr mojo_image_downloader_
;
772 // Tracks a navigation happening in this frame. Note that while there can be
773 // two navigations in the same FrameTreeNode, there can only be one
774 // navigation per RenderFrameHost.
775 // PlzNavigate: before the navigation is ready to be committed, the
776 // NavigationHandle for it is owned by the NavigationRequest.
777 scoped_ptr
<NavigationHandleImpl
> navigation_handle_
;
779 // NOTE: This must be the last member.
780 base::WeakPtrFactory
<RenderFrameHostImpl
> weak_ptr_factory_
;
782 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl
);
785 } // namespace content
787 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_