Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / content / browser / frame_host / render_frame_host_impl.h
blob498785d2f8f634470b29ffee8f52eed578c04e52
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/ax_content_node_data.h"
21 #include "content/common/content_export.h"
22 #include "content/common/frame_message_enums.h"
23 #include "content/common/frame_replication_state.h"
24 #include "content/common/image_downloader/image_downloader.mojom.h"
25 #include "content/common/mojo/service_registry_impl.h"
26 #include "content/common/navigation_params.h"
27 #include "content/public/browser/render_frame_host.h"
28 #include "content/public/common/javascript_message_type.h"
29 #include "net/http/http_response_headers.h"
30 #include "third_party/WebKit/public/web/WebTextDirection.h"
31 #include "third_party/WebKit/public/web/WebTreeScopeType.h"
32 #include "ui/accessibility/ax_node_data.h"
33 #include "ui/base/page_transition_types.h"
35 #if defined(OS_ANDROID)
36 #include "content/browser/mojo/service_registry_android.h"
37 #endif
39 class GURL;
40 struct AccessibilityHostMsg_EventParams;
41 struct AccessibilityHostMsg_FindInPageResultParams;
42 struct AccessibilityHostMsg_LocationChangeParams;
43 struct FrameHostMsg_DidFailProvisionalLoadWithError_Params;
44 struct FrameHostMsg_OpenURL_Params;
45 struct FrameMsg_TextTrackSettings_Params;
46 #if defined(OS_MACOSX) || defined(OS_ANDROID)
47 struct FrameHostMsg_ShowPopup_Params;
48 #endif
50 namespace base {
51 class FilePath;
52 class ListValue;
55 namespace content {
57 class CrossProcessFrameConnector;
58 class CrossSiteTransferringRequest;
59 class FrameMojoShell;
60 class FrameTree;
61 class FrameTreeNode;
62 class NavigationHandleImpl;
63 class PermissionServiceContext;
64 class RenderFrameHostDelegate;
65 class RenderFrameProxyHost;
66 class RenderProcessHost;
67 class RenderViewHostImpl;
68 class RenderWidgetHostDelegate;
69 class RenderWidgetHostImpl;
70 class RenderWidgetHostView;
71 class ResourceRequestBody;
72 class StreamHandle;
73 class TimeoutMonitor;
74 struct ContextMenuParams;
75 struct GlobalRequestID;
76 struct Referrer;
77 struct ResourceResponse;
79 // Flag arguments for RenderFrameHost creation.
80 enum CreateRenderFrameFlags {
81 // The RFH will be initially placed on the swapped out hosts list.
82 CREATE_RF_SWAPPED_OUT = 1 << 0,
83 // The new RenderFrame is being created for a navigation of the
84 // top-level frame.
85 CREATE_RF_FOR_MAIN_FRAME_NAVIGATION = 1 << 1,
86 // The RenderFrame is initially hidden.
87 CREATE_RF_HIDDEN = 1 << 2,
90 class CONTENT_EXPORT RenderFrameHostImpl
91 : public RenderFrameHost,
92 public BrowserAccessibilityDelegate {
93 public:
94 using AXTreeSnapshotCallback =
95 base::Callback<void(const ui::AXTreeUpdate<ui::AXNodeData>&)>;
97 // Keeps track of the state of the RenderFrameHostImpl, particularly with
98 // respect to swap out.
99 enum RenderFrameHostImplState {
100 // The standard state for a RFH handling the communication with an active
101 // RenderFrame.
102 STATE_DEFAULT = 0,
103 // The RFH has not received the SwapOutACK yet, but the new page has
104 // committed in a different RFH. Upon reception of the SwapOutACK, the RFH
105 // will either enter STATE_SWAPPED_OUT (if it is a main frame and there are
106 // other active frames in its SiteInstance) or it will be deleted.
107 STATE_PENDING_SWAP_OUT,
108 // The RFH is swapped out and stored inside a RenderFrameProxyHost, being
109 // used as a placeholder to allow cross-process communication. Only main
110 // frames can enter this state.
111 STATE_SWAPPED_OUT,
113 // Helper function to determine whether the RFH state should contribute to the
114 // number of active frames of a SiteInstance or not.
115 static bool IsRFHStateActive(RenderFrameHostImplState rfh_state);
117 // An accessibility reset is only allowed to prevent very rare corner cases
118 // or race conditions where the browser and renderer get out of sync. If
119 // this happens more than this many times, kill the renderer.
120 static const int kMaxAccessibilityResets = 5;
122 static RenderFrameHostImpl* FromID(int process_id, int routing_id);
123 static RenderFrameHostImpl* FromAXTreeID(
124 AXTreeIDRegistry::AXTreeID ax_tree_id);
126 ~RenderFrameHostImpl() override;
128 // RenderFrameHost
129 int GetRoutingID() override;
130 AXTreeIDRegistry::AXTreeID GetAXTreeID() 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;
161 // IPC::Sender
162 bool Send(IPC::Message* msg) override;
164 // IPC::Listener
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,
178 int start_offset,
179 int end_offset) override;
180 void AccessibilitySetValue(int acc_obj_id, const base::string16& value)
181 override;
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;
192 // Creates a RenderFrame in the renderer process. Only called for
193 // cross-process subframe navigations in --site-per-process.
194 bool CreateRenderFrame(int proxy_routing_id,
195 int opener_routing_id,
196 int parent_routing_id,
197 int previous_sibling_routing_id);
199 // Tracks whether the RenderFrame for this RenderFrameHost has been created in
200 // the renderer process. This is currently only used for subframes.
201 // TODO(creis): Use this for main frames as well when RVH goes away.
202 void SetRenderFrameCreated(bool created);
204 // Called for renderer-created windows to resume requests from this frame,
205 // after they are blocked in RenderWidgetHelper::CreateNewWindow.
206 void Init();
208 int routing_id() const { return routing_id_; }
209 void OnCreateChildFrame(int new_routing_id,
210 blink::WebTreeScopeType scope,
211 const std::string& frame_name,
212 blink::WebSandboxFlags sandbox_flags);
214 RenderViewHostImpl* render_view_host() { return render_view_host_; }
215 RenderFrameHostDelegate* delegate() { return delegate_; }
216 FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
218 // Returns this RenderFrameHost's loading state. This method is only used by
219 // FrameTreeNode. The proper way to check whether a frame is loading is to
220 // call FrameTreeNode::IsLoading.
221 bool is_loading() const { return is_loading_; }
223 // This returns the RenderFrameHost's owned RenderWidgetHost if it has one,
224 // or else it returns nullptr.
225 // If the RenderFrameHost is the page's main frame, this returns instead a
226 // pointer to the RenderViewHost (which inherits RenderWidgetHost).
227 RenderWidgetHostImpl* GetRenderWidgetHost();
229 // This returns the RenderWidgetHostView that can be used to control
230 // focus and visibility for this frame.
231 RenderWidgetHostView* GetView();
233 // This function is called when this is a swapped out RenderFrameHost that
234 // lives in the same process as the parent frame. The
235 // |cross_process_frame_connector| allows the non-swapped-out
236 // RenderFrameHost for a frame to communicate with the parent process
237 // so that it may composite drawing data.
239 // Ownership is not transfered.
240 void set_cross_process_frame_connector(
241 CrossProcessFrameConnector* cross_process_frame_connector) {
242 cross_process_frame_connector_ = cross_process_frame_connector;
245 void set_render_frame_proxy_host(RenderFrameProxyHost* proxy) {
246 render_frame_proxy_host_ = proxy;
249 // Returns a bitwise OR of bindings types that have been enabled for this
250 // RenderFrameHostImpl's RenderView. See BindingsPolicy for details.
251 // TODO(creis): Make bindings frame-specific, to support cases like <webview>.
252 int GetEnabledBindings();
254 NavigationHandleImpl* navigation_handle() const {
255 return navigation_handle_.get();
258 // Called when a new navigation starts in this RenderFrameHost. Ownership of
259 // |navigation_handle| is transferred.
260 // PlzNavigate: called when a navigation is ready to commit in this
261 // RenderFrameHost.
262 void SetNavigationHandle(scoped_ptr<NavigationHandleImpl> navigation_handle);
264 // Gives the ownership of |navigation_handle_| to the caller.
265 // This happens during transfer navigations, where it should be transferred
266 // from the RenderFrameHost that issued the initial request to the new
267 // RenderFrameHost that will issue the transferring request.
268 scoped_ptr<NavigationHandleImpl> PassNavigationHandleOwnership();
270 // Called on the pending RenderFrameHost when the network response is ready to
271 // commit. We should ensure that the old RenderFrameHost runs its unload
272 // handler and determine whether a transfer to a different RenderFrameHost is
273 // needed.
274 void OnCrossSiteResponse(
275 const GlobalRequestID& global_request_id,
276 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request,
277 const std::vector<GURL>& transfer_url_chain,
278 const Referrer& referrer,
279 ui::PageTransition page_transition,
280 bool should_replace_current_entry);
282 // Tells the renderer that this RenderFrame is being swapped out for one in a
283 // different renderer process. It should run its unload handler and move to
284 // a blank document. If |proxy| is not null, it should also create a
285 // RenderFrameProxy to replace the RenderFrame and set it to |is_loading|
286 // state. The renderer should preserve the RenderFrameProxy object until it
287 // exits, in case we come back. The renderer can exit if it has no other
288 // active RenderFrames, but not until WasSwappedOut is called.
289 void SwapOut(RenderFrameProxyHost* proxy, bool is_loading);
291 // Whether an ongoing navigation is waiting for a BeforeUnload ACK from the
292 // RenderFrame. Currently this only happens in cross-site navigations.
293 // PlzNavigate: this happens in every browser-initiated navigation that is not
294 // same-page.
295 bool is_waiting_for_beforeunload_ack() const {
296 return is_waiting_for_beforeunload_ack_;
299 // Whether the RFH is waiting for an unload ACK from the renderer.
300 bool IsWaitingForUnloadACK() const;
302 // Called when either the SwapOut request has been acknowledged or has timed
303 // out.
304 void OnSwappedOut();
306 // Whether this RenderFrameHost has been swapped out, such that the frame is
307 // now rendered by a RenderFrameHost in a different process.
308 bool is_swapped_out() const { return rfh_state_ == STATE_SWAPPED_OUT; }
310 // The current state of this RFH.
311 RenderFrameHostImplState rfh_state() const { return rfh_state_; }
313 // Sends the given navigation message. Use this rather than sending it
314 // yourself since this does the internal bookkeeping described below. This
315 // function takes ownership of the provided message pointer.
317 // If a cross-site request is in progress, we may be suspended while waiting
318 // for the onbeforeunload handler, so this function might buffer the message
319 // rather than sending it.
320 void Navigate(const CommonNavigationParams& common_params,
321 const StartNavigationParams& start_params,
322 const RequestNavigationParams& request_params);
324 // Navigates to an interstitial page represented by the provided data URL.
325 void NavigateToInterstitialURL(const GURL& data_url);
327 // Treat this prospective navigation as though it originated from the frame.
328 // Used, e.g., for a navigation request that originated from a RemoteFrame.
329 // |source_site_instance| is the SiteInstance of the frame that initiated the
330 // navigation.
331 // TODO(creis): Remove this method and have RenderFrameProxyHost call
332 // RequestOpenURL with its FrameTreeNode.
333 void OpenURL(const FrameHostMsg_OpenURL_Params& params,
334 SiteInstance* source_site_instance);
336 // Stop the load in progress.
337 void Stop();
339 // Returns whether navigation messages are currently suspended for this
340 // RenderFrameHost. Only true during a cross-site navigation, while waiting
341 // for the onbeforeunload handler.
342 bool are_navigations_suspended() const { return navigations_suspended_; }
344 // Suspends (or unsuspends) any navigation messages from being sent from this
345 // RenderFrameHost. This is called when a pending RenderFrameHost is created
346 // for a cross-site navigation, because we must suspend any navigations until
347 // we hear back from the old renderer's onbeforeunload handler. Note that it
348 // is important that only one navigation event happen after calling this
349 // method with |suspend| equal to true. If |suspend| is false and there is a
350 // suspended_nav_message_, this will send the message. This function should
351 // only be called to toggle the state; callers should check
352 // are_navigations_suspended() first. If |suspend| is false, the time that the
353 // user decided the navigation should proceed should be passed as
354 // |proceed_time|.
355 void SetNavigationsSuspended(bool suspend,
356 const base::TimeTicks& proceed_time);
358 // Clears any suspended navigation state after a cross-site navigation is
359 // canceled or suspended. This is important if we later return to this
360 // RenderFrameHost.
361 void CancelSuspendedNavigations();
363 // Runs the beforeunload handler for this frame. |for_navigation| indicates
364 // whether this call is for the current frame during a cross-process
365 // navigation. False means we're closing the entire tab.
366 // PlzNavigate: this call happens on all browser-initiated navigations.
367 void DispatchBeforeUnload(bool for_navigation);
369 // Returns true if a call to DispatchBeforeUnload will actually send the
370 // BeforeUnload IPC. This is the case if the current renderer is live and this
371 // frame is the main frame.
372 bool ShouldDispatchBeforeUnload();
374 // Update the frame's opener in the renderer process in response to the
375 // opener being modified (e.g., with window.open or being set to null) in
376 // another renderer process.
377 void UpdateOpener();
379 // Deletes the current selection plus the specified number of characters
380 // before and after the selection or caret.
381 void ExtendSelectionAndDelete(size_t before, size_t after);
383 // Notifies the RenderFrame that the JavaScript message that was shown was
384 // closed by the user.
385 void JavaScriptDialogClosed(IPC::Message* reply_msg,
386 bool success,
387 const base::string16& user_input,
388 bool dialog_was_suppressed);
390 // Send a message to the renderer process to change the accessibility mode.
391 void SetAccessibilityMode(AccessibilityMode AccessibilityMode);
393 // Request a one-time snapshot of the accessibility tree without changing
394 // the accessibility mode.
395 void RequestAXTreeSnapshot(AXTreeSnapshotCallback callback);
397 // Resets the accessibility serializer in the renderer.
398 void AccessibilityReset();
400 // Turn on accessibility testing. The given callback will be run
401 // every time an accessibility notification is received from the
402 // renderer process, and the accessibility tree it sent can be
403 // retrieved using GetAXTreeForTesting().
404 void SetAccessibilityCallbackForTesting(
405 const base::Callback<void(ui::AXEvent, int)>& callback);
407 // Send a message to the render process to change text track style settings.
408 void SetTextTrackSettings(const FrameMsg_TextTrackSettings_Params& params);
410 // Returns a snapshot of the accessibility tree received from the
411 // renderer as of the last time an accessibility notification was
412 // received.
413 const ui::AXTree* GetAXTreeForTesting();
415 // Access the BrowserAccessibilityManager if it already exists.
416 BrowserAccessibilityManager* browser_accessibility_manager() const {
417 return browser_accessibility_manager_.get();
420 // If accessibility is enabled, get the BrowserAccessibilityManager for
421 // this frame, or create one if it doesn't exist yet, otherwise return
422 // NULL.
423 BrowserAccessibilityManager* GetOrCreateBrowserAccessibilityManager();
425 void set_no_create_browser_accessibility_manager_for_testing(bool flag) {
426 no_create_browser_accessibility_manager_for_testing_ = flag;
429 #if defined(OS_WIN)
430 void SetParentNativeViewAccessible(
431 gfx::NativeViewAccessible accessible_parent);
432 gfx::NativeViewAccessible GetParentNativeViewAccessible() const;
433 #elif defined(OS_MACOSX)
434 // Select popup menu related methods (for external popup menus).
435 void DidSelectPopupMenuItem(int selected_index);
436 void DidCancelPopupMenu();
437 #elif defined(OS_ANDROID)
438 void DidSelectPopupMenuItems(const std::vector<int>& selected_indices);
439 void DidCancelPopupMenu();
440 #endif
442 // PlzNavigate: Indicates that a navigation is ready to commit and can be
443 // handled by this RenderFrame.
444 void CommitNavigation(ResourceResponse* response,
445 scoped_ptr<StreamHandle> body,
446 const CommonNavigationParams& common_params,
447 const RequestNavigationParams& request_params);
449 // PlzNavigate
450 // Indicates that a navigation failed and that this RenderFrame should display
451 // an error page.
452 void FailedNavigation(const CommonNavigationParams& common_params,
453 const RequestNavigationParams& request_params,
454 bool has_stale_copy_in_cache,
455 int error_code);
457 // Sets up the Mojo connection between this instance and its associated render
458 // frame if it has not yet been set up.
459 void SetUpMojoIfNeeded();
461 // Tears down the browser-side state relating to the Mojo connection between
462 // this instance and its associated render frame.
463 void InvalidateMojoConnection();
465 // Returns whether the frame is focused. A frame is considered focused when it
466 // is the parent chain of the focused frame within the frame tree. In
467 // addition, its associated RenderWidgetHost has to be focused.
468 bool IsFocused();
470 // Returns the Mojo ImageDownloader service.
471 const image_downloader::ImageDownloaderPtr& GetMojoImageDownloader();
473 protected:
474 friend class RenderFrameHostFactory;
476 // |flags| is a combination of CreateRenderFrameFlags.
477 // TODO(nasko): Remove dependency on RenderViewHost here. RenderProcessHost
478 // should be the abstraction needed here, but we need RenderViewHost to pass
479 // into WebContentsObserver::FrameDetached for now.
480 RenderFrameHostImpl(SiteInstance* site_instance,
481 RenderViewHostImpl* render_view_host,
482 RenderFrameHostDelegate* delegate,
483 RenderWidgetHostDelegate* rwh_delegate,
484 FrameTree* frame_tree,
485 FrameTreeNode* frame_tree_node,
486 int32 routing_id,
487 int32 widget_routing_id,
488 int32 surface_id,
489 int flags);
491 private:
492 friend class TestRenderFrameHost;
493 friend class TestRenderViewHost;
495 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest, CrashSubframe);
497 // IPC Message handlers.
498 void OnAddMessageToConsole(int32 level,
499 const base::string16& message,
500 int32 line_no,
501 const base::string16& source_id);
502 void OnDetach();
503 void OnFrameFocused();
504 void OnOpenURL(const FrameHostMsg_OpenURL_Params& params);
505 void OnDocumentOnLoadCompleted(
506 FrameMsg_UILoadMetricsReportType::Value report_type,
507 base::TimeTicks ui_timestamp);
508 void OnDidStartProvisionalLoadForFrame(const GURL& url);
509 void OnDidFailProvisionalLoadWithError(
510 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params);
511 void OnDidFailLoadWithError(
512 const GURL& url,
513 int error_code,
514 const base::string16& error_description,
515 bool was_ignored_by_handler);
516 void OnDidCommitProvisionalLoad(const IPC::Message& msg);
517 void OnDidDropNavigation();
518 void OnBeforeUnloadACK(
519 bool proceed,
520 const base::TimeTicks& renderer_before_unload_start_time,
521 const base::TimeTicks& renderer_before_unload_end_time);
522 void OnSwapOutACK();
523 void OnRenderProcessGone(int status, int error_code);
524 void OnContextMenu(const ContextMenuParams& params);
525 void OnJavaScriptExecuteResponse(int id, const base::ListValue& result);
526 void OnVisualStateResponse(uint64 id);
527 void OnRunJavaScriptMessage(const base::string16& message,
528 const base::string16& default_prompt,
529 const GURL& frame_url,
530 JavaScriptMessageType type,
531 IPC::Message* reply_msg);
532 void OnRunBeforeUnloadConfirm(const GURL& frame_url,
533 const base::string16& message,
534 bool is_reload,
535 IPC::Message* reply_msg);
536 void OnTextSurroundingSelectionResponse(const base::string16& content,
537 size_t start_offset,
538 size_t end_offset);
539 void OnDidAccessInitialDocument();
540 void OnDidChangeOpener(int32 opener_routing_id);
541 void OnDidChangeName(const std::string& name);
542 void OnDidAssignPageId(int32 page_id);
543 void OnDidChangeSandboxFlags(int32 frame_routing_id,
544 blink::WebSandboxFlags flags);
545 void OnUpdateTitle(const base::string16& title,
546 blink::WebTextDirection title_direction);
547 void OnUpdateEncoding(const std::string& encoding);
548 void OnBeginNavigation(const CommonNavigationParams& common_params,
549 const BeginNavigationParams& begin_params,
550 scoped_refptr<ResourceRequestBody> body);
551 void OnDispatchLoad();
552 void OnAccessibilityEvents(
553 const std::vector<AccessibilityHostMsg_EventParams>& params,
554 int reset_token);
555 void OnAccessibilityLocationChanges(
556 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params);
557 void OnAccessibilityFindInPageResult(
558 const AccessibilityHostMsg_FindInPageResultParams& params);
559 void OnAccessibilitySnapshotResponse(
560 int callback_id,
561 const ui::AXTreeUpdate<AXContentNodeData>& 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);
569 void OnHidePopup();
570 #endif
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 // Asserts that the given RenderFrameHostImpl is part of the same browser
585 // context (and crashes if not), then returns whether the given frame is
586 // part of the same site instance.
587 bool IsSameSiteInstance(RenderFrameHostImpl* other_render_frame_host);
589 // Informs the content client that geolocation permissions were used.
590 void DidUseGeolocationPermission();
592 void UpdatePermissionsForNavigation(
593 const CommonNavigationParams& common_params,
594 const RequestNavigationParams& request_params);
596 // Returns true if the ExecuteJavaScript() API can be used on this host.
597 bool CanExecuteJavaScript();
599 // Map a routing ID from a frame in the same frame tree to a globally
600 // unique AXTreeID.
601 AXTreeIDRegistry::AXTreeID RoutingIDToAXTreeID(int routing_id);
603 // Map a browser plugin instance ID to the AXTreeID of the plugin's
604 // main frame.
605 AXTreeIDRegistry::AXTreeID BrowserPluginInstanceIDToAXTreeID(int routing_id);
607 // Convert the content-layer-specific AXContentNodeData to a general-purpose
608 // AXNodeData structure.
609 void AXContentNodeDataToAXNodeData(const AXContentNodeData& src,
610 ui::AXNodeData* dst);
612 // For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
613 // refcount that calls Shutdown when it reaches zero. This allows each
614 // RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
615 // we have a RenderViewHost for each RenderFrameHost.
616 // TODO(creis): RenderViewHost will eventually go away and be replaced with
617 // some form of page context.
618 RenderViewHostImpl* render_view_host_;
620 RenderFrameHostDelegate* delegate_;
622 // The SiteInstance associated with this RenderFrameHost. All content drawn
623 // in this RenderFrameHost is part of this SiteInstance. Cannot change over
624 // time.
625 scoped_refptr<SiteInstanceImpl> site_instance_;
627 // The renderer process this RenderFrameHost is associated with. It is
628 // equivalent to the result of site_instance_->GetProcess(), but that
629 // method has the side effect of creating the process if it doesn't exist.
630 // Cache a pointer to avoid unnecessary process creation.
631 RenderProcessHost* process_;
633 // |cross_process_frame_connector_| passes messages from an out-of-process
634 // child frame to the parent process for compositing.
636 // This is only non-NULL when this is the swapped out RenderFrameHost in
637 // the same site instance as this frame's parent.
639 // See the class comment above CrossProcessFrameConnector for more
640 // information.
642 // This will move to RenderFrameProxyHost when that class is created.
643 CrossProcessFrameConnector* cross_process_frame_connector_;
645 // The proxy created for this RenderFrameHost. It is used to send and receive
646 // IPC messages while in swapped out state.
647 // TODO(nasko): This can be removed once we don't have a swapped out state on
648 // RenderFrameHosts. See https://crbug.com/357747.
649 RenderFrameProxyHost* render_frame_proxy_host_;
651 // Reference to the whole frame tree that this RenderFrameHost belongs to.
652 // Allows this RenderFrameHost to add and remove nodes in response to
653 // messages from the renderer requesting DOM manipulation.
654 FrameTree* frame_tree_;
656 // The FrameTreeNode which this RenderFrameHostImpl is hosted in.
657 FrameTreeNode* frame_tree_node_;
659 // The mapping of pending JavaScript calls created by
660 // ExecuteJavaScript and their corresponding callbacks.
661 std::map<int, JavaScriptResultCallback> javascript_callbacks_;
662 std::map<uint64, VisualStateCallback> visual_state_callbacks_;
664 // RenderFrameHosts that need management of the rendering and input events
665 // for their frame subtrees require RenderWidgetHosts. This typically
666 // means frames that are rendered in different processes from their parent
667 // frames.
668 // TODO(kenrb): Later this will also be used on the top-level frame, when
669 // RenderFrameHost owns its RenderViewHost.
670 RenderWidgetHostImpl* render_widget_host_;
672 int routing_id_;
674 // The current state of this RenderFrameHost.
675 RenderFrameHostImplState rfh_state_;
677 // Tracks whether the RenderFrame for this RenderFrameHost has been created in
678 // the renderer process. Currently only used for subframes.
679 // TODO(creis): Use this for main frames as well when RVH goes away.
680 bool render_frame_created_;
682 // Whether we should buffer outgoing Navigate messages rather than sending
683 // them. This will be true when a RenderFrameHost is created for a cross-site
684 // request, until we hear back from the onbeforeunload handler of the old
685 // RenderFrameHost.
686 bool navigations_suspended_;
688 // Holds the parameters for a suspended navigation. This can only happen while
689 // this RFH is the pending RenderFrameHost of a RenderFrameHostManager. There
690 // will only ever be one suspended navigation, because RenderFrameHostManager
691 // will destroy the pending RenderFrameHost and create a new one if a second
692 // navigation occurs.
693 // PlzNavigate: unused as navigations are never suspended.
694 scoped_ptr<NavigationParams> suspended_nav_params_;
696 // When the last BeforeUnload message was sent.
697 base::TimeTicks send_before_unload_start_time_;
699 // Set to true when there is a pending FrameMsg_BeforeUnload message. This
700 // ensures we don't spam the renderer with multiple beforeunload requests.
701 // When either this value or IsWaitingForUnloadACK is true, the value of
702 // unload_ack_is_for_cross_site_transition_ indicates whether this is for a
703 // cross-site transition or a tab close attempt.
704 // TODO(clamy): Remove this boolean and add one more state to the state
705 // machine.
706 bool is_waiting_for_beforeunload_ack_;
708 // Valid only when is_waiting_for_beforeunload_ack_ or
709 // IsWaitingForUnloadACK is true. This tells us if the unload request
710 // is for closing the entire tab ( = false), or only this RenderFrameHost in
711 // the case of a navigation ( = true). Currently only cross-site navigations
712 // require a beforeUnload/unload ACK.
713 // PlzNavigate: all navigations require a beforeUnload ACK.
714 bool unload_ack_is_for_navigation_;
716 // Indicates whether this RenderFrameHost is in the process of loading a
717 // document or not.
718 bool is_loading_;
720 // PlzNavigate
721 // Used to track whether a commit is expected in this frame. Only used in
722 // tests.
723 bool pending_commit_;
725 // Used to swap out or shut down this RFH when the unload event is taking too
726 // long to execute, depending on the number of active frames in the
727 // SiteInstance.
728 scoped_ptr<TimeoutMonitor> swapout_event_monitor_timeout_;
730 scoped_ptr<ServiceRegistryImpl> service_registry_;
732 #if defined(OS_ANDROID)
733 scoped_ptr<ServiceRegistryAndroid> service_registry_android_;
734 #endif
736 // The object managing the accessibility tree for this frame.
737 scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_;
739 // This is nonzero if we sent an accessibility reset to the renderer and
740 // we're waiting for an IPC containing this reset token (sequentially
741 // assigned) and a complete replacement accessibility tree.
742 int accessibility_reset_token_;
744 // A count of the number of times we needed to reset accessibility, so
745 // we don't keep trying to reset forever.
746 int accessibility_reset_count_;
748 // The mapping from callback id to corresponding callback for pending
749 // accessibility tree snapshot calls created by RequestAXTreeSnapshot.
750 std::map<int, AXTreeSnapshotCallback> ax_tree_snapshot_callbacks_;
752 // Callback when an event is received, for testing.
753 base::Callback<void(ui::AXEvent, int)> accessibility_testing_callback_;
754 // The most recently received accessibility tree - for testing only.
755 scoped_ptr<ui::AXTree> ax_tree_for_testing_;
756 // Flag to not create a BrowserAccessibilityManager, for testing. If one
757 // already exists it will still be used.
758 bool no_create_browser_accessibility_manager_for_testing_;
760 // PlzNavigate: Owns the stream used in navigations to store the body of the
761 // response once it has started.
762 scoped_ptr<StreamHandle> stream_handle_;
764 // Context shared for each PermissionService instance created for this RFH.
765 scoped_ptr<PermissionServiceContext> permission_service_context_;
767 // The frame's Mojo Shell service.
768 scoped_ptr<FrameMojoShell> frame_mojo_shell_;
770 // Holder of Mojo connection with ImageDownloader service in RenderFrame.
771 image_downloader::ImageDownloaderPtr mojo_image_downloader_;
773 // Tracks a navigation happening in this frame. Note that while there can be
774 // two navigations in the same FrameTreeNode, there can only be one
775 // navigation per RenderFrameHost.
776 // PlzNavigate: before the navigation is ready to be committed, the
777 // NavigationHandle for it is owned by the NavigationRequest.
778 scoped_ptr<NavigationHandleImpl> navigation_handle_;
780 // NOTE: This must be the last member.
781 base::WeakPtrFactory<RenderFrameHostImpl> weak_ptr_factory_;
783 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl);
786 } // namespace content
788 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_