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