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

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, 5 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 int routing_id, 160 int routing_id,
153 bool is_swapped_out) 161 bool is_swapped_out)
154 : render_view_host_(render_view_host), 162 : render_view_host_(render_view_host),
155 delegate_(delegate), 163 delegate_(delegate),
156 cross_process_frame_connector_(NULL), 164 cross_process_frame_connector_(NULL),
157 render_frame_proxy_host_(NULL), 165 render_frame_proxy_host_(NULL),
158 frame_tree_(frame_tree), 166 frame_tree_(frame_tree),
159 frame_tree_node_(frame_tree_node), 167 frame_tree_node_(frame_tree_node),
160 routing_id_(routing_id), 168 routing_id_(routing_id),
161 is_swapped_out_(is_swapped_out), 169 is_swapped_out_(is_swapped_out),
162 weak_ptr_factory_(this) { 170 weak_ptr_factory_(this),
171 accessibility_mode_(AccessibilityModeOff) {
163 frame_tree_->RegisterRenderFrameHost(this); 172 frame_tree_->RegisterRenderFrameHost(this);
164 GetProcess()->AddRoute(routing_id_, this); 173 GetProcess()->AddRoute(routing_id_, this);
165 g_routing_id_frame_map.Get().insert(std::make_pair( 174 g_routing_id_frame_map.Get().insert(std::make_pair(
166 RenderFrameHostID(GetProcess()->GetID(), routing_id_), 175 RenderFrameHostID(GetProcess()->GetID(), routing_id_),
167 this)); 176 this));
168 177
169 if (GetProcess()->GetServiceRegistry()) { 178 if (GetProcess()->GetServiceRegistry()) {
170 RenderFrameSetupPtr setup; 179 RenderFrameSetupPtr setup;
171 GetProcess()->GetServiceRegistry()->ConnectToRemoteService(&setup); 180 GetProcess()->GetServiceRegistry()->ConnectToRemoteService(&setup);
172 mojo::ServiceProviderPtr service_provider; 181 mojo::ServiceProviderPtr service_provider;
173 setup->GetServiceProviderForFrame(routing_id_, 182 setup->GetServiceProviderForFrame(routing_id_,
174 mojo::Get(&service_provider)); 183 mojo::Get(&service_provider));
175 service_registry_.BindRemoteServiceProvider( 184 service_registry_.BindRemoteServiceProvider(
176 service_provider.PassMessagePipe()); 185 service_provider.PassMessagePipe());
177 } 186 }
187
188 accessibility_mode_ = delegate_->GetAccessibilityMode();
178 } 189 }
179 190
180 RenderFrameHostImpl::~RenderFrameHostImpl() { 191 RenderFrameHostImpl::~RenderFrameHostImpl() {
181 GetProcess()->RemoveRoute(routing_id_); 192 GetProcess()->RemoveRoute(routing_id_);
182 g_routing_id_frame_map.Get().erase( 193 g_routing_id_frame_map.Get().erase(
183 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 194 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
184 if (delegate_) 195 if (delegate_)
185 delegate_->RenderFrameDeleted(this); 196 delegate_->RenderFrameDeleted(this);
186 197
187 // Notify the FrameTree that this RFH is going away, allowing it to shut down 198 // Notify the FrameTree that this RFH is going away, allowing it to shut down
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) 348 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle)
338 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) 349 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding)
339 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission, 350 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_RequestPermission,
340 OnRequestDesktopNotificationPermission) 351 OnRequestDesktopNotificationPermission)
341 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show, 352 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Show,
342 OnShowDesktopNotification) 353 OnShowDesktopNotification)
343 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel, 354 IPC_MESSAGE_HANDLER(DesktopNotificationHostMsg_Cancel,
344 OnCancelDesktopNotification) 355 OnCancelDesktopNotification)
345 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, 356 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse,
346 OnTextSurroundingSelectionResponse) 357 OnTextSurroundingSelectionResponse)
358 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents)
359 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges,
360 OnAccessibilityLocationChanges)
347 IPC_END_MESSAGE_MAP() 361 IPC_END_MESSAGE_MAP()
348 362
349 return handled; 363 return handled;
350 } 364 }
351 365
366 void RenderFrameHostImpl::AccessibilitySetFocus(int object_id) {
367 Send(new AccessibilityMsg_SetFocus(routing_id_, object_id));
368 }
369
370 void RenderFrameHostImpl::AccessibilityDoDefaultAction(int object_id) {
371 Send(new AccessibilityMsg_DoDefaultAction(routing_id_, object_id));
372 }
373
374 void RenderFrameHostImpl::AccessibilityShowMenu(const gfx::Point& point) {
375 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
376 render_view_host_->GetView());
377 if (view)
378 view->AccessibilityShowMenu(point);
379 }
380
381 void RenderFrameHostImpl::AccessibilityScrollToMakeVisible(
382 int acc_obj_id, 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, 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
352 void RenderFrameHostImpl::Init() { 431 void RenderFrameHostImpl::Init() {
353 GetProcess()->ResumeRequestsForView(routing_id_); 432 GetProcess()->ResumeRequestsForView(routing_id_);
354 } 433 }
355 434
356 void RenderFrameHostImpl::OnAddMessageToConsole( 435 void RenderFrameHostImpl::OnAddMessageToConsole(
357 int32 level, 436 int32 level,
358 const base::string16& message, 437 const base::string16& message,
359 int32 line_no, 438 int32 line_no,
360 const base::string16& source_id) { 439 const base::string16& source_id) {
361 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
763 WebTextDirectionToChromeTextDirection( 842 WebTextDirectionToChromeTextDirection(
764 title_direction)); 843 title_direction));
765 } 844 }
766 845
767 void RenderFrameHostImpl::OnUpdateEncoding(const std::string& encoding_name) { 846 void RenderFrameHostImpl::OnUpdateEncoding(const std::string& encoding_name) {
768 // 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
769 // mirroring works correctly, add a check here to enforce it. 848 // mirroring works correctly, add a check here to enforce it.
770 delegate_->UpdateEncoding(this, encoding_name); 849 delegate_->UpdateEncoding(this, encoding_name);
771 } 850 }
772 851
852 void RenderFrameHostImpl::OnAccessibilityEvents(
853 const std::vector<AccessibilityHostMsg_EventParams>& params) {
854 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
855 render_view_host_->GetView());
856
857 if ((accessibility_mode() != AccessibilityModeOff) && view &&
858 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) {
859 if (accessibility_mode() & AccessibilityModeFlagPlatform) {
860 GetOrCreateBrowserAccessibilityManager();
861 if (browser_accessibility_manager_)
862 browser_accessibility_manager_->OnAccessibilityEvents(params);
863 }
864
865 std::vector<AXEventNotificationDetails> details;
ncarter (slow) 2014/07/15 01:23:28 (maybe) details.reserve(params.size());
dmazzoni 2014/07/15 07:55:03 Done.
866 for (unsigned int i = 0; i < params.size(); ++i) {
ncarter (slow) 2014/07/15 01:23:28 Use size_t here.
dmazzoni 2014/07/15 07:55:03 Done.
867 const AccessibilityHostMsg_EventParams& param = params[i];
868 AXEventNotificationDetails detail(param.update.node_id_to_clear,
869 param.update.nodes,
870 param.event_type,
871 param.id,
872 GetProcess()->GetID(),
873 routing_id_);
874 details.push_back(detail);
875 }
876
877 delegate_->AccessibilityEventReceived(details);
878 }
879
880 // Always send an ACK or the renderer can be in a bad state.
881 Send(new AccessibilityMsg_Events_ACK(routing_id_));
882
883 // The rest of this code is just for testing; bail out if we're not
884 // in that mode.
885 if (accessibility_testing_callback_.is_null())
886 return;
887
888 for (unsigned i = 0; i < params.size(); i++) {
ncarter (slow) 2014/07/15 01:23:28 Use size_t here
dmazzoni 2014/07/15 07:55:04 Done.
889 const AccessibilityHostMsg_EventParams& param = params[i];
890 if (static_cast<int>(param.event_type) < 0)
891 continue;
892 if (!ax_tree_for_testing_) {
893 ax_tree_for_testing_.reset(new ui::AXTree(param.update));
894 } else {
895 CHECK(ax_tree_for_testing_->Unserialize(param.update))
896 << ax_tree_for_testing_->error();
897 }
898 accessibility_testing_callback_.Run(param.event_type, param.id);
899 }
900 }
901
902 void RenderFrameHostImpl::OnAccessibilityLocationChanges(
903 const std::vector<AccessibilityHostMsg_LocationChangeParams>& params) {
904 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
905 render_view_host_->GetView());
906 if (view &&
907 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) {
908 if (accessibility_mode() & AccessibilityModeFlagPlatform) {
909 if (!browser_accessibility_manager_) {
910 browser_accessibility_manager_.reset(
911 view->CreateBrowserAccessibilityManager(this));
912 }
913 if (browser_accessibility_manager_)
914 browser_accessibility_manager_->OnLocationChanges(params);
915 }
916 // TODO(aboxhall): send location change events to web contents observers too
917 }
918 }
919
773 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) { 920 void RenderFrameHostImpl::SetPendingShutdown(const base::Closure& on_swap_out) {
774 render_view_host_->SetPendingShutdown(on_swap_out); 921 render_view_host_->SetPendingShutdown(on_swap_out);
775 } 922 }
776 923
777 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) { 924 bool RenderFrameHostImpl::CanCommitURL(const GURL& url) {
778 // TODO(creis): We should also check for WebUI pages here. Also, when the 925 // TODO(creis): We should also check for WebUI pages here. Also, when the
779 // out-of-process iframes implementation is ready, we should check for 926 // out-of-process iframes implementation is ready, we should check for
780 // cross-site URLs that are not allowed to commit in this process. 927 // cross-site URLs that are not allowed to commit in this process.
781 928
782 // Give the client a chance to disallow URLs from committing. 929 // Give the client a chance to disallow URLs from committing.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 void RenderFrameHostImpl::NotificationClosed(int notification_id) { 1077 void RenderFrameHostImpl::NotificationClosed(int notification_id) {
931 cancel_notification_callbacks_.erase(notification_id); 1078 cancel_notification_callbacks_.erase(notification_id);
932 } 1079 }
933 1080
934 void RenderFrameHostImpl::DesktopNotificationPermissionRequestDone( 1081 void RenderFrameHostImpl::DesktopNotificationPermissionRequestDone(
935 int callback_context) { 1082 int callback_context) {
936 Send(new DesktopNotificationMsg_PermissionRequestDone( 1083 Send(new DesktopNotificationMsg_PermissionRequestDone(
937 routing_id_, callback_context)); 1084 routing_id_, callback_context));
938 } 1085 }
939 1086
1087 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) {
1088 accessibility_mode_ = mode;
1089 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode));
1090 }
1091
1092 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting(
1093 const base::Callback<void(ui::AXEvent, int)>& callback) {
1094 accessibility_testing_callback_ = callback;
1095 }
1096
1097 const ui::AXTree* RenderFrameHostImpl::GetAXTreeForTesting() {
1098 return ax_tree_for_testing_.get();
1099 }
1100
1101 BrowserAccessibilityManager*
1102 RenderFrameHostImpl::GetOrCreateBrowserAccessibilityManager() {
1103 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
1104 render_view_host_->GetView());
1105 if (view &&
1106 !browser_accessibility_manager_) {
1107 browser_accessibility_manager_.reset(
1108 view->CreateBrowserAccessibilityManager(this));
1109 }
1110 return browser_accessibility_manager_.get();
1111 }
1112
1113 #if defined(OS_WIN)
1114 void RenderFrameHostImpl::SetParentNativeViewAccessible(
1115 gfx::NativeViewAccessible accessible_parent) {
1116 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
1117 render_view_host_->GetView());
1118 if (view)
1119 view->SetParentNativeViewAccessible(accessible_parent);
1120 }
1121
1122 gfx::NativeViewAccessible
1123 RenderFrameHostImpl::GetParentNativeViewAccessible() const {
1124 return delegate_->GetParentNativeViewAccessible();
1125 }
1126 #endif
ncarter (slow) 2014/07/15 01:23:28 #endif // defined(OS_WIN)
dmazzoni 2014/07/15 07:55:04 Done.
1127
940 void RenderFrameHostImpl::SetHasPendingTransitionRequest( 1128 void RenderFrameHostImpl::SetHasPendingTransitionRequest(
941 bool has_pending_request) { 1129 bool has_pending_request) {
942 BrowserThread::PostTask( 1130 BrowserThread::PostTask(
943 BrowserThread::IO, 1131 BrowserThread::IO,
944 FROM_HERE, 1132 FROM_HERE,
945 base::Bind( 1133 base::Bind(
946 &TransitionRequestManager::SetHasPendingTransitionRequest, 1134 &TransitionRequestManager::SetHasPendingTransitionRequest,
947 base::Unretained(TransitionRequestManager::GetInstance()), 1135 base::Unretained(TransitionRequestManager::GetInstance()),
948 GetProcess()->GetID(), 1136 GetProcess()->GetID(),
949 routing_id_, 1137 routing_id_,
950 has_pending_request)); 1138 has_pending_request));
951 } 1139 }
952 1140
953 } // namespace content 1141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698