| 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 "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "content/browser/accessibility/accessibility_mode_helper.h" |
| 13 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 14 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 12 #include "content/browser/child_process_security_policy_impl.h" | 15 #include "content/browser/child_process_security_policy_impl.h" |
| 13 #include "content/browser/frame_host/cross_process_frame_connector.h" | 16 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 14 #include "content/browser/frame_host/cross_site_transferring_request.h" | 17 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| 15 #include "content/browser/frame_host/frame_tree.h" | 18 #include "content/browser/frame_host/frame_tree.h" |
| 16 #include "content/browser/frame_host/frame_tree_node.h" | 19 #include "content/browser/frame_host/frame_tree_node.h" |
| 17 #include "content/browser/frame_host/navigator.h" | 20 #include "content/browser/frame_host/navigator.h" |
| 18 #include "content/browser/frame_host/render_frame_host_delegate.h" | 21 #include "content/browser/frame_host/render_frame_host_delegate.h" |
| 19 #include "content/browser/frame_host/render_frame_proxy_host.h" | 22 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 20 #include "content/browser/renderer_host/input/input_router.h" | 23 #include "content/browser/renderer_host/input/input_router.h" |
| 21 #include "content/browser/renderer_host/input/timeout_monitor.h" | 24 #include "content/browser/renderer_host/input/timeout_monitor.h" |
| 22 #include "content/browser/renderer_host/render_process_host_impl.h" | 25 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 23 #include "content/browser/renderer_host/render_view_host_impl.h" | 26 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 24 #include "content/browser/renderer_host/render_widget_host_impl.h" | 27 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 28 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 25 #include "content/browser/transition_request_manager.h" | 29 #include "content/browser/transition_request_manager.h" |
| 30 #include "content/common/accessibility_messages.h" |
| 26 #include "content/common/desktop_notification_messages.h" | 31 #include "content/common/desktop_notification_messages.h" |
| 27 #include "content/common/frame_messages.h" | 32 #include "content/common/frame_messages.h" |
| 28 #include "content/common/input_messages.h" | 33 #include "content/common/input_messages.h" |
| 29 #include "content/common/inter_process_time_ticks_converter.h" | 34 #include "content/common/inter_process_time_ticks_converter.h" |
| 30 #include "content/common/render_frame_setup.mojom.h" | 35 #include "content/common/render_frame_setup.mojom.h" |
| 31 #include "content/common/swapped_out_messages.h" | 36 #include "content/common/swapped_out_messages.h" |
| 37 #include "content/public/browser/ax_event_notification_details.h" |
| 38 #include "content/public/browser/browser_accessibility_state.h" |
| 32 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/content_browser_client.h" | 40 #include "content/public/browser/content_browser_client.h" |
| 34 #include "content/public/browser/desktop_notification_delegate.h" | 41 #include "content/public/browser/desktop_notification_delegate.h" |
| 35 #include "content/public/browser/render_process_host.h" | 42 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/render_widget_host_view.h" | 43 #include "content/public/browser/render_widget_host_view.h" |
| 37 #include "content/public/browser/user_metrics.h" | 44 #include "content/public/browser/user_metrics.h" |
| 38 #include "content/public/common/content_constants.h" | 45 #include "content/public/common/content_constants.h" |
| 39 #include "content/public/common/url_constants.h" | 46 #include "content/public/common/url_constants.h" |
| 40 #include "content/public/common/url_utils.h" | 47 #include "content/public/common/url_utils.h" |
| 48 #include "ui/accessibility/ax_tree.h" |
| 41 #include "url/gurl.h" | 49 #include "url/gurl.h" |
| 42 | 50 |
| 43 using base::TimeDelta; | 51 using base::TimeDelta; |
| 44 | 52 |
| 45 namespace content { | 53 namespace content { |
| 46 | 54 |
| 47 namespace { | 55 namespace { |
| 48 | 56 |
| 49 // The (process id, routing id) pair that identifies one RenderFrame. | 57 // The (process id, routing id) pair that identifies one RenderFrame. |
| 50 typedef std::pair<int32, int32> RenderFrameHostID; | 58 typedef std::pair<int32, int32> RenderFrameHostID; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, | 347 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, |
| 340 OnBeginNavigation) | 348 OnBeginNavigation) |
| 341 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission, | 349 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission, |
| 342 OnRequestDesktopNotificationPermission) | 350 OnRequestDesktopNotificationPermission) |
| 343 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show, | 351 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show, |
| 344 OnShowDesktopNotification) | 352 OnShowDesktopNotification) |
| 345 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel, | 353 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel, |
| 346 OnCancelDesktopNotification) | 354 OnCancelDesktopNotification) |
| 347 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, | 355 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, |
| 348 OnTextSurroundingSelectionResponse) | 356 OnTextSurroundingSelectionResponse) |
| 357 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) |
| 358 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, |
| 359 OnAccessibilityLocationChanges) |
| 349 IPC_END_MESSAGE_MAP() | 360 IPC_END_MESSAGE_MAP() |
| 350 | 361 |
| 351 return handled; | 362 return handled; |
| 352 } | 363 } |
| 353 | 364 |
| 365 void RenderFrameHostImpl::AccessibilitySetFocus(int object_id) { |
| 366 Send(new AccessibilityMsg_SetFocus(routing_id_, object_id)); |
| 367 } |
| 368 |
| 369 void RenderFrameHostImpl::AccessibilityDoDefaultAction(int object_id) { |
| 370 Send(new AccessibilityMsg_DoDefaultAction(routing_id_, object_id)); |
| 371 } |
| 372 |
| 373 void RenderFrameHostImpl::AccessibilityShowMenu( |
| 374 const gfx::Point& global_point) { |
| 375 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 376 render_view_host_->GetView()); |
| 377 if (view) |
| 378 view->AccessibilityShowMenu(global_point); |
| 379 } |
| 380 |
| 381 void RenderFrameHostImpl::AccessibilityScrollToMakeVisible( |
| 382 int acc_obj_id, const gfx::Rect& subfocus) { |
| 383 Send(new AccessibilityMsg_ScrollToMakeVisible( |
| 384 routing_id_, acc_obj_id, subfocus)); |
| 385 } |
| 386 |
| 387 void RenderFrameHostImpl::AccessibilityScrollToPoint( |
| 388 int acc_obj_id, const gfx::Point& point) { |
| 389 Send(new AccessibilityMsg_ScrollToPoint( |
| 390 routing_id_, acc_obj_id, point)); |
| 391 } |
| 392 |
| 393 void RenderFrameHostImpl::AccessibilitySetTextSelection( |
| 394 int object_id, int start_offset, int end_offset) { |
| 395 Send(new AccessibilityMsg_SetTextSelection( |
| 396 routing_id_, object_id, start_offset, end_offset)); |
| 397 } |
| 398 |
| 399 bool RenderFrameHostImpl::AccessibilityViewHasFocus() const { |
| 400 RenderWidgetHostView* view = render_view_host_->GetView(); |
| 401 if (view) |
| 402 return view->HasFocus(); |
| 403 return false; |
| 404 } |
| 405 |
| 406 gfx::Rect RenderFrameHostImpl::AccessibilityGetViewBounds() const { |
| 407 RenderWidgetHostView* view = render_view_host_->GetView(); |
| 408 if (view) |
| 409 return view->GetViewBounds(); |
| 410 return gfx::Rect(); |
| 411 } |
| 412 |
| 413 gfx::Point RenderFrameHostImpl::AccessibilityOriginInScreen( |
| 414 const gfx::Rect& bounds) const { |
| 415 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 416 render_view_host_->GetView()); |
| 417 if (view) |
| 418 return view->AccessibilityOriginInScreen(bounds); |
| 419 return gfx::Point(); |
| 420 } |
| 421 |
| 422 void RenderFrameHostImpl::AccessibilityHitTest(const gfx::Point& point) { |
| 423 Send(new AccessibilityMsg_HitTest(routing_id_, point)); |
| 424 } |
| 425 |
| 426 void RenderFrameHostImpl::AccessibilityFatalError() { |
| 427 Send(new AccessibilityMsg_FatalError(routing_id_)); |
| 428 browser_accessibility_manager_.reset(NULL); |
| 429 } |
| 430 |
| 354 void RenderFrameHostImpl::Init() { | 431 void RenderFrameHostImpl::Init() { |
| 355 GetProcess()->ResumeRequestsForView(routing_id_); | 432 GetProcess()->ResumeRequestsForView(routing_id_); |
| 356 } | 433 } |
| 357 | 434 |
| 358 void RenderFrameHostImpl::OnAddMessageToConsole( | 435 void RenderFrameHostImpl::OnAddMessageToConsole( |
| 359 int32 level, | 436 int32 level, |
| 360 const base::string16& message, | 437 const base::string16& message, |
| 361 int32 line_no, | 438 int32 line_no, |
| 362 const base::string16& source_id) { | 439 const base::string16& source_id) { |
| 363 if (delegate_->AddMessageToConsole(level, message, line_no, source_id)) | 440 if (delegate_->AddMessageToConsole(level, message, line_no, source_id)) |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 WebTextDirectionToChromeTextDirection( | 842 WebTextDirectionToChromeTextDirection( |
| 766 title_direction)); | 843 title_direction)); |
| 767 } | 844 } |
| 768 | 845 |
| 769 void RenderFrameHostImpl::OnUpdateEncoding(const std::string& encoding_name) { | 846 void RenderFrameHostImpl::OnUpdateEncoding(const std::string& encoding_name) { |
| 770 // This message is only sent for top-level frames. TODO(avi): when frame tree | 847 // This message is only sent for top-level frames. TODO(avi): when frame tree |
| 771 // mirroring works correctly, add a check here to enforce it. | 848 // mirroring works correctly, add a check here to enforce it. |
| 772 delegate_->UpdateEncoding(this, encoding_name); | 849 delegate_->UpdateEncoding(this, encoding_name); |
| 773 } | 850 } |
| 774 | 851 |
| 852 |
| 775 void RenderFrameHostImpl::OnBeginNavigation( | 853 void RenderFrameHostImpl::OnBeginNavigation( |
| 776 const FrameHostMsg_BeginNavigation_Params& params) { | 854 const FrameHostMsg_BeginNavigation_Params& params) { |
| 777 #if defined(USE_BROWSER_SIDE_NAVIGATION) | 855 #if defined(USE_BROWSER_SIDE_NAVIGATION) |
| 778 frame_tree_node()->render_manager()->OnBeginNavigation(params); | 856 frame_tree_node()->render_manager()->OnBeginNavigation(params); |
| 779 #endif | 857 #endif |
| 780 } | 858 } |
| 781 | 859 |
| 860 void RenderFrameHostImpl::OnAccessibilityEvents( |
| 861 const std::vector<AccessibilityHostMsg_EventParams>& params) { |
| 862 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 863 render_view_host_->GetView()); |
| 864 |
| 865 |
| 866 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode(); |
| 867 if ((accessibility_mode != AccessibilityModeOff) && view && |
| 868 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) { |
| 869 if (accessibility_mode & AccessibilityModeFlagPlatform) { |
| 870 GetOrCreateBrowserAccessibilityManager(); |
| 871 if (browser_accessibility_manager_) |
| 872 browser_accessibility_manager_->OnAccessibilityEvents(params); |
| 873 } |
| 874 |
| 875 std::vector<AXEventNotificationDetails> details; |
| 876 details.reserve(params.size()); |
| 877 for (size_t i = 0; i < params.size(); ++i) { |
| 878 const AccessibilityHostMsg_EventParams& param = params[i]; |
| 879 AXEventNotificationDetails detail(param.update.node_id_to_clear, |
| 880 param.update.nodes, |
| 881 param.event_type, |
| 882 param.id, |
| 883 GetProcess()->GetID(), |
| 884 routing_id_); |
| 885 details.push_back(detail); |
| 886 } |
| 887 |
| 888 delegate_->AccessibilityEventReceived(details); |
| 889 } |
| 890 |
| 891 // Always send an ACK or the renderer can be in a bad state. |
| 892 Send(new AccessibilityMsg_Events_ACK(routing_id_)); |
| 893 |
| 894 // The rest of this code is just for testing; bail out if we're not |
| 895 // in that mode. |
| 896 if (accessibility_testing_callback_.is_null()) |
| 897 return; |
| 898 |
| 899 for (size_t i = 0; i < params.size(); i++) { |
| 900 const AccessibilityHostMsg_EventParams& param = params[i]; |
| 901 if (static_cast<int>(param.event_type) < 0) |
| 902 continue; |
| 903 if (!ax_tree_for_testing_) { |
| 904 ax_tree_for_testing_.reset(new ui::AXTree(param.update)); |
| 905 } else { |
| 906 CHECK(ax_tree_for_testing_->Unserialize(param.update)) |
| 907 << ax_tree_for_testing_->error(); |
| 908 } |
| 909 accessibility_testing_callback_.Run(param.event_type, param.id); |
| 910 } |
| 911 } |
| 912 |
| 913 void RenderFrameHostImpl::OnAccessibilityLocationChanges( |
| 914 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) { |
| 915 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 916 render_view_host_->GetView()); |
| 917 if (view && |
| 918 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) { |
| 919 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode(); |
| 920 if (accessibility_mode & AccessibilityModeFlagPlatform) { |
| 921 if (!browser_accessibility_manager_) { |
| 922 browser_accessibility_manager_.reset( |
| 923 view->CreateBrowserAccessibilityManager(this)); |
| 924 } |
| 925 if (browser_accessibility_manager_) |
| 926 browser_accessibility_manager_->OnLocationChanges(params); |
| 927 } |
| 928 // TODO(aboxhall): send location change events to web contents observers too |
| 929 } |
| 930 } |
| 931 |
| 782 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { | 932 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { |
| 783 render_view_host_->SetPendingShutdown(on_swap_out); | 933 render_view_host_->SetPendingShutdown(on_swap_out); |
| 784 } | 934 } |
| 785 | 935 |
| 786 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { | 936 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { |
| 787 // TODO(creis): We should also check for WebUI pages here. Also, when the | 937 // TODO(creis): We should also check for WebUI pages here. Also, when the |
| 788 // out-of-process iframes implementation is ready, we should check for | 938 // out-of-process iframes implementation is ready, we should check for |
| 789 // cross-site URLs that are not allowed to commit in this process. | 939 // cross-site URLs that are not allowed to commit in this process. |
| 790 | 940 |
| 791 // Give the client a chance to disallow URLs from committing. | 941 // Give the client a chance to disallow URLs from committing. |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 void RenderFrameHostImpl::NotificationClosed(int notification_id) { | 1089 void RenderFrameHostImpl::NotificationClosed(int notification_id) { |
| 940 cancel_notification_callbacks_.erase(notification_id); | 1090 cancel_notification_callbacks_.erase(notification_id); |
| 941 } | 1091 } |
| 942 | 1092 |
| 943 void RenderFrameHostImpl::DesktopNotificationPermissionRequestDone( | 1093 void RenderFrameHostImpl::DesktopNotificationPermissionRequestDone( |
| 944 int callback_context) { | 1094 int callback_context) { |
| 945 Send(new DesktopNotificationMsg_PermissionRequestDone( | 1095 Send(new DesktopNotificationMsg_PermissionRequestDone( |
| 946 routing_id_, callback_context)); | 1096 routing_id_, callback_context)); |
| 947 } | 1097 } |
| 948 | 1098 |
| 1099 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) { |
| 1100 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode)); |
| 1101 } |
| 1102 |
| 1103 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting( |
| 1104 const base::Callback<void(ui::AXEvent, int)>& callback) { |
| 1105 accessibility_testing_callback_ = callback; |
| 1106 } |
| 1107 |
| 1108 const ui::AXTree* RenderFrameHostImpl::GetAXTreeForTesting() { |
| 1109 return ax_tree_for_testing_.get(); |
| 1110 } |
| 1111 |
| 1112 BrowserAccessibilityManager* |
| 1113 RenderFrameHostImpl::GetOrCreateBrowserAccessibilityManager() { |
| 1114 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 1115 render_view_host_->GetView()); |
| 1116 if (view && |
| 1117 !browser_accessibility_manager_) { |
| 1118 browser_accessibility_manager_.reset( |
| 1119 view->CreateBrowserAccessibilityManager(this)); |
| 1120 } |
| 1121 return browser_accessibility_manager_.get(); |
| 1122 } |
| 1123 |
| 1124 #if defined(OS_WIN) |
| 1125 void RenderFrameHostImpl::SetParentNativeViewAccessible( |
| 1126 gfx::NativeViewAccessible accessible_parent) { |
| 1127 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 1128 render_view_host_->GetView()); |
| 1129 if (view) |
| 1130 view->SetParentNativeViewAccessible(accessible_parent); |
| 1131 } |
| 1132 |
| 1133 gfx::NativeViewAccessible |
| 1134 RenderFrameHostImpl::GetParentNativeViewAccessible() const { |
| 1135 return delegate_->GetParentNativeViewAccessible(); |
| 1136 } |
| 1137 #endif // defined(OS_WIN) |
| 1138 |
| 949 void RenderFrameHostImpl::SetHasPendingTransitionRequest( | 1139 void RenderFrameHostImpl::SetHasPendingTransitionRequest( |
| 950 bool has_pending_request) { | 1140 bool has_pending_request) { |
| 951 BrowserThread::PostTask( | 1141 BrowserThread::PostTask( |
| 952 BrowserThread::IO, | 1142 BrowserThread::IO, |
| 953 FROM_HERE, | 1143 FROM_HERE, |
| 954 base::Bind( | 1144 base::Bind( |
| 955 &TransitionRequestManager::SetHasPendingTransitionRequest, | 1145 &TransitionRequestManager::SetHasPendingTransitionRequest, |
| 956 base::Unretained(TransitionRequestManager::GetInstance()), | 1146 base::Unretained(TransitionRequestManager::GetInstance()), |
| 957 GetProcess()->GetID(), | 1147 GetProcess()->GetID(), |
| 958 routing_id_, | 1148 routing_id_, |
| 959 has_pending_request)); | 1149 has_pending_request)); |
| 960 } | 1150 } |
| 961 | 1151 |
| 962 } // namespace content | 1152 } // namespace content |
| OLD | NEW |