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 #include "content/browser/frame_host/render_frame_host_impl.h" | 5 #include "content/browser/frame_host/render_frame_host_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/metrics/user_metrics_action.h" | 10 #include "base/metrics/user_metrics_action.h" |
11 #include "content/browser/accessibility/accessibility_mode_helper.h" | |
12 #include "content/browser/accessibility/browser_accessibility_manager.h" | |
13 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | |
11 #include "content/browser/child_process_security_policy_impl.h" | 14 #include "content/browser/child_process_security_policy_impl.h" |
12 #include "content/browser/frame_host/cross_process_frame_connector.h" | 15 #include "content/browser/frame_host/cross_process_frame_connector.h" |
13 #include "content/browser/frame_host/cross_site_transferring_request.h" | 16 #include "content/browser/frame_host/cross_site_transferring_request.h" |
14 #include "content/browser/frame_host/frame_tree.h" | 17 #include "content/browser/frame_host/frame_tree.h" |
15 #include "content/browser/frame_host/frame_tree_node.h" | 18 #include "content/browser/frame_host/frame_tree_node.h" |
16 #include "content/browser/frame_host/navigator.h" | 19 #include "content/browser/frame_host/navigator.h" |
17 #include "content/browser/frame_host/render_frame_host_delegate.h" | 20 #include "content/browser/frame_host/render_frame_host_delegate.h" |
18 #include "content/browser/renderer_host/input/input_router.h" | 21 #include "content/browser/renderer_host/input/input_router.h" |
19 #include "content/browser/renderer_host/input/timeout_monitor.h" | 22 #include "content/browser/renderer_host/input/timeout_monitor.h" |
20 #include "content/browser/renderer_host/render_view_host_impl.h" | 23 #include "content/browser/renderer_host/render_view_host_impl.h" |
24 #include "content/browser/renderer_host/render_widget_host_view_base.h" | |
25 #include "content/common/accessibility_messages.h" | |
21 #include "content/common/desktop_notification_messages.h" | 26 #include "content/common/desktop_notification_messages.h" |
22 #include "content/common/frame_messages.h" | 27 #include "content/common/frame_messages.h" |
23 #include "content/common/input_messages.h" | 28 #include "content/common/input_messages.h" |
24 #include "content/common/inter_process_time_ticks_converter.h" | 29 #include "content/common/inter_process_time_ticks_converter.h" |
25 #include "content/common/swapped_out_messages.h" | 30 #include "content/common/swapped_out_messages.h" |
31 #include "content/public/browser/ax_event_notification_details.h" | |
32 #include "content/public/browser/browser_accessibility_state.h" | |
26 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/content_browser_client.h" | 34 #include "content/public/browser/content_browser_client.h" |
28 #include "content/public/browser/desktop_notification_delegate.h" | 35 #include "content/public/browser/desktop_notification_delegate.h" |
29 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
30 #include "content/public/browser/render_widget_host_view.h" | 37 #include "content/public/browser/render_widget_host_view.h" |
31 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
32 #include "content/public/common/url_constants.h" | 39 #include "content/public/common/url_constants.h" |
33 #include "content/public/common/url_utils.h" | 40 #include "content/public/common/url_utils.h" |
41 #include "ui/accessibility/ax_tree.h" | |
34 #include "url/gurl.h" | 42 #include "url/gurl.h" |
35 | 43 |
36 using base::TimeDelta; | 44 using base::TimeDelta; |
37 | 45 |
38 namespace content { | 46 namespace content { |
39 | 47 |
40 namespace { | 48 namespace { |
41 | 49 |
42 // The (process id, routing id) pair that identifies one RenderFrame. | 50 // The (process id, routing id) pair that identifies one RenderFrame. |
43 typedef std::pair<int32, int32> RenderFrameHostID; | 51 typedef std::pair<int32, int32> RenderFrameHostID; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 FrameTreeNode* frame_tree_node, | 138 FrameTreeNode* frame_tree_node, |
131 int routing_id, | 139 int routing_id, |
132 bool is_swapped_out) | 140 bool is_swapped_out) |
133 : render_view_host_(render_view_host), | 141 : render_view_host_(render_view_host), |
134 delegate_(delegate), | 142 delegate_(delegate), |
135 cross_process_frame_connector_(NULL), | 143 cross_process_frame_connector_(NULL), |
136 frame_tree_(frame_tree), | 144 frame_tree_(frame_tree), |
137 frame_tree_node_(frame_tree_node), | 145 frame_tree_node_(frame_tree_node), |
138 routing_id_(routing_id), | 146 routing_id_(routing_id), |
139 is_swapped_out_(is_swapped_out), | 147 is_swapped_out_(is_swapped_out), |
140 weak_ptr_factory_(this) { | 148 weak_ptr_factory_(this), |
149 accessibility_mode_(AccessibilityModeOff) { | |
141 frame_tree_->RegisterRenderFrameHost(this); | 150 frame_tree_->RegisterRenderFrameHost(this); |
142 GetProcess()->AddRoute(routing_id_, this); | 151 GetProcess()->AddRoute(routing_id_, this); |
143 g_routing_id_frame_map.Get().insert(std::make_pair( | 152 g_routing_id_frame_map.Get().insert(std::make_pair( |
144 RenderFrameHostID(GetProcess()->GetID(), routing_id_), | 153 RenderFrameHostID(GetProcess()->GetID(), routing_id_), |
145 this)); | 154 this)); |
155 SetAccessibilityMode(delegate->GetAccessibilityMode()); | |
146 } | 156 } |
147 | 157 |
148 RenderFrameHostImpl::~RenderFrameHostImpl() { | 158 RenderFrameHostImpl::~RenderFrameHostImpl() { |
149 GetProcess()->RemoveRoute(routing_id_); | 159 GetProcess()->RemoveRoute(routing_id_); |
150 g_routing_id_frame_map.Get().erase( | 160 g_routing_id_frame_map.Get().erase( |
151 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); | 161 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
152 if (delegate_) | 162 if (delegate_) |
153 delegate_->RenderFrameDeleted(this); | 163 delegate_->RenderFrameDeleted(this); |
154 | 164 |
155 // Notify the FrameTree that this RFH is going away, allowing it to shut down | 165 // Notify the FrameTree that this RFH is going away, allowing it to shut down |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 OnRunBeforeUnloadConfirm) | 302 OnRunBeforeUnloadConfirm) |
293 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument, | 303 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument, |
294 OnDidAccessInitialDocument) | 304 OnDidAccessInitialDocument) |
295 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisownOpener, OnDidDisownOpener) | 305 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisownOpener, OnDidDisownOpener) |
296 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission, | 306 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission, |
297 OnRequestDesktopNotificationPermission) | 307 OnRequestDesktopNotificationPermission) |
298 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show, | 308 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show, |
299 OnShowDesktopNotification) | 309 OnShowDesktopNotification) |
300 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel, | 310 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel, |
301 OnCancelDesktopNotification) | 311 OnCancelDesktopNotification) |
312 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) | |
313 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, | |
314 OnAccessibilityLocationChanges) | |
302 IPC_END_MESSAGE_MAP_EX() | 315 IPC_END_MESSAGE_MAP_EX() |
303 | 316 |
304 if (!msg_is_ok) { | 317 if (!msg_is_ok) { |
305 // The message had a handler, but its de-serialization failed. | 318 // The message had a handler, but its de-serialization failed. |
306 // Kill the renderer. | 319 // Kill the renderer. |
307 RecordAction(base::UserMetricsAction("BadMessageTerminate_RFH")); | 320 RecordAction(base::UserMetricsAction("BadMessageTerminate_RFH")); |
308 GetProcess()->ReceivedBadMessage(); | 321 GetProcess()->ReceivedBadMessage(); |
309 } | 322 } |
310 | 323 |
311 return handled; | 324 return handled; |
312 } | 325 } |
313 | 326 |
327 void RenderFrameHostImpl::AccessibilitySetFocus(int object_id) { | |
328 Send(new AccessibilityMsg_SetFocus(GetRoutingID(), object_id)); | |
nasko
2014/05/12 17:28:01
nit: The pattern in this class is to use routing_i
dmazzoni
2014/05/13 06:36:52
Done.
| |
329 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | |
330 render_view_host_->GetView()); | |
331 if (view) | |
332 view->OnAccessibilitySetFocus(object_id); | |
333 } | |
334 | |
335 void RenderFrameHostImpl::AccessibilityDoDefaultAction(int object_id) { | |
336 Send(new AccessibilityMsg_DoDefaultAction(GetRoutingID(), object_id)); | |
337 } | |
338 | |
339 void RenderFrameHostImpl::AccessibilityShowMenu(int object_id) { | |
340 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | |
341 render_view_host_->GetView()); | |
342 if (view) | |
343 view->AccessibilityShowMenu(object_id); | |
344 } | |
345 | |
346 void RenderFrameHostImpl::AccessibilityScrollToMakeVisible( | |
347 int acc_obj_id, gfx::Rect subfocus) { | |
348 Send(new AccessibilityMsg_ScrollToMakeVisible( | |
349 GetRoutingID(), acc_obj_id, subfocus)); | |
350 } | |
351 | |
352 void RenderFrameHostImpl::AccessibilityScrollToPoint( | |
353 int acc_obj_id, gfx::Point point) { | |
354 Send(new AccessibilityMsg_ScrollToPoint( | |
355 GetRoutingID(), acc_obj_id, point)); | |
356 } | |
357 | |
358 void RenderFrameHostImpl::AccessibilitySetTextSelection( | |
359 int object_id, int start_offset, int end_offset) { | |
360 Send(new AccessibilityMsg_SetTextSelection( | |
361 GetRoutingID(), object_id, start_offset, end_offset)); | |
362 } | |
363 | |
364 bool RenderFrameHostImpl::AccessibilityViewHasFocus() const { | |
365 RenderWidgetHostView* view = render_view_host_->GetView(); | |
366 if (view) | |
367 return view->HasFocus(); | |
368 return false; | |
369 } | |
370 | |
371 gfx::Rect RenderFrameHostImpl::AccessibilityGetViewBounds() const { | |
372 RenderWidgetHostView* view = render_view_host_->GetView(); | |
373 if (view) | |
374 return view->GetViewBounds(); | |
375 return gfx::Rect(); | |
376 } | |
377 | |
378 gfx::Point RenderFrameHostImpl::AccessibilityOriginInScreen( | |
379 const gfx::Rect& bounds) const { | |
380 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | |
381 render_view_host_->GetView()); | |
382 if (view) | |
383 return view->AccessibilityOriginInScreen(bounds); | |
384 return gfx::Point(); | |
385 } | |
386 | |
387 void RenderFrameHostImpl::AccessibilityFatalError() { | |
388 Send(new AccessibilityMsg_FatalError(GetRoutingID())); | |
389 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | |
390 render_view_host_->GetView()); | |
391 if (view) | |
392 view->SetBrowserAccessibilityManager(NULL); | |
393 } | |
394 | |
314 void RenderFrameHostImpl::Init() { | 395 void RenderFrameHostImpl::Init() { |
315 GetProcess()->ResumeRequestsForView(routing_id_); | 396 GetProcess()->ResumeRequestsForView(routing_id_); |
316 } | 397 } |
317 | 398 |
318 void RenderFrameHostImpl::OnAddMessageToConsole( | 399 void RenderFrameHostImpl::OnAddMessageToConsole( |
319 int32 level, | 400 int32 level, |
320 const base::string16& message, | 401 const base::string16& message, |
321 int32 line_no, | 402 int32 line_no, |
322 const base::string16& source_id) { | 403 const base::string16& source_id) { |
323 if (delegate_->AddMessageToConsole(level, message, line_no, source_id)) | 404 if (delegate_->AddMessageToConsole(level, message, line_no, source_id)) |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 void RenderFrameHostImpl::OnDidAccessInitialDocument() { | 769 void RenderFrameHostImpl::OnDidAccessInitialDocument() { |
689 delegate_->DidAccessInitialDocument(); | 770 delegate_->DidAccessInitialDocument(); |
690 } | 771 } |
691 | 772 |
692 void RenderFrameHostImpl::OnDidDisownOpener() { | 773 void RenderFrameHostImpl::OnDidDisownOpener() { |
693 // This message is only sent for top-level frames. TODO(avi): when frame tree | 774 // This message is only sent for top-level frames. TODO(avi): when frame tree |
694 // mirroring works correctly, add a check here to enforce it. | 775 // mirroring works correctly, add a check here to enforce it. |
695 delegate_->DidDisownOpener(this); | 776 delegate_->DidDisownOpener(this); |
696 } | 777 } |
697 | 778 |
779 void RenderFrameHostImpl::OnAccessibilityEvents( | |
780 const std::vector<AccessibilityHostMsg_EventParams>& params) { | |
781 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | |
782 render_view_host_->GetView()); | |
783 | |
784 if ((accessibility_mode() != AccessibilityModeOff) && view && | |
785 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) { | |
786 if (accessibility_mode() & AccessibilityModeFlagPlatform) { | |
787 view->CreateBrowserAccessibilityManagerIfNeeded(this); | |
788 BrowserAccessibilityManager* manager = | |
789 view->GetBrowserAccessibilityManager(); | |
790 if (manager) | |
791 manager->OnAccessibilityEvents(params); | |
792 } | |
793 | |
794 std::vector<AXEventNotificationDetails> details; | |
795 for (unsigned int i = 0; i < params.size(); ++i) { | |
796 const AccessibilityHostMsg_EventParams& param = params[i]; | |
797 AXEventNotificationDetails detail(param.update.nodes, | |
798 param.event_type, | |
799 param.id, | |
800 GetProcess()->GetID(), | |
801 GetRoutingID()); | |
802 details.push_back(detail); | |
803 } | |
804 | |
805 delegate_->AccessibilityEventReceived(details); | |
806 } | |
807 | |
808 // Always send an ACK or the renderer can be in a bad state. | |
809 Send(new AccessibilityMsg_Events_ACK(GetRoutingID())); | |
810 | |
811 // The rest of this code is just for testing; bail out if we're not | |
812 // in that mode. | |
813 if (accessibility_testing_callback_.is_null()) | |
814 return; | |
815 | |
816 for (unsigned i = 0; i < params.size(); i++) { | |
817 const AccessibilityHostMsg_EventParams& param = params[i]; | |
818 if (static_cast<int>(param.event_type) < 0) | |
819 continue; | |
820 if (!ax_tree_) | |
821 ax_tree_.reset(new ui::AXTree(param.update)); | |
822 else | |
823 CHECK(ax_tree_->Unserialize(param.update)) << ax_tree_->error(); | |
824 accessibility_testing_callback_.Run(param.event_type); | |
825 } | |
826 } | |
827 | |
828 void RenderFrameHostImpl::OnAccessibilityLocationChanges( | |
829 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) { | |
830 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | |
831 render_view_host_->GetView()); | |
832 if (view && | |
833 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) { | |
834 if (accessibility_mode() & AccessibilityModeFlagPlatform) { | |
835 view->CreateBrowserAccessibilityManagerIfNeeded(this); | |
836 BrowserAccessibilityManager* manager = | |
837 view->GetBrowserAccessibilityManager(); | |
838 if (manager) | |
839 manager->OnLocationChanges(params); | |
840 } | |
841 // TODO(aboxhall): send location change events to web contents observers too | |
842 } | |
843 } | |
844 | |
698 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { | 845 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { |
699 render_view_host_->SetPendingShutdown(on_swap_out); | 846 render_view_host_->SetPendingShutdown(on_swap_out); |
700 } | 847 } |
701 | 848 |
702 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { | 849 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { |
703 // TODO(creis): We should also check for WebUI pages here. Also, when the | 850 // TODO(creis): We should also check for WebUI pages here. Also, when the |
704 // out-of-process iframes implementation is ready, we should check for | 851 // out-of-process iframes implementation is ready, we should check for |
705 // cross-site URLs that are not allowed to commit in this process. | 852 // cross-site URLs that are not allowed to commit in this process. |
706 | 853 |
707 // Give the client a chance to disallow URLs from committing. | 854 // Give the client a chance to disallow URLs from committing. |
708 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); | 855 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); |
709 } | 856 } |
710 | 857 |
858 void RenderFrameHostImpl::DesktopNotificationPermissionRequestDone( | |
859 int callback_context) { | |
860 Send(new DesktopNotificationMsg_PermissionRequestDone( | |
861 routing_id_, callback_context)); | |
862 } | |
863 | |
711 void RenderFrameHostImpl::Navigate(const FrameMsg_Navigate_Params& params) { | 864 void RenderFrameHostImpl::Navigate(const FrameMsg_Navigate_Params& params) { |
712 TRACE_EVENT0("frame_host", "RenderFrameHostImpl::Navigate"); | 865 TRACE_EVENT0("frame_host", "RenderFrameHostImpl::Navigate"); |
713 // Browser plugin guests are not allowed to navigate outside web-safe schemes, | 866 // Browser plugin guests are not allowed to navigate outside web-safe schemes, |
714 // so do not grant them the ability to request additional URLs. | 867 // so do not grant them the ability to request additional URLs. |
715 if (!GetProcess()->IsGuest()) { | 868 if (!GetProcess()->IsGuest()) { |
716 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( | 869 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( |
717 GetProcess()->GetID(), params.url); | 870 GetProcess()->GetID(), params.url); |
718 if (params.url.SchemeIs(kDataScheme) && | 871 if (params.url.SchemeIs(kDataScheme) && |
719 params.base_url_for_data_url.SchemeIs(kFileScheme)) { | 872 params.base_url_for_data_url.SchemeIs(kFileScheme)) { |
720 // If 'data:' is used, and we have a 'file:' base url, grant access to | 873 // If 'data:' is used, and we have a 'file:' base url, grant access to |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
848 render_view_host_->delegate_->RendererUnresponsive( | 1001 render_view_host_->delegate_->RendererUnresponsive( |
849 render_view_host_, | 1002 render_view_host_, |
850 render_view_host_->is_waiting_for_beforeunload_ack(), | 1003 render_view_host_->is_waiting_for_beforeunload_ack(), |
851 render_view_host_->IsWaitingForUnloadACK()); | 1004 render_view_host_->IsWaitingForUnloadACK()); |
852 } | 1005 } |
853 | 1006 |
854 void RenderFrameHostImpl::NotificationClosed(int notification_id) { | 1007 void RenderFrameHostImpl::NotificationClosed(int notification_id) { |
855 cancel_notification_callbacks_.erase(notification_id); | 1008 cancel_notification_callbacks_.erase(notification_id); |
856 } | 1009 } |
857 | 1010 |
858 void RenderFrameHostImpl::DesktopNotificationPermissionRequestDone( | 1011 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) { |
859 int callback_context) { | 1012 accessibility_mode_ = mode; |
860 Send(new DesktopNotificationMsg_PermissionRequestDone( | 1013 Send(new FrameMsg_SetAccessibilityMode(GetRoutingID(), mode)); |
861 routing_id_, callback_context)); | |
862 } | 1014 } |
863 | 1015 |
1016 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting( | |
1017 const base::Callback<void(ui::AXEvent)>& callback) { | |
1018 accessibility_testing_callback_ = callback; | |
1019 } | |
1020 | |
1021 const ui::AXTree* RenderFrameHostImpl::GetAXTreeForTesting() { | |
1022 return ax_tree_.get(); | |
1023 } | |
1024 | |
1025 #if defined(OS_WIN) | |
1026 void RenderFrameHostImpl::SetParentNativeViewAccessible( | |
1027 gfx::NativeViewAccessible accessible_parent) { | |
1028 RenderWidgetHostView* view = render_view_host_->GetView(); | |
1029 if (view) | |
1030 view_->SetParentNativeViewAccessible(accessible_parent); | |
1031 } | |
1032 | |
1033 gfx::NativeViewAccessible | |
1034 RenderFrameHostImpl::GetParentNativeViewAccessible() const { | |
1035 return delegate_->GetParentNativeViewAccessible(); | |
1036 } | |
1037 #endif | |
1038 | |
864 } // namespace content | 1039 } // namespace content |
OLD | NEW |