Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: content/browser/frame_host/render_frame_host_impl.cc

Issue 273423004: Migrate accessibility from RenderView to RenderFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 WebTextDirectionToChromeTextDirection( 844 WebTextDirectionToChromeTextDirection(
768 title_direction)); 845 title_direction));
769 } 846 }
770 847
771 void RenderFrameHostImpl::OnUpdateEncoding(const std::string& encoding_name) { 848 void RenderFrameHostImpl::OnUpdateEncoding(const std::string& encoding_name) {
772 // This message is only sent for top-level frames. TODO(avi): when frame tree 849 // This message is only sent for top-level frames. TODO(avi): when frame tree
773 // mirroring works correctly, add a check here to enforce it. 850 // mirroring works correctly, add a check here to enforce it.
774 delegate_->UpdateEncoding(this, encoding_name); 851 delegate_->UpdateEncoding(this, encoding_name);
775 } 852 }
776 853
854
777 void RenderFrameHostImpl::OnBeginNavigation( 855 void RenderFrameHostImpl::OnBeginNavigation(
778 const FrameHostMsg_BeginNavigation_Params& params) { 856 const FrameHostMsg_BeginNavigation_Params& params) {
779 #if defined(USE_BROWSER_SIDE_NAVIGATION) 857 #if defined(USE_BROWSER_SIDE_NAVIGATION)
780 frame_tree_node()->render_manager()->OnBeginNavigation(params); 858 frame_tree_node()->render_manager()->OnBeginNavigation(params);
781 #endif 859 #endif
782 } 860 }
783 861
862 void RenderFrameHostImpl::OnAccessibilityEvents(
863 const std::vector<AccessibilityHostMsg_EventParams>& params) {
864 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
865 render_view_host_->GetView());
866
867
868 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode();
869 if ((accessibility_mode != AccessibilityModeOff) && view &&
870 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) {
871 if (accessibility_mode & AccessibilityModeFlagPlatform) {
872 GetOrCreateBrowserAccessibilityManager();
873 if (browser_accessibility_manager_)
874 browser_accessibility_manager_->OnAccessibilityEvents(params);
875 }
876
877 std::vector<AXEventNotificationDetails> details;
878 details.reserve(params.size());
879 for (size_t i = 0; i < params.size(); ++i) {
880 const AccessibilityHostMsg_EventParams& param = params[i];
881 AXEventNotificationDetails detail(param.update.node_id_to_clear,
882 param.update.nodes,
883 param.event_type,
884 param.id,
885 GetProcess()->GetID(),
886 routing_id_);
887 details.push_back(detail);
888 }
889
890 delegate_->AccessibilityEventReceived(details);
891 }
892
893 // Always send an ACK or the renderer can be in a bad state.
894 Send(new AccessibilityMsg_Events_ACK(routing_id_));
895
896 // The rest of this code is just for testing; bail out if we're not
897 // in that mode.
898 if (accessibility_testing_callback_.is_null())
899 return;
900
901 for (size_t i = 0; i < params.size(); i++) {
902 const AccessibilityHostMsg_EventParams& param = params[i];
903 if (static_cast<int>(param.event_type) < 0)
904 continue;
905 if (!ax_tree_for_testing_) {
906 ax_tree_for_testing_.reset(new ui::AXTree(param.update));
907 } else {
908 CHECK(ax_tree_for_testing_->Unserialize(param.update))
909 << ax_tree_for_testing_->error();
910 }
911 accessibility_testing_callback_.Run(param.event_type, param.id);
912 }
913 }
914
915 void RenderFrameHostImpl::OnAccessibilityLocationChanges(
916 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) {
917 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
918 render_view_host_->GetView());
919 if (view &&
920 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) {
921 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode();
922 if (accessibility_mode & AccessibilityModeFlagPlatform) {
923 if (!browser_accessibility_manager_) {
924 browser_accessibility_manager_.reset(
925 view->CreateBrowserAccessibilityManager(this));
926 }
927 if (browser_accessibility_manager_)
928 browser_accessibility_manager_->OnLocationChanges(params);
929 }
930 // TODO(aboxhall): send location change events to web contents observers too
931 }
932 }
933
784 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { 934 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) {
785 render_view_host_->SetPendingShutdown(on_swap_out); 935 render_view_host_->SetPendingShutdown(on_swap_out);
786 } 936 }
787 937
788 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { 938 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) {
789 // TODO(creis): We should also check for WebUI pages here. Also, when the 939 // TODO(creis): We should also check for WebUI pages here. Also, when the
790 // out-of-process iframes implementation is ready, we should check for 940 // out-of-process iframes implementation is ready, we should check for
791 // cross-site URLs that are not allowed to commit in this process. 941 // cross-site URLs that are not allowed to commit in this process.
792 942
793 // Give the client a chance to disallow URLs from committing. 943 // Give the client a chance to disallow URLs from committing.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 void RenderFrameHostImpl::NotificationClosed(int notification_id) { 1091 void RenderFrameHostImpl::NotificationClosed(int notification_id) {
942 cancel_notification_callbacks_.erase(notification_id); 1092 cancel_notification_callbacks_.erase(notification_id);
943 } 1093 }
944 1094
945 void RenderFrameHostImpl::DesktopNotificationPermissionRequestDone( 1095 void RenderFrameHostImpl::DesktopNotificationPermissionRequestDone(
946 int callback_context) { 1096 int callback_context) {
947 Send(new DesktopNotificationMsg_PermissionRequestDone( 1097 Send(new DesktopNotificationMsg_PermissionRequestDone(
948 routing_id_, callback_context)); 1098 routing_id_, callback_context));
949 } 1099 }
950 1100
1101 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) {
1102 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode));
1103 }
1104
1105 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting(
1106 const base::Callback<void(ui::AXEvent, int)>& callback) {
1107 accessibility_testing_callback_ = callback;
1108 }
1109
1110 const ui::AXTree* RenderFrameHostImpl::GetAXTreeForTesting() {
1111 return ax_tree_for_testing_.get();
1112 }
1113
1114 BrowserAccessibilityManager*
1115 RenderFrameHostImpl::GetOrCreateBrowserAccessibilityManager() {
1116 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
1117 render_view_host_->GetView());
1118 if (view &&
1119 !browser_accessibility_manager_) {
1120 browser_accessibility_manager_.reset(
1121 view->CreateBrowserAccessibilityManager(this));
1122 }
1123 return browser_accessibility_manager_.get();
1124 }
1125
1126 #if defined(OS_WIN)
1127 void RenderFrameHostImpl::SetParentNativeViewAccessible(
1128 gfx::NativeViewAccessible accessible_parent) {
1129 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
1130 render_view_host_->GetView());
1131 if (view)
1132 view->SetParentNativeViewAccessible(accessible_parent);
1133 }
1134
1135 gfx::NativeViewAccessible
1136 RenderFrameHostImpl::GetParentNativeViewAccessible() const {
1137 return delegate_->GetParentNativeViewAccessible();
1138 }
1139 #endif // defined(OS_WIN)
1140
951 void RenderFrameHostImpl::SetHasPendingTransitionRequest( 1141 void RenderFrameHostImpl::SetHasPendingTransitionRequest(
952 bool has_pending_request) { 1142 bool has_pending_request) {
953 BrowserThread::PostTask( 1143 BrowserThread::PostTask(
954 BrowserThread::IO, 1144 BrowserThread::IO,
955 FROM_HERE, 1145 FROM_HERE,
956 base::Bind( 1146 base::Bind(
957 &TransitionRequestManager::SetHasPendingTransitionRequest, 1147 &TransitionRequestManager::SetHasPendingTransitionRequest,
958 base::Unretained(TransitionRequestManager::GetInstance()), 1148 base::Unretained(TransitionRequestManager::GetInstance()),
959 GetProcess()->GetID(), 1149 GetProcess()->GetID(),
960 routing_id_, 1150 routing_id_,
961 has_pending_request)); 1151 has_pending_request));
962 } 1152 }
963 1153
964 } // namespace content 1154 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.h ('k') | content/browser/renderer_host/legacy_render_widget_host_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698