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

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

Issue 2765443004: AndroidOverlay implementation using Dialog. (Closed)
Patch Set: cl feedback, fixed browsertests Created 3 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
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.h ('k') | content/common/frame_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // WebView). 154 // WebView).
155 bool g_allow_injecting_javascript = false; 155 bool g_allow_injecting_javascript = false;
156 156
157 // The (process id, routing id) pair that identifies one RenderFrame. 157 // The (process id, routing id) pair that identifies one RenderFrame.
158 typedef std::pair<int32_t, int32_t> RenderFrameHostID; 158 typedef std::pair<int32_t, int32_t> RenderFrameHostID;
159 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*> 159 typedef base::hash_map<RenderFrameHostID, RenderFrameHostImpl*>
160 RoutingIDFrameMap; 160 RoutingIDFrameMap;
161 base::LazyInstance<RoutingIDFrameMap>::DestructorAtExit g_routing_id_frame_map = 161 base::LazyInstance<RoutingIDFrameMap>::DestructorAtExit g_routing_id_frame_map =
162 LAZY_INSTANCE_INITIALIZER; 162 LAZY_INSTANCE_INITIALIZER;
163 163
164 #if defined(OS_ANDROID)
165 typedef base::hash_map<base::UnguessableToken,
166 RenderFrameHostImpl*,
167 base::UnguessableTokenHash>
168 TokenFrameMap;
169 base::LazyInstance<TokenFrameMap>::Leaky g_token_frame_map =
170 LAZY_INSTANCE_INITIALIZER;
171 #endif
172
164 // Translate a WebKit text direction into a base::i18n one. 173 // Translate a WebKit text direction into a base::i18n one.
165 base::i18n::TextDirection WebTextDirectionToChromeTextDirection( 174 base::i18n::TextDirection WebTextDirectionToChromeTextDirection(
166 blink::WebTextDirection dir) { 175 blink::WebTextDirection dir) {
167 switch (dir) { 176 switch (dir) {
168 case blink::WebTextDirectionLeftToRight: 177 case blink::WebTextDirectionLeftToRight:
169 return base::i18n::LEFT_TO_RIGHT; 178 return base::i18n::LEFT_TO_RIGHT;
170 case blink::WebTextDirectionRightToLeft: 179 case blink::WebTextDirectionRightToLeft:
171 return base::i18n::RIGHT_TO_LEFT; 180 return base::i18n::RIGHT_TO_LEFT;
172 default: 181 default:
173 NOTREACHED(); 182 NOTREACHED();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 358
350 // static 359 // static
351 RenderFrameHostImpl* RenderFrameHostImpl::FromAXTreeID( 360 RenderFrameHostImpl* RenderFrameHostImpl::FromAXTreeID(
352 ui::AXTreeIDRegistry::AXTreeID ax_tree_id) { 361 ui::AXTreeIDRegistry::AXTreeID ax_tree_id) {
353 DCHECK_CURRENTLY_ON(BrowserThread::UI); 362 DCHECK_CURRENTLY_ON(BrowserThread::UI);
354 ui::AXTreeIDRegistry::FrameID frame_id = 363 ui::AXTreeIDRegistry::FrameID frame_id =
355 ui::AXTreeIDRegistry::GetInstance()->GetFrameID(ax_tree_id); 364 ui::AXTreeIDRegistry::GetInstance()->GetFrameID(ax_tree_id);
356 return RenderFrameHostImpl::FromID(frame_id.first, frame_id.second); 365 return RenderFrameHostImpl::FromID(frame_id.first, frame_id.second);
357 } 366 }
358 367
368 #if defined(OS_ANDROID)
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 #endif
377
359 RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance, 378 RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance,
360 RenderViewHostImpl* render_view_host, 379 RenderViewHostImpl* render_view_host,
361 RenderFrameHostDelegate* delegate, 380 RenderFrameHostDelegate* delegate,
362 RenderWidgetHostDelegate* rwh_delegate, 381 RenderWidgetHostDelegate* rwh_delegate,
363 FrameTree* frame_tree, 382 FrameTree* frame_tree,
364 FrameTreeNode* frame_tree_node, 383 FrameTreeNode* frame_tree_node,
365 int32_t routing_id, 384 int32_t routing_id,
366 int32_t widget_routing_id, 385 int32_t widget_routing_id,
367 bool hidden, 386 bool hidden,
368 bool renderer_initiated_creation) 387 bool renderer_initiated_creation)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 // so we do it early while |this| object is still in a sane state. 473 // so we do it early while |this| object is still in a sane state.
455 navigation_handle_.reset(); 474 navigation_handle_.reset();
456 475
457 // Release the WebUI instances before all else as the WebUI may accesses the 476 // Release the WebUI instances before all else as the WebUI may accesses the
458 // RenderFrameHost during cleanup. 477 // RenderFrameHost during cleanup.
459 ClearAllWebUI(); 478 ClearAllWebUI();
460 479
461 GetProcess()->RemoveRoute(routing_id_); 480 GetProcess()->RemoveRoute(routing_id_);
462 g_routing_id_frame_map.Get().erase( 481 g_routing_id_frame_map.Get().erase(
463 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); 482 RenderFrameHostID(GetProcess()->GetID(), routing_id_));
483 #if defined(OS_ANDROID)
484 if (overlay_routing_token_.has_value())
485 g_token_frame_map.Get().erase(overlay_routing_token_.value());
486 #endif
464 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 487 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
465 base::Bind(&NotifyRenderFrameDetachedOnIO, 488 base::Bind(&NotifyRenderFrameDetachedOnIO,
466 GetProcess()->GetID(), routing_id_)); 489 GetProcess()->GetID(), routing_id_));
467 490
468 site_instance_->RemoveObserver(this); 491 site_instance_->RemoveObserver(this);
469 492
470 if (delegate_ && render_frame_created_) 493 if (delegate_ && render_frame_created_)
471 delegate_->RenderFrameDeleted(this); 494 delegate_->RenderFrameDeleted(this);
472 495
473 // If this was the last active frame in the SiteInstance, the 496 // If this was the last active frame in the SiteInstance, the
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 530
508 int RenderFrameHostImpl::GetRoutingID() { 531 int RenderFrameHostImpl::GetRoutingID() {
509 return routing_id_; 532 return routing_id_;
510 } 533 }
511 534
512 ui::AXTreeIDRegistry::AXTreeID RenderFrameHostImpl::GetAXTreeID() { 535 ui::AXTreeIDRegistry::AXTreeID RenderFrameHostImpl::GetAXTreeID() {
513 return ui::AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID( 536 return ui::AXTreeIDRegistry::GetInstance()->GetOrCreateAXTreeID(
514 GetProcess()->GetID(), routing_id_); 537 GetProcess()->GetID(), routing_id_);
515 } 538 }
516 539
540 #if defined(OS_ANDROID)
541 const base::UnguessableToken& RenderFrameHostImpl::GetOverlayRoutingToken() {
542 if (!overlay_routing_token_.has_value()) {
dcheng 2017/04/06 07:14:51 Slightly shorter to omit has_value()
liberato (no reviews please) 2017/04/10 21:24:53 Done.
543 overlay_routing_token_ = base::UnguessableToken::Create();
544 g_token_frame_map.Get().insert(
dcheng 2017/04/06 07:14:51 Out of curiosity, does emplace work now?
liberato (no reviews please) 2017/04/10 21:24:53 yes, thanks. done.
545 std::make_pair(overlay_routing_token_.value(), this));
546 }
547
548 return overlay_routing_token_.value();
dcheng 2017/04/06 07:14:51 Shorter alternative: return *overlay_routing_token
liberato (no reviews please) 2017/04/10 21:24:53 Done, and elsewhere.
549 }
550 #endif
551
517 SiteInstanceImpl* RenderFrameHostImpl::GetSiteInstance() { 552 SiteInstanceImpl* RenderFrameHostImpl::GetSiteInstance() {
518 return site_instance_.get(); 553 return site_instance_.get();
519 } 554 }
520 555
521 RenderProcessHost* RenderFrameHostImpl::GetProcess() { 556 RenderProcessHost* RenderFrameHostImpl::GetProcess() {
522 return process_; 557 return process_;
523 } 558 }
524 559
525 RenderFrameHostImpl* RenderFrameHostImpl::GetParent() { 560 RenderFrameHostImpl* RenderFrameHostImpl::GetParent() {
526 return parent_; 561 return parent_;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 IPC_MESSAGE_HANDLER(FrameHostMsg_FocusedNodeChanged, OnFocusedNodeChanged) 849 IPC_MESSAGE_HANDLER(FrameHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
815 IPC_MESSAGE_HANDLER(FrameHostMsg_SetHasReceivedUserGesture, 850 IPC_MESSAGE_HANDLER(FrameHostMsg_SetHasReceivedUserGesture,
816 OnSetHasReceivedUserGesture) 851 OnSetHasReceivedUserGesture)
817 #if BUILDFLAG(USE_EXTERNAL_POPUP_MENU) 852 #if BUILDFLAG(USE_EXTERNAL_POPUP_MENU)
818 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup) 853 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowPopup, OnShowPopup)
819 IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup, OnHidePopup) 854 IPC_MESSAGE_HANDLER(FrameHostMsg_HidePopup, OnHidePopup)
820 #endif 855 #endif
821 #if defined(OS_ANDROID) 856 #if defined(OS_ANDROID)
822 IPC_MESSAGE_HANDLER(FrameHostMsg_NavigationHandledByEmbedder, 857 IPC_MESSAGE_HANDLER(FrameHostMsg_NavigationHandledByEmbedder,
823 OnNavigationHandledByEmbedder) 858 OnNavigationHandledByEmbedder)
859 IPC_MESSAGE_HANDLER(FrameHostMsg_RequestOverlayRoutingToken,
860 OnRequestOverlayRoutingToken)
824 #endif 861 #endif
825 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowCreatedWindow, OnShowCreatedWindow) 862 IPC_MESSAGE_HANDLER(FrameHostMsg_ShowCreatedWindow, OnShowCreatedWindow)
826 IPC_END_MESSAGE_MAP() 863 IPC_END_MESSAGE_MAP()
827 864
828 // No further actions here, since we may have been deleted. 865 // No further actions here, since we may have been deleted.
829 return handled; 866 return handled;
830 } 867 }
831 868
832 void RenderFrameHostImpl::OnAssociatedInterfaceRequest( 869 void RenderFrameHostImpl::OnAssociatedInterfaceRequest(
833 const std::string& interface_name, 870 const std::string& interface_name,
(...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after
2427 } 2464 }
2428 #endif 2465 #endif
2429 2466
2430 #if defined(OS_ANDROID) 2467 #if defined(OS_ANDROID)
2431 void RenderFrameHostImpl::OnNavigationHandledByEmbedder() { 2468 void RenderFrameHostImpl::OnNavigationHandledByEmbedder() {
2432 if (navigation_handle_) 2469 if (navigation_handle_)
2433 navigation_handle_->set_net_error_code(net::ERR_ABORTED); 2470 navigation_handle_->set_net_error_code(net::ERR_ABORTED);
2434 2471
2435 OnDidStopLoading(); 2472 OnDidStopLoading();
2436 } 2473 }
2474
2475 void RenderFrameHostImpl::OnRequestOverlayRoutingToken() {
2476 // Make sure that we have a token.
2477 GetOverlayRoutingToken();
2478
2479 Send(new FrameMsg_SetOverlayRoutingToken(routing_id_,
2480 overlay_routing_token_.value()));
2481 }
2437 #endif 2482 #endif
2438 2483
2439 void RenderFrameHostImpl::OnShowCreatedWindow(int pending_widget_routing_id, 2484 void RenderFrameHostImpl::OnShowCreatedWindow(int pending_widget_routing_id,
2440 WindowOpenDisposition disposition, 2485 WindowOpenDisposition disposition,
2441 const gfx::Rect& initial_rect, 2486 const gfx::Rect& initial_rect,
2442 bool user_gesture) { 2487 bool user_gesture) {
2443 delegate_->ShowCreatedWindow(GetProcess()->GetID(), pending_widget_routing_id, 2488 delegate_->ShowCreatedWindow(GetProcess()->GetID(), pending_widget_routing_id,
2444 disposition, initial_rect, user_gesture); 2489 disposition, initial_rect, user_gesture);
2445 } 2490 }
2446 2491
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after
3675 service_manager::mojom::InterfaceProviderPtr provider; 3720 service_manager::mojom::InterfaceProviderPtr provider;
3676 BindInterfaceRegistryForRenderFrameHost(mojo::MakeRequest(&provider), this); 3721 BindInterfaceRegistryForRenderFrameHost(mojo::MakeRequest(&provider), this);
3677 java_interfaces_.reset(new service_manager::InterfaceProvider); 3722 java_interfaces_.reset(new service_manager::InterfaceProvider);
3678 java_interfaces_->Bind(std::move(provider)); 3723 java_interfaces_->Bind(std::move(provider));
3679 } 3724 }
3680 return java_interfaces_.get(); 3725 return java_interfaces_.get();
3681 } 3726 }
3682 #endif 3727 #endif
3683 3728
3684 } // namespace content 3729 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/render_frame_host_impl.h ('k') | content/common/frame_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698