Chromium Code Reviews| 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/interstitial_page_impl.h" | 5 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 should_discard_pending_nav_entry_(new_navigation), | 156 should_discard_pending_nav_entry_(new_navigation), |
| 157 enabled_(true), | 157 enabled_(true), |
| 158 action_taken_(NO_ACTION), | 158 action_taken_(NO_ACTION), |
| 159 render_view_host_(NULL), | 159 render_view_host_(NULL), |
| 160 // TODO(nasko): The InterstitialPageImpl will need to provide its own | 160 // TODO(nasko): The InterstitialPageImpl will need to provide its own |
| 161 // NavigationControllerImpl to the Navigator, which is separate from | 161 // NavigationControllerImpl to the Navigator, which is separate from |
| 162 // the WebContents one, so we can enforce no navigation policy here. | 162 // the WebContents one, so we can enforce no navigation policy here. |
| 163 // While we get the code to a point to do this, pass NULL for it. | 163 // While we get the code to a point to do this, pass NULL for it. |
| 164 // TODO(creis): We will also need to pass delegates for the RVHM as we | 164 // TODO(creis): We will also need to pass delegates for the RVHM as we |
| 165 // start to use it. | 165 // start to use it. |
| 166 frame_tree_(new InterstitialPageNavigatorImpl(this, controller_), | 166 frame_tree_(new FrameTree(new InterstitialPageNavigatorImpl(this, |
|
Avi (use Gerrit)
2017/05/23 22:44:15
base::MakeUnique<>
| |
| 167 this, | 167 controller_), |
| 168 this, | 168 this, |
| 169 this, | 169 this, |
| 170 static_cast<WebContentsImpl*>(web_contents)), | 170 this, |
| 171 static_cast<WebContentsImpl*>(web_contents))), | |
| 171 original_child_id_(web_contents->GetRenderProcessHost()->GetID()), | 172 original_child_id_(web_contents->GetRenderProcessHost()->GetID()), |
| 172 original_rvh_id_(web_contents->GetRenderViewHost()->GetRoutingID()), | 173 original_rvh_id_(web_contents->GetRenderViewHost()->GetRoutingID()), |
| 173 should_revert_web_contents_title_(false), | 174 should_revert_web_contents_title_(false), |
| 174 resource_dispatcher_host_notified_(false), | 175 resource_dispatcher_host_notified_(false), |
| 175 rvh_delegate_view_(new InterstitialPageRVHDelegateView(this)), | 176 rvh_delegate_view_(new InterstitialPageRVHDelegateView(this)), |
| 176 create_view_(true), | 177 create_view_(true), |
| 177 pause_throbber_(false), | 178 pause_throbber_(false), |
| 178 delegate_(delegate), | 179 delegate_(delegate), |
| 179 weak_ptr_factory_(this) { | 180 weak_ptr_factory_(this) { |
| 180 InitInterstitialPageMap(); | 181 InitInterstitialPageMap(); |
| 181 } | 182 } |
| 182 | 183 |
| 183 InterstitialPageImpl::~InterstitialPageImpl() { | 184 InterstitialPageImpl::~InterstitialPageImpl() { |
| 185 // RenderViewHostImpl::RenderWidgetLostFocus() will be eventually executed in | |
| 186 // the destructor of FrameTree. It uses InterstitialPageRVHDelegate, which | |
| 187 // will be deleted because std::unique_ptr<InterstitialPageRVHDelegateView> is | |
| 188 // placed after frame_tree_. See bug http://crbug.com/725594. | |
| 189 frame_tree_.reset(); | |
| 184 } | 190 } |
| 185 | 191 |
| 186 void InterstitialPageImpl::Show() { | 192 void InterstitialPageImpl::Show() { |
| 187 if (!enabled()) | 193 if (!enabled()) |
| 188 return; | 194 return; |
| 189 | 195 |
| 190 // If an interstitial is already showing or about to be shown, close it before | 196 // If an interstitial is already showing or about to be shown, close it before |
| 191 // showing the new one. | 197 // showing the new one. |
| 192 // Be careful not to take an action on the old interstitial more than once. | 198 // Be careful not to take an action on the old interstitial more than once. |
| 193 InterstitialPageMap::const_iterator iter = | 199 InterstitialPageMap::const_iterator iter = |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 static_cast<WebContentsImpl*>(web_contents_) | 246 static_cast<WebContentsImpl*>(web_contents_) |
| 241 ->DidChangeVisibleSecurityState(); | 247 ->DidChangeVisibleSecurityState(); |
| 242 } | 248 } |
| 243 | 249 |
| 244 DCHECK(!render_view_host_); | 250 DCHECK(!render_view_host_); |
| 245 render_view_host_ = CreateRenderViewHost(); | 251 render_view_host_ = CreateRenderViewHost(); |
| 246 CreateWebContentsView(); | 252 CreateWebContentsView(); |
| 247 | 253 |
| 248 GURL data_url = GURL("data:text/html;charset=utf-8," + | 254 GURL data_url = GURL("data:text/html;charset=utf-8," + |
| 249 net::EscapePath(delegate_->GetHTMLContents())); | 255 net::EscapePath(delegate_->GetHTMLContents())); |
| 250 frame_tree_.root()->current_frame_host()->NavigateToInterstitialURL(data_url); | 256 frame_tree_->root()->current_frame_host()->NavigateToInterstitialURL(data_url) ; |
| 251 frame_tree_.root()->current_frame_host()->UpdateAccessibilityMode(); | 257 frame_tree_->root()->current_frame_host()->UpdateAccessibilityMode(); |
| 252 | 258 |
| 253 notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_PENDING, | 259 notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_PENDING, |
| 254 Source<NavigationController>(controller_)); | 260 Source<NavigationController>(controller_)); |
| 255 } | 261 } |
| 256 | 262 |
| 257 void InterstitialPageImpl::Hide() { | 263 void InterstitialPageImpl::Hide() { |
| 258 // We may have already been hidden, and are just waiting to be deleted. | 264 // We may have already been hidden, and are just waiting to be deleted. |
| 259 // We can't check for enabled() here, because some callers have already | 265 // We can't check for enabled() here, because some callers have already |
| 260 // called Disable. | 266 // called Disable. |
| 261 if (!render_view_host_) | 267 if (!render_view_host_) |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 289 ->Focus(); | 295 ->Focus(); |
| 290 } | 296 } |
| 291 | 297 |
| 292 // Delete this and call Shutdown on the RVH asynchronously, as we may have | 298 // Delete this and call Shutdown on the RVH asynchronously, as we may have |
| 293 // been called from a RVH delegate method, and we can't delete the RVH out | 299 // been called from a RVH delegate method, and we can't delete the RVH out |
| 294 // from under itself. | 300 // from under itself. |
| 295 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( | 301 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( |
| 296 FROM_HERE, base::Bind(&InterstitialPageImpl::Shutdown, | 302 FROM_HERE, base::Bind(&InterstitialPageImpl::Shutdown, |
| 297 weak_ptr_factory_.GetWeakPtr())); | 303 weak_ptr_factory_.GetWeakPtr())); |
| 298 render_view_host_ = NULL; | 304 render_view_host_ = NULL; |
| 299 frame_tree_.root()->ResetForNewProcess(); | 305 frame_tree_->root()->ResetForNewProcess(); |
| 300 controller_->delegate()->DetachInterstitialPage(); | 306 controller_->delegate()->DetachInterstitialPage(); |
| 301 // Let's revert to the original title if necessary. | 307 // Let's revert to the original title if necessary. |
| 302 NavigationEntry* entry = controller_->GetVisibleEntry(); | 308 NavigationEntry* entry = controller_->GetVisibleEntry(); |
| 303 if (entry && !new_navigation_ && should_revert_web_contents_title_) | 309 if (entry && !new_navigation_ && should_revert_web_contents_title_) |
| 304 web_contents_->UpdateTitleForEntry(entry, original_web_contents_title_); | 310 web_contents_->UpdateTitleForEntry(entry, original_web_contents_title_); |
| 305 | 311 |
| 306 static_cast<WebContentsImpl*>(web_contents_)->DidChangeVisibleSecurityState(); | 312 static_cast<WebContentsImpl*>(web_contents_)->DidChangeVisibleSecurityState(); |
| 307 | 313 |
| 308 InterstitialPageMap::iterator iter = | 314 InterstitialPageMap::iterator iter = |
| 309 g_web_contents_to_interstitial_page->find(web_contents_); | 315 g_web_contents_to_interstitial_page->find(web_contents_); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 } | 426 } |
| 421 | 427 |
| 422 AccessibilityMode InterstitialPageImpl::GetAccessibilityMode() const { | 428 AccessibilityMode InterstitialPageImpl::GetAccessibilityMode() const { |
| 423 if (web_contents_) | 429 if (web_contents_) |
| 424 return static_cast<WebContentsImpl*>(web_contents_)->GetAccessibilityMode(); | 430 return static_cast<WebContentsImpl*>(web_contents_)->GetAccessibilityMode(); |
| 425 else | 431 else |
| 426 return AccessibilityMode(); | 432 return AccessibilityMode(); |
| 427 } | 433 } |
| 428 | 434 |
| 429 void InterstitialPageImpl::Cut() { | 435 void InterstitialPageImpl::Cut() { |
| 430 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); | 436 FrameTreeNode* focused_node = frame_tree_->GetFocusedFrame(); |
| 431 if (!focused_node) | 437 if (!focused_node) |
| 432 return; | 438 return; |
| 433 | 439 |
| 434 focused_node->current_frame_host()->Send( | 440 focused_node->current_frame_host()->Send( |
| 435 new InputMsg_Cut(focused_node->current_frame_host()->GetRoutingID())); | 441 new InputMsg_Cut(focused_node->current_frame_host()->GetRoutingID())); |
| 436 RecordAction(base::UserMetricsAction("Cut")); | 442 RecordAction(base::UserMetricsAction("Cut")); |
| 437 } | 443 } |
| 438 | 444 |
| 439 void InterstitialPageImpl::Copy() { | 445 void InterstitialPageImpl::Copy() { |
| 440 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); | 446 FrameTreeNode* focused_node = frame_tree_->GetFocusedFrame(); |
| 441 if (!focused_node) | 447 if (!focused_node) |
| 442 return; | 448 return; |
| 443 | 449 |
| 444 focused_node->current_frame_host()->Send( | 450 focused_node->current_frame_host()->Send( |
| 445 new InputMsg_Copy(focused_node->current_frame_host()->GetRoutingID())); | 451 new InputMsg_Copy(focused_node->current_frame_host()->GetRoutingID())); |
| 446 RecordAction(base::UserMetricsAction("Copy")); | 452 RecordAction(base::UserMetricsAction("Copy")); |
| 447 } | 453 } |
| 448 | 454 |
| 449 void InterstitialPageImpl::Paste() { | 455 void InterstitialPageImpl::Paste() { |
| 450 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); | 456 FrameTreeNode* focused_node = frame_tree_->GetFocusedFrame(); |
| 451 if (!focused_node) | 457 if (!focused_node) |
| 452 return; | 458 return; |
| 453 | 459 |
| 454 focused_node->current_frame_host()->Send( | 460 focused_node->current_frame_host()->Send( |
| 455 new InputMsg_Paste(focused_node->current_frame_host()->GetRoutingID())); | 461 new InputMsg_Paste(focused_node->current_frame_host()->GetRoutingID())); |
| 456 RecordAction(base::UserMetricsAction("Paste")); | 462 RecordAction(base::UserMetricsAction("Paste")); |
| 457 } | 463 } |
| 458 | 464 |
| 459 void InterstitialPageImpl::SelectAll() { | 465 void InterstitialPageImpl::SelectAll() { |
| 460 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); | 466 FrameTreeNode* focused_node = frame_tree_->GetFocusedFrame(); |
| 461 if (!focused_node) | 467 if (!focused_node) |
| 462 return; | 468 return; |
| 463 | 469 |
| 464 focused_node->current_frame_host()->Send(new InputMsg_SelectAll( | 470 focused_node->current_frame_host()->Send(new InputMsg_SelectAll( |
| 465 focused_node->current_frame_host()->GetRoutingID())); | 471 focused_node->current_frame_host()->GetRoutingID())); |
| 466 RecordAction(base::UserMetricsAction("SelectAll")); | 472 RecordAction(base::UserMetricsAction("SelectAll")); |
| 467 } | 473 } |
| 468 | 474 |
| 469 RenderViewHostDelegateView* InterstitialPageImpl::GetDelegateView() { | 475 RenderViewHostDelegateView* InterstitialPageImpl::GetDelegateView() { |
| 470 return rvh_delegate_view_.get(); | 476 return rvh_delegate_view_.get(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 static_cast<DOMStorageContextWrapper*>( | 585 static_cast<DOMStorageContextWrapper*>( |
| 580 BrowserContext::GetStoragePartition( | 586 BrowserContext::GetStoragePartition( |
| 581 browser_context, site_instance.get())->GetDOMStorageContext()); | 587 browser_context, site_instance.get())->GetDOMStorageContext()); |
| 582 session_storage_namespace_ = | 588 session_storage_namespace_ = |
| 583 new SessionStorageNamespaceImpl(dom_storage_context); | 589 new SessionStorageNamespaceImpl(dom_storage_context); |
| 584 | 590 |
| 585 // Use the RenderViewHost from our FrameTree. | 591 // Use the RenderViewHost from our FrameTree. |
| 586 // TODO(avi): The view routing ID can be restored to MSG_ROUTING_NONE once | 592 // TODO(avi): The view routing ID can be restored to MSG_ROUTING_NONE once |
| 587 // RenderViewHostImpl has-a RenderWidgetHostImpl. https://crbug.com/545684 | 593 // RenderViewHostImpl has-a RenderWidgetHostImpl. https://crbug.com/545684 |
| 588 int32_t widget_routing_id = site_instance->GetProcess()->GetNextRoutingID(); | 594 int32_t widget_routing_id = site_instance->GetProcess()->GetNextRoutingID(); |
| 589 frame_tree_.root()->render_manager()->Init( | 595 frame_tree_->root()->render_manager()->Init( |
| 590 site_instance.get(), widget_routing_id, MSG_ROUTING_NONE, | 596 site_instance.get(), widget_routing_id, MSG_ROUTING_NONE, |
| 591 widget_routing_id, false); | 597 widget_routing_id, false); |
| 592 return frame_tree_.root()->current_frame_host()->render_view_host(); | 598 return frame_tree_->root()->current_frame_host()->render_view_host(); |
| 593 } | 599 } |
| 594 | 600 |
| 595 WebContentsView* InterstitialPageImpl::CreateWebContentsView() { | 601 WebContentsView* InterstitialPageImpl::CreateWebContentsView() { |
| 596 if (!enabled() || !create_view_) | 602 if (!enabled() || !create_view_) |
| 597 return NULL; | 603 return NULL; |
| 598 WebContentsView* wcv = | 604 WebContentsView* wcv = |
| 599 static_cast<WebContentsImpl*>(web_contents())->GetView(); | 605 static_cast<WebContentsImpl*>(web_contents())->GetView(); |
| 600 RenderWidgetHostViewBase* view = | 606 RenderWidgetHostViewBase* view = |
| 601 wcv->CreateViewForWidget(render_view_host_->GetWidget(), false); | 607 wcv->CreateViewForWidget(render_view_host_->GetWidget(), false); |
| 602 RenderWidgetHostImpl::From(render_view_host_->GetWidget())->SetView(view); | 608 RenderWidgetHostImpl::From(render_view_host_->GetWidget())->SetView(view); |
| 603 render_view_host_->GetMainFrame()->AllowBindings( | 609 render_view_host_->GetMainFrame()->AllowBindings( |
| 604 BINDINGS_POLICY_DOM_AUTOMATION); | 610 BINDINGS_POLICY_DOM_AUTOMATION); |
| 605 | 611 |
| 606 render_view_host_->CreateRenderView(MSG_ROUTING_NONE, | 612 render_view_host_->CreateRenderView(MSG_ROUTING_NONE, |
| 607 MSG_ROUTING_NONE, | 613 MSG_ROUTING_NONE, |
| 608 FrameReplicationState(), | 614 FrameReplicationState(), |
| 609 false); | 615 false); |
| 610 controller_->delegate()->RenderFrameForInterstitialPageCreated( | 616 controller_->delegate()->RenderFrameForInterstitialPageCreated( |
| 611 frame_tree_.root()->current_frame_host()); | 617 frame_tree_->root()->current_frame_host()); |
| 612 view->SetSize(web_contents()->GetContainerBounds().size()); | 618 view->SetSize(web_contents()->GetContainerBounds().size()); |
| 613 // Don't show the interstitial until we have navigated to it. | 619 // Don't show the interstitial until we have navigated to it. |
| 614 view->Hide(); | 620 view->Hide(); |
| 615 return wcv; | 621 return wcv; |
| 616 } | 622 } |
| 617 | 623 |
| 618 void InterstitialPageImpl::Proceed() { | 624 void InterstitialPageImpl::Proceed() { |
| 619 // Don't repeat this if we are already shutting down. We cannot check for | 625 // Don't repeat this if we are already shutting down. We cannot check for |
| 620 // enabled() here, because we may have called Disable without calling Hide. | 626 // enabled() here, because we may have called Disable without calling Hide. |
| 621 if (!render_view_host_) | 627 if (!render_view_host_) |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 int32_t render_view_route_id, | 752 int32_t render_view_route_id, |
| 747 int32_t main_frame_route_id, | 753 int32_t main_frame_route_id, |
| 748 int32_t main_frame_widget_route_id, | 754 int32_t main_frame_widget_route_id, |
| 749 const mojom::CreateNewWindowParams& params, | 755 const mojom::CreateNewWindowParams& params, |
| 750 SessionStorageNamespace* session_storage_namespace) { | 756 SessionStorageNamespace* session_storage_namespace) { |
| 751 NOTREACHED() << "InterstitialPage does not support showing popups."; | 757 NOTREACHED() << "InterstitialPage does not support showing popups."; |
| 752 } | 758 } |
| 753 | 759 |
| 754 void InterstitialPageImpl::SetFocusedFrame(FrameTreeNode* node, | 760 void InterstitialPageImpl::SetFocusedFrame(FrameTreeNode* node, |
| 755 SiteInstance* source) { | 761 SiteInstance* source) { |
| 756 frame_tree_.SetFocusedFrame(node, source); | 762 frame_tree_->SetFocusedFrame(node, source); |
| 757 | 763 |
| 758 if (web_contents_) { | 764 if (web_contents_) { |
| 759 static_cast<WebContentsImpl*>(web_contents_) | 765 static_cast<WebContentsImpl*>(web_contents_) |
| 760 ->SetAsFocusedWebContentsIfNecessary(); | 766 ->SetAsFocusedWebContentsIfNecessary(); |
| 761 } | 767 } |
| 762 } | 768 } |
| 763 | 769 |
| 764 void InterstitialPageImpl::CreateNewWidget(int32_t render_process_id, | 770 void InterstitialPageImpl::CreateNewWidget(int32_t render_process_id, |
| 765 int32_t route_id, | 771 int32_t route_id, |
| 766 blink::WebPopupType popup_type) { | 772 blink::WebPopupType popup_type) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 792 NOTREACHED() | 798 NOTREACHED() |
| 793 << "InterstitialPage does not support showing full screen popups."; | 799 << "InterstitialPage does not support showing full screen popups."; |
| 794 } | 800 } |
| 795 | 801 |
| 796 SessionStorageNamespace* InterstitialPageImpl::GetSessionStorageNamespace( | 802 SessionStorageNamespace* InterstitialPageImpl::GetSessionStorageNamespace( |
| 797 SiteInstance* instance) { | 803 SiteInstance* instance) { |
| 798 return session_storage_namespace_.get(); | 804 return session_storage_namespace_.get(); |
| 799 } | 805 } |
| 800 | 806 |
| 801 FrameTree* InterstitialPageImpl::GetFrameTree() { | 807 FrameTree* InterstitialPageImpl::GetFrameTree() { |
| 802 return &frame_tree_; | 808 return frame_tree_.get(); |
| 803 } | 809 } |
| 804 | 810 |
| 805 void InterstitialPageImpl::Disable() { | 811 void InterstitialPageImpl::Disable() { |
| 806 enabled_ = false; | 812 enabled_ = false; |
| 807 } | 813 } |
| 808 | 814 |
| 809 void InterstitialPageImpl::Shutdown() { | 815 void InterstitialPageImpl::Shutdown() { |
| 810 delete this; | 816 delete this; |
| 811 } | 817 } |
| 812 | 818 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 985 RenderWidgetHostInputEventRouter* InterstitialPageImpl::GetInputEventRouter() { | 991 RenderWidgetHostInputEventRouter* InterstitialPageImpl::GetInputEventRouter() { |
| 986 WebContentsImpl* web_contents_impl = | 992 WebContentsImpl* web_contents_impl = |
| 987 static_cast<WebContentsImpl*>(web_contents_); | 993 static_cast<WebContentsImpl*>(web_contents_); |
| 988 if (!web_contents_impl) | 994 if (!web_contents_impl) |
| 989 return nullptr; | 995 return nullptr; |
| 990 | 996 |
| 991 return web_contents_impl->GetInputEventRouter(); | 997 return web_contents_impl->GetInputEventRouter(); |
| 992 } | 998 } |
| 993 | 999 |
| 994 } // namespace content | 1000 } // namespace content |
| OLD | NEW |