Roll ANGLE e754fb8..6ffeb74
[chromium-blink-merge.git] / content / browser / frame_host / render_frame_host_impl.h
blob1d0188516c689326f5f1f6ab0ba62ce80ab90499
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_
8 #include <map>
9 #include <vector>
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"
35 #endif
37 class GURL;
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;
46 #endif
48 namespace base {
49 class FilePath;
50 class ListValue;
53 namespace content {
55 class CrossProcessFrameConnector;
56 class CrossSiteTransferringRequest;
57 class FrameMojoShell;
58 class FrameTree;
59 class FrameTreeNode;
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;
69 class StreamHandle;
70 class TimeoutMonitor;
71 struct ContextMenuParams;
72 struct GlobalRequestID;
73 struct Referrer;
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
81 // top-level frame.
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 {
94 public:
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
102 // RenderFrame.
103 STATE_DEFAULT = 0,
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.
112 STATE_SWAPPED_OUT,
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;
127 // RenderFrameHost
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;
154 // IPC::Sender
155 bool Send(IPC::Message* msg) override;
157 // IPC::Listener
158 bool OnMessageReceived(const IPC::Message& msg) override;
160 // BrowserAccessibilityDelegate
161 void AccessibilitySetFocus(int acc_obj_id) override;
162 void AccessibilityDoDefaultAction(int acc_obj_id) override;
163 void AccessibilityShowContextMenu(int acc_obj_id) override;
164 void AccessibilityScrollToMakeVisible(int acc_obj_id,
165 const gfx::Rect& subfocus) override;
166 void AccessibilityScrollToPoint(int acc_obj_id,
167 const gfx::Point& point) override;
168 void AccessibilitySetTextSelection(int acc_obj_id,
169 int start_offset,
170 int end_offset) override;
171 void AccessibilitySetValue(int acc_obj_id, const base::string16& value)
172 override;
173 bool AccessibilityViewHasFocus() const override;
174 gfx::Rect AccessibilityGetViewBounds() const override;
175 gfx::Point AccessibilityOriginInScreen(
176 const gfx::Rect& bounds) const override;
177 void AccessibilityHitTest(const gfx::Point& point) override;
178 void AccessibilitySetAccessibilityFocus(int acc_obj_id) override;
179 void AccessibilityFatalError() override;
180 gfx::AcceleratedWidget AccessibilityGetAcceleratedWidget() override;
181 gfx::NativeViewAccessible AccessibilityGetNativeViewAccessible() override;
182 BrowserAccessibilityManager* AccessibilityGetChildFrame(
183 int accessibility_node_id) override;
184 void AccessibilityGetAllChildFrames(
185 std::vector<BrowserAccessibilityManager*>* child_frames) override;
186 BrowserAccessibility* AccessibilityGetParentFrame() override;
188 // Creates a RenderFrame in the renderer process. Only called for
189 // cross-process subframe navigations in --site-per-process.
190 bool CreateRenderFrame(int parent_routing_id,
191 int previous_sibling_routing_id,
192 int proxy_routing_id);
194 // Returns whether the RenderFrame in the renderer process has been created
195 // and still has a connection. This is valid for all frames.
196 bool IsRenderFrameLive();
198 // Tracks whether the RenderFrame for this RenderFrameHost has been created in
199 // the renderer process. This is currently only used for subframes.
200 // TODO(creis): Use this for main frames as well when RVH goes away.
201 void SetRenderFrameCreated(bool created);
203 // Called for renderer-created windows to resume requests from this frame,
204 // after they are blocked in RenderWidgetHelper::CreateNewWindow.
205 void Init();
207 int routing_id() const { return routing_id_; }
208 void OnCreateChildFrame(int new_routing_id,
209 blink::WebTreeScopeType scope,
210 const std::string& frame_name,
211 blink::WebSandboxFlags sandbox_flags);
213 RenderViewHostImpl* render_view_host() { return render_view_host_; }
214 RenderFrameHostDelegate* delegate() { return delegate_; }
215 FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
217 // Returns this RenderFrameHost's loading state. This method is only used by
218 // FrameTreeNode. The proper way to check whether a frame is loading is to
219 // call FrameTreeNode::IsLoading.
220 bool is_loading() const { return is_loading_; }
222 // This returns the RenderFrameHost's owned RenderWidgetHost if it has one,
223 // or else it returns nullptr.
224 // If the RenderFrameHost is the page's main frame, this returns instead a
225 // pointer to the RenderViewHost (which inherits RenderWidgetHost).
226 RenderWidgetHostImpl* GetRenderWidgetHost();
228 // This returns the RenderWidgetHostView that can be used to control
229 // focus and visibility for this frame.
230 RenderWidgetHostView* GetView();
232 // This function is called when this is a swapped out RenderFrameHost that
233 // lives in the same process as the parent frame. The
234 // |cross_process_frame_connector| allows the non-swapped-out
235 // RenderFrameHost for a frame to communicate with the parent process
236 // so that it may composite drawing data.
238 // Ownership is not transfered.
239 void set_cross_process_frame_connector(
240 CrossProcessFrameConnector* cross_process_frame_connector) {
241 cross_process_frame_connector_ = cross_process_frame_connector;
244 void set_render_frame_proxy_host(RenderFrameProxyHost* proxy) {
245 render_frame_proxy_host_ = proxy;
248 // Returns a bitwise OR of bindings types that have been enabled for this
249 // RenderFrameHostImpl's RenderView. See BindingsPolicy for details.
250 // TODO(creis): Make bindings frame-specific, to support cases like <webview>.
251 int GetEnabledBindings();
253 // Called on the pending RenderFrameHost when the network response is ready to
254 // commit. We should ensure that the old RenderFrameHost runs its unload
255 // handler and determine whether a transfer to a different RenderFrameHost is
256 // needed.
257 void OnCrossSiteResponse(
258 const GlobalRequestID& global_request_id,
259 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request,
260 const std::vector<GURL>& transfer_url_chain,
261 const Referrer& referrer,
262 ui::PageTransition page_transition,
263 bool should_replace_current_entry);
265 // Tells the renderer that this RenderFrame is being swapped out for one in a
266 // different renderer process. It should run its unload handler and move to
267 // a blank document. If |proxy| is not null, it should also create a
268 // RenderFrameProxy to replace the RenderFrame and set it to |is_loading|
269 // state. The renderer should preserve the RenderFrameProxy object until it
270 // exits, in case we come back. The renderer can exit if it has no other
271 // active RenderFrames, but not until WasSwappedOut is called.
272 void SwapOut(RenderFrameProxyHost* proxy, bool is_loading);
274 // Whether an ongoing navigation is waiting for a BeforeUnload ACK from the
275 // RenderFrame. Currently this only happens in cross-site navigations.
276 // PlzNavigate: this happens in every browser-initiated navigation that is not
277 // same-page.
278 bool IsWaitingForBeforeUnloadACK() const;
280 // Whether the RFH is waiting for an unload ACK from the renderer.
281 bool IsWaitingForUnloadACK() const;
283 // Called when either the SwapOut request has been acknowledged or has timed
284 // out.
285 void OnSwappedOut();
287 // Whether this RenderFrameHost has been swapped out, such that the frame is
288 // now rendered by a RenderFrameHost in a different process.
289 bool is_swapped_out() const { return rfh_state_ == STATE_SWAPPED_OUT; }
291 // The current state of this RFH.
292 RenderFrameHostImplState rfh_state() const { return rfh_state_; }
294 // Sends the given navigation message. Use this rather than sending it
295 // yourself since this does the internal bookkeeping described below. This
296 // function takes ownership of the provided message pointer.
298 // If a cross-site request is in progress, we may be suspended while waiting
299 // for the onbeforeunload handler, so this function might buffer the message
300 // rather than sending it.
301 void Navigate(const CommonNavigationParams& common_params,
302 const StartNavigationParams& start_params,
303 const RequestNavigationParams& request_params);
305 // Load the specified URL; this is a shortcut for Navigate().
306 void NavigateToURL(const GURL& url);
308 // Treat this prospective navigation as though it originated from the frame.
309 // Used, e.g., for a navigation request that originated from a RemoteFrame.
310 // |source_site_instance| is the SiteInstance of the frame that initiated the
311 // navigation.
312 // TODO(creis): Remove this method and have RenderFrameProxyHost call
313 // RequestOpenURL with its FrameTreeNode.
314 void OpenURL(const FrameHostMsg_OpenURL_Params& params,
315 SiteInstance* source_site_instance);
317 // Stop the load in progress.
318 void Stop();
320 // Returns whether navigation messages are currently suspended for this
321 // RenderFrameHost. Only true during a cross-site navigation, while waiting
322 // for the onbeforeunload handler.
323 bool are_navigations_suspended() const { return navigations_suspended_; }
325 // Suspends (or unsuspends) any navigation messages from being sent from this
326 // RenderFrameHost. This is called when a pending RenderFrameHost is created
327 // for a cross-site navigation, because we must suspend any navigations until
328 // we hear back from the old renderer's onbeforeunload handler. Note that it
329 // is important that only one navigation event happen after calling this
330 // method with |suspend| equal to true. If |suspend| is false and there is a
331 // suspended_nav_message_, this will send the message. This function should
332 // only be called to toggle the state; callers should check
333 // are_navigations_suspended() first. If |suspend| is false, the time that the
334 // user decided the navigation should proceed should be passed as
335 // |proceed_time|.
336 void SetNavigationsSuspended(bool suspend,
337 const base::TimeTicks& proceed_time);
339 // Clears any suspended navigation state after a cross-site navigation is
340 // canceled or suspended. This is important if we later return to this
341 // RenderFrameHost.
342 void CancelSuspendedNavigations();
344 // Runs the beforeunload handler for this frame. |for_navigation| indicates
345 // whether this call is for the current frame during a cross-process
346 // navigation. False means we're closing the entire tab.
347 // PlzNavigate: this call happens on all browser-initiated navigations.
348 void DispatchBeforeUnload(bool for_navigation);
350 // Set the frame's opener to null in the renderer process in response to an
351 // action in another renderer process.
352 void DisownOpener();
354 // Deletes the current selection plus the specified number of characters
355 // before and after the selection or caret.
356 void ExtendSelectionAndDelete(size_t before, size_t after);
358 // Notifies the RenderFrame that the JavaScript message that was shown was
359 // closed by the user.
360 void JavaScriptDialogClosed(IPC::Message* reply_msg,
361 bool success,
362 const base::string16& user_input,
363 bool dialog_was_suppressed);
365 // Send a message to the renderer process to change the accessibility mode.
366 void SetAccessibilityMode(AccessibilityMode AccessibilityMode);
368 // Request a one-time snapshot of the accessibility tree without changing
369 // the accessibility mode.
370 void RequestAXTreeSnapshot(AXTreeSnapshotCallback callback);
372 // Turn on accessibility testing. The given callback will be run
373 // every time an accessibility notification is received from the
374 // renderer process, and the accessibility tree it sent can be
375 // retrieved using GetAXTreeForTesting().
376 void SetAccessibilityCallbackForTesting(
377 const base::Callback<void(ui::AXEvent, int)>& callback);
379 // Send a message to the render process to change text track style settings.
380 void SetTextTrackSettings(const FrameMsg_TextTrackSettings_Params& params);
382 // Returns a snapshot of the accessibility tree received from the
383 // renderer as of the last time an accessibility notification was
384 // received.
385 const ui::AXTree* GetAXTreeForTesting();
387 // Access the BrowserAccessibilityManager if it already exists.
388 BrowserAccessibilityManager* browser_accessibility_manager() const {
389 return browser_accessibility_manager_.get();
392 // If accessibility is enabled, get the BrowserAccessibilityManager for
393 // this frame, or create one if it doesn't exist yet, otherwise return
394 // NULL.
395 BrowserAccessibilityManager* GetOrCreateBrowserAccessibilityManager();
397 void set_no_create_browser_accessibility_manager_for_testing(bool flag) {
398 no_create_browser_accessibility_manager_for_testing_ = flag;
401 #if defined(OS_WIN)
402 void SetParentNativeViewAccessible(
403 gfx::NativeViewAccessible accessible_parent);
404 gfx::NativeViewAccessible GetParentNativeViewAccessible() const;
405 #elif defined(OS_MACOSX)
406 // Select popup menu related methods (for external popup menus).
407 void DidSelectPopupMenuItem(int selected_index);
408 void DidCancelPopupMenu();
409 #elif defined(OS_ANDROID)
410 void DidSelectPopupMenuItems(const std::vector<int>& selected_indices);
411 void DidCancelPopupMenu();
412 #endif
414 // PlzNavigate: Indicates that a navigation is ready to commit and can be
415 // handled by this RenderFrame.
416 void CommitNavigation(ResourceResponse* response,
417 scoped_ptr<StreamHandle> body,
418 const CommonNavigationParams& common_params,
419 const RequestNavigationParams& request_params);
421 // PlzNavigate
422 // Indicates that a navigation failed and that this RenderFrame should display
423 // an error page.
424 void FailedNavigation(const CommonNavigationParams& common_params,
425 const RequestNavigationParams& request_params,
426 bool has_stale_copy_in_cache,
427 int error_code);
429 // Sets up the Mojo connection between this instance and its associated render
430 // frame if it has not yet been set up.
431 void SetUpMojoIfNeeded();
433 // Tears down the browser-side state relating to the Mojo connection between
434 // this instance and its associated render frame.
435 void InvalidateMojoConnection();
437 // Returns whether the frame is focused. A frame is considered focused when it
438 // is the parent chain of the focused frame within the frame tree. In
439 // addition, its associated RenderWidgetHost has to be focused.
440 bool IsFocused();
442 protected:
443 friend class RenderFrameHostFactory;
445 // |flags| is a combination of CreateRenderFrameFlags.
446 // TODO(nasko): Remove dependency on RenderViewHost here. RenderProcessHost
447 // should be the abstraction needed here, but we need RenderViewHost to pass
448 // into WebContentsObserver::FrameDetached for now.
449 RenderFrameHostImpl(SiteInstance* site_instance,
450 RenderViewHostImpl* render_view_host,
451 RenderFrameHostDelegate* delegate,
452 RenderWidgetHostDelegate* rwh_delegate,
453 FrameTree* frame_tree,
454 FrameTreeNode* frame_tree_node,
455 int routing_id,
456 int flags);
458 private:
459 friend class TestRenderFrameHost;
460 friend class TestRenderViewHost;
462 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest, CrashSubframe);
464 // IPC Message handlers.
465 void OnAddMessageToConsole(int32 level,
466 const base::string16& message,
467 int32 line_no,
468 const base::string16& source_id);
469 void OnDetach();
470 void OnFrameFocused();
471 void OnOpenURL(const FrameHostMsg_OpenURL_Params& params);
472 void OnDocumentOnLoadCompleted(
473 FrameMsg_UILoadMetricsReportType::Value report_type,
474 base::TimeTicks ui_timestamp);
475 void OnDidStartProvisionalLoadForFrame(const GURL& url);
476 void OnDidFailProvisionalLoadWithError(
477 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params);
478 void OnDidFailLoadWithError(
479 const GURL& url,
480 int error_code,
481 const base::string16& error_description);
482 void OnDidCommitProvisionalLoad(const IPC::Message& msg);
483 void OnDidDropNavigation();
484 void OnBeforeUnloadACK(
485 bool proceed,
486 const base::TimeTicks& renderer_before_unload_start_time,
487 const base::TimeTicks& renderer_before_unload_end_time);
488 void OnSwapOutACK();
489 void OnRenderProcessGone(int status, int error_code);
490 void OnContextMenu(const ContextMenuParams& params);
491 void OnJavaScriptExecuteResponse(int id, const base::ListValue& result);
492 void OnVisualStateResponse(uint64 id);
493 void OnRunJavaScriptMessage(const base::string16& message,
494 const base::string16& default_prompt,
495 const GURL& frame_url,
496 JavaScriptMessageType type,
497 IPC::Message* reply_msg);
498 void OnRunBeforeUnloadConfirm(const GURL& frame_url,
499 const base::string16& message,
500 bool is_reload,
501 IPC::Message* reply_msg);
502 void OnTextSurroundingSelectionResponse(const base::string16& content,
503 size_t start_offset,
504 size_t end_offset);
505 void OnDidAccessInitialDocument();
506 void OnDidDisownOpener();
507 void OnDidChangeName(const std::string& name);
508 void OnDidAssignPageId(int32 page_id);
509 void OnDidChangeSandboxFlags(int32 frame_routing_id,
510 blink::WebSandboxFlags flags);
511 void OnUpdateTitle(const base::string16& title,
512 blink::WebTextDirection title_direction);
513 void OnUpdateEncoding(const std::string& encoding);
514 void OnBeginNavigation(const CommonNavigationParams& common_params,
515 const BeginNavigationParams& begin_params,
516 scoped_refptr<ResourceRequestBody> body);
517 void OnDispatchLoad();
518 void OnAccessibilityEvents(
519 const std::vector<AccessibilityHostMsg_EventParams>& params,
520 int reset_token);
521 void OnAccessibilityLocationChanges(
522 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params);
523 void OnAccessibilityFindInPageResult(
524 const AccessibilityHostMsg_FindInPageResultParams& params);
525 void OnAccessibilitySnapshotResponse(int callback_id,
526 const ui::AXTreeUpdate& snapshot);
527 void OnToggleFullscreen(bool enter_fullscreen);
528 void OnDidStartLoading(bool to_different_document);
529 void OnDidStopLoading();
530 void OnDidChangeLoadProgress(double load_progress);
532 #if defined(OS_MACOSX) || defined(OS_ANDROID)
533 void OnShowPopup(const FrameHostMsg_ShowPopup_Params& params);
534 void OnHidePopup();
535 #endif
537 // Registers Mojo services that this frame host makes available.
538 void RegisterMojoServices();
540 // Updates the state of this RenderFrameHost and clears any waiting state
541 // that is no longer relevant.
542 void SetState(RenderFrameHostImplState rfh_state);
544 // Returns whether the given URL is allowed to commit in the current process.
545 // This is a more conservative check than RenderProcessHost::FilterURL, since
546 // it will be used to kill processes that commit unauthorized URLs.
547 bool CanCommitURL(const GURL& url);
549 // Update the the singleton FrameAccessibility instance with a map
550 // from accessibility node id to the frame routing id of a cross-process
551 // iframe.
552 void UpdateCrossProcessIframeAccessibility(
553 const std::map<int32, int>& node_to_frame_routing_id_map);
555 // Update the the singleton FrameAccessibility instance with a map
556 // from accessibility node id to the browser plugin instance id of a
557 // guest WebContents.
558 void UpdateGuestFrameAccessibility(
559 const std::map<int32, int>& node_to_browser_plugin_instance_id_map);
561 // Asserts that the given RenderFrameHostImpl is part of the same browser
562 // context (and crashes if not), then returns whether the given frame is
563 // part of the same site instance.
564 bool IsSameSiteInstance(RenderFrameHostImpl* other_render_frame_host);
566 // Informs the content client that geolocation permissions were used.
567 void DidUseGeolocationPermission();
569 void UpdatePermissionsForNavigation(
570 const CommonNavigationParams& common_params,
571 const RequestNavigationParams& request_params);
573 // For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
574 // refcount that calls Shutdown when it reaches zero. This allows each
575 // RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
576 // we have a RenderViewHost for each RenderFrameHost.
577 // TODO(creis): RenderViewHost will eventually go away and be replaced with
578 // some form of page context.
579 RenderViewHostImpl* render_view_host_;
581 RenderFrameHostDelegate* delegate_;
583 // The SiteInstance associated with this RenderFrameHost. All content drawn
584 // in this RenderFrameHost is part of this SiteInstance. Cannot change over
585 // time.
586 scoped_refptr<SiteInstanceImpl> site_instance_;
588 // The renderer process this RenderFrameHost is associated with. It is
589 // equivalent to the result of site_instance_->GetProcess(), but that
590 // method has the side effect of creating the process if it doesn't exist.
591 // Cache a pointer to avoid unnecessary process creation.
592 RenderProcessHost* process_;
594 // |cross_process_frame_connector_| passes messages from an out-of-process
595 // child frame to the parent process for compositing.
597 // This is only non-NULL when this is the swapped out RenderFrameHost in
598 // the same site instance as this frame's parent.
600 // See the class comment above CrossProcessFrameConnector for more
601 // information.
603 // This will move to RenderFrameProxyHost when that class is created.
604 CrossProcessFrameConnector* cross_process_frame_connector_;
606 // The proxy created for this RenderFrameHost. It is used to send and receive
607 // IPC messages while in swapped out state.
608 // TODO(nasko): This can be removed once we don't have a swapped out state on
609 // RenderFrameHosts. See https://crbug.com/357747.
610 RenderFrameProxyHost* render_frame_proxy_host_;
612 // Reference to the whole frame tree that this RenderFrameHost belongs to.
613 // Allows this RenderFrameHost to add and remove nodes in response to
614 // messages from the renderer requesting DOM manipulation.
615 FrameTree* frame_tree_;
617 // The FrameTreeNode which this RenderFrameHostImpl is hosted in.
618 FrameTreeNode* frame_tree_node_;
620 // The mapping of pending JavaScript calls created by
621 // ExecuteJavaScript and their corresponding callbacks.
622 std::map<int, JavaScriptResultCallback> javascript_callbacks_;
623 std::map<uint64, VisualStateCallback> visual_state_callbacks_;
625 // RenderFrameHosts that need management of the rendering and input events
626 // for their frame subtrees require RenderWidgetHosts. This typically
627 // means frames that are rendered in different processes from their parent
628 // frames.
629 // TODO(kenrb): Later this will also be used on the top-level frame, when
630 // RenderFrameHost owns its RenderViewHost.
631 RenderWidgetHostImpl* render_widget_host_;
633 int routing_id_;
635 // The current state of this RenderFrameHost.
636 RenderFrameHostImplState rfh_state_;
638 // Tracks whether the RenderFrame for this RenderFrameHost has been created in
639 // the renderer process. Currently only used for subframes.
640 // TODO(creis): Use this for main frames as well when RVH goes away.
641 bool render_frame_created_;
643 // Whether we should buffer outgoing Navigate messages rather than sending
644 // them. This will be true when a RenderFrameHost is created for a cross-site
645 // request, until we hear back from the onbeforeunload handler of the old
646 // RenderFrameHost.
647 bool navigations_suspended_;
649 // Holds the parameters for a suspended navigation. This can only happen while
650 // this RFH is the pending RenderFrameHost of a RenderFrameHostManager. There
651 // will only ever be one suspended navigation, because RenderFrameHostManager
652 // will destroy the pending RenderFrameHost and create a new one if a second
653 // navigation occurs.
654 // PlzNavigate: unused as navigations are never suspended.
655 scoped_ptr<NavigationParams> suspended_nav_params_;
657 // When the last BeforeUnload message was sent.
658 base::TimeTicks send_before_unload_start_time_;
660 // Set to true when there is a pending FrameMsg_ShouldClose message. This
661 // ensures we don't spam the renderer with multiple beforeunload requests.
662 // When either this value or IsWaitingForUnloadACK is true, the value of
663 // unload_ack_is_for_cross_site_transition_ indicates whether this is for a
664 // cross-site transition or a tab close attempt.
665 // TODO(clamy): Remove this boolean and add one more state to the state
666 // machine.
667 bool is_waiting_for_beforeunload_ack_;
669 // Valid only when is_waiting_for_beforeunload_ack_ or
670 // IsWaitingForUnloadACK is true. This tells us if the unload request
671 // is for closing the entire tab ( = false), or only this RenderFrameHost in
672 // the case of a navigation ( = true). Currently only cross-site navigations
673 // require a beforeUnload/unload ACK.
674 // PlzNavigate: all navigations require a beforeUnload ACK.
675 bool unload_ack_is_for_navigation_;
677 // Indicates whether this RenderFrameHost is in the process of loading a
678 // document or not.
679 bool is_loading_;
681 // PlzNavigate
682 // Used to track whether a commit is expected in this frame. Only used in
683 // tests.
684 bool pending_commit_;
686 // Used to swap out or shut down this RFH when the unload event is taking too
687 // long to execute, depending on the number of active frames in the
688 // SiteInstance.
689 scoped_ptr<TimeoutMonitor> swapout_event_monitor_timeout_;
691 scoped_ptr<ServiceRegistryImpl> service_registry_;
693 #if defined(OS_ANDROID)
694 scoped_ptr<ServiceRegistryAndroid> service_registry_android_;
695 #endif
697 // The object managing the accessibility tree for this frame.
698 scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_;
700 // This is nonzero if we sent an accessibility reset to the renderer and
701 // we're waiting for an IPC containing this reset token (sequentially
702 // assigned) and a complete replacement accessibility tree.
703 int accessibility_reset_token_;
705 // A count of the number of times we needed to reset accessibility, so
706 // we don't keep trying to reset forever.
707 int accessibility_reset_count_;
709 // The mapping from callback id to corresponding callback for pending
710 // accessibility tree snapshot calls created by RequestAXTreeSnapshot.
711 std::map<int, AXTreeSnapshotCallback> ax_tree_snapshot_callbacks_;
713 // Callback when an event is received, for testing.
714 base::Callback<void(ui::AXEvent, int)> accessibility_testing_callback_;
715 // The most recently received accessibility tree - for testing only.
716 scoped_ptr<ui::AXTree> ax_tree_for_testing_;
717 // Flag to not create a BrowserAccessibilityManager, for testing. If one
718 // already exists it will still be used.
719 bool no_create_browser_accessibility_manager_for_testing_;
721 // PlzNavigate: Owns the stream used in navigations to store the body of the
722 // response once it has started.
723 scoped_ptr<StreamHandle> stream_handle_;
725 // Context shared for each PermissionService instance created for this RFH.
726 scoped_ptr<PermissionServiceContext> permission_service_context_;
728 // The frame's Mojo Shell service.
729 scoped_ptr<FrameMojoShell> frame_mojo_shell_;
731 // NOTE: This must be the last member.
732 base::WeakPtrFactory<RenderFrameHostImpl> weak_ptr_factory_;
734 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl);
737 } // namespace content
739 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_