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/frame_host/render_frame_proxy_host.h" | 21 #include "content/browser/frame_host/render_frame_proxy_host.h" |
19 #include "content/browser/renderer_host/input/input_router.h" | 22 #include "content/browser/renderer_host/input/input_router.h" |
20 #include "content/browser/renderer_host/input/timeout_monitor.h" | 23 #include "content/browser/renderer_host/input/timeout_monitor.h" |
21 #include "content/browser/renderer_host/render_view_host_impl.h" | 24 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 25 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 26 #include "content/common/accessibility_messages.h" |
22 #include "content/common/desktop_notification_messages.h" | 27 #include "content/common/desktop_notification_messages.h" |
23 #include "content/common/frame_messages.h" | 28 #include "content/common/frame_messages.h" |
24 #include "content/common/input_messages.h" | 29 #include "content/common/input_messages.h" |
25 #include "content/common/inter_process_time_ticks_converter.h" | 30 #include "content/common/inter_process_time_ticks_converter.h" |
26 #include "content/common/swapped_out_messages.h" | 31 #include "content/common/swapped_out_messages.h" |
| 32 #include "content/public/browser/ax_event_notification_details.h" |
| 33 #include "content/public/browser/browser_accessibility_state.h" |
27 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/content_browser_client.h" | 35 #include "content/public/browser/content_browser_client.h" |
29 #include "content/public/browser/desktop_notification_delegate.h" | 36 #include "content/public/browser/desktop_notification_delegate.h" |
30 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
31 #include "content/public/browser/render_widget_host_view.h" | 38 #include "content/public/browser/render_widget_host_view.h" |
32 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
33 #include "content/public/common/content_constants.h" | 40 #include "content/public/common/content_constants.h" |
34 #include "content/public/common/url_constants.h" | 41 #include "content/public/common/url_constants.h" |
35 #include "content/public/common/url_utils.h" | 42 #include "content/public/common/url_utils.h" |
| 43 #include "ui/accessibility/ax_tree.h" |
36 #include "url/gurl.h" | 44 #include "url/gurl.h" |
37 | 45 |
38 using base::TimeDelta; | 46 using base::TimeDelta; |
39 | 47 |
40 namespace content { | 48 namespace content { |
41 | 49 |
42 namespace { | 50 namespace { |
43 | 51 |
44 // The (process id, routing id) pair that identifies one RenderFrame. | 52 // The (process id, routing id) pair that identifies one RenderFrame. |
45 typedef std::pair<int32, int32> RenderFrameHostID; | 53 typedef std::pair<int32, int32> RenderFrameHostID; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 int routing_id, | 155 int routing_id, |
148 bool is_swapped_out) | 156 bool is_swapped_out) |
149 : render_view_host_(render_view_host), | 157 : render_view_host_(render_view_host), |
150 delegate_(delegate), | 158 delegate_(delegate), |
151 cross_process_frame_connector_(NULL), | 159 cross_process_frame_connector_(NULL), |
152 render_frame_proxy_host_(NULL), | 160 render_frame_proxy_host_(NULL), |
153 frame_tree_(frame_tree), | 161 frame_tree_(frame_tree), |
154 frame_tree_node_(frame_tree_node), | 162 frame_tree_node_(frame_tree_node), |
155 routing_id_(routing_id), | 163 routing_id_(routing_id), |
156 is_swapped_out_(is_swapped_out), | 164 is_swapped_out_(is_swapped_out), |
157 weak_ptr_factory_(this) { | 165 weak_ptr_factory_(this), |
| 166 accessibility_mode_(AccessibilityModeOff) { |
158 frame_tree_->RegisterRenderFrameHost(this); | 167 frame_tree_->RegisterRenderFrameHost(this); |
159 GetProcess()->AddRoute(routing_id_, this); | 168 GetProcess()->AddRoute(routing_id_, this); |
160 g_routing_id_frame_map.Get().insert(std::make_pair( | 169 g_routing_id_frame_map.Get().insert(std::make_pair( |
161 RenderFrameHostID(GetProcess()->GetID(), routing_id_), | 170 RenderFrameHostID(GetProcess()->GetID(), routing_id_), |
162 this)); | 171 this)); |
| 172 SetAccessibilityMode(delegate->GetAccessibilityMode()); |
163 } | 173 } |
164 | 174 |
165 RenderFrameHostImpl::~RenderFrameHostImpl() { | 175 RenderFrameHostImpl::~RenderFrameHostImpl() { |
166 GetProcess()->RemoveRoute(routing_id_); | 176 GetProcess()->RemoveRoute(routing_id_); |
167 g_routing_id_frame_map.Get().erase( | 177 g_routing_id_frame_map.Get().erase( |
168 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); | 178 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
169 if (delegate_) | 179 if (delegate_) |
170 delegate_->RenderFrameDeleted(this); | 180 delegate_->RenderFrameDeleted(this); |
171 | 181 |
172 // Notify the FrameTree that this RFH is going away, allowing it to shut down | 182 // Notify the FrameTree that this RFH is going away, allowing it to shut down |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 OnDidAccessInitialDocument) | 323 OnDidAccessInitialDocument) |
314 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisownOpener, OnDidDisownOpener) | 324 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisownOpener, OnDidDisownOpener) |
315 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) | 325 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) |
316 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) | 326 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) |
317 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission, | 327 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission, |
318 OnRequestDesktopNotificationPermission) | 328 OnRequestDesktopNotificationPermission) |
319 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show, | 329 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show, |
320 OnShowDesktopNotification) | 330 OnShowDesktopNotification) |
321 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel, | 331 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel, |
322 OnCancelDesktopNotification) | 332 OnCancelDesktopNotification) |
| 333 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) |
| 334 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, |
| 335 OnAccessibilityLocationChanges) |
323 IPC_END_MESSAGE_MAP() | 336 IPC_END_MESSAGE_MAP() |
324 | 337 |
325 return handled; | 338 return handled; |
326 } | 339 } |
327 | 340 |
| 341 void RenderFrameHostImpl::AccessibilitySetFocus(int object_id) { |
| 342 Send(new AccessibilityMsg_SetFocus(routing_id_, object_id)); |
| 343 } |
| 344 |
| 345 void RenderFrameHostImpl::AccessibilityDoDefaultAction(int object_id) { |
| 346 Send(new AccessibilityMsg_DoDefaultAction(routing_id_, object_id)); |
| 347 } |
| 348 |
| 349 void RenderFrameHostImpl::AccessibilityShowMenu(const gfx::Point& point) { |
| 350 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 351 render_view_host_->GetView()); |
| 352 if (view) |
| 353 view->AccessibilityShowMenu(point); |
| 354 } |
| 355 |
| 356 void RenderFrameHostImpl::AccessibilityScrollToMakeVisible( |
| 357 int acc_obj_id, gfx::Rect subfocus) { |
| 358 Send(new AccessibilityMsg_ScrollToMakeVisible( |
| 359 routing_id_, acc_obj_id, subfocus)); |
| 360 } |
| 361 |
| 362 void RenderFrameHostImpl::AccessibilityScrollToPoint( |
| 363 int acc_obj_id, gfx::Point point) { |
| 364 Send(new AccessibilityMsg_ScrollToPoint( |
| 365 routing_id_, acc_obj_id, point)); |
| 366 } |
| 367 |
| 368 void RenderFrameHostImpl::AccessibilitySetTextSelection( |
| 369 int object_id, int start_offset, int end_offset) { |
| 370 Send(new AccessibilityMsg_SetTextSelection( |
| 371 routing_id_, object_id, start_offset, end_offset)); |
| 372 } |
| 373 |
| 374 bool RenderFrameHostImpl::AccessibilityViewHasFocus() const { |
| 375 RenderWidgetHostView* view = render_view_host_->GetView(); |
| 376 if (view) |
| 377 return view->HasFocus(); |
| 378 return false; |
| 379 } |
| 380 |
| 381 gfx::Rect RenderFrameHostImpl::AccessibilityGetViewBounds() const { |
| 382 RenderWidgetHostView* view = render_view_host_->GetView(); |
| 383 if (view) |
| 384 return view->GetViewBounds(); |
| 385 return gfx::Rect(); |
| 386 } |
| 387 |
| 388 gfx::Point RenderFrameHostImpl::AccessibilityOriginInScreen( |
| 389 const gfx::Rect& bounds) const { |
| 390 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 391 render_view_host_->GetView()); |
| 392 if (view) |
| 393 return view->AccessibilityOriginInScreen(bounds); |
| 394 return gfx::Point(); |
| 395 } |
| 396 |
| 397 void RenderFrameHostImpl::AccessibilityHitTest(const gfx::Point& point) { |
| 398 Send(new AccessibilityMsg_HitTest(routing_id_, point)); |
| 399 } |
| 400 |
| 401 void RenderFrameHostImpl::AccessibilityFatalError() { |
| 402 Send(new AccessibilityMsg_FatalError(routing_id_)); |
| 403 browser_accessibility_manager_.reset(NULL); |
| 404 } |
| 405 |
328 void RenderFrameHostImpl::Init() { | 406 void RenderFrameHostImpl::Init() { |
329 GetProcess()->ResumeRequestsForView(routing_id_); | 407 GetProcess()->ResumeRequestsForView(routing_id_); |
330 } | 408 } |
331 | 409 |
332 void RenderFrameHostImpl::OnAddMessageToConsole( | 410 void RenderFrameHostImpl::OnAddMessageToConsole( |
333 int32 level, | 411 int32 level, |
334 const base::string16& message, | 412 const base::string16& message, |
335 int32 line_no, | 413 int32 line_no, |
336 const base::string16& source_id) { | 414 const base::string16& source_id) { |
337 if (delegate_->AddMessageToConsole(level, message, line_no, source_id)) | 415 if (delegate_->AddMessageToConsole(level, message, line_no, source_id)) |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 WebTextDirectionToChromeTextDirection( | 796 WebTextDirectionToChromeTextDirection( |
719 title_direction)); | 797 title_direction)); |
720 } | 798 } |
721 | 799 |
722 void RenderFrameHostImpl::OnUpdateEncoding(const std::string& encoding_name) { | 800 void RenderFrameHostImpl::OnUpdateEncoding(const std::string& encoding_name) { |
723 // This message is only sent for top-level frames. TODO(avi): when frame tree | 801 // This message is only sent for top-level frames. TODO(avi): when frame tree |
724 // mirroring works correctly, add a check here to enforce it. | 802 // mirroring works correctly, add a check here to enforce it. |
725 delegate_->UpdateEncoding(this, encoding_name); | 803 delegate_->UpdateEncoding(this, encoding_name); |
726 } | 804 } |
727 | 805 |
| 806 void RenderFrameHostImpl::OnAccessibilityEvents( |
| 807 const std::vector<AccessibilityHostMsg_EventParams>& params) { |
| 808 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 809 render_view_host_->GetView()); |
| 810 |
| 811 if ((accessibility_mode() != AccessibilityModeOff) && view && |
| 812 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) { |
| 813 if (accessibility_mode() & AccessibilityModeFlagPlatform) { |
| 814 if (!browser_accessibility_manager_) { |
| 815 browser_accessibility_manager_.reset( |
| 816 view->CreateBrowserAccessibilityManager(this)); |
| 817 } |
| 818 if (browser_accessibility_manager_) |
| 819 browser_accessibility_manager_->OnAccessibilityEvents(params); |
| 820 } |
| 821 |
| 822 std::vector<AXEventNotificationDetails> details; |
| 823 for (unsigned int i = 0; i < params.size(); ++i) { |
| 824 const AccessibilityHostMsg_EventParams& param = params[i]; |
| 825 AXEventNotificationDetails detail(param.update.nodes, |
| 826 param.event_type, |
| 827 param.id, |
| 828 GetProcess()->GetID(), |
| 829 routing_id_); |
| 830 details.push_back(detail); |
| 831 } |
| 832 |
| 833 delegate_->AccessibilityEventReceived(details); |
| 834 } |
| 835 |
| 836 // Always send an ACK or the renderer can be in a bad state. |
| 837 Send(new AccessibilityMsg_Events_ACK(routing_id_)); |
| 838 |
| 839 // The rest of this code is just for testing; bail out if we're not |
| 840 // in that mode. |
| 841 if (accessibility_testing_callback_.is_null()) |
| 842 return; |
| 843 |
| 844 for (unsigned i = 0; i < params.size(); i++) { |
| 845 const AccessibilityHostMsg_EventParams& param = params[i]; |
| 846 if (static_cast<int>(param.event_type) < 0) |
| 847 continue; |
| 848 if (!ax_tree_for_testing_) { |
| 849 ax_tree_for_testing_.reset(new ui::AXTree(param.update)); |
| 850 } else { |
| 851 CHECK(ax_tree_for_testing_->Unserialize(param.update)) |
| 852 << ax_tree_for_testing_->error(); |
| 853 } |
| 854 accessibility_testing_callback_.Run(param.event_type); |
| 855 } |
| 856 } |
| 857 |
| 858 void RenderFrameHostImpl::OnAccessibilityLocationChanges( |
| 859 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) { |
| 860 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 861 render_view_host_->GetView()); |
| 862 if (view && |
| 863 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) { |
| 864 if (accessibility_mode() & AccessibilityModeFlagPlatform) { |
| 865 if (!browser_accessibility_manager_) { |
| 866 browser_accessibility_manager_.reset( |
| 867 view->CreateBrowserAccessibilityManager(this)); |
| 868 } |
| 869 if (browser_accessibility_manager_) |
| 870 browser_accessibility_manager_->OnLocationChanges(params); |
| 871 } |
| 872 // TODO(aboxhall): send location change events to web contents observers too |
| 873 } |
| 874 } |
| 875 |
728 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { | 876 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { |
729 render_view_host_->SetPendingShutdown(on_swap_out); | 877 render_view_host_->SetPendingShutdown(on_swap_out); |
730 } | 878 } |
731 | 879 |
732 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { | 880 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { |
733 // TODO(creis): We should also check for WebUI pages here. Also, when the | 881 // TODO(creis): We should also check for WebUI pages here. Also, when the |
734 // out-of-process iframes implementation is ready, we should check for | 882 // out-of-process iframes implementation is ready, we should check for |
735 // cross-site URLs that are not allowed to commit in this process. | 883 // cross-site URLs that are not allowed to commit in this process. |
736 | 884 |
737 // Give the client a chance to disallow URLs from committing. | 885 // Give the client a chance to disallow URLs from committing. |
738 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); | 886 return GetContentClient()->browser()->CanCommitURL(GetProcess(), url); |
739 } | 887 } |
740 | 888 |
| 889 void RenderFrameHostImpl::DesktopNotificationPermissionRequestDone( |
| 890 int callback_context) { |
| 891 Send(new DesktopNotificationMsg_PermissionRequestDone( |
| 892 routing_id_, callback_context)); |
| 893 } |
| 894 |
741 void RenderFrameHostImpl::Navigate(const FrameMsg_Navigate_Params& params) { | 895 void RenderFrameHostImpl::Navigate(const FrameMsg_Navigate_Params& params) { |
742 TRACE_EVENT0("frame_host", "RenderFrameHostImpl::Navigate"); | 896 TRACE_EVENT0("frame_host", "RenderFrameHostImpl::Navigate"); |
743 // Browser plugin guests are not allowed to navigate outside web-safe schemes, | 897 // Browser plugin guests are not allowed to navigate outside web-safe schemes, |
744 // so do not grant them the ability to request additional URLs. | 898 // so do not grant them the ability to request additional URLs. |
745 if (!GetProcess()->IsGuest()) { | 899 if (!GetProcess()->IsGuest()) { |
746 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( | 900 ChildProcessSecurityPolicyImpl::GetInstance()->GrantRequestURL( |
747 GetProcess()->GetID(), params.url); | 901 GetProcess()->GetID(), params.url); |
748 if (params.url.SchemeIs(kDataScheme) && | 902 if (params.url.SchemeIs(kDataScheme) && |
749 params.base_url_for_data_url.SchemeIs(kFileScheme)) { | 903 params.base_url_for_data_url.SchemeIs(kFileScheme)) { |
750 // If 'data:' is used, and we have a 'file:' base url, grant access to | 904 // 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... |
878 render_view_host_->delegate_->RendererUnresponsive( | 1032 render_view_host_->delegate_->RendererUnresponsive( |
879 render_view_host_, | 1033 render_view_host_, |
880 render_view_host_->is_waiting_for_beforeunload_ack(), | 1034 render_view_host_->is_waiting_for_beforeunload_ack(), |
881 render_view_host_->IsWaitingForUnloadACK()); | 1035 render_view_host_->IsWaitingForUnloadACK()); |
882 } | 1036 } |
883 | 1037 |
884 void RenderFrameHostImpl::NotificationClosed(int notification_id) { | 1038 void RenderFrameHostImpl::NotificationClosed(int notification_id) { |
885 cancel_notification_callbacks_.erase(notification_id); | 1039 cancel_notification_callbacks_.erase(notification_id); |
886 } | 1040 } |
887 | 1041 |
888 void RenderFrameHostImpl::DesktopNotificationPermissionRequestDone( | 1042 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) { |
889 int callback_context) { | 1043 accessibility_mode_ = mode; |
890 Send(new DesktopNotificationMsg_PermissionRequestDone( | 1044 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode)); |
891 routing_id_, callback_context)); | |
892 } | 1045 } |
893 | 1046 |
| 1047 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting( |
| 1048 const base::Callback<void(ui::AXEvent)>& callback) { |
| 1049 accessibility_testing_callback_ = callback; |
| 1050 } |
| 1051 |
| 1052 const ui::AXTree* RenderFrameHostImpl::GetAXTreeForTesting() { |
| 1053 return ax_tree_for_testing_.get(); |
| 1054 } |
| 1055 |
| 1056 #if defined(OS_WIN) |
| 1057 void RenderFrameHostImpl::SetParentNativeViewAccessible( |
| 1058 gfx::NativeViewAccessible accessible_parent) { |
| 1059 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 1060 render_view_host_->GetView()); |
| 1061 if (view) |
| 1062 view->SetParentNativeViewAccessible(accessible_parent); |
| 1063 } |
| 1064 |
| 1065 gfx::NativeViewAccessible |
| 1066 RenderFrameHostImpl::GetParentNativeViewAccessible() const { |
| 1067 return delegate_->GetParentNativeViewAccessible(); |
| 1068 } |
| 1069 #endif |
| 1070 |
894 } // namespace content | 1071 } // namespace content |
OLD | NEW |