[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / frame_host / render_frame_host_impl.h
blob18463b35513168e1b4f6ed0bf80ad61bc9e555ce
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 RenderFrame is initially hidden.
84 CREATE_RF_HIDDEN = 1 << 1,
87 class CONTENT_EXPORT RenderFrameHostImpl
88 : public RenderFrameHost,
89 public BrowserAccessibilityDelegate {
90 public:
91 using AXTreeSnapshotCallback =
92 base::Callback<void(const ui::AXTreeUpdate<ui::AXNodeData>&)>;
94 // Keeps track of the state of the RenderFrameHostImpl, particularly with
95 // respect to swap out.
96 enum RenderFrameHostImplState {
97 // The standard state for a RFH handling the communication with an active
98 // RenderFrame.
99 STATE_DEFAULT = 0,
100 // The RFH has not received the SwapOutACK yet, but the new page has
101 // committed in a different RFH. Upon reception of the SwapOutACK, the RFH
102 // will either enter STATE_SWAPPED_OUT (if it is a main frame and there are
103 // other active frames in its SiteInstance) or it will be deleted.
104 STATE_PENDING_SWAP_OUT,
105 // The RFH is swapped out and stored inside a RenderFrameProxyHost, being
106 // used as a placeholder to allow cross-process communication. Only main
107 // frames can enter this state.
108 STATE_SWAPPED_OUT,
110 // Helper function to determine whether the RFH state should contribute to the
111 // number of active frames of a SiteInstance or not.
112 static bool IsRFHStateActive(RenderFrameHostImplState rfh_state);
114 // An accessibility reset is only allowed to prevent very rare corner cases
115 // or race conditions where the browser and renderer get out of sync. If
116 // this happens more than this many times, kill the renderer.
117 static const int kMaxAccessibilityResets = 5;
119 static RenderFrameHostImpl* FromID(int process_id, int routing_id);
120 static RenderFrameHostImpl* FromAXTreeID(
121 AXTreeIDRegistry::AXTreeID ax_tree_id);
123 ~RenderFrameHostImpl() override;
125 // RenderFrameHost
126 int GetRoutingID() override;
127 AXTreeIDRegistry::AXTreeID GetAXTreeID() override;
128 SiteInstanceImpl* GetSiteInstance() override;
129 RenderProcessHost* GetProcess() override;
130 RenderFrameHost* GetParent() override;
131 const std::string& GetFrameName() override;
132 bool IsCrossProcessSubframe() override;
133 GURL GetLastCommittedURL() override;
134 gfx::NativeView GetNativeView() override;
135 void AddMessageToConsole(ConsoleMessageLevel level,
136 const std::string& message) override;
137 void ExecuteJavaScript(const base::string16& javascript) override;
138 void ExecuteJavaScript(const base::string16& javascript,
139 const JavaScriptResultCallback& callback) override;
140 void ExecuteJavaScriptForTests(const base::string16& javascript) override;
141 void ExecuteJavaScriptForTests(
142 const base::string16& javascript,
143 const JavaScriptResultCallback& callback) override;
144 void ExecuteJavaScriptWithUserGestureForTests(
145 const base::string16& javascript) override;
146 void ExecuteJavaScriptInIsolatedWorld(
147 const base::string16& javascript,
148 const JavaScriptResultCallback& callback,
149 int world_id) override;
150 void ActivateFindInPageResultForAccessibility(int request_id) override;
151 RenderViewHost* GetRenderViewHost() override;
152 ServiceRegistry* GetServiceRegistry() override;
153 blink::WebPageVisibilityState GetVisibilityState() override;
154 void InsertVisualStateCallback(
155 const VisualStateCallback& callback) override;
156 bool IsRenderFrameLive() override;
158 // IPC::Sender
159 bool Send(IPC::Message* msg) override;
161 // IPC::Listener
162 bool OnMessageReceived(const IPC::Message& msg) override;
164 // BrowserAccessibilityDelegate
165 void AccessibilitySetFocus(int acc_obj_id) override;
166 void AccessibilityDoDefaultAction(int acc_obj_id) override;
167 void AccessibilityShowContextMenu(int acc_obj_id) override;
168 void AccessibilityScrollToMakeVisible(int acc_obj_id,
169 const gfx::Rect& subfocus) override;
170 void AccessibilityScrollToPoint(int acc_obj_id,
171 const gfx::Point& point) override;
172 void AccessibilitySetScrollOffset(int acc_obj_id,
173 const gfx::Point& offset) override;
174 void AccessibilitySetTextSelection(int acc_obj_id,
175 int start_offset,
176 int end_offset) override;
177 void AccessibilitySetValue(int acc_obj_id, const base::string16& value)
178 override;
179 bool AccessibilityViewHasFocus() const override;
180 gfx::Rect AccessibilityGetViewBounds() const override;
181 gfx::Point AccessibilityOriginInScreen(
182 const gfx::Rect& bounds) const override;
183 void AccessibilityHitTest(const gfx::Point& point) override;
184 void AccessibilitySetAccessibilityFocus(int acc_obj_id) override;
185 void AccessibilityFatalError() override;
186 gfx::AcceleratedWidget AccessibilityGetAcceleratedWidget() override;
187 gfx::NativeViewAccessible AccessibilityGetNativeViewAccessible() override;
189 // Creates a RenderFrame in the renderer process. Only called for
190 // cross-process subframe navigations in --site-per-process.
191 bool CreateRenderFrame(int proxy_routing_id,
192 int opener_routing_id,
193 int parent_routing_id,
194 int previous_sibling_routing_id);
196 // Tracks whether the RenderFrame for this RenderFrameHost has been created in
197 // the renderer process. This is currently only used for subframes.
198 // TODO(creis): Use this for main frames as well when RVH goes away.
199 void SetRenderFrameCreated(bool created);
201 // Called for renderer-created windows to resume requests from this frame,
202 // after they are blocked in RenderWidgetHelper::CreateNewWindow.
203 void Init();
205 int routing_id() const { return routing_id_; }
206 void OnCreateChildFrame(int new_routing_id,
207 blink::WebTreeScopeType scope,
208 const std::string& frame_name,
209 blink::WebSandboxFlags sandbox_flags);
211 RenderViewHostImpl* render_view_host() { return render_view_host_; }
212 RenderFrameHostDelegate* delegate() { return delegate_; }
213 FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
215 // Returns this RenderFrameHost's loading state. This method is only used by
216 // FrameTreeNode. The proper way to check whether a frame is loading is to
217 // call FrameTreeNode::IsLoading.
218 bool is_loading() const { return is_loading_; }
220 // This returns the RenderFrameHost's owned RenderWidgetHost if it has one,
221 // or else it returns nullptr.
222 // If the RenderFrameHost is the page's main frame, this returns instead a
223 // pointer to the RenderViewHost (which inherits RenderWidgetHost).
224 RenderWidgetHostImpl* GetRenderWidgetHost();
226 // This returns the RenderWidgetHostView that can be used to control
227 // focus and visibility for this frame.
228 RenderWidgetHostView* GetView();
230 // This function is called when this is a swapped out RenderFrameHost that
231 // lives in the same process as the parent frame. The
232 // |cross_process_frame_connector| allows the non-swapped-out
233 // RenderFrameHost for a frame to communicate with the parent process
234 // so that it may composite drawing data.
236 // Ownership is not transfered.
237 void set_cross_process_frame_connector(
238 CrossProcessFrameConnector* cross_process_frame_connector) {
239 cross_process_frame_connector_ = cross_process_frame_connector;
242 void set_render_frame_proxy_host(RenderFrameProxyHost* proxy) {
243 render_frame_proxy_host_ = proxy;
246 // Returns a bitwise OR of bindings types that have been enabled for this
247 // RenderFrameHostImpl's RenderView. See BindingsPolicy for details.
248 // TODO(creis): Make bindings frame-specific, to support cases like <webview>.
249 int GetEnabledBindings();
251 NavigationHandleImpl* navigation_handle() const {
252 return navigation_handle_.get();
255 // Called when a new navigation starts in this RenderFrameHost. Ownership of
256 // |navigation_handle| is transferred.
257 // PlzNavigate: called when a navigation is ready to commit in this
258 // RenderFrameHost.
259 void SetNavigationHandle(scoped_ptr<NavigationHandleImpl> navigation_handle);
261 // Gives the ownership of |navigation_handle_| to the caller.
262 // This happens during transfer navigations, where it should be transferred
263 // from the RenderFrameHost that issued the initial request to the new
264 // RenderFrameHost that will issue the transferring request.
265 scoped_ptr<NavigationHandleImpl> PassNavigationHandleOwnership();
267 // Called on the pending RenderFrameHost when the network response is ready to
268 // commit. We should ensure that the old RenderFrameHost runs its unload
269 // handler and determine whether a transfer to a different RenderFrameHost is
270 // needed.
271 void OnCrossSiteResponse(
272 const GlobalRequestID& global_request_id,
273 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request,
274 const std::vector<GURL>& transfer_url_chain,
275 const Referrer& referrer,
276 ui::PageTransition page_transition,
277 bool should_replace_current_entry);
279 // Tells the renderer that this RenderFrame is being swapped out for one in a
280 // different renderer process. It should run its unload handler and move to
281 // a blank document. If |proxy| is not null, it should also create a
282 // RenderFrameProxy to replace the RenderFrame and set it to |is_loading|
283 // state. The renderer should preserve the RenderFrameProxy object until it
284 // exits, in case we come back. The renderer can exit if it has no other
285 // active RenderFrames, but not until WasSwappedOut is called.
286 void SwapOut(RenderFrameProxyHost* proxy, bool is_loading);
288 // Whether an ongoing navigation is waiting for a BeforeUnload ACK from the
289 // RenderFrame. Currently this only happens in cross-site navigations.
290 // PlzNavigate: this happens in every browser-initiated navigation that is not
291 // same-page.
292 bool is_waiting_for_beforeunload_ack() const {
293 return is_waiting_for_beforeunload_ack_;
296 // Whether the RFH is waiting for an unload ACK from the renderer.
297 bool IsWaitingForUnloadACK() const;
299 // Called when either the SwapOut request has been acknowledged or has timed
300 // out.
301 void OnSwappedOut();
303 // Whether this RenderFrameHost has been swapped out, such that the frame is
304 // now rendered by a RenderFrameHost in a different process.
305 bool is_swapped_out() const { return rfh_state_ == STATE_SWAPPED_OUT; }
307 // The current state of this RFH.
308 RenderFrameHostImplState rfh_state() const { return rfh_state_; }
310 // Sends the given navigation message. Use this rather than sending it
311 // yourself since this does the internal bookkeeping described below. This
312 // function takes ownership of the provided message pointer.
314 // If a cross-site request is in progress, we may be suspended while waiting
315 // for the onbeforeunload handler, so this function might buffer the message
316 // rather than sending it.
317 void Navigate(const CommonNavigationParams& common_params,
318 const StartNavigationParams& start_params,
319 const RequestNavigationParams& request_params);
321 // Navigates to an interstitial page represented by the provided data URL.
322 void NavigateToInterstitialURL(const GURL& data_url);
324 // Treat this prospective navigation as though it originated from the frame.
325 // Used, e.g., for a navigation request that originated from a RemoteFrame.
326 // |source_site_instance| is the SiteInstance of the frame that initiated the
327 // navigation.
328 // TODO(creis): Remove this method and have RenderFrameProxyHost call
329 // RequestOpenURL with its FrameTreeNode.
330 void OpenURL(const FrameHostMsg_OpenURL_Params& params,
331 SiteInstance* source_site_instance);
333 // Stop the load in progress.
334 void Stop();
336 // Returns whether navigation messages are currently suspended for this
337 // RenderFrameHost. Only true during a cross-site navigation, while waiting
338 // for the onbeforeunload handler.
339 bool are_navigations_suspended() const { return navigations_suspended_; }
341 // Suspends (or unsuspends) any navigation messages from being sent from this
342 // RenderFrameHost. This is called when a pending RenderFrameHost is created
343 // for a cross-site navigation, because we must suspend any navigations until
344 // we hear back from the old renderer's onbeforeunload handler. Note that it
345 // is important that only one navigation event happen after calling this
346 // method with |suspend| equal to true. If |suspend| is false and there is a
347 // suspended_nav_message_, this will send the message. This function should
348 // only be called to toggle the state; callers should check
349 // are_navigations_suspended() first. If |suspend| is false, the time that the
350 // user decided the navigation should proceed should be passed as
351 // |proceed_time|.
352 void SetNavigationsSuspended(bool suspend,
353 const base::TimeTicks& proceed_time);
355 // Clears any suspended navigation state after a cross-site navigation is
356 // canceled or suspended. This is important if we later return to this
357 // RenderFrameHost.
358 void CancelSuspendedNavigations();
360 // Runs the beforeunload handler for this frame. |for_navigation| indicates
361 // whether this call is for the current frame during a cross-process
362 // navigation. False means we're closing the entire tab.
363 // PlzNavigate: this call happens on all browser-initiated navigations.
364 void DispatchBeforeUnload(bool for_navigation);
366 // Returns true if a call to DispatchBeforeUnload will actually send the
367 // BeforeUnload IPC. This is the case if the current renderer is live and this
368 // frame is the main frame.
369 bool ShouldDispatchBeforeUnload();
371 // Update the frame's opener in the renderer process in response to the
372 // opener being modified (e.g., with window.open or being set to null) in
373 // another renderer process.
374 void UpdateOpener();
376 // Deletes the current selection plus the specified number of characters
377 // before and after the selection or caret.
378 void ExtendSelectionAndDelete(size_t before, size_t after);
380 // Notifies the RenderFrame that the JavaScript message that was shown was
381 // closed by the user.
382 void JavaScriptDialogClosed(IPC::Message* reply_msg,
383 bool success,
384 const base::string16& user_input,
385 bool dialog_was_suppressed);
387 // Send a message to the renderer process to change the accessibility mode.
388 void SetAccessibilityMode(AccessibilityMode AccessibilityMode);
390 // Request a one-time snapshot of the accessibility tree without changing
391 // the accessibility mode.
392 void RequestAXTreeSnapshot(AXTreeSnapshotCallback callback);
394 // Resets the accessibility serializer in the renderer.
395 void AccessibilityReset();
397 // Turn on accessibility testing. The given callback will be run
398 // every time an accessibility notification is received from the
399 // renderer process, and the accessibility tree it sent can be
400 // retrieved using GetAXTreeForTesting().
401 void SetAccessibilityCallbackForTesting(
402 const base::Callback<void(ui::AXEvent, int)>& callback);
404 // Send a message to the render process to change text track style settings.
405 void SetTextTrackSettings(const FrameMsg_TextTrackSettings_Params& params);
407 // Returns a snapshot of the accessibility tree received from the
408 // renderer as of the last time an accessibility notification was
409 // received.
410 const ui::AXTree* GetAXTreeForTesting();
412 // Access the BrowserAccessibilityManager if it already exists.
413 BrowserAccessibilityManager* browser_accessibility_manager() const {
414 return browser_accessibility_manager_.get();
417 // If accessibility is enabled, get the BrowserAccessibilityManager for
418 // this frame, or create one if it doesn't exist yet, otherwise return
419 // NULL.
420 BrowserAccessibilityManager* GetOrCreateBrowserAccessibilityManager();
422 void set_no_create_browser_accessibility_manager_for_testing(bool flag) {
423 no_create_browser_accessibility_manager_for_testing_ = flag;
426 #if defined(OS_WIN)
427 void SetParentNativeViewAccessible(
428 gfx::NativeViewAccessible accessible_parent);
429 gfx::NativeViewAccessible GetParentNativeViewAccessible() const;
430 #elif defined(OS_MACOSX)
431 // Select popup menu related methods (for external popup menus).
432 void DidSelectPopupMenuItem(int selected_index);
433 void DidCancelPopupMenu();
434 #elif defined(OS_ANDROID)
435 void DidSelectPopupMenuItems(const std::vector<int>& selected_indices);
436 void DidCancelPopupMenu();
437 #endif
439 // PlzNavigate: Indicates that a navigation is ready to commit and can be
440 // handled by this RenderFrame.
441 void CommitNavigation(ResourceResponse* response,
442 scoped_ptr<StreamHandle> body,
443 const CommonNavigationParams& common_params,
444 const RequestNavigationParams& request_params);
446 // PlzNavigate
447 // Indicates that a navigation failed and that this RenderFrame should display
448 // an error page.
449 void FailedNavigation(const CommonNavigationParams& common_params,
450 const RequestNavigationParams& request_params,
451 bool has_stale_copy_in_cache,
452 int error_code);
454 // Sets up the Mojo connection between this instance and its associated render
455 // frame if it has not yet been set up.
456 void SetUpMojoIfNeeded();
458 // Tears down the browser-side state relating to the Mojo connection between
459 // this instance and its associated render frame.
460 void InvalidateMojoConnection();
462 // Returns whether the frame is focused. A frame is considered focused when it
463 // is the parent chain of the focused frame within the frame tree. In
464 // addition, its associated RenderWidgetHost has to be focused.
465 bool IsFocused();
467 // Returns the Mojo ImageDownloader service.
468 const image_downloader::ImageDownloaderPtr& GetMojoImageDownloader();
470 protected:
471 friend class RenderFrameHostFactory;
473 // |flags| is a combination of CreateRenderFrameFlags.
474 // TODO(nasko): Remove dependency on RenderViewHost here. RenderProcessHost
475 // should be the abstraction needed here, but we need RenderViewHost to pass
476 // into WebContentsObserver::FrameDetached for now.
477 RenderFrameHostImpl(SiteInstance* site_instance,
478 RenderViewHostImpl* render_view_host,
479 RenderFrameHostDelegate* delegate,
480 RenderWidgetHostDelegate* rwh_delegate,
481 FrameTree* frame_tree,
482 FrameTreeNode* frame_tree_node,
483 int32 routing_id,
484 int32 widget_routing_id,
485 int32 surface_id,
486 int flags);
488 private:
489 friend class TestRenderFrameHost;
490 friend class TestRenderViewHost;
492 FRIEND_TEST_ALL_PREFIXES(SitePerProcessBrowserTest, CrashSubframe);
494 // IPC Message handlers.
495 void OnAddMessageToConsole(int32 level,
496 const base::string16& message,
497 int32 line_no,
498 const base::string16& source_id);
499 void OnDetach();
500 void OnFrameFocused();
501 void OnOpenURL(const FrameHostMsg_OpenURL_Params& params);
502 void OnDocumentOnLoadCompleted(
503 FrameMsg_UILoadMetricsReportType::Value report_type,
504 base::TimeTicks ui_timestamp);
505 void OnDidStartProvisionalLoadForFrame(const GURL& url);
506 void OnDidFailProvisionalLoadWithError(
507 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params);
508 void OnDidFailLoadWithError(
509 const GURL& url,
510 int error_code,
511 const base::string16& error_description,
512 bool was_ignored_by_handler);
513 void OnDidCommitProvisionalLoad(const IPC::Message& msg);
514 void OnDidDropNavigation();
515 void OnBeforeUnloadACK(
516 bool proceed,
517 const base::TimeTicks& renderer_before_unload_start_time,
518 const base::TimeTicks& renderer_before_unload_end_time);
519 void OnSwapOutACK();
520 void OnRenderProcessGone(int status, int error_code);
521 void OnContextMenu(const ContextMenuParams& params);
522 void OnJavaScriptExecuteResponse(int id, const base::ListValue& result);
523 void OnVisualStateResponse(uint64 id);
524 void OnRunJavaScriptMessage(const base::string16& message,
525 const base::string16& default_prompt,
526 const GURL& frame_url,
527 JavaScriptMessageType type,
528 IPC::Message* reply_msg);
529 void OnRunBeforeUnloadConfirm(const GURL& frame_url,
530 const base::string16& message,
531 bool is_reload,
532 IPC::Message* reply_msg);
533 void OnTextSurroundingSelectionResponse(const base::string16& content,
534 size_t start_offset,
535 size_t end_offset);
536 void OnDidAccessInitialDocument();
537 void OnDidChangeOpener(int32 opener_routing_id);
538 void OnDidChangeName(const std::string& name);
539 void OnDidAssignPageId(int32 page_id);
540 void OnDidChangeSandboxFlags(int32 frame_routing_id,
541 blink::WebSandboxFlags flags);
542 void OnUpdateTitle(const base::string16& title,
543 blink::WebTextDirection title_direction);
544 void OnUpdateEncoding(const std::string& encoding);
545 void OnBeginNavigation(const CommonNavigationParams& common_params,
546 const BeginNavigationParams& begin_params,
547 scoped_refptr<ResourceRequestBody> body);
548 void OnDispatchLoad();
549 void OnAccessibilityEvents(
550 const std::vector<AccessibilityHostMsg_EventParams>& params,
551 int reset_token);
552 void OnAccessibilityLocationChanges(
553 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params);
554 void OnAccessibilityFindInPageResult(
555 const AccessibilityHostMsg_FindInPageResultParams& params);
556 void OnAccessibilitySnapshotResponse(
557 int callback_id,
558 const ui::AXTreeUpdate<AXContentNodeData>& snapshot);
559 void OnToggleFullscreen(bool enter_fullscreen);
560 void OnDidStartLoading(bool to_different_document);
561 void OnDidStopLoading();
562 void OnDidChangeLoadProgress(double load_progress);
564 #if defined(OS_MACOSX) || defined(OS_ANDROID)
565 void OnShowPopup(const FrameHostMsg_ShowPopup_Params& params);
566 void OnHidePopup();
567 #endif
569 // Registers Mojo services that this frame host makes available.
570 void RegisterMojoServices();
572 // Updates the state of this RenderFrameHost and clears any waiting state
573 // that is no longer relevant.
574 void SetState(RenderFrameHostImplState rfh_state);
576 // Returns whether the given URL is allowed to commit in the current process.
577 // This is a more conservative check than RenderProcessHost::FilterURL, since
578 // it will be used to kill processes that commit unauthorized URLs.
579 bool CanCommitURL(const GURL& url);
581 // Asserts that the given RenderFrameHostImpl is part of the same browser
582 // context (and crashes if not), then returns whether the given frame is
583 // part of the same site instance.
584 bool IsSameSiteInstance(RenderFrameHostImpl* other_render_frame_host);
586 // Informs the content client that geolocation permissions were used.
587 void DidUseGeolocationPermission();
589 void UpdatePermissionsForNavigation(
590 const CommonNavigationParams& common_params,
591 const RequestNavigationParams& request_params);
593 // Returns true if the ExecuteJavaScript() API can be used on this host.
594 bool CanExecuteJavaScript();
596 // Map a routing ID from a frame in the same frame tree to a globally
597 // unique AXTreeID.
598 AXTreeIDRegistry::AXTreeID RoutingIDToAXTreeID(int routing_id);
600 // Map a browser plugin instance ID to the AXTreeID of the plugin's
601 // main frame.
602 AXTreeIDRegistry::AXTreeID BrowserPluginInstanceIDToAXTreeID(int routing_id);
604 // Convert the content-layer-specific AXContentNodeData to a general-purpose
605 // AXNodeData structure.
606 void AXContentNodeDataToAXNodeData(const AXContentNodeData& src,
607 ui::AXNodeData* dst);
609 // For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
610 // refcount that calls Shutdown when it reaches zero. This allows each
611 // RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
612 // we have a RenderViewHost for each RenderFrameHost.
613 // TODO(creis): RenderViewHost will eventually go away and be replaced with
614 // some form of page context.
615 RenderViewHostImpl* render_view_host_;
617 RenderFrameHostDelegate* delegate_;
619 // The SiteInstance associated with this RenderFrameHost. All content drawn
620 // in this RenderFrameHost is part of this SiteInstance. Cannot change over
621 // time.
622 scoped_refptr<SiteInstanceImpl> site_instance_;
624 // The renderer process this RenderFrameHost is associated with. It is
625 // equivalent to the result of site_instance_->GetProcess(), but that
626 // method has the side effect of creating the process if it doesn't exist.
627 // Cache a pointer to avoid unnecessary process creation.
628 RenderProcessHost* process_;
630 // |cross_process_frame_connector_| passes messages from an out-of-process
631 // child frame to the parent process for compositing.
633 // This is only non-NULL when this is the swapped out RenderFrameHost in
634 // the same site instance as this frame's parent.
636 // See the class comment above CrossProcessFrameConnector for more
637 // information.
639 // This will move to RenderFrameProxyHost when that class is created.
640 CrossProcessFrameConnector* cross_process_frame_connector_;
642 // The proxy created for this RenderFrameHost. It is used to send and receive
643 // IPC messages while in swapped out state.
644 // TODO(nasko): This can be removed once we don't have a swapped out state on
645 // RenderFrameHosts. See https://crbug.com/357747.
646 RenderFrameProxyHost* render_frame_proxy_host_;
648 // Reference to the whole frame tree that this RenderFrameHost belongs to.
649 // Allows this RenderFrameHost to add and remove nodes in response to
650 // messages from the renderer requesting DOM manipulation.
651 FrameTree* frame_tree_;
653 // The FrameTreeNode which this RenderFrameHostImpl is hosted in.
654 FrameTreeNode* frame_tree_node_;
656 // The mapping of pending JavaScript calls created by
657 // ExecuteJavaScript and their corresponding callbacks.
658 std::map<int, JavaScriptResultCallback> javascript_callbacks_;
659 std::map<uint64, VisualStateCallback> visual_state_callbacks_;
661 // RenderFrameHosts that need management of the rendering and input events
662 // for their frame subtrees require RenderWidgetHosts. This typically
663 // means frames that are rendered in different processes from their parent
664 // frames.
665 // TODO(kenrb): Later this will also be used on the top-level frame, when
666 // RenderFrameHost owns its RenderViewHost.
667 RenderWidgetHostImpl* render_widget_host_;
669 int routing_id_;
671 // The current state of this RenderFrameHost.
672 RenderFrameHostImplState rfh_state_;
674 // Tracks whether the RenderFrame for this RenderFrameHost has been created in
675 // the renderer process. Currently only used for subframes.
676 // TODO(creis): Use this for main frames as well when RVH goes away.
677 bool render_frame_created_;
679 // Whether we should buffer outgoing Navigate messages rather than sending
680 // them. This will be true when a RenderFrameHost is created for a cross-site
681 // request, until we hear back from the onbeforeunload handler of the old
682 // RenderFrameHost.
683 bool navigations_suspended_;
685 // Holds the parameters for a suspended navigation. This can only happen while
686 // this RFH is the pending RenderFrameHost of a RenderFrameHostManager. There
687 // will only ever be one suspended navigation, because RenderFrameHostManager
688 // will destroy the pending RenderFrameHost and create a new one if a second
689 // navigation occurs.
690 // PlzNavigate: unused as navigations are never suspended.
691 scoped_ptr<NavigationParams> suspended_nav_params_;
693 // When the last BeforeUnload message was sent.
694 base::TimeTicks send_before_unload_start_time_;
696 // Set to true when there is a pending FrameMsg_BeforeUnload message. This
697 // ensures we don't spam the renderer with multiple beforeunload requests.
698 // When either this value or IsWaitingForUnloadACK is true, the value of
699 // unload_ack_is_for_cross_site_transition_ indicates whether this is for a
700 // cross-site transition or a tab close attempt.
701 // TODO(clamy): Remove this boolean and add one more state to the state
702 // machine.
703 bool is_waiting_for_beforeunload_ack_;
705 // Valid only when is_waiting_for_beforeunload_ack_ or
706 // IsWaitingForUnloadACK is true. This tells us if the unload request
707 // is for closing the entire tab ( = false), or only this RenderFrameHost in
708 // the case of a navigation ( = true). Currently only cross-site navigations
709 // require a beforeUnload/unload ACK.
710 // PlzNavigate: all navigations require a beforeUnload ACK.
711 bool unload_ack_is_for_navigation_;
713 // Indicates whether this RenderFrameHost is in the process of loading a
714 // document or not.
715 bool is_loading_;
717 // PlzNavigate
718 // Used to track whether a commit is expected in this frame. Only used in
719 // tests.
720 bool pending_commit_;
722 // Used to swap out or shut down this RFH when the unload event is taking too
723 // long to execute, depending on the number of active frames in the
724 // SiteInstance.
725 scoped_ptr<TimeoutMonitor> swapout_event_monitor_timeout_;
727 scoped_ptr<ServiceRegistryImpl> service_registry_;
729 #if defined(OS_ANDROID)
730 scoped_ptr<ServiceRegistryAndroid> service_registry_android_;
731 #endif
733 // The object managing the accessibility tree for this frame.
734 scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_;
736 // This is nonzero if we sent an accessibility reset to the renderer and
737 // we're waiting for an IPC containing this reset token (sequentially
738 // assigned) and a complete replacement accessibility tree.
739 int accessibility_reset_token_;
741 // A count of the number of times we needed to reset accessibility, so
742 // we don't keep trying to reset forever.
743 int accessibility_reset_count_;
745 // The mapping from callback id to corresponding callback for pending
746 // accessibility tree snapshot calls created by RequestAXTreeSnapshot.
747 std::map<int, AXTreeSnapshotCallback> ax_tree_snapshot_callbacks_;
749 // Callback when an event is received, for testing.
750 base::Callback<void(ui::AXEvent, int)> accessibility_testing_callback_;
751 // The most recently received accessibility tree - for testing only.
752 scoped_ptr<ui::AXTree> ax_tree_for_testing_;
753 // Flag to not create a BrowserAccessibilityManager, for testing. If one
754 // already exists it will still be used.
755 bool no_create_browser_accessibility_manager_for_testing_;
757 // PlzNavigate: Owns the stream used in navigations to store the body of the
758 // response once it has started.
759 scoped_ptr<StreamHandle> stream_handle_;
761 // Context shared for each PermissionService instance created for this RFH.
762 scoped_ptr<PermissionServiceContext> permission_service_context_;
764 // The frame's Mojo Shell service.
765 scoped_ptr<FrameMojoShell> frame_mojo_shell_;
767 // Holder of Mojo connection with ImageDownloader service in RenderFrame.
768 image_downloader::ImageDownloaderPtr mojo_image_downloader_;
770 // Tracks a navigation happening in this frame. Note that while there can be
771 // two navigations in the same FrameTreeNode, there can only be one
772 // navigation per RenderFrameHost.
773 // PlzNavigate: before the navigation is ready to be committed, the
774 // NavigationHandle for it is owned by the NavigationRequest.
775 scoped_ptr<NavigationHandleImpl> navigation_handle_;
777 // NOTE: This must be the last member.
778 base::WeakPtrFactory<RenderFrameHostImpl> weak_ptr_factory_;
780 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl);
783 } // namespace content
785 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_