| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 // WebView). | 158 // WebView). |
| 159 bool g_allow_injecting_javascript = false; | 159 bool g_allow_injecting_javascript = false; |
| 160 | 160 |
| 161 // The (process id, routing id) pair that identifies one RenderFrame. | 161 // The (process id, routing id) pair that identifies one RenderFrame. |
| 162 typedef std::pair<int32_t, int32_t> RenderFrameHostID; | 162 typedef std::pair<int32_t, int32_t> RenderFrameHostID; |
| 163 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> | 163 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> |
| 164 RoutingIDFrameMap; | 164 RoutingIDFrameMap; |
| 165 base::LazyInstance<RoutingIDFrameMap>::DestructorAtExit g_routing_id_frame_map = | 165 base::LazyInstance<RoutingIDFrameMap>::DestructorAtExit g_routing_id_frame_map = |
| 166 LAZY_INSTANCE_INITIALIZER; | 166 LAZY_INSTANCE_INITIALIZER; |
| 167 | 167 |
| 168 using TokenFrameMap = base::hash_map<base::UnguessableToken, |
| 169 RenderFrameHostImpl*, |
| 170 base::UnguessableTokenHash>; |
| 171 base::LazyInstance<TokenFrameMap>::Leaky g_token_frame_map = |
| 172 LAZY_INSTANCE_INITIALIZER; |
| 173 |
| 168 // Translate a WebKit text direction into a base::i18n one. | 174 // Translate a WebKit text direction into a base::i18n one. |
| 169 base::i18n::TextDirection WebTextDirectionToChromeTextDirection( | 175 base::i18n::TextDirection WebTextDirectionToChromeTextDirection( |
| 170 blink::WebTextDirection dir) { | 176 blink::WebTextDirection dir) { |
| 171 switch (dir) { | 177 switch (dir) { |
| 172 case blink::kWebTextDirectionLeftToRight: | 178 case blink::kWebTextDirectionLeftToRight: |
| 173 return base::i18n::LEFT_TO_RIGHT; | 179 return base::i18n::LEFT_TO_RIGHT; |
| 174 case blink::kWebTextDirectionRightToLeft: | 180 case blink::kWebTextDirectionRightToLeft: |
| 175 return base::i18n::RIGHT_TO_LEFT; | 181 return base::i18n::RIGHT_TO_LEFT; |
| 176 default: | 182 default: |
| 177 NOTREACHED(); | 183 NOTREACHED(); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 359 |
| 354 // static | 360 // static |
| 355 RenderFrameHostImpl* RenderFrameHostImpl::FromAXTreeID( | 361 RenderFrameHostImpl* RenderFrameHostImpl::FromAXTreeID( |
| 356 ui::AXTreeIDRegistry::AXTreeID ax_tree_id) { | 362 ui::AXTreeIDRegistry::AXTreeID ax_tree_id) { |
| 357 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 363 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 358 ui::AXTreeIDRegistry::FrameID frame_id = | 364 ui::AXTreeIDRegistry::FrameID frame_id = |
| 359 ui::AXTreeIDRegistry::GetInstance()->GetFrameID(ax_tree_id); | 365 ui::AXTreeIDRegistry::GetInstance()->GetFrameID(ax_tree_id); |
| 360 return RenderFrameHostImpl::FromID(frame_id.first, frame_id.second); | 366 return RenderFrameHostImpl::FromID(frame_id.first, frame_id.second); |
| 361 } | 367 } |
| 362 | 368 |
| 369 // static |
| 370 RenderFrameHostImpl* RenderFrameHostImpl::FromOverlayRoutingToken( |
| 371 const base::UnguessableToken& token) { |
| 372 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 373 auto it = g_token_frame_map.Get().find(token); |
| 374 return it == g_token_frame_map.Get().end() ? nullptr : it->second; |
| 375 } |
| 376 |
| 363 RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance, | 377 RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance, |
| 364 RenderViewHostImpl* render_view_host, | 378 RenderViewHostImpl* render_view_host, |
| 365 RenderFrameHostDelegate* delegate, | 379 RenderFrameHostDelegate* delegate, |
| 366 RenderWidgetHostDelegate* rwh_delegate, | 380 RenderWidgetHostDelegate* rwh_delegate, |
| 367 FrameTree* frame_tree, | 381 FrameTree* frame_tree, |
| 368 FrameTreeNode* frame_tree_node, | 382 FrameTreeNode* frame_tree_node, |
| 369 int32_t routing_id, | 383 int32_t routing_id, |
| 370 int32_t widget_routing_id, | 384 int32_t widget_routing_id, |
| 371 bool hidden, | 385 bool hidden, |
| 372 bool renderer_initiated_creation) | 386 bool renderer_initiated_creation) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 // so we do it early while |this| object is still in a sane state. | 472 // so we do it early while |this| object is still in a sane state. |
| 459 navigation_handle_.reset(); | 473 navigation_handle_.reset(); |
| 460 | 474 |
| 461 // Release the WebUI instances before all else as the WebUI may accesses the | 475 // Release the WebUI instances before all else as the WebUI may accesses the |
| 462 // RenderFrameHost during cleanup. | 476 // RenderFrameHost during cleanup. |
| 463 ClearAllWebUI(); | 477 ClearAllWebUI(); |
| 464 | 478 |
| 465 GetProcess()->RemoveRoute(routing_id_); | 479 GetProcess()->RemoveRoute(routing_id_); |
| 466 g_routing_id_frame_map.Get().erase( | 480 g_routing_id_frame_map.Get().erase( |
| 467 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); | 481 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
| 482 |
| 483 if (overlay_routing_token_) |
| 484 g_token_frame_map.Get().erase(*overlay_routing_token_); |
| 485 |
| 468 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 486 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 469 base::Bind(&NotifyRenderFrameDetachedOnIO, | 487 base::Bind(&NotifyRenderFrameDetachedOnIO, |
| 470 GetProcess()->GetID(), routing_id_)); | 488 GetProcess()->GetID(), routing_id_)); |
| 471 | 489 |
| 472 site_instance_->RemoveObserver(this); | 490 site_instance_->RemoveObserver(this); |
| 473 | 491 |
| 474 if (delegate_ && render_frame_created_) | 492 if (delegate_ && render_frame_created_) |
| 475 delegate_->RenderFrameDeleted(this); | 493 delegate_->RenderFrameDeleted(this); |
| 476 | 494 |
| 477 // If this was the last active frame in the SiteInstance, the | 495 // If this was the last active frame in the SiteInstance, the |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 | 529 |
| 512 int RenderFrameHostImpl::GetRoutingID() { | 530 int RenderFrameHostImpl::GetRoutingID() { |
| 513 return routing_id_; | 531 return routing_id_; |
| 514 } | 532 } |
| 515 | 533 |
| 516 ui::AXTreeIDRegistry::AXTreeID RenderFrameHostImpl::GetAXTreeID() { | 534 ui::AXTreeIDRegistry::AXTreeID RenderFrameHostImpl::GetAXTreeID() { |
| 517 return ui::AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID( | 535 return ui::AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID( |
| 518 GetProcess()->GetID(), routing_id_); | 536 GetProcess()->GetID(), routing_id_); |
| 519 } | 537 } |
| 520 | 538 |
| 539 const base::UnguessableToken& RenderFrameHostImpl::GetOverlayRoutingToken() { |
| 540 if (!overlay_routing_token_) { |
| 541 overlay_routing_token_ = base::UnguessableToken::Create(); |
| 542 g_token_frame_map.Get().emplace(*overlay_routing_token_, this); |
| 543 } |
| 544 |
| 545 return *overlay_routing_token_; |
| 546 } |
| 547 |
| 521 SiteInstanceImpl* RenderFrameHostImpl::GetSiteInstance() { | 548 SiteInstanceImpl* RenderFrameHostImpl::GetSiteInstance() { |
| 522 return site_instance_.get(); | 549 return site_instance_.get(); |
| 523 } | 550 } |
| 524 | 551 |
| 525 RenderProcessHost* RenderFrameHostImpl::GetProcess() { | 552 RenderProcessHost* RenderFrameHostImpl::GetProcess() { |
| 526 return process_; | 553 return process_; |
| 527 } | 554 } |
| 528 | 555 |
| 529 RenderFrameHostImpl* RenderFrameHostImpl::GetParent() { | 556 RenderFrameHostImpl* RenderFrameHostImpl::GetParent() { |
| 530 return parent_; | 557 return parent_; |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 IPC_MESSAGE_HANDLER(FrameHostMsg_SetHasReceivedUserGesture, | 842 IPC_MESSAGE_HANDLER(FrameHostMsg_SetHasReceivedUserGesture, |
| 816 OnSetHasReceivedUserGesture) | 843 OnSetHasReceivedUserGesture) |
| 817 #if BUILDFLAG(USE_EXTERNAL_POPUP_MENU) | 844 #if BUILDFLAG(USE_EXTERNAL_POPUP_MENU) |
| 818 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup) | 845 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup) |
| 819 IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup, OnHidePopup) | 846 IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup, OnHidePopup) |
| 820 #endif | 847 #endif |
| 821 #if defined(OS_ANDROID) | 848 #if defined(OS_ANDROID) |
| 822 IPC_MESSAGE_HANDLER(FrameHostMsg_NavigationHandledByEmbedder, | 849 IPC_MESSAGE_HANDLER(FrameHostMsg_NavigationHandledByEmbedder, |
| 823 OnNavigationHandledByEmbedder) | 850 OnNavigationHandledByEmbedder) |
| 824 #endif | 851 #endif |
| 852 IPC_MESSAGE_HANDLER(FrameHostMsg_RequestOverlayRoutingToken, |
| 853 OnRequestOverlayRoutingToken) |
| 825 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowCreatedWindow, OnShowCreatedWindow) | 854 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowCreatedWindow, OnShowCreatedWindow) |
| 826 IPC_END_MESSAGE_MAP() | 855 IPC_END_MESSAGE_MAP() |
| 827 | 856 |
| 828 // No further actions here, since we may have been deleted. | 857 // No further actions here, since we may have been deleted. |
| 829 return handled; | 858 return handled; |
| 830 } | 859 } |
| 831 | 860 |
| 832 void RenderFrameHostImpl::OnAssociatedInterfaceRequest( | 861 void RenderFrameHostImpl::OnAssociatedInterfaceRequest( |
| 833 const std::string& interface_name, | 862 const std::string& interface_name, |
| 834 mojo::ScopedInterfaceEndpointHandle handle) { | 863 mojo::ScopedInterfaceEndpointHandle handle) { |
| (...skipping 1632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2467 | 2496 |
| 2468 #if defined(OS_ANDROID) | 2497 #if defined(OS_ANDROID) |
| 2469 void RenderFrameHostImpl::OnNavigationHandledByEmbedder() { | 2498 void RenderFrameHostImpl::OnNavigationHandledByEmbedder() { |
| 2470 if (navigation_handle_) | 2499 if (navigation_handle_) |
| 2471 navigation_handle_->set_net_error_code(net::ERR_ABORTED); | 2500 navigation_handle_->set_net_error_code(net::ERR_ABORTED); |
| 2472 | 2501 |
| 2473 OnDidStopLoading(); | 2502 OnDidStopLoading(); |
| 2474 } | 2503 } |
| 2475 #endif | 2504 #endif |
| 2476 | 2505 |
| 2506 void RenderFrameHostImpl::OnRequestOverlayRoutingToken() { |
| 2507 // Make sure that we have a token. |
| 2508 GetOverlayRoutingToken(); |
| 2509 |
| 2510 Send(new FrameMsg_SetOverlayRoutingToken(routing_id_, |
| 2511 *overlay_routing_token_)); |
| 2512 } |
| 2513 |
| 2477 void RenderFrameHostImpl::OnShowCreatedWindow(int pending_widget_routing_id, | 2514 void RenderFrameHostImpl::OnShowCreatedWindow(int pending_widget_routing_id, |
| 2478 WindowOpenDisposition disposition, | 2515 WindowOpenDisposition disposition, |
| 2479 const gfx::Rect& initial_rect, | 2516 const gfx::Rect& initial_rect, |
| 2480 bool user_gesture) { | 2517 bool user_gesture) { |
| 2481 delegate_->ShowCreatedWindow(GetProcess()->GetID(), pending_widget_routing_id, | 2518 delegate_->ShowCreatedWindow(GetProcess()->GetID(), pending_widget_routing_id, |
| 2482 disposition, initial_rect, user_gesture); | 2519 disposition, initial_rect, user_gesture); |
| 2483 } | 2520 } |
| 2484 | 2521 |
| 2485 void RenderFrameHostImpl::CreateNewWindow( | 2522 void RenderFrameHostImpl::CreateNewWindow( |
| 2486 mojom::CreateNewWindowParamsPtr params, | 2523 mojom::CreateNewWindowParamsPtr params, |
| (...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3856 } | 3893 } |
| 3857 | 3894 |
| 3858 void RenderFrameHostImpl::ForwardGetInterfaceToRenderFrame( | 3895 void RenderFrameHostImpl::ForwardGetInterfaceToRenderFrame( |
| 3859 const std::string& interface_name, | 3896 const std::string& interface_name, |
| 3860 mojo::ScopedMessagePipeHandle pipe) { | 3897 mojo::ScopedMessagePipeHandle pipe) { |
| 3861 GetRemoteInterfaces()->GetInterface(interface_name, std::move(pipe)); | 3898 GetRemoteInterfaces()->GetInterface(interface_name, std::move(pipe)); |
| 3862 } | 3899 } |
| 3863 #endif | 3900 #endif |
| 3864 | 3901 |
| 3865 } // namespace content | 3902 } // namespace content |
| OLD | NEW |