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

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

Powered by Google App Engine
This is Rietveld 408576698