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 #include "content/browser/frame_host/render_frame_host_impl.h"
8 #include "base/command_line.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/lazy_instance.h"
11 #include "base/metrics/histogram.h"
12 #include "base/metrics/user_metrics_action.h"
13 #include "base/process/kill.h"
14 #include "base/time/time.h"
15 #include "content/browser/accessibility/accessibility_mode_helper.h"
16 #include "content/browser/accessibility/browser_accessibility_manager.h"
17 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
18 #include "content/browser/child_process_security_policy_impl.h"
19 #include "content/browser/frame_host/cross_process_frame_connector.h"
20 #include "content/browser/frame_host/cross_site_transferring_request.h"
21 #include "content/browser/frame_host/frame_accessibility.h"
22 #include "content/browser/frame_host/frame_tree.h"
23 #include "content/browser/frame_host/frame_tree_node.h"
24 #include "content/browser/frame_host/navigation_request.h"
25 #include "content/browser/frame_host/navigator.h"
26 #include "content/browser/frame_host/navigator_impl.h"
27 #include "content/browser/frame_host/render_frame_host_delegate.h"
28 #include "content/browser/frame_host/render_frame_proxy_host.h"
29 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
30 #include "content/browser/geolocation/geolocation_service_context.h"
31 #include "content/browser/permissions/permission_service_context.h"
32 #include "content/browser/permissions/permission_service_impl.h"
33 #include "content/browser/presentation/presentation_service_impl.h"
34 #include "content/browser/renderer_host/input/input_router.h"
35 #include "content/browser/renderer_host/input/timeout_monitor.h"
36 #include "content/browser/renderer_host/render_process_host_impl.h"
37 #include "content/browser/renderer_host/render_view_host_delegate.h"
38 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
39 #include "content/browser/renderer_host/render_view_host_impl.h"
40 #include "content/browser/renderer_host/render_widget_host_impl.h"
41 #include "content/browser/renderer_host/render_widget_host_view_base.h"
42 #include "content/browser/transition_request_manager.h"
43 #include "content/common/accessibility_messages.h"
44 #include "content/common/frame_messages.h"
45 #include "content/common/input_messages.h"
46 #include "content/common/inter_process_time_ticks_converter.h"
47 #include "content/common/navigation_params.h"
48 #include "content/common/render_frame_setup.mojom.h"
49 #include "content/common/swapped_out_messages.h"
50 #include "content/public/browser/ax_event_notification_details.h"
51 #include "content/public/browser/browser_accessibility_state.h"
52 #include "content/public/browser/browser_context.h"
53 #include "content/public/browser/browser_plugin_guest_manager.h"
54 #include "content/public/browser/browser_thread.h"
55 #include "content/public/browser/content_browser_client.h"
56 #include "content/public/browser/render_process_host.h"
57 #include "content/public/browser/render_widget_host_view.h"
58 #include "content/public/browser/stream_handle.h"
59 #include "content/public/browser/user_metrics.h"
60 #include "content/public/common/content_constants.h"
61 #include "content/public/common/content_switches.h"
62 #include "content/public/common/url_constants.h"
63 #include "content/public/common/url_utils.h"
64 #include "ui/accessibility/ax_tree.h"
67 #if defined(OS_MACOSX)
68 #include "content/browser/frame_host/popup_menu_helper_mac.h"
71 #if defined(ENABLE_MEDIA_MOJO_RENDERER)
72 #include "media/mojo/interfaces/media_renderer.mojom.h"
73 #include "media/mojo/services/mojo_renderer_service.h"
76 using base::TimeDelta
;
82 // The next value to use for the accessibility reset token.
83 int g_next_accessibility_reset_token
= 1;
85 // The (process id, routing id) pair that identifies one RenderFrame.
86 typedef std::pair
<int32
, int32
> RenderFrameHostID
;
87 typedef base::hash_map
<RenderFrameHostID
, RenderFrameHostImpl
*>
89 base::LazyInstance
<RoutingIDFrameMap
> g_routing_id_frame_map
=
90 LAZY_INSTANCE_INITIALIZER
;
92 // Translate a WebKit text direction into a base::i18n one.
93 base::i18n::TextDirection
WebTextDirectionToChromeTextDirection(
94 blink::WebTextDirection dir
) {
96 case blink::WebTextDirectionLeftToRight
:
97 return base::i18n::LEFT_TO_RIGHT
;
98 case blink::WebTextDirectionRightToLeft
:
99 return base::i18n::RIGHT_TO_LEFT
;
102 return base::i18n::UNKNOWN_DIRECTION
;
109 bool RenderFrameHostImpl::IsRFHStateActive(RenderFrameHostImplState rfh_state
) {
110 return rfh_state
== STATE_DEFAULT
;
114 RenderFrameHost
* RenderFrameHost::FromID(int render_process_id
,
115 int render_frame_id
) {
116 return RenderFrameHostImpl::FromID(render_process_id
, render_frame_id
);
120 RenderFrameHostImpl
* RenderFrameHostImpl::FromID(int process_id
,
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI
));
123 RoutingIDFrameMap
* frames
= g_routing_id_frame_map
.Pointer();
124 RoutingIDFrameMap::iterator it
= frames
->find(
125 RenderFrameHostID(process_id
, routing_id
));
126 return it
== frames
->end() ? NULL
: it
->second
;
129 RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance
* site_instance
,
130 RenderViewHostImpl
* render_view_host
,
131 RenderFrameHostDelegate
* delegate
,
132 RenderWidgetHostDelegate
* rwh_delegate
,
133 FrameTree
* frame_tree
,
134 FrameTreeNode
* frame_tree_node
,
137 : render_view_host_(render_view_host
),
139 site_instance_(static_cast<SiteInstanceImpl
*>(site_instance
)),
140 process_(site_instance
->GetProcess()),
141 cross_process_frame_connector_(NULL
),
142 render_frame_proxy_host_(NULL
),
143 frame_tree_(frame_tree
),
144 frame_tree_node_(frame_tree_node
),
145 routing_id_(routing_id
),
146 render_frame_created_(false),
147 navigations_suspended_(false),
148 has_beforeunload_handlers_(false),
149 has_unload_handlers_(false),
150 override_sudden_termination_status_(false),
151 is_waiting_for_beforeunload_ack_(false),
152 unload_ack_is_for_navigation_(false),
153 accessibility_reset_token_(0),
154 accessibility_reset_count_(0),
155 no_create_browser_accessibility_manager_for_testing_(false),
156 weak_ptr_factory_(this) {
157 bool is_swapped_out
= !!(flags
& CREATE_RF_SWAPPED_OUT
);
158 bool hidden
= !!(flags
& CREATE_RF_HIDDEN
);
159 frame_tree_
->RegisterRenderFrameHost(this);
160 GetProcess()->AddRoute(routing_id_
, this);
161 g_routing_id_frame_map
.Get().insert(std::make_pair(
162 RenderFrameHostID(GetProcess()->GetID(), routing_id_
),
165 if (is_swapped_out
) {
166 rfh_state_
= STATE_SWAPPED_OUT
;
168 rfh_state_
= STATE_DEFAULT
;
169 GetSiteInstance()->increment_active_frame_count();
173 swapout_event_monitor_timeout_
.reset(new TimeoutMonitor(base::Bind(
174 &RenderFrameHostImpl::OnSwappedOut
, weak_ptr_factory_
.GetWeakPtr())));
176 if (flags
& CREATE_RF_NEEDS_RENDER_WIDGET_HOST
) {
177 render_widget_host_
.reset(new RenderWidgetHostImpl(
178 rwh_delegate
, GetProcess(), MSG_ROUTING_NONE
, hidden
));
179 render_widget_host_
->set_owned_by_render_frame_host(true);
183 RenderFrameHostImpl::~RenderFrameHostImpl() {
184 GetProcess()->RemoveRoute(routing_id_
);
185 g_routing_id_frame_map
.Get().erase(
186 RenderFrameHostID(GetProcess()->GetID(), routing_id_
));
188 if (delegate_
&& render_frame_created_
)
189 delegate_
->RenderFrameDeleted(this);
191 FrameAccessibility::GetInstance()->OnRenderFrameHostDestroyed(this);
193 // If this was swapped out, it already decremented the active frame count of
194 // the SiteInstance it belongs to.
195 if (IsRFHStateActive(rfh_state_
))
196 GetSiteInstance()->decrement_active_frame_count();
198 // Notify the FrameTree that this RFH is going away, allowing it to shut down
199 // the corresponding RenderViewHost if it is no longer needed.
200 frame_tree_
->UnregisterRenderFrameHost(this);
202 // NULL out the swapout timer; in crash dumps this member will be null only if
204 swapout_event_monitor_timeout_
.reset();
206 for (const auto& iter
: visual_state_callbacks_
) {
207 iter
.second
.Run(false);
210 if (render_widget_host_
)
211 render_widget_host_
->Cleanup();
214 int RenderFrameHostImpl::GetRoutingID() {
218 SiteInstanceImpl
* RenderFrameHostImpl::GetSiteInstance() {
219 return site_instance_
.get();
222 RenderProcessHost
* RenderFrameHostImpl::GetProcess() {
226 RenderFrameHost
* RenderFrameHostImpl::GetParent() {
227 FrameTreeNode
* parent_node
= frame_tree_node_
->parent();
230 return parent_node
->current_frame_host();
233 const std::string
& RenderFrameHostImpl::GetFrameName() {
234 return frame_tree_node_
->frame_name();
237 bool RenderFrameHostImpl::IsCrossProcessSubframe() {
238 FrameTreeNode
* parent_node
= frame_tree_node_
->parent();
241 return GetSiteInstance() !=
242 parent_node
->current_frame_host()->GetSiteInstance();
245 GURL
RenderFrameHostImpl::GetLastCommittedURL() {
246 return frame_tree_node_
->current_url();
249 gfx::NativeView
RenderFrameHostImpl::GetNativeView() {
250 RenderWidgetHostView
* view
= render_view_host_
->GetView();
253 return view
->GetNativeView();
256 void RenderFrameHostImpl::ExecuteJavaScript(
257 const base::string16
& javascript
) {
258 Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_
,
263 void RenderFrameHostImpl::ExecuteJavaScript(
264 const base::string16
& javascript
,
265 const JavaScriptResultCallback
& callback
) {
266 static int next_id
= 1;
268 Send(new FrameMsg_JavaScriptExecuteRequest(routing_id_
,
271 javascript_callbacks_
.insert(std::make_pair(key
, callback
));
274 void RenderFrameHostImpl::ExecuteJavaScriptForTests(
275 const base::string16
& javascript
) {
276 Send(new FrameMsg_JavaScriptExecuteRequestForTests(routing_id_
,
281 RenderViewHost
* RenderFrameHostImpl::GetRenderViewHost() {
282 return render_view_host_
;
285 ServiceRegistry
* RenderFrameHostImpl::GetServiceRegistry() {
286 return service_registry_
.get();
289 blink::WebPageVisibilityState
RenderFrameHostImpl::GetVisibilityState() {
290 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops
291 // returning nullptr in some cases. See https://crbug.com/455245.
292 blink::WebPageVisibilityState visibility_state
=
293 RenderWidgetHostImpl::From(GetView()->GetRenderWidgetHost())->is_hidden()
294 ? blink::WebPageVisibilityStateHidden
295 : blink::WebPageVisibilityStateVisible
;
296 GetContentClient()->browser()->OverridePageVisibilityState(this,
298 return visibility_state
;
301 bool RenderFrameHostImpl::Send(IPC::Message
* message
) {
302 if (IPC_MESSAGE_ID_CLASS(message
->type()) == InputMsgStart
) {
303 return render_view_host_
->input_router()->SendInput(
304 make_scoped_ptr(message
));
307 return GetProcess()->Send(message
);
310 bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message
&msg
) {
311 // Filter out most IPC messages if this frame is swapped out.
312 // We still want to handle certain ACKs to keep our state consistent.
313 if (is_swapped_out()) {
314 if (!SwappedOutMessages::CanHandleWhileSwappedOut(msg
)) {
315 // If this is a synchronous message and we decided not to handle it,
316 // we must send an error reply, or else the renderer will be stuck
317 // and won't respond to future requests.
319 IPC::Message
* reply
= IPC::SyncMessage::GenerateReply(&msg
);
320 reply
->set_reply_error();
323 // Don't continue looking for someone to handle it.
328 if (delegate_
->OnMessageReceived(this, msg
))
331 RenderFrameProxyHost
* proxy
=
332 frame_tree_node_
->render_manager()->GetProxyToParent();
333 if (proxy
&& proxy
->cross_process_frame_connector() &&
334 proxy
->cross_process_frame_connector()->OnMessageReceived(msg
))
338 IPC_BEGIN_MESSAGE_MAP(RenderFrameHostImpl
, msg
)
339 IPC_MESSAGE_HANDLER(FrameHostMsg_AddMessageToConsole
, OnAddMessageToConsole
)
340 IPC_MESSAGE_HANDLER(FrameHostMsg_Detach
, OnDetach
)
341 IPC_MESSAGE_HANDLER(FrameHostMsg_FrameFocused
, OnFrameFocused
)
342 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartProvisionalLoadForFrame
,
343 OnDidStartProvisionalLoadForFrame
)
344 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailProvisionalLoadWithError
,
345 OnDidFailProvisionalLoadWithError
)
346 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError
,
347 OnDidFailLoadWithError
)
348 IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad
,
349 OnDidCommitProvisionalLoad(msg
))
350 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDropNavigation
, OnDidDropNavigation
)
351 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL
, OnOpenURL
)
352 IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted
,
353 OnDocumentOnLoadCompleted
)
354 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnload_ACK
, OnBeforeUnloadACK
)
355 IPC_MESSAGE_HANDLER(FrameHostMsg_BeforeUnloadHandlersPresent
,
356 OnBeforeUnloadHandlersPresent
)
357 IPC_MESSAGE_HANDLER(FrameHostMsg_UnloadHandlersPresent
,
358 OnUnloadHandlersPresent
)
359 IPC_MESSAGE_HANDLER(FrameHostMsg_SwapOut_ACK
, OnSwapOutACK
)
360 IPC_MESSAGE_HANDLER(FrameHostMsg_ContextMenu
, OnContextMenu
)
361 IPC_MESSAGE_HANDLER(FrameHostMsg_JavaScriptExecuteResponse
,
362 OnJavaScriptExecuteResponse
)
363 IPC_MESSAGE_HANDLER(FrameHostMsg_VisualStateResponse
,
364 OnVisualStateResponse
)
365 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunJavaScriptMessage
,
366 OnRunJavaScriptMessage
)
367 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunBeforeUnloadConfirm
,
368 OnRunBeforeUnloadConfirm
)
369 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument
,
370 OnDidAccessInitialDocument
)
371 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisownOpener
, OnDidDisownOpener
)
372 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAssignPageId
, OnDidAssignPageId
)
373 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle
, OnUpdateTitle
)
374 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding
, OnUpdateEncoding
)
375 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation
,
377 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad
, OnDispatchLoad
)
378 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse
,
379 OnTextSurroundingSelectionResponse
)
380 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events
, OnAccessibilityEvents
)
381 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges
,
382 OnAccessibilityLocationChanges
)
383 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_FindInPageResult
,
384 OnAccessibilityFindInPageResult
)
385 IPC_MESSAGE_HANDLER(FrameHostMsg_ToggleFullscreen
, OnToggleFullscreen
)
386 // The following message is synthetic and doesn't come from RenderFrame, but
387 // from RenderProcessHost.
388 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone
, OnRenderProcessGone
)
389 #if defined(OS_MACOSX) || defined(OS_ANDROID)
390 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup
, OnShowPopup
)
391 IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup
, OnHidePopup
)
393 IPC_END_MESSAGE_MAP()
395 // No further actions here, since we may have been deleted.
399 void RenderFrameHostImpl::AccessibilitySetFocus(int object_id
) {
400 Send(new AccessibilityMsg_SetFocus(routing_id_
, object_id
));
403 void RenderFrameHostImpl::AccessibilityDoDefaultAction(int object_id
) {
404 Send(new AccessibilityMsg_DoDefaultAction(routing_id_
, object_id
));
407 void RenderFrameHostImpl::AccessibilityShowMenu(
408 const gfx::Point
& global_point
) {
409 RenderWidgetHostViewBase
* view
= static_cast<RenderWidgetHostViewBase
*>(
410 render_view_host_
->GetView());
412 view
->AccessibilityShowMenu(global_point
);
415 void RenderFrameHostImpl::AccessibilityScrollToMakeVisible(
416 int acc_obj_id
, const gfx::Rect
& subfocus
) {
417 Send(new AccessibilityMsg_ScrollToMakeVisible(
418 routing_id_
, acc_obj_id
, subfocus
));
421 void RenderFrameHostImpl::AccessibilityScrollToPoint(
422 int acc_obj_id
, const gfx::Point
& point
) {
423 Send(new AccessibilityMsg_ScrollToPoint(
424 routing_id_
, acc_obj_id
, point
));
427 void RenderFrameHostImpl::AccessibilitySetTextSelection(
428 int object_id
, int start_offset
, int end_offset
) {
429 Send(new AccessibilityMsg_SetTextSelection(
430 routing_id_
, object_id
, start_offset
, end_offset
));
433 void RenderFrameHostImpl::AccessibilitySetValue(
434 int object_id
, const base::string16
& value
) {
435 Send(new AccessibilityMsg_SetValue(routing_id_
, object_id
, value
));
438 bool RenderFrameHostImpl::AccessibilityViewHasFocus() const {
439 RenderWidgetHostView
* view
= render_view_host_
->GetView();
441 return view
->HasFocus();
445 gfx::Rect
RenderFrameHostImpl::AccessibilityGetViewBounds() const {
446 RenderWidgetHostView
* view
= render_view_host_
->GetView();
448 return view
->GetViewBounds();
452 gfx::Point
RenderFrameHostImpl::AccessibilityOriginInScreen(
453 const gfx::Rect
& bounds
) const {
454 RenderWidgetHostViewBase
* view
= static_cast<RenderWidgetHostViewBase
*>(
455 render_view_host_
->GetView());
457 return view
->AccessibilityOriginInScreen(bounds
);
461 void RenderFrameHostImpl::AccessibilityHitTest(const gfx::Point
& point
) {
462 Send(new AccessibilityMsg_HitTest(routing_id_
, point
));
465 void RenderFrameHostImpl::AccessibilitySetAccessibilityFocus(int acc_obj_id
) {
466 Send(new AccessibilityMsg_SetAccessibilityFocus(routing_id_
, acc_obj_id
));
469 void RenderFrameHostImpl::AccessibilityFatalError() {
470 browser_accessibility_manager_
.reset(NULL
);
471 if (accessibility_reset_token_
)
474 accessibility_reset_count_
++;
475 if (accessibility_reset_count_
>= kMaxAccessibilityResets
) {
476 Send(new AccessibilityMsg_FatalError(routing_id_
));
478 accessibility_reset_token_
= g_next_accessibility_reset_token
++;
479 UMA_HISTOGRAM_COUNTS("Accessibility.FrameResetCount", 1);
480 Send(new AccessibilityMsg_Reset(routing_id_
, accessibility_reset_token_
));
484 gfx::AcceleratedWidget
485 RenderFrameHostImpl::AccessibilityGetAcceleratedWidget() {
486 RenderWidgetHostViewBase
* view
= static_cast<RenderWidgetHostViewBase
*>(
487 render_view_host_
->GetView());
489 return view
->AccessibilityGetAcceleratedWidget();
490 return gfx::kNullAcceleratedWidget
;
493 gfx::NativeViewAccessible
494 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() {
495 RenderWidgetHostViewBase
* view
= static_cast<RenderWidgetHostViewBase
*>(
496 render_view_host_
->GetView());
498 return view
->AccessibilityGetNativeViewAccessible();
502 BrowserAccessibilityManager
* RenderFrameHostImpl::AccessibilityGetChildFrame(
503 int accessibility_node_id
) {
504 RenderFrameHostImpl
* child_frame
=
505 FrameAccessibility::GetInstance()->GetChild(this, accessibility_node_id
);
506 if (!child_frame
|| IsSameSiteInstance(child_frame
))
509 return child_frame
->GetOrCreateBrowserAccessibilityManager();
512 void RenderFrameHostImpl::AccessibilityGetAllChildFrames(
513 std::vector
<BrowserAccessibilityManager
*>* child_frames
) {
514 std::vector
<RenderFrameHostImpl
*> child_frame_hosts
;
515 FrameAccessibility::GetInstance()->GetAllChildFrames(
516 this, &child_frame_hosts
);
517 for (size_t i
= 0; i
< child_frame_hosts
.size(); ++i
) {
518 RenderFrameHostImpl
* child_frame_host
= child_frame_hosts
[i
];
519 if (!child_frame_host
|| IsSameSiteInstance(child_frame_host
))
522 BrowserAccessibilityManager
* manager
=
523 child_frame_host
->GetOrCreateBrowserAccessibilityManager();
525 child_frames
->push_back(manager
);
529 BrowserAccessibility
* RenderFrameHostImpl::AccessibilityGetParentFrame() {
530 RenderFrameHostImpl
* parent_frame
= NULL
;
531 int parent_node_id
= 0;
532 if (!FrameAccessibility::GetInstance()->GetParent(
533 this, &parent_frame
, &parent_node_id
)) {
537 // As a sanity check, make sure the frame we're going to return belongs
538 // to the same BrowserContext.
539 if (GetSiteInstance()->GetBrowserContext() !=
540 parent_frame
->GetSiteInstance()->GetBrowserContext()) {
545 BrowserAccessibilityManager
* manager
=
546 parent_frame
->browser_accessibility_manager();
550 return manager
->GetFromID(parent_node_id
);
553 bool RenderFrameHostImpl::CreateRenderFrame(int parent_routing_id
,
554 int proxy_routing_id
) {
555 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame");
556 DCHECK(!IsRenderFrameLive()) << "Creating frame twice";
558 // The process may (if we're sharing a process with another host that already
559 // initialized it) or may not (we have our own process or the old process
560 // crashed) have been initialized. Calling Init multiple times will be
561 // ignored, so this is safe.
562 if (!GetProcess()->Init())
565 DCHECK(GetProcess()->HasConnection());
567 FrameMsg_NewFrame_WidgetParams widget_params
;
568 if (render_widget_host_
) {
569 widget_params
.routing_id
= render_widget_host_
->GetRoutingID();
570 widget_params
.surface_id
= render_widget_host_
->surface_id();
571 widget_params
.hidden
= render_widget_host_
->is_hidden();
573 // MSG_ROUTING_NONE will prevent a new RenderWidget from being created in
574 // the renderer process.
575 widget_params
.routing_id
= MSG_ROUTING_NONE
;
576 widget_params
.surface_id
= 0;
577 widget_params
.hidden
= true;
580 Send(new FrameMsg_NewFrame(routing_id_
, parent_routing_id
, proxy_routing_id
,
581 frame_tree_node()->current_replication_state(),
584 // The RenderWidgetHost takes ownership of its view. It is tied to the
585 // lifetime of the current RenderProcessHost for this RenderFrameHost.
586 if (render_widget_host_
) {
587 RenderWidgetHostView
* rwhv
=
588 new RenderWidgetHostViewChildFrame(render_widget_host_
.get());
592 if (proxy_routing_id
!= MSG_ROUTING_NONE
) {
593 RenderFrameProxyHost
* proxy
= RenderFrameProxyHost::FromID(
594 GetProcess()->GetID(), proxy_routing_id
);
595 // We have also created a RenderFrameProxy in FrameMsg_NewFrame above, so
597 proxy
->set_render_frame_proxy_created(true);
600 // The renderer now has a RenderFrame for this RenderFrameHost. Note that
601 // this path is only used for out-of-process iframes. Main frame RenderFrames
602 // are created with their RenderView, and same-site iframes are created at the
603 // time of OnCreateChildFrame.
604 SetRenderFrameCreated(true);
609 bool RenderFrameHostImpl::IsRenderFrameLive() {
610 // RenderFrames are created for main frames at the same time as RenderViews,
611 // so we rely on IsRenderViewLive. For subframes, we keep track of each
612 // RenderFrame individually with render_frame_created_.
613 bool is_live
= !GetParent() ?
614 render_view_host_
->IsRenderViewLive() :
615 GetProcess()->HasConnection() && render_frame_created_
;
617 // Sanity check: the RenderView should always be live if the RenderFrame is.
618 DCHECK(!is_live
|| render_view_host_
->IsRenderViewLive());
623 void RenderFrameHostImpl::SetRenderFrameCreated(bool created
) {
624 // If the current status is different than the new status, the delegate
625 // needs to be notified.
626 if (delegate_
&& (created
!= render_frame_created_
)) {
628 delegate_
->RenderFrameCreated(this);
630 delegate_
->RenderFrameDeleted(this);
633 render_frame_created_
= created
;
634 if (created
&& render_widget_host_
)
635 render_widget_host_
->InitForFrame();
638 void RenderFrameHostImpl::Init() {
639 GetProcess()->ResumeRequestsForView(routing_id_
);
642 void RenderFrameHostImpl::OnAddMessageToConsole(
644 const base::string16
& message
,
646 const base::string16
& source_id
) {
647 if (delegate_
->AddMessageToConsole(level
, message
, line_no
, source_id
))
650 // Pass through log level only on WebUI pages to limit console spew.
651 const bool is_web_ui
=
652 HasWebUIScheme(delegate_
->GetMainFrameLastCommittedURL());
653 const int32 resolved_level
= is_web_ui
? level
: ::logging::LOG_INFO
;
655 // LogMessages can be persisted so this shouldn't be logged in incognito mode.
656 // This rule is not applied to WebUI pages, because source code of WebUI is a
657 // part of Chrome source code, and we want to treat messages from WebUI the
658 // same way as we treat log messages from native code.
659 if (::logging::GetMinLogLevel() <= resolved_level
&&
661 !GetSiteInstance()->GetBrowserContext()->IsOffTheRecord())) {
662 logging::LogMessage("CONSOLE", line_no
, resolved_level
).stream()
663 << "\"" << message
<< "\", source: " << source_id
<< " (" << line_no
668 void RenderFrameHostImpl::OnCreateChildFrame(int new_routing_id
,
669 const std::string
& frame_name
,
670 SandboxFlags sandbox_flags
) {
671 // It is possible that while a new RenderFrameHost was committed, the
672 // RenderFrame corresponding to this host sent an IPC message to create a
673 // frame and it is delivered after this host is swapped out.
674 // Ignore such messages, as we know this RenderFrameHost is going away.
675 if (rfh_state_
!= RenderFrameHostImpl::STATE_DEFAULT
)
678 RenderFrameHostImpl
* new_frame
= frame_tree_
->AddFrame(
679 frame_tree_node_
, GetProcess()->GetID(), new_routing_id
, frame_name
);
683 new_frame
->frame_tree_node()->set_sandbox_flags(sandbox_flags
);
685 // We know that the RenderFrame has been created in this case, immediately
686 // after the CreateChildFrame IPC was sent.
687 new_frame
->SetRenderFrameCreated(true);
690 void RenderFrameHostImpl::OnDetach() {
691 frame_tree_
->RemoveFrame(frame_tree_node_
);
694 void RenderFrameHostImpl::OnFrameFocused() {
695 frame_tree_
->SetFocusedFrame(frame_tree_node_
);
698 void RenderFrameHostImpl::OnOpenURL(const FrameHostMsg_OpenURL_Params
& params
) {
699 OpenURL(params
, GetSiteInstance());
702 void RenderFrameHostImpl::OnDocumentOnLoadCompleted(
703 FrameMsg_UILoadMetricsReportType::Value report_type
,
704 base::TimeTicks ui_timestamp
) {
705 if (report_type
== FrameMsg_UILoadMetricsReportType::REPORT_LINK
) {
706 UMA_HISTOGRAM_CUSTOM_TIMES("Navigation.UI_OnLoadComplete.Link",
707 base::TimeTicks::Now() - ui_timestamp
,
708 base::TimeDelta::FromMilliseconds(10),
709 base::TimeDelta::FromMinutes(10), 100);
710 } else if (report_type
== FrameMsg_UILoadMetricsReportType::REPORT_INTENT
) {
711 UMA_HISTOGRAM_CUSTOM_TIMES("Navigation.UI_OnLoadComplete.Intent",
712 base::TimeTicks::Now() - ui_timestamp
,
713 base::TimeDelta::FromMilliseconds(10),
714 base::TimeDelta::FromMinutes(10), 100);
716 // This message is only sent for top-level frames. TODO(avi): when frame tree
717 // mirroring works correctly, add a check here to enforce it.
718 delegate_
->DocumentOnLoadCompleted(this);
721 void RenderFrameHostImpl::OnDidStartProvisionalLoadForFrame(
723 bool is_transition_navigation
) {
724 frame_tree_node_
->navigator()->DidStartProvisionalLoad(
725 this, url
, is_transition_navigation
);
728 void RenderFrameHostImpl::OnDidFailProvisionalLoadWithError(
729 const FrameHostMsg_DidFailProvisionalLoadWithError_Params
& params
) {
730 frame_tree_node_
->navigator()->DidFailProvisionalLoadWithError(this, params
);
733 void RenderFrameHostImpl::OnDidFailLoadWithError(
736 const base::string16
& error_description
) {
737 GURL
validated_url(url
);
738 GetProcess()->FilterURL(false, &validated_url
);
740 frame_tree_node_
->navigator()->DidFailLoadWithError(
741 this, validated_url
, error_code
, error_description
);
744 // Called when the renderer navigates. For every frame loaded, we'll get this
745 // notification containing parameters identifying the navigation.
747 // Subframes are identified by the page transition type. For subframes loaded
748 // as part of a wider page load, the page_id will be the same as for the top
749 // level frame. If the user explicitly requests a subframe navigation, we will
750 // get a new page_id because we need to create a new navigation entry for that
752 void RenderFrameHostImpl::OnDidCommitProvisionalLoad(const IPC::Message
& msg
) {
753 // Read the parameters out of the IPC message directly to avoid making another
754 // copy when we filter the URLs.
755 PickleIterator
iter(msg
);
756 FrameHostMsg_DidCommitProvisionalLoad_Params validated_params
;
757 if (!IPC::ParamTraits
<FrameHostMsg_DidCommitProvisionalLoad_Params
>::
758 Read(&msg
, &iter
, &validated_params
))
760 TRACE_EVENT1("navigation", "RenderFrameHostImpl::OnDidCommitProvisionalLoad",
761 "url", validated_params
.url
.possibly_invalid_spec());
763 // If we're waiting for a cross-site beforeunload ack from this renderer and
764 // we receive a Navigate message from the main frame, then the renderer was
765 // navigating already and sent it before hearing the FrameMsg_Stop message.
766 // We do not want to cancel the pending navigation in this case, since the
767 // old page will soon be stopped. Instead, treat this as a beforeunload ack
768 // to allow the pending navigation to continue.
769 if (is_waiting_for_beforeunload_ack_
&&
770 unload_ack_is_for_navigation_
&&
771 ui::PageTransitionIsMainFrame(validated_params
.transition
)) {
772 base::TimeTicks approx_renderer_start_time
= send_before_unload_start_time_
;
773 OnBeforeUnloadACK(true, approx_renderer_start_time
, base::TimeTicks::Now());
777 // If we're waiting for an unload ack from this renderer and we receive a
778 // Navigate message, then the renderer was navigating before it received the
779 // unload request. It will either respond to the unload request soon or our
780 // timer will expire. Either way, we should ignore this message, because we
781 // have already committed to closing this renderer.
782 if (IsWaitingForUnloadACK())
785 if (validated_params
.report_type
==
786 FrameMsg_UILoadMetricsReportType::REPORT_LINK
) {
787 UMA_HISTOGRAM_CUSTOM_TIMES(
788 "Navigation.UI_OnCommitProvisionalLoad.Link",
789 base::TimeTicks::Now() - validated_params
.ui_timestamp
,
790 base::TimeDelta::FromMilliseconds(10), base::TimeDelta::FromMinutes(10),
792 } else if (validated_params
.report_type
==
793 FrameMsg_UILoadMetricsReportType::REPORT_INTENT
) {
794 UMA_HISTOGRAM_CUSTOM_TIMES(
795 "Navigation.UI_OnCommitProvisionalLoad.Intent",
796 base::TimeTicks::Now() - validated_params
.ui_timestamp
,
797 base::TimeDelta::FromMilliseconds(10), base::TimeDelta::FromMinutes(10),
801 RenderProcessHost
* process
= GetProcess();
803 // Attempts to commit certain off-limits URL should be caught more strictly
804 // than our FilterURL checks below. If a renderer violates this policy, it
806 if (!CanCommitURL(validated_params
.url
)) {
807 VLOG(1) << "Blocked URL " << validated_params
.url
.spec();
808 validated_params
.url
= GURL(url::kAboutBlankURL
);
809 RecordAction(base::UserMetricsAction("CanCommitURL_BlockedAndKilled"));
810 // Kills the process.
811 process
->ReceivedBadMessage();
814 // Without this check, an evil renderer can trick the browser into creating
815 // a navigation entry for a banned URL. If the user clicks the back button
816 // followed by the forward button (or clicks reload, or round-trips through
817 // session restore, etc), we'll think that the browser commanded the
818 // renderer to load the URL and grant the renderer the privileges to request
819 // the URL. To prevent this attack, we block the renderer from inserting
820 // banned URLs into the navigation controller in the first place.
821 process
->FilterURL(false, &validated_params
.url
);
822 process
->FilterURL(true, &validated_params
.referrer
.url
);
823 for (std::vector
<GURL
>::iterator
it(validated_params
.redirects
.begin());
824 it
!= validated_params
.redirects
.end(); ++it
) {
825 process
->FilterURL(false, &(*it
));
827 process
->FilterURL(true, &validated_params
.searchable_form_url
);
829 // Without this check, the renderer can trick the browser into using
830 // filenames it can't access in a future session restore.
831 if (!render_view_host_
->CanAccessFilesOfPageState(
832 validated_params
.page_state
)) {
833 GetProcess()->ReceivedBadMessage();
837 accessibility_reset_count_
= 0;
838 frame_tree_node()->navigator()->DidNavigate(this, validated_params
);
841 void RenderFrameHostImpl::OnDidDropNavigation() {
842 // At the end of Navigate(), the delegate's DidStartLoading is called to force
843 // the spinner to start, even if the renderer didn't yet begin the load. If it
844 // turns out that the renderer dropped the navigation, we need to turn off the
846 delegate_
->DidStopLoading(this);
849 RenderWidgetHostImpl
* RenderFrameHostImpl::GetRenderWidgetHost() {
850 if (render_widget_host_
)
851 return render_widget_host_
.get();
853 // TODO(kenrb): When RenderViewHost no longer inherits RenderWidgetHost,
854 // we can remove this fallback. Currently it is only used for the main
857 return static_cast<RenderWidgetHostImpl
*>(render_view_host_
);
862 RenderWidgetHostView
* RenderFrameHostImpl::GetView() {
863 RenderFrameHostImpl
* frame
= this;
865 if (frame
->render_widget_host_
)
866 return frame
->render_widget_host_
->GetView();
867 frame
= static_cast<RenderFrameHostImpl
*>(frame
->GetParent());
870 return render_view_host_
->GetView();
873 int RenderFrameHostImpl::GetEnabledBindings() {
874 return render_view_host_
->GetEnabledBindings();
877 void RenderFrameHostImpl::OnCrossSiteResponse(
878 const GlobalRequestID
& global_request_id
,
879 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request
,
880 const std::vector
<GURL
>& transfer_url_chain
,
881 const Referrer
& referrer
,
882 ui::PageTransition page_transition
,
883 bool should_replace_current_entry
) {
884 frame_tree_node_
->render_manager()->OnCrossSiteResponse(
885 this, global_request_id
, cross_site_transferring_request
.Pass(),
886 transfer_url_chain
, referrer
, page_transition
,
887 should_replace_current_entry
);
890 void RenderFrameHostImpl::OnDeferredAfterResponseStarted(
891 const GlobalRequestID
& global_request_id
,
892 const TransitionLayerData
& transition_data
) {
893 frame_tree_node_
->render_manager()->OnDeferredAfterResponseStarted(
894 global_request_id
, this);
896 if (GetParent() || !delegate_
->WillHandleDeferAfterResponseStarted())
897 frame_tree_node_
->render_manager()->ResumeResponseDeferredAtStart();
899 delegate_
->DidDeferAfterResponseStarted(transition_data
);
902 void RenderFrameHostImpl::SwapOut(
903 RenderFrameProxyHost
* proxy
,
905 // The end of this event is in OnSwapOutACK when the RenderFrame has completed
906 // the operation and sends back an IPC message.
907 // The trace event may not end properly if the ACK times out. We expect this
908 // to be fixed when RenderViewHostImpl::OnSwapOut moves to RenderFrameHost.
909 TRACE_EVENT_ASYNC_BEGIN0("navigation", "RenderFrameHostImpl::SwapOut", this);
911 // If this RenderFrameHost is not in the default state, it must have already
912 // gone through this, therefore just return.
913 if (rfh_state_
!= RenderFrameHostImpl::STATE_DEFAULT
) {
914 NOTREACHED() << "RFH should be in default state when calling SwapOut.";
918 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT
);
919 swapout_event_monitor_timeout_
->Start(
920 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS
));
922 // There may be no proxy if there are no active views in the process.
923 int proxy_routing_id
= MSG_ROUTING_NONE
;
924 FrameReplicationState replication_state
;
926 set_render_frame_proxy_host(proxy
);
927 proxy_routing_id
= proxy
->GetRoutingID();
928 replication_state
= proxy
->frame_tree_node()->current_replication_state();
931 if (IsRenderFrameLive()) {
932 Send(new FrameMsg_SwapOut(routing_id_
, proxy_routing_id
, is_loading
,
937 delegate_
->SwappedOut(this);
940 void RenderFrameHostImpl::OnBeforeUnloadACK(
942 const base::TimeTicks
& renderer_before_unload_start_time
,
943 const base::TimeTicks
& renderer_before_unload_end_time
) {
944 TRACE_EVENT_ASYNC_END0(
945 "navigation", "RenderFrameHostImpl::BeforeUnload", this);
946 DCHECK(!GetParent());
947 // If this renderer navigated while the beforeunload request was in flight, we
948 // may have cleared this state in OnDidCommitProvisionalLoad, in which case we
949 // can ignore this message.
950 // However renderer might also be swapped out but we still want to proceed
951 // with navigation, otherwise it would block future navigations. This can
952 // happen when pending cross-site navigation is canceled by a second one just
953 // before OnDidCommitProvisionalLoad while current RVH is waiting for commit
954 // but second navigation is started from the beginning.
955 if (!is_waiting_for_beforeunload_ack_
) {
958 DCHECK(!send_before_unload_start_time_
.is_null());
960 // Sets a default value for before_unload_end_time so that the browser
961 // survives a hacked renderer.
962 base::TimeTicks before_unload_end_time
= renderer_before_unload_end_time
;
963 if (!renderer_before_unload_start_time
.is_null() &&
964 !renderer_before_unload_end_time
.is_null()) {
965 // When passing TimeTicks across process boundaries, we need to compensate
966 // for any skew between the processes. Here we are converting the
967 // renderer's notion of before_unload_end_time to TimeTicks in the browser
968 // process. See comments in inter_process_time_ticks_converter.h for more.
969 base::TimeTicks receive_before_unload_ack_time
= base::TimeTicks::Now();
970 InterProcessTimeTicksConverter
converter(
971 LocalTimeTicks::FromTimeTicks(send_before_unload_start_time_
),
972 LocalTimeTicks::FromTimeTicks(receive_before_unload_ack_time
),
973 RemoteTimeTicks::FromTimeTicks(renderer_before_unload_start_time
),
974 RemoteTimeTicks::FromTimeTicks(renderer_before_unload_end_time
));
975 LocalTimeTicks browser_before_unload_end_time
=
976 converter
.ToLocalTimeTicks(
977 RemoteTimeTicks::FromTimeTicks(renderer_before_unload_end_time
));
978 before_unload_end_time
= browser_before_unload_end_time
.ToTimeTicks();
980 // Collect UMA on the inter-process skew.
981 bool is_skew_additive
= false;
982 if (converter
.IsSkewAdditiveForMetrics()) {
983 is_skew_additive
= true;
984 base::TimeDelta skew
= converter
.GetSkewForMetrics();
985 if (skew
>= base::TimeDelta()) {
987 "InterProcessTimeTicks.BrowserBehind_RendererToBrowser", skew
);
990 "InterProcessTimeTicks.BrowserAhead_RendererToBrowser", -skew
);
993 UMA_HISTOGRAM_BOOLEAN(
994 "InterProcessTimeTicks.IsSkewAdditive_RendererToBrowser",
997 base::TimeDelta on_before_unload_overhead_time
=
998 (receive_before_unload_ack_time
- send_before_unload_start_time_
) -
999 (renderer_before_unload_end_time
- renderer_before_unload_start_time
);
1000 UMA_HISTOGRAM_TIMES("Navigation.OnBeforeUnloadOverheadTime",
1001 on_before_unload_overhead_time
);
1003 frame_tree_node_
->navigator()->LogBeforeUnloadTime(
1004 renderer_before_unload_start_time
, renderer_before_unload_end_time
);
1006 // Resets beforeunload waiting state.
1007 is_waiting_for_beforeunload_ack_
= false;
1008 render_view_host_
->decrement_in_flight_event_count();
1009 render_view_host_
->StopHangMonitorTimeout();
1010 send_before_unload_start_time_
= base::TimeTicks();
1012 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1013 switches::kEnableBrowserSideNavigation
)) {
1014 // TODO(clamy): see if before_unload_end_time should be transmitted to the
1016 frame_tree_node_
->navigator()->OnBeforeUnloadACK(
1017 frame_tree_node_
, proceed
);
1019 frame_tree_node_
->render_manager()->OnBeforeUnloadACK(
1020 unload_ack_is_for_navigation_
, proceed
,
1021 before_unload_end_time
);
1024 // If canceled, notify the delegate to cancel its pending navigation entry.
1026 render_view_host_
->GetDelegate()->DidCancelLoading();
1029 bool RenderFrameHostImpl::IsWaitingForBeforeUnloadACK() const {
1030 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
1031 switches::kEnableBrowserSideNavigation
)) {
1032 return is_waiting_for_beforeunload_ack_
;
1034 return frame_tree_node_
->navigator()->IsWaitingForBeforeUnloadACK(
1038 bool RenderFrameHostImpl::IsWaitingForUnloadACK() const {
1039 return render_view_host_
->is_waiting_for_close_ack_
||
1040 rfh_state_
== STATE_PENDING_SWAP_OUT
;
1043 bool RenderFrameHostImpl::SuddenTerminationAllowed() const {
1044 return override_sudden_termination_status_
||
1045 (!has_beforeunload_handlers_
&& !has_unload_handlers_
);
1048 void RenderFrameHostImpl::OnSwapOutACK() {
1052 void RenderFrameHostImpl::OnRenderProcessGone(int status
, int exit_code
) {
1053 if (frame_tree_node_
->IsMainFrame()) {
1054 // Keep the termination status so we can get at it later when we
1055 // need to know why it died.
1056 render_view_host_
->render_view_termination_status_
=
1057 static_cast<base::TerminationStatus
>(status
);
1060 // Reset frame tree state associated with this process. This must happen
1061 // before RenderViewTerminated because observers expect the subframes of any
1062 // affected frames to be cleared first.
1063 // Note: When a RenderFrameHost is swapped out there is a different one
1064 // which is the current host. In this case, the FrameTreeNode state must
1066 if (!is_swapped_out())
1067 frame_tree_node_
->ResetForNewProcess();
1069 // Reset state for the current RenderFrameHost once the FrameTreeNode has been
1071 SetRenderFrameCreated(false);
1072 InvalidateMojoConnection();
1074 if (frame_tree_node_
->IsMainFrame()) {
1075 // RenderViewHost/RenderWidgetHost needs to reset some stuff.
1076 render_view_host_
->RendererExited(
1077 render_view_host_
->render_view_termination_status_
, exit_code
);
1079 render_view_host_
->delegate_
->RenderViewTerminated(
1080 render_view_host_
, static_cast<base::TerminationStatus
>(status
),
1085 void RenderFrameHostImpl::OnSwappedOut() {
1086 // Ignore spurious swap out ack.
1087 if (rfh_state_
!= STATE_PENDING_SWAP_OUT
)
1090 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this);
1091 swapout_event_monitor_timeout_
->Stop();
1093 if (frame_tree_node_
->render_manager()->DeleteFromPendingList(this)) {
1094 // We are now deleted.
1098 // If this RFH wasn't pending deletion, then it is now swapped out.
1099 SetState(RenderFrameHostImpl::STATE_SWAPPED_OUT
);
1102 void RenderFrameHostImpl::OnContextMenu(const ContextMenuParams
& params
) {
1103 // Validate the URLs in |params|. If the renderer can't request the URLs
1104 // directly, don't show them in the context menu.
1105 ContextMenuParams
validated_params(params
);
1106 RenderProcessHost
* process
= GetProcess();
1108 // We don't validate |unfiltered_link_url| so that this field can be used
1109 // when users want to copy the original link URL.
1110 process
->FilterURL(true, &validated_params
.link_url
);
1111 process
->FilterURL(true, &validated_params
.src_url
);
1112 process
->FilterURL(false, &validated_params
.page_url
);
1113 process
->FilterURL(true, &validated_params
.frame_url
);
1115 delegate_
->ShowContextMenu(this, validated_params
);
1118 void RenderFrameHostImpl::OnJavaScriptExecuteResponse(
1119 int id
, const base::ListValue
& result
) {
1120 const base::Value
* result_value
;
1121 if (!result
.Get(0, &result_value
)) {
1122 // Programming error or rogue renderer.
1123 NOTREACHED() << "Got bad arguments for OnJavaScriptExecuteResponse";
1127 std::map
<int, JavaScriptResultCallback
>::iterator it
=
1128 javascript_callbacks_
.find(id
);
1129 if (it
!= javascript_callbacks_
.end()) {
1130 it
->second
.Run(result_value
);
1131 javascript_callbacks_
.erase(it
);
1133 NOTREACHED() << "Received script response for unknown request";
1137 void RenderFrameHostImpl::OnVisualStateResponse(uint64 id
) {
1138 auto it
= visual_state_callbacks_
.find(id
);
1139 if (it
!= visual_state_callbacks_
.end()) {
1140 it
->second
.Run(true);
1141 visual_state_callbacks_
.erase(it
);
1143 NOTREACHED() << "Received script response for unknown request";
1147 void RenderFrameHostImpl::OnRunJavaScriptMessage(
1148 const base::string16
& message
,
1149 const base::string16
& default_prompt
,
1150 const GURL
& frame_url
,
1151 JavaScriptMessageType type
,
1152 IPC::Message
* reply_msg
) {
1153 // While a JS message dialog is showing, tabs in the same process shouldn't
1154 // process input events.
1155 GetProcess()->SetIgnoreInputEvents(true);
1156 render_view_host_
->StopHangMonitorTimeout();
1157 delegate_
->RunJavaScriptMessage(this, message
, default_prompt
,
1158 frame_url
, type
, reply_msg
);
1161 void RenderFrameHostImpl::OnRunBeforeUnloadConfirm(
1162 const GURL
& frame_url
,
1163 const base::string16
& message
,
1165 IPC::Message
* reply_msg
) {
1166 // While a JS beforeunload dialog is showing, tabs in the same process
1167 // shouldn't process input events.
1168 GetProcess()->SetIgnoreInputEvents(true);
1169 render_view_host_
->StopHangMonitorTimeout();
1170 delegate_
->RunBeforeUnloadConfirm(this, message
, is_reload
, reply_msg
);
1173 void RenderFrameHostImpl::OnTextSurroundingSelectionResponse(
1174 const base::string16
& content
,
1175 size_t start_offset
,
1176 size_t end_offset
) {
1177 render_view_host_
->OnTextSurroundingSelectionResponse(
1178 content
, start_offset
, end_offset
);
1181 void RenderFrameHostImpl::OnDidAccessInitialDocument() {
1182 delegate_
->DidAccessInitialDocument();
1185 void RenderFrameHostImpl::OnDidDisownOpener() {
1186 // This message is only sent for top-level frames. TODO(avi): when frame tree
1187 // mirroring works correctly, add a check here to enforce it.
1188 delegate_
->DidDisownOpener(this);
1191 void RenderFrameHostImpl::OnDidAssignPageId(int32 page_id
) {
1192 // Update the RVH's current page ID so that future IPCs from the renderer
1193 // correspond to the new page.
1194 render_view_host_
->page_id_
= page_id
;
1197 void RenderFrameHostImpl::OnUpdateTitle(
1198 const base::string16
& title
,
1199 blink::WebTextDirection title_direction
) {
1200 // This message is only sent for top-level frames. TODO(avi): when frame tree
1201 // mirroring works correctly, add a check here to enforce it.
1202 if (title
.length() > kMaxTitleChars
) {
1203 NOTREACHED() << "Renderer sent too many characters in title.";
1207 delegate_
->UpdateTitle(this, render_view_host_
->page_id_
, title
,
1208 WebTextDirectionToChromeTextDirection(
1212 void RenderFrameHostImpl::OnUpdateEncoding(const std::string
& encoding_name
) {
1213 // This message is only sent for top-level frames. TODO(avi): when frame tree
1214 // mirroring works correctly, add a check here to enforce it.
1215 delegate_
->UpdateEncoding(this, encoding_name
);
1218 void RenderFrameHostImpl::OnBeginNavigation(
1219 const CommonNavigationParams
& common_params
,
1220 const BeginNavigationParams
& begin_params
,
1221 scoped_refptr
<ResourceRequestBody
> body
) {
1222 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
1223 switches::kEnableBrowserSideNavigation
));
1224 frame_tree_node()->navigator()->OnBeginNavigation(
1225 frame_tree_node(), common_params
, begin_params
, body
);
1228 void RenderFrameHostImpl::OnDispatchLoad() {
1229 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
1230 switches::kSitePerProcess
));
1231 // Only frames with an out-of-process parent frame should be sending this
1233 RenderFrameProxyHost
* proxy
=
1234 frame_tree_node()->render_manager()->GetProxyToParent();
1236 GetProcess()->ReceivedBadMessage();
1240 proxy
->Send(new FrameMsg_DispatchLoad(proxy
->GetRoutingID()));
1243 void RenderFrameHostImpl::OnAccessibilityEvents(
1244 const std::vector
<AccessibilityHostMsg_EventParams
>& params
,
1246 // Don't process this IPC if either we're waiting on a reset and this
1247 // IPC doesn't have the matching token ID, or if we're not waiting on a
1248 // reset but this message includes a reset token.
1249 if (accessibility_reset_token_
!= reset_token
) {
1250 Send(new AccessibilityMsg_Events_ACK(routing_id_
));
1253 accessibility_reset_token_
= 0;
1255 RenderWidgetHostViewBase
* view
= static_cast<RenderWidgetHostViewBase
*>(
1256 render_view_host_
->GetView());
1258 AccessibilityMode accessibility_mode
= delegate_
->GetAccessibilityMode();
1259 if ((accessibility_mode
!= AccessibilityModeOff
) && view
&&
1260 RenderFrameHostImpl::IsRFHStateActive(rfh_state())) {
1261 if (accessibility_mode
& AccessibilityModeFlagPlatform
) {
1262 GetOrCreateBrowserAccessibilityManager();
1263 if (browser_accessibility_manager_
)
1264 browser_accessibility_manager_
->OnAccessibilityEvents(params
);
1267 if (browser_accessibility_manager_
) {
1268 // Get the frame routing ids from out-of-process iframes and
1269 // browser plugin instance ids from guests and update the mappings in
1270 // FrameAccessibility.
1271 for (size_t i
= 0; i
< params
.size(); ++i
) {
1272 const AccessibilityHostMsg_EventParams
& param
= params
[i
];
1273 UpdateCrossProcessIframeAccessibility(
1274 param
.node_to_frame_routing_id_map
);
1275 UpdateGuestFrameAccessibility(
1276 param
.node_to_browser_plugin_instance_id_map
);
1280 // Send the updates to the automation extension API.
1281 std::vector
<AXEventNotificationDetails
> details
;
1282 details
.reserve(params
.size());
1283 for (size_t i
= 0; i
< params
.size(); ++i
) {
1284 const AccessibilityHostMsg_EventParams
& param
= params
[i
];
1285 AXEventNotificationDetails
detail(param
.update
.node_id_to_clear
,
1289 GetProcess()->GetID(),
1291 details
.push_back(detail
);
1294 delegate_
->AccessibilityEventReceived(details
);
1297 // Always send an ACK or the renderer can be in a bad state.
1298 Send(new AccessibilityMsg_Events_ACK(routing_id_
));
1300 // The rest of this code is just for testing; bail out if we're not
1302 if (accessibility_testing_callback_
.is_null())
1305 for (size_t i
= 0; i
< params
.size(); i
++) {
1306 const AccessibilityHostMsg_EventParams
& param
= params
[i
];
1307 if (static_cast<int>(param
.event_type
) < 0)
1310 if (!ax_tree_for_testing_
) {
1311 if (browser_accessibility_manager_
) {
1312 ax_tree_for_testing_
.reset(new ui::AXTree(
1313 browser_accessibility_manager_
->SnapshotAXTreeForTesting()));
1315 ax_tree_for_testing_
.reset(new ui::AXTree());
1316 CHECK(ax_tree_for_testing_
->Unserialize(param
.update
))
1317 << ax_tree_for_testing_
->error();
1320 CHECK(ax_tree_for_testing_
->Unserialize(param
.update
))
1321 << ax_tree_for_testing_
->error();
1323 accessibility_testing_callback_
.Run(param
.event_type
, param
.id
);
1327 void RenderFrameHostImpl::OnAccessibilityLocationChanges(
1328 const std::vector
<AccessibilityHostMsg_LocationChangeParams
>& params
) {
1329 if (accessibility_reset_token_
)
1332 RenderWidgetHostViewBase
* view
= static_cast<RenderWidgetHostViewBase
*>(
1333 render_view_host_
->GetView());
1334 if (view
&& RenderFrameHostImpl::IsRFHStateActive(rfh_state())) {
1335 AccessibilityMode accessibility_mode
= delegate_
->GetAccessibilityMode();
1336 if (accessibility_mode
& AccessibilityModeFlagPlatform
) {
1337 BrowserAccessibilityManager
* manager
=
1338 GetOrCreateBrowserAccessibilityManager();
1340 manager
->OnLocationChanges(params
);
1342 // TODO(aboxhall): send location change events to web contents observers too
1346 void RenderFrameHostImpl::OnAccessibilityFindInPageResult(
1347 const AccessibilityHostMsg_FindInPageResultParams
& params
) {
1348 AccessibilityMode accessibility_mode
= delegate_
->GetAccessibilityMode();
1349 if (accessibility_mode
& AccessibilityModeFlagPlatform
) {
1350 BrowserAccessibilityManager
* manager
=
1351 GetOrCreateBrowserAccessibilityManager();
1353 manager
->OnFindInPageResult(
1354 params
.request_id
, params
.match_index
, params
.start_id
,
1355 params
.start_offset
, params
.end_id
, params
.end_offset
);
1360 void RenderFrameHostImpl::OnToggleFullscreen(bool enter_fullscreen
) {
1361 if (enter_fullscreen
)
1362 delegate_
->EnterFullscreenMode(GetLastCommittedURL().GetOrigin());
1364 delegate_
->ExitFullscreenMode();
1366 // The previous call might change the fullscreen state. We need to make sure
1367 // the renderer is aware of that, which is done via the resize message.
1368 render_view_host_
->WasResized();
1371 void RenderFrameHostImpl::OnBeforeUnloadHandlersPresent(bool present
) {
1372 has_beforeunload_handlers_
= present
;
1375 void RenderFrameHostImpl::OnUnloadHandlersPresent(bool present
) {
1376 has_unload_handlers_
= present
;
1379 #if defined(OS_MACOSX) || defined(OS_ANDROID)
1380 void RenderFrameHostImpl::OnShowPopup(
1381 const FrameHostMsg_ShowPopup_Params
& params
) {
1382 RenderViewHostDelegateView
* view
=
1383 render_view_host_
->delegate_
->GetDelegateView();
1385 view
->ShowPopupMenu(this,
1388 params
.item_font_size
,
1389 params
.selected_item
,
1391 params
.right_aligned
,
1392 params
.allow_multiple_selection
);
1396 void RenderFrameHostImpl::OnHidePopup() {
1397 RenderViewHostDelegateView
* view
=
1398 render_view_host_
->delegate_
->GetDelegateView();
1400 view
->HidePopupMenu();
1404 #if defined(ENABLE_MEDIA_MOJO_RENDERER)
1405 static void CreateMediaRendererService(
1406 mojo::InterfaceRequest
<mojo::MediaRenderer
> request
) {
1407 media::MojoRendererService
* service
= new media::MojoRendererService();
1408 mojo::BindToRequest(service
, &request
);
1412 void RenderFrameHostImpl::RegisterMojoServices() {
1413 GeolocationServiceContext
* geolocation_service_context
=
1414 delegate_
? delegate_
->GetGeolocationServiceContext() : NULL
;
1415 if (geolocation_service_context
) {
1416 // TODO(creis): Bind process ID here so that GeolocationServiceImpl
1417 // can perform permissions checks once site isolation is complete.
1419 GetServiceRegistry()->AddService
<GeolocationService
>(
1420 base::Bind(&GeolocationServiceContext::CreateService
,
1421 base::Unretained(geolocation_service_context
),
1422 base::Bind(&RenderFrameHostImpl::DidUseGeolocationPermission
,
1423 base::Unretained(this))));
1426 if (!permission_service_context_
)
1427 permission_service_context_
.reset(new PermissionServiceContext(this));
1429 GetServiceRegistry()->AddService
<PermissionService
>(
1430 base::Bind(&PermissionServiceContext::CreateService
,
1431 base::Unretained(permission_service_context_
.get())));
1433 GetServiceRegistry()->AddService
<presentation::PresentationService
>(
1434 base::Bind(&PresentationServiceImpl::CreateMojoService
,
1435 base::Unretained(this)));
1437 #if defined(ENABLE_MEDIA_MOJO_RENDERER)
1438 GetServiceRegistry()->AddService
<mojo::MediaRenderer
>(
1439 base::Bind(&CreateMediaRendererService
));
1443 void RenderFrameHostImpl::SetState(RenderFrameHostImplState rfh_state
) {
1444 // Only main frames should be swapped out and retained inside a proxy host.
1445 if (rfh_state
== STATE_SWAPPED_OUT
)
1446 CHECK(!GetParent());
1448 // We update the number of RenderFrameHosts in a SiteInstance when the swapped
1449 // out status of a RenderFrameHost gets flipped to/from active.
1450 if (!IsRFHStateActive(rfh_state_
) && IsRFHStateActive(rfh_state
))
1451 GetSiteInstance()->increment_active_frame_count();
1452 else if (IsRFHStateActive(rfh_state_
) && !IsRFHStateActive(rfh_state
))
1453 GetSiteInstance()->decrement_active_frame_count();
1455 // The active and swapped out state of the RVH is determined by its main
1456 // frame, since subframes should have their own widgets.
1457 if (frame_tree_node_
->IsMainFrame()) {
1458 render_view_host_
->set_is_active(IsRFHStateActive(rfh_state
));
1459 render_view_host_
->set_is_swapped_out(rfh_state
== STATE_SWAPPED_OUT
);
1462 // Whenever we change the RFH state to and from active or swapped out state,
1463 // we should not be waiting for beforeunload or close acks. We clear them
1464 // here to be safe, since they can cause navigations to be ignored in
1465 // OnDidCommitProvisionalLoad.
1466 // TODO(creis): Move is_waiting_for_beforeunload_ack_ into the state machine.
1467 if (rfh_state
== STATE_DEFAULT
||
1468 rfh_state
== STATE_SWAPPED_OUT
||
1469 rfh_state_
== STATE_DEFAULT
||
1470 rfh_state_
== STATE_SWAPPED_OUT
) {
1471 if (is_waiting_for_beforeunload_ack_
) {
1472 is_waiting_for_beforeunload_ack_
= false;
1473 render_view_host_
->decrement_in_flight_event_count();
1474 render_view_host_
->StopHangMonitorTimeout();
1476 send_before_unload_start_time_
= base::TimeTicks();
1477 render_view_host_
->is_waiting_for_close_ack_
= false;
1479 rfh_state_
= rfh_state
;
1482 bool RenderFrameHostImpl::CanCommitURL(const GURL
& url
) {
1483 // TODO(creis): We should also check for WebUI pages here. Also, when the
1484 // out-of-process iframes implementation is ready, we should check for
1485 // cross-site URLs that are not allowed to commit in this process.
1487 // Give the client a chance to disallow URLs from committing.
1488 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url
);
1491 void RenderFrameHostImpl::Navigate(const FrameMsg_Navigate_Params
& params
) {
1492 TRACE_EVENT0("navigation", "RenderFrameHostImpl::Navigate");
1493 // Browser plugin guests are not allowed to navigate outside web-safe schemes,
1494 // so do not grant them the ability to request additional URLs.
1495 if (!GetProcess()->IsIsolatedGuest()) {
1496 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL(
1497 GetProcess()->GetID(), params
.common_params
.url
);
1498 if (params
.common_params
.url
.SchemeIs(url::kDataScheme
) &&
1499 params
.common_params
.base_url_for_data_url
.SchemeIs(url::kFileScheme
)) {
1500 // If 'data:' is used, and we have a 'file:' base url, grant access to
1502 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL(
1503 GetProcess()->GetID(), params
.common_params
.base_url_for_data_url
);
1507 // We may be returning to an existing NavigationEntry that had been granted
1508 // file access. If this is a different process, we will need to grant the
1509 // access again. The files listed in the page state are validated when they
1510 // are received from the renderer to prevent abuse.
1511 if (params
.commit_params
.page_state
.IsValid()) {
1512 render_view_host_
->GrantFileAccessFromPageState(
1513 params
.commit_params
.page_state
);
1516 // Only send the message if we aren't suspended at the start of a cross-site
1518 if (navigations_suspended_
) {
1519 // Shouldn't be possible to have a second navigation while suspended, since
1520 // navigations will only be suspended during a cross-site request. If a
1521 // second navigation occurs, RenderFrameHostManager will cancel this pending
1522 // RFH and create a new pending RFH.
1523 DCHECK(!suspended_nav_params_
.get());
1524 suspended_nav_params_
.reset(new FrameMsg_Navigate_Params(params
));
1526 // Get back to a clean state, in case we start a new navigation without
1527 // completing a RFH swap or unload handler.
1528 SetState(RenderFrameHostImpl::STATE_DEFAULT
);
1530 Send(new FrameMsg_Navigate(routing_id_
, params
));
1533 // Force the throbber to start. We do this because Blink's "started
1534 // loading" message will be received asynchronously from the UI of the
1535 // browser. But we want to keep the throbber in sync with what's happening
1536 // in the UI. For example, we want to start throbbing immediately when the
1537 // user navigates even if the renderer is delayed. There is also an issue
1538 // with the throbber starting because the WebUI (which controls whether the
1539 // favicon is displayed) happens synchronously. If the start loading
1540 // messages was asynchronous, then the default favicon would flash in.
1542 // Blink doesn't send throb notifications for JavaScript URLs, so we
1543 // don't want to either.
1544 if (!params
.common_params
.url
.SchemeIs(url::kJavaScriptScheme
))
1545 delegate_
->DidStartLoading(this, true);
1548 void RenderFrameHostImpl::NavigateToURL(const GURL
& url
) {
1549 FrameMsg_Navigate_Params params
;
1550 params
.common_params
.url
= url
;
1551 params
.common_params
.transition
= ui::PAGE_TRANSITION_LINK
;
1552 params
.common_params
.navigation_type
= FrameMsg_Navigate_Type::NORMAL
;
1553 params
.commit_params
.browser_navigation_start
= base::TimeTicks::Now();
1554 params
.page_id
= -1;
1555 params
.pending_history_list_offset
= -1;
1556 params
.current_history_list_offset
= -1;
1557 params
.current_history_list_length
= 0;
1561 void RenderFrameHostImpl::OpenURL(const FrameHostMsg_OpenURL_Params
& params
,
1562 SiteInstance
* source_site_instance
) {
1563 GURL
validated_url(params
.url
);
1564 GetProcess()->FilterURL(false, &validated_url
);
1566 TRACE_EVENT1("navigation", "RenderFrameHostImpl::OpenURL", "url",
1567 validated_url
.possibly_invalid_spec());
1568 frame_tree_node_
->navigator()->RequestOpenURL(
1569 this, validated_url
, source_site_instance
, params
.referrer
,
1570 params
.disposition
, params
.should_replace_current_entry
,
1571 params
.user_gesture
);
1574 void RenderFrameHostImpl::Stop() {
1575 Send(new FrameMsg_Stop(routing_id_
));
1578 void RenderFrameHostImpl::DispatchBeforeUnload(bool for_navigation
) {
1579 // TODO(creis): Support beforeunload on subframes. For now just pretend that
1580 // the handler ran and allowed the navigation to proceed.
1581 if (GetParent() || !IsRenderFrameLive()) {
1582 // We don't have a live renderer, so just skip running beforeunload.
1583 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
1584 switches::kEnableBrowserSideNavigation
)) {
1585 frame_tree_node_
->navigator()->OnBeforeUnloadACK(
1586 frame_tree_node_
, true);
1588 frame_tree_node_
->render_manager()->OnBeforeUnloadACK(
1589 for_navigation
, true, base::TimeTicks::Now());
1593 TRACE_EVENT_ASYNC_BEGIN0(
1594 "navigation", "RenderFrameHostImpl::BeforeUnload", this);
1596 // This may be called more than once (if the user clicks the tab close button
1597 // several times, or if she clicks the tab close button then the browser close
1598 // button), and we only send the message once.
1599 if (is_waiting_for_beforeunload_ack_
) {
1600 // Some of our close messages could be for the tab, others for cross-site
1601 // transitions. We always want to think it's for closing the tab if any
1602 // of the messages were, since otherwise it might be impossible to close
1603 // (if there was a cross-site "close" request pending when the user clicked
1604 // the close button). We want to keep the "for cross site" flag only if
1605 // both the old and the new ones are also for cross site.
1606 unload_ack_is_for_navigation_
=
1607 unload_ack_is_for_navigation_
&& for_navigation
;
1609 // Start the hang monitor in case the renderer hangs in the beforeunload
1611 is_waiting_for_beforeunload_ack_
= true;
1612 unload_ack_is_for_navigation_
= for_navigation
;
1613 // Increment the in-flight event count, to ensure that input events won't
1614 // cancel the timeout timer.
1615 render_view_host_
->increment_in_flight_event_count();
1616 render_view_host_
->StartHangMonitorTimeout(
1617 TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS
));
1618 send_before_unload_start_time_
= base::TimeTicks::Now();
1619 Send(new FrameMsg_BeforeUnload(routing_id_
));
1623 void RenderFrameHostImpl::DisownOpener() {
1624 Send(new FrameMsg_DisownOpener(GetRoutingID()));
1627 void RenderFrameHostImpl::ExtendSelectionAndDelete(size_t before
,
1629 Send(new InputMsg_ExtendSelectionAndDelete(routing_id_
, before
, after
));
1632 void RenderFrameHostImpl::JavaScriptDialogClosed(
1633 IPC::Message
* reply_msg
,
1635 const base::string16
& user_input
,
1636 bool dialog_was_suppressed
) {
1637 GetProcess()->SetIgnoreInputEvents(false);
1638 bool is_waiting
= is_waiting_for_beforeunload_ack_
|| IsWaitingForUnloadACK();
1640 // If we are executing as part of (before)unload event handling, we don't
1641 // want to use the regular hung_renderer_delay_ms_ if the user has agreed to
1642 // leave the current page. In this case, use the regular timeout value used
1643 // during the (before)unload handling.
1645 render_view_host_
->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(
1646 success
? RenderViewHostImpl::kUnloadTimeoutMS
1647 : render_view_host_
->hung_renderer_delay_ms_
));
1650 FrameHostMsg_RunJavaScriptMessage::WriteReplyParams(reply_msg
,
1651 success
, user_input
);
1654 // If we are waiting for an unload or beforeunload ack and the user has
1655 // suppressed messages, kill the tab immediately; a page that's spamming
1656 // alerts in onbeforeunload is presumably malicious, so there's no point in
1657 // continuing to run its script and dragging out the process.
1658 // This must be done after sending the reply since RenderView can't close
1659 // correctly while waiting for a response.
1660 if (is_waiting
&& dialog_was_suppressed
)
1661 render_view_host_
->delegate_
->RendererUnresponsive(render_view_host_
);
1665 void RenderFrameHostImpl::CommitNavigation(
1666 ResourceResponse
* response
,
1667 scoped_ptr
<StreamHandle
> body
,
1668 const CommonNavigationParams
& common_params
,
1669 const CommitNavigationParams
& commit_params
) {
1670 DCHECK((response
&& body
.get()) ||
1671 !NavigationRequest::ShouldMakeNetworkRequest(common_params
.url
));
1672 // TODO(clamy): Check if we have to add security checks for the browser plugin
1675 // Get back to a clean state, in case we start a new navigation without
1676 // completing a RFH swap or unload handler.
1677 SetState(RenderFrameHostImpl::STATE_DEFAULT
);
1679 const GURL body_url
= body
.get() ? body
->GetURL() : GURL();
1680 const ResourceResponseHead head
= response
?
1681 response
->head
: ResourceResponseHead();
1682 Send(new FrameMsg_CommitNavigation(
1683 routing_id_
, head
, body_url
, common_params
, commit_params
));
1684 // TODO(clamy): Check if we should start the throbber for non javascript urls
1687 // TODO(clamy): Release the stream handle once the renderer has finished
1689 stream_handle_
= body
.Pass();
1692 void RenderFrameHostImpl::SetUpMojoIfNeeded() {
1693 if (service_registry_
.get())
1696 service_registry_
.reset(new ServiceRegistryImpl());
1697 if (!GetProcess()->GetServiceRegistry())
1700 RegisterMojoServices();
1701 RenderFrameSetupPtr setup
;
1702 GetProcess()->GetServiceRegistry()->ConnectToRemoteService(&setup
);
1704 mojo::ServiceProviderPtr exposed_services
;
1705 service_registry_
->Bind(GetProxy(&exposed_services
));
1707 mojo::ServiceProviderPtr services
;
1708 setup
->ExchangeServiceProviders(routing_id_
, GetProxy(&services
),
1709 exposed_services
.Pass());
1710 service_registry_
->BindRemoteServiceProvider(services
.Pass());
1712 #if defined(OS_ANDROID)
1713 service_registry_android_
.reset(
1714 new ServiceRegistryAndroid(service_registry_
.get()));
1718 void RenderFrameHostImpl::InvalidateMojoConnection() {
1719 #if defined(OS_ANDROID)
1720 // The Android-specific service registry has a reference to
1721 // |service_registry_| and thus must be torn down first.
1722 service_registry_android_
.reset();
1725 service_registry_
.reset();
1728 bool RenderFrameHostImpl::IsFocused() {
1729 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops
1730 // returning nullptr in some cases. See https://crbug.com/455245.
1731 return RenderWidgetHostImpl::From(
1732 GetView()->GetRenderWidgetHost())->is_focused() &&
1733 frame_tree_
->GetFocusedFrame() &&
1734 (frame_tree_
->GetFocusedFrame() == frame_tree_node() ||
1735 frame_tree_
->GetFocusedFrame()->IsDescendantOf(frame_tree_node()));
1738 void RenderFrameHostImpl::UpdateCrossProcessIframeAccessibility(
1739 const std::map
<int32
, int>& node_to_frame_routing_id_map
) {
1740 for (const auto& iter
: node_to_frame_routing_id_map
) {
1741 // This is the id of the accessibility node that has a child frame.
1742 int32 node_id
= iter
.first
;
1743 // The routing id from either a RenderFrame or a RenderFrameProxy.
1744 int frame_routing_id
= iter
.second
;
1746 FrameTree
* frame_tree
= frame_tree_node()->frame_tree();
1747 FrameTreeNode
* child_frame_tree_node
= frame_tree
->FindByRoutingID(
1748 GetProcess()->GetID(), frame_routing_id
);
1750 if (child_frame_tree_node
) {
1751 FrameAccessibility::GetInstance()->AddChildFrame(
1752 this, node_id
, child_frame_tree_node
->frame_tree_node_id());
1757 void RenderFrameHostImpl::UpdateGuestFrameAccessibility(
1758 const std::map
<int32
, int>& node_to_browser_plugin_instance_id_map
) {
1759 for (const auto& iter
: node_to_browser_plugin_instance_id_map
) {
1760 // This is the id of the accessibility node that hosts a plugin.
1761 int32 node_id
= iter
.first
;
1762 // The id of the browser plugin.
1763 int browser_plugin_instance_id
= iter
.second
;
1764 FrameAccessibility::GetInstance()->AddGuestWebContents(
1765 this, node_id
, browser_plugin_instance_id
);
1769 bool RenderFrameHostImpl::IsSameSiteInstance(
1770 RenderFrameHostImpl
* other_render_frame_host
) {
1771 // As a sanity check, make sure the frame belongs to the same BrowserContext.
1772 CHECK_EQ(GetSiteInstance()->GetBrowserContext(),
1773 other_render_frame_host
->GetSiteInstance()->GetBrowserContext());
1774 return GetSiteInstance() == other_render_frame_host
->GetSiteInstance();
1777 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode
) {
1778 Send(new FrameMsg_SetAccessibilityMode(routing_id_
, mode
));
1781 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting(
1782 const base::Callback
<void(ui::AXEvent
, int)>& callback
) {
1783 accessibility_testing_callback_
= callback
;
1786 const ui::AXTree
* RenderFrameHostImpl::GetAXTreeForTesting() {
1787 return ax_tree_for_testing_
.get();
1790 BrowserAccessibilityManager
*
1791 RenderFrameHostImpl::GetOrCreateBrowserAccessibilityManager() {
1792 RenderWidgetHostViewBase
* view
= static_cast<RenderWidgetHostViewBase
*>(
1793 render_view_host_
->GetView());
1795 !browser_accessibility_manager_
&&
1796 !no_create_browser_accessibility_manager_for_testing_
) {
1797 browser_accessibility_manager_
.reset(
1798 view
->CreateBrowserAccessibilityManager(this));
1799 if (browser_accessibility_manager_
)
1800 UMA_HISTOGRAM_COUNTS("Accessibility.FrameEnabledCount", 1);
1802 UMA_HISTOGRAM_COUNTS("Accessibility.FrameDidNotEnableCount", 1);
1804 return browser_accessibility_manager_
.get();
1807 void RenderFrameHostImpl::ActivateFindInPageResultForAccessibility(
1809 AccessibilityMode accessibility_mode
= delegate_
->GetAccessibilityMode();
1810 if (accessibility_mode
& AccessibilityModeFlagPlatform
) {
1811 BrowserAccessibilityManager
* manager
=
1812 GetOrCreateBrowserAccessibilityManager();
1814 manager
->ActivateFindInPageResult(request_id
);
1818 void RenderFrameHostImpl::InsertVisualStateCallback(
1819 const VisualStateCallback
& callback
) {
1820 static uint64 next_id
= 1;
1821 uint64 key
= next_id
++;
1822 Send(new FrameMsg_VisualStateRequest(routing_id_
, key
));
1823 visual_state_callbacks_
.insert(std::make_pair(key
, callback
));
1828 void RenderFrameHostImpl::SetParentNativeViewAccessible(
1829 gfx::NativeViewAccessible accessible_parent
) {
1830 RenderWidgetHostViewBase
* view
= static_cast<RenderWidgetHostViewBase
*>(
1831 render_view_host_
->GetView());
1833 view
->SetParentNativeViewAccessible(accessible_parent
);
1836 gfx::NativeViewAccessible
1837 RenderFrameHostImpl::GetParentNativeViewAccessible() const {
1838 return delegate_
->GetParentNativeViewAccessible();
1841 #elif defined(OS_MACOSX)
1843 void RenderFrameHostImpl::DidSelectPopupMenuItem(int selected_index
) {
1844 Send(new FrameMsg_SelectPopupMenuItem(routing_id_
, selected_index
));
1847 void RenderFrameHostImpl::DidCancelPopupMenu() {
1848 Send(new FrameMsg_SelectPopupMenuItem(routing_id_
, -1));
1851 #elif defined(OS_ANDROID)
1853 void RenderFrameHostImpl::DidSelectPopupMenuItems(
1854 const std::vector
<int>& selected_indices
) {
1855 Send(new FrameMsg_SelectPopupMenuItems(routing_id_
, false, selected_indices
));
1858 void RenderFrameHostImpl::DidCancelPopupMenu() {
1859 Send(new FrameMsg_SelectPopupMenuItems(
1860 routing_id_
, true, std::vector
<int>()));
1865 void RenderFrameHostImpl::ClearPendingTransitionRequestData() {
1866 BrowserThread::PostTask(
1870 &TransitionRequestManager::ClearPendingTransitionRequestData
,
1871 base::Unretained(TransitionRequestManager::GetInstance()),
1872 GetProcess()->GetID(),
1876 void RenderFrameHostImpl::SetNavigationsSuspended(
1878 const base::TimeTicks
& proceed_time
) {
1879 // This should only be called to toggle the state.
1880 DCHECK(navigations_suspended_
!= suspend
);
1882 navigations_suspended_
= suspend
;
1883 if (navigations_suspended_
) {
1884 TRACE_EVENT_ASYNC_BEGIN0("navigation",
1885 "RenderFrameHostImpl navigation suspended", this);
1887 TRACE_EVENT_ASYNC_END0("navigation",
1888 "RenderFrameHostImpl navigation suspended", this);
1891 if (!suspend
&& suspended_nav_params_
) {
1892 // There's navigation message params waiting to be sent. Now that we're not
1893 // suspended anymore, resume navigation by sending them. If we were swapped
1894 // out, we should also stop filtering out the IPC messages now.
1895 SetState(RenderFrameHostImpl::STATE_DEFAULT
);
1897 DCHECK(!proceed_time
.is_null());
1898 suspended_nav_params_
->commit_params
.browser_navigation_start
=
1900 Send(new FrameMsg_Navigate(routing_id_
, *suspended_nav_params_
));
1901 suspended_nav_params_
.reset();
1905 void RenderFrameHostImpl::CancelSuspendedNavigations() {
1906 // Clear any state if a pending navigation is canceled or preempted.
1907 if (suspended_nav_params_
)
1908 suspended_nav_params_
.reset();
1910 TRACE_EVENT_ASYNC_END0("navigation",
1911 "RenderFrameHostImpl navigation suspended", this);
1912 navigations_suspended_
= false;
1915 void RenderFrameHostImpl::DidUseGeolocationPermission() {
1916 RenderFrameHost
* top_frame
= frame_tree_node()->frame_tree()->GetMainFrame();
1917 GetContentClient()->browser()->RegisterPermissionUsage(
1918 PERMISSION_GEOLOCATION
,
1919 delegate_
->GetAsWebContents(),
1920 GetLastCommittedURL().GetOrigin(),
1921 top_frame
->GetLastCommittedURL().GetOrigin());
1924 } // namespace content