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

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

Issue 1051923003: Add a WebContentsImpl API to snapshot the accessibility tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Scoped trace, clean up callbacks Created 5 years, 8 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
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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 #include "content/public/browser/permission_type.h" 57 #include "content/public/browser/permission_type.h"
58 #include "content/public/browser/render_process_host.h" 58 #include "content/public/browser/render_process_host.h"
59 #include "content/public/browser/render_widget_host_view.h" 59 #include "content/public/browser/render_widget_host_view.h"
60 #include "content/public/browser/stream_handle.h" 60 #include "content/public/browser/stream_handle.h"
61 #include "content/public/browser/user_metrics.h" 61 #include "content/public/browser/user_metrics.h"
62 #include "content/public/common/content_constants.h" 62 #include "content/public/common/content_constants.h"
63 #include "content/public/common/content_switches.h" 63 #include "content/public/common/content_switches.h"
64 #include "content/public/common/url_constants.h" 64 #include "content/public/common/url_constants.h"
65 #include "content/public/common/url_utils.h" 65 #include "content/public/common/url_utils.h"
66 #include "ui/accessibility/ax_tree.h" 66 #include "ui/accessibility/ax_tree.h"
67 #include "ui/accessibility/ax_tree_update.h"
67 #include "url/gurl.h" 68 #include "url/gurl.h"
68 69
69 #if defined(OS_MACOSX) 70 #if defined(OS_MACOSX)
70 #include "content/browser/frame_host/popup_menu_helper_mac.h" 71 #include "content/browser/frame_host/popup_menu_helper_mac.h"
71 #endif 72 #endif
72 73
73 #if defined(ENABLE_MEDIA_MOJO_RENDERER) 74 #if defined(ENABLE_MEDIA_MOJO_RENDERER)
74 #include "media/mojo/interfaces/media_renderer.mojom.h" 75 #include "media/mojo/interfaces/media_renderer.mojom.h"
75 #include "media/mojo/services/mojo_renderer_service.h" 76 #include "media/mojo/services/mojo_renderer_service.h"
76 #endif 77 #endif
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, 375 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation,
375 OnBeginNavigation) 376 OnBeginNavigation)
376 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) 377 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad)
377 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, 378 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse,
378 OnTextSurroundingSelectionResponse) 379 OnTextSurroundingSelectionResponse)
379 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) 380 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents)
380 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, 381 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges,
381 OnAccessibilityLocationChanges) 382 OnAccessibilityLocationChanges)
382 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_FindInPageResult, 383 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_FindInPageResult,
383 OnAccessibilityFindInPageResult) 384 OnAccessibilityFindInPageResult)
385 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_SnapshotResponse,
386 OnAccessibilitySnapshotResponse)
384 IPC_MESSAGE_HANDLER(FrameHostMsg_ToggleFullscreen, OnToggleFullscreen) 387 IPC_MESSAGE_HANDLER(FrameHostMsg_ToggleFullscreen, OnToggleFullscreen)
385 // The following message is synthetic and doesn't come from RenderFrame, but 388 // The following message is synthetic and doesn't come from RenderFrame, but
386 // from RenderProcessHost. 389 // from RenderProcessHost.
387 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone) 390 IPC_MESSAGE_HANDLER(FrameHostMsg_RenderProcessGone, OnRenderProcessGone)
388 #if defined(OS_MACOSX) || defined(OS_ANDROID) 391 #if defined(OS_MACOSX) || defined(OS_ANDROID)
389 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup) 392 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup)
390 IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup, OnHidePopup) 393 IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup, OnHidePopup)
391 #endif 394 #endif
392 IPC_END_MESSAGE_MAP() 395 IPC_END_MESSAGE_MAP()
393 396
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 1074
1072 if (frame_tree_node_->IsMainFrame()) { 1075 if (frame_tree_node_->IsMainFrame()) {
1073 // RenderViewHost/RenderWidgetHost needs to reset some stuff. 1076 // RenderViewHost/RenderWidgetHost needs to reset some stuff.
1074 render_view_host_->RendererExited( 1077 render_view_host_->RendererExited(
1075 render_view_host_->render_view_termination_status_, exit_code); 1078 render_view_host_->render_view_termination_status_, exit_code);
1076 1079
1077 render_view_host_->delegate_->RenderViewTerminated( 1080 render_view_host_->delegate_->RenderViewTerminated(
1078 render_view_host_, static_cast<base::TerminationStatus>(status), 1081 render_view_host_, static_cast<base::TerminationStatus>(status),
1079 exit_code); 1082 exit_code);
1080 } 1083 }
1084
1085 // Execute any pending AX tree snapshot callbacks with an empty response,
1086 // since we're never going to get a response from this renderer.
1087 for (auto iter = ax_tree_snapshot_callbacks_.begin();
1088 iter != ax_tree_snapshot_callbacks_.end();
1089 ++iter) {
1090 iter->second.Run(ui::AXTreeUpdate());
Charlie Reis 2015/04/10 20:18:07 Sanity check: we've seen security bugs in the past
dmazzoni 2015/04/10 21:57:12 Not unless the caller binds the callback to an Unr
Charlie Reis 2015/04/10 22:15:46 I'll have to take your word for it; ScopedJavaGlob
1091 }
1092 ax_tree_snapshot_callbacks_.clear();
1081 } 1093 }
1082 1094
1083 void RenderFrameHostImpl::OnSwappedOut() { 1095 void RenderFrameHostImpl::OnSwappedOut() {
1084 // Ignore spurious swap out ack. 1096 // Ignore spurious swap out ack.
1085 if (rfh_state_ != STATE_PENDING_SWAP_OUT) 1097 if (rfh_state_ != STATE_PENDING_SWAP_OUT)
1086 return; 1098 return;
1087 1099
1088 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this); 1100 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this);
1089 swapout_event_monitor_timeout_->Stop(); 1101 swapout_event_monitor_timeout_->Stop();
1090 1102
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 BrowserAccessibilityManager* manager = 1397 BrowserAccessibilityManager* manager =
1386 GetOrCreateBrowserAccessibilityManager(); 1398 GetOrCreateBrowserAccessibilityManager();
1387 if (manager) { 1399 if (manager) {
1388 manager->OnFindInPageResult( 1400 manager->OnFindInPageResult(
1389 params.request_id, params.match_index, params.start_id, 1401 params.request_id, params.match_index, params.start_id,
1390 params.start_offset, params.end_id, params.end_offset); 1402 params.start_offset, params.end_id, params.end_offset);
1391 } 1403 }
1392 } 1404 }
1393 } 1405 }
1394 1406
1407 void RenderFrameHostImpl::OnAccessibilitySnapshotResponse(
1408 int request_id,
Charlie Reis 2015/04/10 20:18:07 Actually, let's call this callback_id (throughout
dmazzoni 2015/04/10 21:57:12 Done.
1409 const ui::AXTreeUpdate& snapshot) {
1410 std::map<int, AXTreeSnapshotCallback>::iterator it =
1411 ax_tree_snapshot_callbacks_.find(request_id);
1412 if (it != ax_tree_snapshot_callbacks_.end()) {
1413 it->second.Run(snapshot);
1414 ax_tree_snapshot_callbacks_.erase(it);
1415 } else {
1416 NOTREACHED() << "Received AX tree snapshot response for unknown request";
1417 }
1418 }
1419
1395 void RenderFrameHostImpl::OnToggleFullscreen(bool enter_fullscreen) { 1420 void RenderFrameHostImpl::OnToggleFullscreen(bool enter_fullscreen) {
1396 if (enter_fullscreen) 1421 if (enter_fullscreen)
1397 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin()); 1422 delegate_->EnterFullscreenMode(GetLastCommittedURL().GetOrigin());
1398 else 1423 else
1399 delegate_->ExitFullscreenMode(); 1424 delegate_->ExitFullscreenMode();
1400 1425
1401 // The previous call might change the fullscreen state. We need to make sure 1426 // The previous call might change the fullscreen state. We need to make sure
1402 // the renderer is aware of that, which is done via the resize message. 1427 // the renderer is aware of that, which is done via the resize message.
1403 render_view_host_->WasResized(); 1428 render_view_host_->WasResized();
1404 } 1429 }
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 // As a sanity check, make sure the frame belongs to the same BrowserContext. 1823 // As a sanity check, make sure the frame belongs to the same BrowserContext.
1799 CHECK_EQ(GetSiteInstance()->GetBrowserContext(), 1824 CHECK_EQ(GetSiteInstance()->GetBrowserContext(),
1800 other_render_frame_host->GetSiteInstance()->GetBrowserContext()); 1825 other_render_frame_host->GetSiteInstance()->GetBrowserContext());
1801 return GetSiteInstance() == other_render_frame_host->GetSiteInstance(); 1826 return GetSiteInstance() == other_render_frame_host->GetSiteInstance();
1802 } 1827 }
1803 1828
1804 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) { 1829 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) {
1805 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode)); 1830 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode));
1806 } 1831 }
1807 1832
1833 void RenderFrameHostImpl::RequestAXTreeSnapshot(
1834 AXTreeSnapshotCallback callback) {
1835 static int next_id = 1;
1836 int id = next_id++;
1837 Send(new AccessibilityMsg_SnapshotTree(routing_id_, id));
1838 ax_tree_snapshot_callbacks_.insert(std::make_pair(id, callback));
1839 }
1840
1808 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting( 1841 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting(
1809 const base::Callback<void(ui::AXEvent, int)>& callback) { 1842 const base::Callback<void(ui::AXEvent, int)>& callback) {
1810 accessibility_testing_callback_ = callback; 1843 accessibility_testing_callback_ = callback;
1811 } 1844 }
1812 1845
1813 void RenderFrameHostImpl::SetTextTrackSettings( 1846 void RenderFrameHostImpl::SetTextTrackSettings(
1814 const FrameMsg_TextTrackSettings_Params& params) { 1847 const FrameMsg_TextTrackSettings_Params& params) {
1815 DCHECK(!GetParent()); 1848 DCHECK(!GetParent());
1816 Send(new FrameMsg_SetTextTrackSettings(routing_id_, params)); 1849 Send(new FrameMsg_SetTextTrackSettings(routing_id_, params));
1817 } 1850 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 return; 1988 return;
1956 1989
1957 permission_manager->RegisterPermissionUsage( 1990 permission_manager->RegisterPermissionUsage(
1958 PermissionType::GEOLOCATION, 1991 PermissionType::GEOLOCATION,
1959 GetLastCommittedURL().GetOrigin(), 1992 GetLastCommittedURL().GetOrigin(),
1960 frame_tree_node()->frame_tree()->GetMainFrame() 1993 frame_tree_node()->frame_tree()->GetMainFrame()
1961 ->GetLastCommittedURL().GetOrigin()); 1994 ->GetLastCommittedURL().GetOrigin());
1962 } 1995 }
1963 1996
1964 } // namespace content 1997 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698