OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_ |
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_ | 6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "content/browser/accessibility/browser_accessibility_manager.h" | 17 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 18 #include "content/browser/site_instance_impl.h" |
18 #include "content/common/accessibility_mode_enums.h" | 19 #include "content/common/accessibility_mode_enums.h" |
19 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
20 #include "content/common/mojo/service_registry_impl.h" | 21 #include "content/common/mojo/service_registry_impl.h" |
21 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
22 #include "content/public/common/javascript_message_type.h" | 23 #include "content/public/common/javascript_message_type.h" |
23 #include "net/http/http_response_headers.h" | 24 #include "net/http/http_response_headers.h" |
24 #include "third_party/WebKit/public/platform/WebNotificationPermission.h" | 25 #include "third_party/WebKit/public/platform/WebNotificationPermission.h" |
25 #include "third_party/WebKit/public/web/WebTextDirection.h" | 26 #include "third_party/WebKit/public/web/WebTextDirection.h" |
26 #include "ui/accessibility/ax_node_data.h" | 27 #include "ui/accessibility/ax_node_data.h" |
27 #include "ui/base/page_transition_types.h" | 28 #include "ui/base/page_transition_types.h" |
(...skipping 18 matching lines...) Expand all Loading... |
46 | 47 |
47 class CrossProcessFrameConnector; | 48 class CrossProcessFrameConnector; |
48 class CrossSiteTransferringRequest; | 49 class CrossSiteTransferringRequest; |
49 class FrameTree; | 50 class FrameTree; |
50 class FrameTreeNode; | 51 class FrameTreeNode; |
51 class RenderFrameHostDelegate; | 52 class RenderFrameHostDelegate; |
52 class RenderFrameProxyHost; | 53 class RenderFrameProxyHost; |
53 class RenderProcessHost; | 54 class RenderProcessHost; |
54 class RenderViewHostImpl; | 55 class RenderViewHostImpl; |
55 class RenderWidgetHostImpl; | 56 class RenderWidgetHostImpl; |
| 57 class TimeoutMonitor; |
56 struct ContextMenuParams; | 58 struct ContextMenuParams; |
57 struct GlobalRequestID; | 59 struct GlobalRequestID; |
58 struct Referrer; | 60 struct Referrer; |
59 struct ShowDesktopNotificationHostMsgParams; | 61 struct ShowDesktopNotificationHostMsgParams; |
60 struct TransitionLayerData; | 62 struct TransitionLayerData; |
61 | 63 |
62 class CONTENT_EXPORT RenderFrameHostImpl | 64 class CONTENT_EXPORT RenderFrameHostImpl |
63 : public RenderFrameHost, | 65 : public RenderFrameHost, |
64 public BrowserAccessibilityDelegate { | 66 public BrowserAccessibilityDelegate { |
65 public: | 67 public: |
| 68 // Keeps track of the state of the RenderFrameHostImpl, particularly with |
| 69 // respect to swap out. |
| 70 enum RenderFrameHostImplState { |
| 71 // The standard state for a RFH handling the communication with an active |
| 72 // RenderFrame. |
| 73 STATE_DEFAULT = 0, |
| 74 // The RFH has not received the SwapOutACK yet, but the new page has |
| 75 // committed in a different RFH. The number of active frames of the RFH |
| 76 // SiteInstanceImpl is not zero. Upon reception of the SwapOutACK, the RFH |
| 77 // will be swapped out. |
| 78 STATE_PENDING_SWAP_OUT, |
| 79 // The RFH has not received the SwapOutACK yet, but the new page has |
| 80 // committed in a different RFH. The number of active frames of the RFH |
| 81 // SiteInstanceImpl is zero. Upon reception of the SwapOutACK, the RFH will |
| 82 // be shutdown. |
| 83 STATE_PENDING_SHUTDOWN, |
| 84 // The RFH is swapped out and stored inside a RenderFrameProxyHost, being |
| 85 // used as a placeholder to allow cross-process communication. |
| 86 STATE_SWAPPED_OUT, |
| 87 }; |
| 88 // Helper function to determine whether the RFH state should contribute to the |
| 89 // number of active frames of a SiteInstance or not. |
| 90 static bool IsRFHStateActive(RenderFrameHostImplState rfh_state); |
| 91 |
66 static RenderFrameHostImpl* FromID(int process_id, int routing_id); | 92 static RenderFrameHostImpl* FromID(int process_id, int routing_id); |
67 | 93 |
68 virtual ~RenderFrameHostImpl(); | 94 virtual ~RenderFrameHostImpl(); |
69 | 95 |
70 // RenderFrameHost | 96 // RenderFrameHost |
71 virtual int GetRoutingID() OVERRIDE; | 97 virtual int GetRoutingID() OVERRIDE; |
72 virtual SiteInstance* GetSiteInstance() OVERRIDE; | 98 virtual SiteInstanceImpl* GetSiteInstance() OVERRIDE; |
73 virtual RenderProcessHost* GetProcess() OVERRIDE; | 99 virtual RenderProcessHost* GetProcess() OVERRIDE; |
74 virtual RenderFrameHost* GetParent() OVERRIDE; | 100 virtual RenderFrameHost* GetParent() OVERRIDE; |
75 virtual const std::string& GetFrameName() OVERRIDE; | 101 virtual const std::string& GetFrameName() OVERRIDE; |
76 virtual bool IsCrossProcessSubframe() OVERRIDE; | 102 virtual bool IsCrossProcessSubframe() OVERRIDE; |
77 virtual GURL GetLastCommittedURL() OVERRIDE; | 103 virtual GURL GetLastCommittedURL() OVERRIDE; |
78 virtual gfx::NativeView GetNativeView() OVERRIDE; | 104 virtual gfx::NativeView GetNativeView() OVERRIDE; |
79 virtual void ExecuteJavaScript( | 105 virtual void ExecuteJavaScript( |
80 const base::string16& javascript) OVERRIDE; | 106 const base::string16& javascript) OVERRIDE; |
81 virtual void ExecuteJavaScript( | 107 virtual void ExecuteJavaScript( |
82 const base::string16& javascript, | 108 const base::string16& javascript, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 const TransitionLayerData& transition_data); | 211 const TransitionLayerData& transition_data); |
186 | 212 |
187 // Tells the renderer that this RenderFrame is being swapped out for one in a | 213 // Tells the renderer that this RenderFrame is being swapped out for one in a |
188 // different renderer process. It should run its unload handler, move to | 214 // different renderer process. It should run its unload handler, move to |
189 // a blank document and create a RenderFrameProxy to replace the RenderFrame. | 215 // a blank document and create a RenderFrameProxy to replace the RenderFrame. |
190 // The renderer should preserve the Proxy object until it exits, in case we | 216 // The renderer should preserve the Proxy object until it exits, in case we |
191 // come back. The renderer can exit if it has no other active RenderFrames, | 217 // come back. The renderer can exit if it has no other active RenderFrames, |
192 // but not until WasSwappedOut is called (when it is no longer visible). | 218 // but not until WasSwappedOut is called (when it is no longer visible). |
193 void SwapOut(RenderFrameProxyHost* proxy); | 219 void SwapOut(RenderFrameProxyHost* proxy); |
194 | 220 |
195 void OnSwappedOut(bool timed_out); | 221 bool is_waiting_for_beforeunload_ack() const { |
196 bool is_swapped_out() { return is_swapped_out_; } | 222 return is_waiting_for_beforeunload_ack_; |
197 void set_swapped_out(bool is_swapped_out) { | |
198 is_swapped_out_ = is_swapped_out; | |
199 } | 223 } |
200 | 224 |
201 // Sets the RVH for |this| as pending shutdown. |on_swap_out| will be called | 225 // Whether the RFH is waiting for an unload ACK from the renderer. |
202 // when the SwapOutACK is received. | 226 bool IsWaitingForUnloadACK() const; |
| 227 |
| 228 // Called when either the SwapOut request has been acknowledged or has timed |
| 229 // out. |
| 230 void OnSwappedOut(); |
| 231 |
| 232 // Whether this RenderFrameHost has been swapped out, such that the frame is |
| 233 // now rendered by a RenderFrameHost in a different process. |
| 234 bool is_swapped_out() const { return rfh_state_ == STATE_SWAPPED_OUT; } |
| 235 |
| 236 // The current state of this RFH. |
| 237 RenderFrameHostImplState rfh_state() const { return rfh_state_; } |
| 238 |
| 239 // Set |this| as pending shutdown. |on_swap_out| will be called |
| 240 // when the SwapOutACK is received, or when the unload timer times out. |
203 void SetPendingShutdown(const base::Closure& on_swap_out); | 241 void SetPendingShutdown(const base::Closure& on_swap_out); |
204 | 242 |
205 // Sends the given navigation message. Use this rather than sending it | 243 // Sends the given navigation message. Use this rather than sending it |
206 // yourself since this does the internal bookkeeping described below. This | 244 // yourself since this does the internal bookkeeping described below. This |
207 // function takes ownership of the provided message pointer. | 245 // function takes ownership of the provided message pointer. |
208 // | 246 // |
209 // If a cross-site request is in progress, we may be suspended while waiting | 247 // If a cross-site request is in progress, we may be suspended while waiting |
210 // for the onbeforeunload handler, so this function might buffer the message | 248 // for the onbeforeunload handler, so this function might buffer the message |
211 // rather than sending it. | 249 // rather than sending it. |
212 void Navigate(const FrameMsg_Navigate_Params& params); | 250 void Navigate(const FrameMsg_Navigate_Params& params); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 void OnAccessibilityEvents( | 418 void OnAccessibilityEvents( |
381 const std::vector<AccessibilityHostMsg_EventParams>& params); | 419 const std::vector<AccessibilityHostMsg_EventParams>& params); |
382 void OnAccessibilityLocationChanges( | 420 void OnAccessibilityLocationChanges( |
383 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params); | 421 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params); |
384 | 422 |
385 #if defined(OS_MACOSX) || defined(OS_ANDROID) | 423 #if defined(OS_MACOSX) || defined(OS_ANDROID) |
386 void OnShowPopup(const FrameHostMsg_ShowPopup_Params& params); | 424 void OnShowPopup(const FrameHostMsg_ShowPopup_Params& params); |
387 void OnHidePopup(); | 425 void OnHidePopup(); |
388 #endif | 426 #endif |
389 | 427 |
| 428 // Updates the state of this RenderFrameHost and clears any waiting state |
| 429 // that is no longer relevant. |
| 430 void SetState(RenderFrameHostImplState rfh_state); |
| 431 |
390 // Returns whether the given URL is allowed to commit in the current process. | 432 // Returns whether the given URL is allowed to commit in the current process. |
391 // This is a more conservative check than RenderProcessHost::FilterURL, since | 433 // This is a more conservative check than RenderProcessHost::FilterURL, since |
392 // it will be used to kill processes that commit unauthorized URLs. | 434 // it will be used to kill processes that commit unauthorized URLs. |
393 bool CanCommitURL(const GURL& url); | 435 bool CanCommitURL(const GURL& url); |
394 | 436 |
395 void PlatformNotificationPermissionRequestDone( | 437 void PlatformNotificationPermissionRequestDone( |
396 int request_id, blink::WebNotificationPermission permission); | 438 int request_id, blink::WebNotificationPermission permission); |
397 | 439 |
398 // Update the the singleton FrameAccessibility instance with a map | 440 // Update the the singleton FrameAccessibility instance with a map |
399 // from accessibility node id to the frame routing id of a cross-process | 441 // from accessibility node id to the frame routing id of a cross-process |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 FrameTreeNode* frame_tree_node_; | 486 FrameTreeNode* frame_tree_node_; |
445 | 487 |
446 // The mapping of pending JavaScript calls created by | 488 // The mapping of pending JavaScript calls created by |
447 // ExecuteJavaScript and their corresponding callbacks. | 489 // ExecuteJavaScript and their corresponding callbacks. |
448 std::map<int, JavaScriptResultCallback> javascript_callbacks_; | 490 std::map<int, JavaScriptResultCallback> javascript_callbacks_; |
449 | 491 |
450 // Map from notification_id to a callback to cancel them. | 492 // Map from notification_id to a callback to cancel them. |
451 std::map<int, base::Closure> cancel_notification_callbacks_; | 493 std::map<int, base::Closure> cancel_notification_callbacks_; |
452 | 494 |
453 int routing_id_; | 495 int routing_id_; |
454 bool is_swapped_out_; | 496 |
| 497 // The current state of this RenderFrameHost. |
| 498 RenderFrameHostImplState rfh_state_; |
455 | 499 |
456 // Tracks whether the RenderFrame for this RenderFrameHost has been created in | 500 // Tracks whether the RenderFrame for this RenderFrameHost has been created in |
457 // the renderer process. Currently only used for subframes. | 501 // the renderer process. Currently only used for subframes. |
458 // TODO(creis): Use this for main frames as well when RVH goes away. | 502 // TODO(creis): Use this for main frames as well when RVH goes away. |
459 bool render_frame_created_; | 503 bool render_frame_created_; |
460 | 504 |
461 // Whether we should buffer outgoing Navigate messages rather than sending | 505 // Whether we should buffer outgoing Navigate messages rather than sending |
462 // them. This will be true when a RenderFrameHost is created for a cross-site | 506 // them. This will be true when a RenderFrameHost is created for a cross-site |
463 // request, until we hear back from the onbeforeunload handler of the old | 507 // request, until we hear back from the onbeforeunload handler of the old |
464 // RenderFrameHost. | 508 // RenderFrameHost. |
465 bool navigations_suspended_; | 509 bool navigations_suspended_; |
466 | 510 |
467 // We only buffer the params for a suspended navigation while this RFH is the | 511 // We only buffer the params for a suspended navigation while this RFH is the |
468 // pending RenderFrameHost of a RenderFrameHostManager. There will only ever | 512 // pending RenderFrameHost of a RenderFrameHostManager. There will only ever |
469 // be one suspended navigation, because RenderFrameHostManager will destroy | 513 // be one suspended navigation, because RenderFrameHostManager will destroy |
470 // the pending RenderFrameHost and create a new one if a second navigation | 514 // the pending RenderFrameHost and create a new one if a second navigation |
471 // occurs. | 515 // occurs. |
472 scoped_ptr<FrameMsg_Navigate_Params> suspended_nav_params_; | 516 scoped_ptr<FrameMsg_Navigate_Params> suspended_nav_params_; |
473 | 517 |
474 // When the last BeforeUnload message was sent. | 518 // When the last BeforeUnload message was sent. |
475 base::TimeTicks send_before_unload_start_time_; | 519 base::TimeTicks send_before_unload_start_time_; |
476 | 520 |
| 521 // Set to true when there is a pending FrameMsg_ShouldClose message. This |
| 522 // ensures we don't spam the renderer with multiple beforeunload requests. |
| 523 // When either this value or IsWaitingForUnloadACK is true, the value of |
| 524 // unload_ack_is_for_cross_site_transition_ indicates whether this is for a |
| 525 // cross-site transition or a tab close attempt. |
| 526 // TODO(clamy): Remove this boolean and add one more state to the state |
| 527 // machine. |
| 528 bool is_waiting_for_beforeunload_ack_; |
| 529 |
| 530 // Valid only when is_waiting_for_beforeunload_ack_ or |
| 531 // IsWaitingForUnloadACK is true. This tells us if the unload request |
| 532 // is for closing the entire tab ( = false), or only this RenderFrameHost in |
| 533 // the case of a cross-site transition ( = true). |
| 534 bool unload_ack_is_for_cross_site_transition_; |
| 535 |
| 536 // Used to swap out or shut down this RFH when the unload event is taking too |
| 537 // long to execute, depending on the number of active frames in the |
| 538 // SiteInstance. |
| 539 scoped_ptr<TimeoutMonitor> swapout_event_monitor_timeout_; |
| 540 |
| 541 // Called after receiving the SwapOutACK when the RFH is in the pending |
| 542 // shutdown state. Also called if the unload timer times out. |
| 543 base::Closure pending_shutdown_on_swap_out_; |
| 544 |
477 ServiceRegistryImpl service_registry_; | 545 ServiceRegistryImpl service_registry_; |
478 | 546 |
479 scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_; | 547 scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_; |
480 | 548 |
481 // Callback when an event is received, for testing. | 549 // Callback when an event is received, for testing. |
482 base::Callback<void(ui::AXEvent, int)> accessibility_testing_callback_; | 550 base::Callback<void(ui::AXEvent, int)> accessibility_testing_callback_; |
483 // The most recently received accessibility tree - for testing only. | 551 // The most recently received accessibility tree - for testing only. |
484 scoped_ptr<ui::AXTree> ax_tree_for_testing_; | 552 scoped_ptr<ui::AXTree> ax_tree_for_testing_; |
485 | 553 |
486 // NOTE: This must be the last member. | 554 // NOTE: This must be the last member. |
487 base::WeakPtrFactory<RenderFrameHostImpl> weak_ptr_factory_; | 555 base::WeakPtrFactory<RenderFrameHostImpl> weak_ptr_factory_; |
488 | 556 |
489 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl); | 557 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl); |
490 }; | 558 }; |
491 | 559 |
492 } // namespace content | 560 } // namespace content |
493 | 561 |
494 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_ | 562 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_ |
OLD | NEW |