| 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_(base::MakeUnique<FrameTree>( |
| 167 this, | 167 new InterstitialPageNavigatorImpl(this, 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( |
| 251 frame_tree_.root()->current_frame_host()->UpdateAccessibilityMode(); | 257 data_url); |
| 258 frame_tree_->root()->current_frame_host()->UpdateAccessibilityMode(); |
| 252 | 259 |
| 253 notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_PENDING, | 260 notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_PENDING, |
| 254 Source<NavigationController>(controller_)); | 261 Source<NavigationController>(controller_)); |
| 255 } | 262 } |
| 256 | 263 |
| 257 void InterstitialPageImpl::Hide() { | 264 void InterstitialPageImpl::Hide() { |
| 258 // We may have already been hidden, and are just waiting to be deleted. | 265 // 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 | 266 // We can't check for enabled() here, because some callers have already |
| 260 // called Disable. | 267 // called Disable. |
| 261 if (!render_view_host_) | 268 if (!render_view_host_) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 289 ->Focus(); | 296 ->Focus(); |
| 290 } | 297 } |
| 291 | 298 |
| 292 // Delete this and call Shutdown on the RVH asynchronously, as we may have | 299 // 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 | 300 // been called from a RVH delegate method, and we can't delete the RVH out |
| 294 // from under itself. | 301 // from under itself. |
| 295 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( | 302 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( |
| 296 FROM_HERE, base::Bind(&InterstitialPageImpl::Shutdown, | 303 FROM_HERE, base::Bind(&InterstitialPageImpl::Shutdown, |
| 297 weak_ptr_factory_.GetWeakPtr())); | 304 weak_ptr_factory_.GetWeakPtr())); |
| 298 render_view_host_ = NULL; | 305 render_view_host_ = NULL; |
| 299 frame_tree_.root()->ResetForNewProcess(); | 306 frame_tree_->root()->ResetForNewProcess(); |
| 300 controller_->delegate()->DetachInterstitialPage(); | 307 controller_->delegate()->DetachInterstitialPage(); |
| 301 // Let's revert to the original title if necessary. | 308 // Let's revert to the original title if necessary. |
| 302 NavigationEntry* entry = controller_->GetVisibleEntry(); | 309 NavigationEntry* entry = controller_->GetVisibleEntry(); |
| 303 if (entry && !new_navigation_ && should_revert_web_contents_title_) | 310 if (entry && !new_navigation_ && should_revert_web_contents_title_) |
| 304 web_contents_->UpdateTitleForEntry(entry, original_web_contents_title_); | 311 web_contents_->UpdateTitleForEntry(entry, original_web_contents_title_); |
| 305 | 312 |
| 306 static_cast<WebContentsImpl*>(web_contents_)->DidChangeVisibleSecurityState(); | 313 static_cast<WebContentsImpl*>(web_contents_)->DidChangeVisibleSecurityState(); |
| 307 | 314 |
| 308 InterstitialPageMap::iterator iter = | 315 InterstitialPageMap::iterator iter = |
| 309 g_web_contents_to_interstitial_page->find(web_contents_); | 316 g_web_contents_to_interstitial_page->find(web_contents_); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 427 } |
| 421 | 428 |
| 422 AccessibilityMode InterstitialPageImpl::GetAccessibilityMode() const { | 429 AccessibilityMode InterstitialPageImpl::GetAccessibilityMode() const { |
| 423 if (web_contents_) | 430 if (web_contents_) |
| 424 return static_cast<WebContentsImpl*>(web_contents_)->GetAccessibilityMode(); | 431 return static_cast<WebContentsImpl*>(web_contents_)->GetAccessibilityMode(); |
| 425 else | 432 else |
| 426 return AccessibilityMode(); | 433 return AccessibilityMode(); |
| 427 } | 434 } |
| 428 | 435 |
| 429 void InterstitialPageImpl::Cut() { | 436 void InterstitialPageImpl::Cut() { |
| 430 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); | 437 FrameTreeNode* focused_node = frame_tree_->GetFocusedFrame(); |
| 431 if (!focused_node) | 438 if (!focused_node) |
| 432 return; | 439 return; |
| 433 | 440 |
| 434 focused_node->current_frame_host()->Send( | 441 focused_node->current_frame_host()->Send( |
| 435 new InputMsg_Cut(focused_node->current_frame_host()->GetRoutingID())); | 442 new InputMsg_Cut(focused_node->current_frame_host()->GetRoutingID())); |
| 436 RecordAction(base::UserMetricsAction("Cut")); | 443 RecordAction(base::UserMetricsAction("Cut")); |
| 437 } | 444 } |
| 438 | 445 |
| 439 void InterstitialPageImpl::Copy() { | 446 void InterstitialPageImpl::Copy() { |
| 440 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); | 447 FrameTreeNode* focused_node = frame_tree_->GetFocusedFrame(); |
| 441 if (!focused_node) | 448 if (!focused_node) |
| 442 return; | 449 return; |
| 443 | 450 |
| 444 focused_node->current_frame_host()->Send( | 451 focused_node->current_frame_host()->Send( |
| 445 new InputMsg_Copy(focused_node->current_frame_host()->GetRoutingID())); | 452 new InputMsg_Copy(focused_node->current_frame_host()->GetRoutingID())); |
| 446 RecordAction(base::UserMetricsAction("Copy")); | 453 RecordAction(base::UserMetricsAction("Copy")); |
| 447 } | 454 } |
| 448 | 455 |
| 449 void InterstitialPageImpl::Paste() { | 456 void InterstitialPageImpl::Paste() { |
| 450 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); | 457 FrameTreeNode* focused_node = frame_tree_->GetFocusedFrame(); |
| 451 if (!focused_node) | 458 if (!focused_node) |
| 452 return; | 459 return; |
| 453 | 460 |
| 454 focused_node->current_frame_host()->Send( | 461 focused_node->current_frame_host()->Send( |
| 455 new InputMsg_Paste(focused_node->current_frame_host()->GetRoutingID())); | 462 new InputMsg_Paste(focused_node->current_frame_host()->GetRoutingID())); |
| 456 RecordAction(base::UserMetricsAction("Paste")); | 463 RecordAction(base::UserMetricsAction("Paste")); |
| 457 } | 464 } |
| 458 | 465 |
| 459 void InterstitialPageImpl::SelectAll() { | 466 void InterstitialPageImpl::SelectAll() { |
| 460 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); | 467 FrameTreeNode* focused_node = frame_tree_->GetFocusedFrame(); |
| 461 if (!focused_node) | 468 if (!focused_node) |
| 462 return; | 469 return; |
| 463 | 470 |
| 464 focused_node->current_frame_host()->Send(new InputMsg_SelectAll( | 471 focused_node->current_frame_host()->Send(new InputMsg_SelectAll( |
| 465 focused_node->current_frame_host()->GetRoutingID())); | 472 focused_node->current_frame_host()->GetRoutingID())); |
| 466 RecordAction(base::UserMetricsAction("SelectAll")); | 473 RecordAction(base::UserMetricsAction("SelectAll")); |
| 467 } | 474 } |
| 468 | 475 |
| 469 RenderViewHostDelegateView* InterstitialPageImpl::GetDelegateView() { | 476 RenderViewHostDelegateView* InterstitialPageImpl::GetDelegateView() { |
| 470 return rvh_delegate_view_.get(); | 477 return rvh_delegate_view_.get(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 static_cast<DOMStorageContextWrapper*>( | 586 static_cast<DOMStorageContextWrapper*>( |
| 580 BrowserContext::GetStoragePartition( | 587 BrowserContext::GetStoragePartition( |
| 581 browser_context, site_instance.get())->GetDOMStorageContext()); | 588 browser_context, site_instance.get())->GetDOMStorageContext()); |
| 582 session_storage_namespace_ = | 589 session_storage_namespace_ = |
| 583 new SessionStorageNamespaceImpl(dom_storage_context); | 590 new SessionStorageNamespaceImpl(dom_storage_context); |
| 584 | 591 |
| 585 // Use the RenderViewHost from our FrameTree. | 592 // Use the RenderViewHost from our FrameTree. |
| 586 // TODO(avi): The view routing ID can be restored to MSG_ROUTING_NONE once | 593 // TODO(avi): The view routing ID can be restored to MSG_ROUTING_NONE once |
| 587 // RenderViewHostImpl has-a RenderWidgetHostImpl. https://crbug.com/545684 | 594 // RenderViewHostImpl has-a RenderWidgetHostImpl. https://crbug.com/545684 |
| 588 int32_t widget_routing_id = site_instance->GetProcess()->GetNextRoutingID(); | 595 int32_t widget_routing_id = site_instance->GetProcess()->GetNextRoutingID(); |
| 589 frame_tree_.root()->render_manager()->Init( | 596 frame_tree_->root()->render_manager()->Init( |
| 590 site_instance.get(), widget_routing_id, MSG_ROUTING_NONE, | 597 site_instance.get(), widget_routing_id, MSG_ROUTING_NONE, |
| 591 widget_routing_id, false); | 598 widget_routing_id, false); |
| 592 return frame_tree_.root()->current_frame_host()->render_view_host(); | 599 return frame_tree_->root()->current_frame_host()->render_view_host(); |
| 593 } | 600 } |
| 594 | 601 |
| 595 WebContentsView* InterstitialPageImpl::CreateWebContentsView() { | 602 WebContentsView* InterstitialPageImpl::CreateWebContentsView() { |
| 596 if (!enabled() || !create_view_) | 603 if (!enabled() || !create_view_) |
| 597 return NULL; | 604 return NULL; |
| 598 WebContentsView* wcv = | 605 WebContentsView* wcv = |
| 599 static_cast<WebContentsImpl*>(web_contents())->GetView(); | 606 static_cast<WebContentsImpl*>(web_contents())->GetView(); |
| 600 RenderWidgetHostViewBase* view = | 607 RenderWidgetHostViewBase* view = |
| 601 wcv->CreateViewForWidget(render_view_host_->GetWidget(), false); | 608 wcv->CreateViewForWidget(render_view_host_->GetWidget(), false); |
| 602 RenderWidgetHostImpl::From(render_view_host_->GetWidget())->SetView(view); | 609 RenderWidgetHostImpl::From(render_view_host_->GetWidget())->SetView(view); |
| 603 render_view_host_->GetMainFrame()->AllowBindings( | 610 render_view_host_->GetMainFrame()->AllowBindings( |
| 604 BINDINGS_POLICY_DOM_AUTOMATION); | 611 BINDINGS_POLICY_DOM_AUTOMATION); |
| 605 | 612 |
| 606 render_view_host_->CreateRenderView(MSG_ROUTING_NONE, | 613 render_view_host_->CreateRenderView(MSG_ROUTING_NONE, |
| 607 MSG_ROUTING_NONE, | 614 MSG_ROUTING_NONE, |
| 608 FrameReplicationState(), | 615 FrameReplicationState(), |
| 609 false); | 616 false); |
| 610 controller_->delegate()->RenderFrameForInterstitialPageCreated( | 617 controller_->delegate()->RenderFrameForInterstitialPageCreated( |
| 611 frame_tree_.root()->current_frame_host()); | 618 frame_tree_->root()->current_frame_host()); |
| 612 view->SetSize(web_contents()->GetContainerBounds().size()); | 619 view->SetSize(web_contents()->GetContainerBounds().size()); |
| 613 // Don't show the interstitial until we have navigated to it. | 620 // Don't show the interstitial until we have navigated to it. |
| 614 view->Hide(); | 621 view->Hide(); |
| 615 return wcv; | 622 return wcv; |
| 616 } | 623 } |
| 617 | 624 |
| 618 void InterstitialPageImpl::Proceed() { | 625 void InterstitialPageImpl::Proceed() { |
| 619 // Don't repeat this if we are already shutting down. We cannot check for | 626 // 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. | 627 // enabled() here, because we may have called Disable without calling Hide. |
| 621 if (!render_view_host_) | 628 if (!render_view_host_) |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 int32_t render_view_route_id, | 753 int32_t render_view_route_id, |
| 747 int32_t main_frame_route_id, | 754 int32_t main_frame_route_id, |
| 748 int32_t main_frame_widget_route_id, | 755 int32_t main_frame_widget_route_id, |
| 749 const mojom::CreateNewWindowParams& params, | 756 const mojom::CreateNewWindowParams& params, |
| 750 SessionStorageNamespace* session_storage_namespace) { | 757 SessionStorageNamespace* session_storage_namespace) { |
| 751 NOTREACHED() << "InterstitialPage does not support showing popups."; | 758 NOTREACHED() << "InterstitialPage does not support showing popups."; |
| 752 } | 759 } |
| 753 | 760 |
| 754 void InterstitialPageImpl::SetFocusedFrame(FrameTreeNode* node, | 761 void InterstitialPageImpl::SetFocusedFrame(FrameTreeNode* node, |
| 755 SiteInstance* source) { | 762 SiteInstance* source) { |
| 756 frame_tree_.SetFocusedFrame(node, source); | 763 frame_tree_->SetFocusedFrame(node, source); |
| 757 | 764 |
| 758 if (web_contents_) { | 765 if (web_contents_) { |
| 759 static_cast<WebContentsImpl*>(web_contents_) | 766 static_cast<WebContentsImpl*>(web_contents_) |
| 760 ->SetAsFocusedWebContentsIfNecessary(); | 767 ->SetAsFocusedWebContentsIfNecessary(); |
| 761 } | 768 } |
| 762 } | 769 } |
| 763 | 770 |
| 764 void InterstitialPageImpl::CreateNewWidget(int32_t render_process_id, | 771 void InterstitialPageImpl::CreateNewWidget(int32_t render_process_id, |
| 765 int32_t route_id, | 772 int32_t route_id, |
| 766 blink::WebPopupType popup_type) { | 773 blink::WebPopupType popup_type) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 792 NOTREACHED() | 799 NOTREACHED() |
| 793 << "InterstitialPage does not support showing full screen popups."; | 800 << "InterstitialPage does not support showing full screen popups."; |
| 794 } | 801 } |
| 795 | 802 |
| 796 SessionStorageNamespace* InterstitialPageImpl::GetSessionStorageNamespace( | 803 SessionStorageNamespace* InterstitialPageImpl::GetSessionStorageNamespace( |
| 797 SiteInstance* instance) { | 804 SiteInstance* instance) { |
| 798 return session_storage_namespace_.get(); | 805 return session_storage_namespace_.get(); |
| 799 } | 806 } |
| 800 | 807 |
| 801 FrameTree* InterstitialPageImpl::GetFrameTree() { | 808 FrameTree* InterstitialPageImpl::GetFrameTree() { |
| 802 return &frame_tree_; | 809 return frame_tree_.get(); |
| 803 } | 810 } |
| 804 | 811 |
| 805 void InterstitialPageImpl::Disable() { | 812 void InterstitialPageImpl::Disable() { |
| 806 enabled_ = false; | 813 enabled_ = false; |
| 807 } | 814 } |
| 808 | 815 |
| 809 void InterstitialPageImpl::Shutdown() { | 816 void InterstitialPageImpl::Shutdown() { |
| 810 delete this; | 817 delete this; |
| 811 } | 818 } |
| 812 | 819 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 RenderWidgetHostInputEventRouter* InterstitialPageImpl::GetInputEventRouter() { | 992 RenderWidgetHostInputEventRouter* InterstitialPageImpl::GetInputEventRouter() { |
| 986 WebContentsImpl* web_contents_impl = | 993 WebContentsImpl* web_contents_impl = |
| 987 static_cast<WebContentsImpl*>(web_contents_); | 994 static_cast<WebContentsImpl*>(web_contents_); |
| 988 if (!web_contents_impl) | 995 if (!web_contents_impl) |
| 989 return nullptr; | 996 return nullptr; |
| 990 | 997 |
| 991 return web_contents_impl->GetInputEventRouter(); | 998 return web_contents_impl->GetInputEventRouter(); |
| 992 } | 999 } |
| 993 | 1000 |
| 994 } // namespace content | 1001 } // namespace content |
| OLD | NEW |