| 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/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" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/metrics/user_metrics_action.h" | 12 #include "base/metrics/user_metrics_action.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "content/browser/accessibility/accessibility_mode_helper.h" | 14 #include "content/browser/accessibility/accessibility_mode_helper.h" |
| 15 #include "content/browser/accessibility/browser_accessibility_manager.h" | 15 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 16 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 16 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 17 #include "content/browser/child_process_security_policy_impl.h" | 17 #include "content/browser/child_process_security_policy_impl.h" |
| 18 #include "content/browser/frame_host/cross_process_frame_connector.h" | 18 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 19 #include "content/browser/frame_host/cross_site_transferring_request.h" | 19 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| 20 #include "content/browser/frame_host/frame_accessibility.h" |
| 20 #include "content/browser/frame_host/frame_tree.h" | 21 #include "content/browser/frame_host/frame_tree.h" |
| 21 #include "content/browser/frame_host/frame_tree_node.h" | 22 #include "content/browser/frame_host/frame_tree_node.h" |
| 22 #include "content/browser/frame_host/navigator.h" | 23 #include "content/browser/frame_host/navigator.h" |
| 23 #include "content/browser/frame_host/render_frame_host_delegate.h" | 24 #include "content/browser/frame_host/render_frame_host_delegate.h" |
| 24 #include "content/browser/frame_host/render_frame_proxy_host.h" | 25 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 25 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 26 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 26 #include "content/browser/renderer_host/input/input_router.h" | 27 #include "content/browser/renderer_host/input/input_router.h" |
| 27 #include "content/browser/renderer_host/input/timeout_monitor.h" | 28 #include "content/browser/renderer_host/input/timeout_monitor.h" |
| 28 #include "content/browser/renderer_host/render_process_host_impl.h" | 29 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 29 #include "content/browser/renderer_host/render_view_host_delegate.h" | 30 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 30 #include "content/browser/renderer_host/render_view_host_delegate_view.h" | 31 #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
| 31 #include "content/browser/renderer_host/render_view_host_impl.h" | 32 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 32 #include "content/browser/renderer_host/render_widget_host_impl.h" | 33 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 33 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 34 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 34 #include "content/browser/transition_request_manager.h" | 35 #include "content/browser/transition_request_manager.h" |
| 35 #include "content/common/accessibility_messages.h" | 36 #include "content/common/accessibility_messages.h" |
| 36 #include "content/common/desktop_notification_messages.h" | 37 #include "content/common/desktop_notification_messages.h" |
| 37 #include "content/common/frame_messages.h" | 38 #include "content/common/frame_messages.h" |
| 38 #include "content/common/input_messages.h" | 39 #include "content/common/input_messages.h" |
| 39 #include "content/common/inter_process_time_ticks_converter.h" | 40 #include "content/common/inter_process_time_ticks_converter.h" |
| 40 #include "content/common/platform_notification_messages.h" | 41 #include "content/common/platform_notification_messages.h" |
| 41 #include "content/common/render_frame_setup.mojom.h" | 42 #include "content/common/render_frame_setup.mojom.h" |
| 42 #include "content/common/swapped_out_messages.h" | 43 #include "content/common/swapped_out_messages.h" |
| 43 #include "content/public/browser/ax_event_notification_details.h" | 44 #include "content/public/browser/ax_event_notification_details.h" |
| 44 #include "content/public/browser/browser_accessibility_state.h" | 45 #include "content/public/browser/browser_accessibility_state.h" |
| 46 #include "content/public/browser/browser_context.h" |
| 47 #include "content/public/browser/browser_plugin_guest_manager.h" |
| 45 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
| 46 #include "content/public/browser/content_browser_client.h" | 49 #include "content/public/browser/content_browser_client.h" |
| 47 #include "content/public/browser/desktop_notification_delegate.h" | 50 #include "content/public/browser/desktop_notification_delegate.h" |
| 48 #include "content/public/browser/render_process_host.h" | 51 #include "content/public/browser/render_process_host.h" |
| 49 #include "content/public/browser/render_widget_host_view.h" | 52 #include "content/public/browser/render_widget_host_view.h" |
| 50 #include "content/public/browser/user_metrics.h" | 53 #include "content/public/browser/user_metrics.h" |
| 51 #include "content/public/common/content_constants.h" | 54 #include "content/public/common/content_constants.h" |
| 52 #include "content/public/common/content_switches.h" | 55 #include "content/public/common/content_switches.h" |
| 53 #include "content/public/common/url_constants.h" | 56 #include "content/public/common/url_constants.h" |
| 54 #include "content/public/common/url_utils.h" | 57 #include "content/public/common/url_utils.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 199 } |
| 197 | 200 |
| 198 RenderFrameHostImpl::~RenderFrameHostImpl() { | 201 RenderFrameHostImpl::~RenderFrameHostImpl() { |
| 199 GetProcess()->RemoveRoute(routing_id_); | 202 GetProcess()->RemoveRoute(routing_id_); |
| 200 g_routing_id_frame_map.Get().erase( | 203 g_routing_id_frame_map.Get().erase( |
| 201 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); | 204 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
| 202 | 205 |
| 203 if (delegate_) | 206 if (delegate_) |
| 204 delegate_->RenderFrameDeleted(this); | 207 delegate_->RenderFrameDeleted(this); |
| 205 | 208 |
| 209 FrameAccessibility::GetInstance()->OnRenderFrameHostDestroyed(this); |
| 210 |
| 206 // Notify the FrameTree that this RFH is going away, allowing it to shut down | 211 // Notify the FrameTree that this RFH is going away, allowing it to shut down |
| 207 // the corresponding RenderViewHost if it is no longer needed. | 212 // the corresponding RenderViewHost if it is no longer needed. |
| 208 frame_tree_->UnregisterRenderFrameHost(this); | 213 frame_tree_->UnregisterRenderFrameHost(this); |
| 209 } | 214 } |
| 210 | 215 |
| 211 int RenderFrameHostImpl::GetRoutingID() { | 216 int RenderFrameHostImpl::GetRoutingID() { |
| 212 return routing_id_; | 217 return routing_id_; |
| 213 } | 218 } |
| 214 | 219 |
| 215 SiteInstance* RenderFrameHostImpl::GetSiteInstance() { | 220 SiteInstance* RenderFrameHostImpl::GetSiteInstance() { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 gfx::NativeViewAccessible | 471 gfx::NativeViewAccessible |
| 467 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() { | 472 RenderFrameHostImpl::AccessibilityGetNativeViewAccessible() { |
| 468 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | 473 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 469 render_view_host_->GetView()); | 474 render_view_host_->GetView()); |
| 470 if (view) | 475 if (view) |
| 471 return view->AccessibilityGetNativeViewAccessible(); | 476 return view->AccessibilityGetNativeViewAccessible(); |
| 472 return NULL; | 477 return NULL; |
| 473 } | 478 } |
| 474 | 479 |
| 475 BrowserAccessibilityManager* RenderFrameHostImpl::AccessibilityGetChildFrame( | 480 BrowserAccessibilityManager* RenderFrameHostImpl::AccessibilityGetChildFrame( |
| 476 int64 frame_tree_node_id) { | 481 int accessibility_node_id) { |
| 477 FrameTreeNode* child_node = FrameTree::GloballyFindByID(frame_tree_node_id); | 482 RenderFrameHostImpl* child_frame = |
| 478 if (!child_node) | 483 FrameAccessibility::GetInstance()->GetChild(this, accessibility_node_id); |
| 484 if (!child_frame) |
| 479 return NULL; | 485 return NULL; |
| 480 | 486 |
| 481 // We should have gotten a node in the same frame tree. | |
| 482 CHECK(child_node->frame_tree() == frame_tree_node()->frame_tree()); | |
| 483 | |
| 484 RenderFrameHostImpl* child_rfhi = child_node->current_frame_host(); | |
| 485 | |
| 486 // Return NULL if this isn't an out-of-process iframe. Same-process iframes | 487 // Return NULL if this isn't an out-of-process iframe. Same-process iframes |
| 487 // are already part of the accessibility tree. | 488 // are already part of the accessibility tree. |
| 488 if (child_rfhi->GetProcess()->GetID() == GetProcess()->GetID()) | 489 if (child_frame->GetProcess()->GetID() == GetProcess()->GetID()) |
| 489 return NULL; | 490 return NULL; |
| 490 | 491 |
| 491 return child_rfhi->GetOrCreateBrowserAccessibilityManager(); | 492 // As a sanity check, make sure the frame we're going to return belongs |
| 493 // to the same BrowserContext. |
| 494 if (GetSiteInstance()->GetBrowserContext() != |
| 495 child_frame->GetSiteInstance()->GetBrowserContext()) { |
| 496 NOTREACHED(); |
| 497 return NULL; |
| 498 } |
| 499 |
| 500 return child_frame->GetOrCreateBrowserAccessibilityManager(); |
| 492 } | 501 } |
| 493 | 502 |
| 494 BrowserAccessibilityManager* | 503 BrowserAccessibility* RenderFrameHostImpl::AccessibilityGetParentFrame() { |
| 495 RenderFrameHostImpl::AccessibilityGetParentFrame() { | 504 RenderFrameHostImpl* parent_frame = NULL; |
| 496 FrameTreeNode* parent_node = frame_tree_node()->parent(); | 505 int parent_node_id = 0; |
| 497 if (!parent_node) | 506 if (!FrameAccessibility::GetInstance()->GetParent( |
| 507 this, &parent_frame, &parent_node_id)) { |
| 508 return NULL; |
| 509 } |
| 510 |
| 511 // As a sanity check, make sure the frame we're going to return belongs |
| 512 // to the same BrowserContext. |
| 513 if (GetSiteInstance()->GetBrowserContext() != |
| 514 parent_frame->GetSiteInstance()->GetBrowserContext()) { |
| 515 NOTREACHED(); |
| 516 return NULL; |
| 517 } |
| 518 |
| 519 BrowserAccessibilityManager* manager = |
| 520 parent_frame->browser_accessibility_manager(); |
| 521 if (!manager) |
| 498 return NULL; | 522 return NULL; |
| 499 | 523 |
| 500 RenderFrameHostImpl* parent_frame = parent_node->current_frame_host(); | 524 return manager->GetFromID(parent_node_id); |
| 501 if (!parent_frame) | |
| 502 return NULL; | |
| 503 | |
| 504 return parent_frame->GetOrCreateBrowserAccessibilityManager(); | |
| 505 } | 525 } |
| 506 | 526 |
| 507 bool RenderFrameHostImpl::CreateRenderFrame(int parent_routing_id) { | 527 bool RenderFrameHostImpl::CreateRenderFrame(int parent_routing_id) { |
| 508 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame"); | 528 TRACE_EVENT0("navigation", "RenderFrameHostImpl::CreateRenderFrame"); |
| 509 DCHECK(!IsRenderFrameLive()) << "Creating frame twice"; | 529 DCHECK(!IsRenderFrameLive()) << "Creating frame twice"; |
| 510 | 530 |
| 511 // The process may (if we're sharing a process with another host that already | 531 // The process may (if we're sharing a process with another host that already |
| 512 // initialized it) or may not (we have our own process or the old process | 532 // initialized it) or may not (we have our own process or the old process |
| 513 // crashed) have been initialized. Calling Init multiple times will be | 533 // crashed) have been initialized. Calling Init multiple times will be |
| 514 // ignored, so this is safe. | 534 // ignored, so this is safe. |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode(); | 1025 AccessibilityMode accessibility_mode = delegate_->GetAccessibilityMode(); |
| 1006 if ((accessibility_mode != AccessibilityModeOff) && view && | 1026 if ((accessibility_mode != AccessibilityModeOff) && view && |
| 1007 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) { | 1027 RenderViewHostImpl::IsRVHStateActive(render_view_host_->rvh_state())) { |
| 1008 if (accessibility_mode & AccessibilityModeFlagPlatform) { | 1028 if (accessibility_mode & AccessibilityModeFlagPlatform) { |
| 1009 GetOrCreateBrowserAccessibilityManager(); | 1029 GetOrCreateBrowserAccessibilityManager(); |
| 1010 if (browser_accessibility_manager_) | 1030 if (browser_accessibility_manager_) |
| 1011 browser_accessibility_manager_->OnAccessibilityEvents(params); | 1031 browser_accessibility_manager_->OnAccessibilityEvents(params); |
| 1012 } | 1032 } |
| 1013 | 1033 |
| 1014 if (browser_accessibility_manager_) { | 1034 if (browser_accessibility_manager_) { |
| 1015 // Get the frame routing ids from out-of-process iframes and use them | 1035 // Get the frame routing ids from out-of-process iframes and |
| 1016 // to notify our BrowserAccessibilityManager of the frame tree node id of | 1036 // browser plugin instance ids from guests and update the mappings in |
| 1017 // any of its child frames. | 1037 // FrameAccessibility. |
| 1018 for (unsigned int i = 0; i < params.size(); ++i) { | 1038 for (unsigned int i = 0; i < params.size(); ++i) { |
| 1019 const AccessibilityHostMsg_EventParams& param = params[i]; | 1039 const AccessibilityHostMsg_EventParams& param = params[i]; |
| 1020 std::map<int32, int>::const_iterator iter; | 1040 UpdateCrossProcessIframeAccessibility( |
| 1021 for (iter = param.node_to_frame_routing_id_map.begin(); | 1041 param.node_to_frame_routing_id_map); |
| 1022 iter != param.node_to_frame_routing_id_map.end(); | 1042 UpdateGuestFrameAccessibility( |
| 1023 ++iter) { | 1043 param.node_to_browser_plugin_instance_id_map); |
| 1024 // This is the id of the accessibility node that has a child frame. | |
| 1025 int32 node_id = iter->first; | |
| 1026 // The routing id from either a RenderFrame or a RenderFrameProxy. | |
| 1027 int frame_routing_id = iter->second; | |
| 1028 | |
| 1029 FrameTree* frame_tree = frame_tree_node()->frame_tree(); | |
| 1030 FrameTreeNode* child_frame_tree_node = frame_tree->FindByRoutingID( | |
| 1031 GetProcess()->GetID(), frame_routing_id); | |
| 1032 if (child_frame_tree_node) { | |
| 1033 browser_accessibility_manager_->SetChildFrameTreeNodeId( | |
| 1034 node_id, child_frame_tree_node->frame_tree_node_id()); | |
| 1035 } | |
| 1036 } | |
| 1037 } | 1044 } |
| 1038 } | 1045 } |
| 1039 | 1046 |
| 1040 // Send the updates to the automation extension API. | 1047 // Send the updates to the automation extension API. |
| 1041 std::vector<AXEventNotificationDetails> details; | 1048 std::vector<AXEventNotificationDetails> details; |
| 1042 details.reserve(params.size()); | 1049 details.reserve(params.size()); |
| 1043 for (size_t i = 0; i < params.size(); ++i) { | 1050 for (size_t i = 0; i < params.size(); ++i) { |
| 1044 const AccessibilityHostMsg_EventParams& param = params[i]; | 1051 const AccessibilityHostMsg_EventParams& param = params[i]; |
| 1045 AXEventNotificationDetails detail(param.update.node_id_to_clear, | 1052 AXEventNotificationDetails detail(param.update.node_id_to_clear, |
| 1046 param.update.nodes, | 1053 param.update.nodes, |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 void RenderFrameHostImpl::NotificationClosed(int notification_id) { | 1304 void RenderFrameHostImpl::NotificationClosed(int notification_id) { |
| 1298 cancel_notification_callbacks_.erase(notification_id); | 1305 cancel_notification_callbacks_.erase(notification_id); |
| 1299 } | 1306 } |
| 1300 | 1307 |
| 1301 void RenderFrameHostImpl::PlatformNotificationPermissionRequestDone( | 1308 void RenderFrameHostImpl::PlatformNotificationPermissionRequestDone( |
| 1302 int request_id, blink::WebNotificationPermission permission) { | 1309 int request_id, blink::WebNotificationPermission permission) { |
| 1303 Send(new PlatformNotificationMsg_PermissionRequestComplete( | 1310 Send(new PlatformNotificationMsg_PermissionRequestComplete( |
| 1304 routing_id_, request_id, permission)); | 1311 routing_id_, request_id, permission)); |
| 1305 } | 1312 } |
| 1306 | 1313 |
| 1314 void RenderFrameHostImpl::UpdateCrossProcessIframeAccessibility( |
| 1315 const std::map<int32, int> node_to_frame_routing_id_map) { |
| 1316 std::map<int32, int>::const_iterator iter; |
| 1317 for (iter = node_to_frame_routing_id_map.begin(); |
| 1318 iter != node_to_frame_routing_id_map.end(); |
| 1319 ++iter) { |
| 1320 // This is the id of the accessibility node that has a child frame. |
| 1321 int32 node_id = iter->first; |
| 1322 // The routing id from either a RenderFrame or a RenderFrameProxy. |
| 1323 int frame_routing_id = iter->second; |
| 1324 |
| 1325 FrameTree* frame_tree = frame_tree_node()->frame_tree(); |
| 1326 FrameTreeNode* child_frame_tree_node = frame_tree->FindByRoutingID( |
| 1327 GetProcess()->GetID(), frame_routing_id); |
| 1328 if (child_frame_tree_node) { |
| 1329 FrameAccessibility::GetInstance()->AddChildFrame( |
| 1330 this, node_id, child_frame_tree_node->frame_tree_node_id()); |
| 1331 } |
| 1332 } |
| 1333 } |
| 1334 |
| 1335 void RenderFrameHostImpl::UpdateGuestFrameAccessibility( |
| 1336 const std::map<int32, int> node_to_browser_plugin_instance_id_map) { |
| 1337 std::map<int32, int>::const_iterator iter; |
| 1338 for (iter = node_to_browser_plugin_instance_id_map.begin(); |
| 1339 iter != node_to_browser_plugin_instance_id_map.end(); |
| 1340 ++iter) { |
| 1341 // This is the id of the accessibility node that hosts a plugin. |
| 1342 int32 node_id = iter->first; |
| 1343 // The id of the browser plugin. |
| 1344 int browser_plugin_instance_id = iter->second; |
| 1345 FrameAccessibility::GetInstance()->AddGuestWebContents( |
| 1346 this, node_id, browser_plugin_instance_id); |
| 1347 } |
| 1348 } |
| 1349 |
| 1307 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) { | 1350 void RenderFrameHostImpl::SetAccessibilityMode(AccessibilityMode mode) { |
| 1308 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode)); | 1351 Send(new FrameMsg_SetAccessibilityMode(routing_id_, mode)); |
| 1309 } | 1352 } |
| 1310 | 1353 |
| 1311 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting( | 1354 void RenderFrameHostImpl::SetAccessibilityCallbackForTesting( |
| 1312 const base::Callback<void(ui::AXEvent, int)>& callback) { | 1355 const base::Callback<void(ui::AXEvent, int)>& callback) { |
| 1313 accessibility_testing_callback_ = callback; | 1356 accessibility_testing_callback_ = callback; |
| 1314 } | 1357 } |
| 1315 | 1358 |
| 1316 const ui::AXTree* RenderFrameHostImpl::GetAXTreeForTesting() { | 1359 const ui::AXTree* RenderFrameHostImpl::GetAXTreeForTesting() { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 // Clear any state if a pending navigation is canceled or preempted. | 1454 // Clear any state if a pending navigation is canceled or preempted. |
| 1412 if (suspended_nav_params_) | 1455 if (suspended_nav_params_) |
| 1413 suspended_nav_params_.reset(); | 1456 suspended_nav_params_.reset(); |
| 1414 | 1457 |
| 1415 TRACE_EVENT_ASYNC_END0("navigation", | 1458 TRACE_EVENT_ASYNC_END0("navigation", |
| 1416 "RenderFrameHostImpl navigation suspended", this); | 1459 "RenderFrameHostImpl navigation suspended", this); |
| 1417 navigations_suspended_ = false; | 1460 navigations_suspended_ = false; |
| 1418 } | 1461 } |
| 1419 | 1462 |
| 1420 } // namespace content | 1463 } // namespace content |
| OLD | NEW |