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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 enabled_(true), | 155 enabled_(true), |
156 action_taken_(NO_ACTION), | 156 action_taken_(NO_ACTION), |
157 render_view_host_(NULL), | 157 render_view_host_(NULL), |
158 // TODO(nasko): The InterstitialPageImpl will need to provide its own | 158 // TODO(nasko): The InterstitialPageImpl will need to provide its own |
159 // NavigationControllerImpl to the Navigator, which is separate from | 159 // NavigationControllerImpl to the Navigator, which is separate from |
160 // the WebContents one, so we can enforce no navigation policy here. | 160 // the WebContents one, so we can enforce no navigation policy here. |
161 // While we get the code to a point to do this, pass NULL for it. | 161 // While we get the code to a point to do this, pass NULL for it. |
162 // TODO(creis): We will also need to pass delegates for the RVHM as we | 162 // TODO(creis): We will also need to pass delegates for the RVHM as we |
163 // start to use it. | 163 // start to use it. |
164 frame_tree_(new InterstitialPageNavigatorImpl(this, controller_), | 164 frame_tree_(new InterstitialPageNavigatorImpl(this, controller_), |
165 NULL, NULL, NULL, NULL), | 165 this, this, this, NULL), |
166 original_child_id_(web_contents->GetRenderProcessHost()->GetID()), | 166 original_child_id_(web_contents->GetRenderProcessHost()->GetID()), |
167 original_rvh_id_(web_contents->GetRenderViewHost()->GetRoutingID()), | 167 original_rvh_id_(web_contents->GetRenderViewHost()->GetRoutingID()), |
168 should_revert_web_contents_title_(false), | 168 should_revert_web_contents_title_(false), |
169 web_contents_was_loading_(false), | 169 web_contents_was_loading_(false), |
170 resource_dispatcher_host_notified_(false), | 170 resource_dispatcher_host_notified_(false), |
171 rvh_delegate_view_(new InterstitialPageRVHDelegateView(this)), | 171 rvh_delegate_view_(new InterstitialPageRVHDelegateView(this)), |
172 create_view_(true), | 172 create_view_(true), |
173 delegate_(delegate), | 173 delegate_(delegate), |
174 weak_ptr_factory_(this) { | 174 weak_ptr_factory_(this) { |
175 InitInterstitialPageMap(); | 175 InitInterstitialPageMap(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 277 |
278 // If the focus was on the interstitial, let's keep it to the page. | 278 // If the focus was on the interstitial, let's keep it to the page. |
279 // (Note that in unit-tests the RVH may not have a view). | 279 // (Note that in unit-tests the RVH may not have a view). |
280 if (render_view_host_->GetView() && | 280 if (render_view_host_->GetView() && |
281 render_view_host_->GetView()->HasFocus() && | 281 render_view_host_->GetView()->HasFocus() && |
282 controller_->delegate()->GetRenderViewHost()->GetView()) { | 282 controller_->delegate()->GetRenderViewHost()->GetView()) { |
283 RenderWidgetHostViewPort::FromRWHV( | 283 RenderWidgetHostViewPort::FromRWHV( |
284 controller_->delegate()->GetRenderViewHost()->GetView())->Focus(); | 284 controller_->delegate()->GetRenderViewHost()->GetView())->Focus(); |
285 } | 285 } |
286 | 286 |
287 // Shutdown the RVH asynchronously, as we may have been called from a RVH | 287 // Delete this and call Shutdown on the RVH asynchronously, as we may have |
288 // delegate method, and we can't delete the RVH out from under itself. | 288 // been called from a RVH delegate method, and we can't delete the RVH out |
| 289 // from under itself. |
289 base::MessageLoop::current()->PostNonNestableTask( | 290 base::MessageLoop::current()->PostNonNestableTask( |
290 FROM_HERE, | 291 FROM_HERE, |
291 base::Bind(&InterstitialPageImpl::Shutdown, | 292 base::Bind(&InterstitialPageImpl::Shutdown, |
292 weak_ptr_factory_.GetWeakPtr(), | 293 weak_ptr_factory_.GetWeakPtr())); |
293 render_view_host_)); | |
294 render_view_host_ = NULL; | 294 render_view_host_ = NULL; |
295 frame_tree_.SwapMainFrame(NULL); | 295 frame_tree_.ResetForMainFrameSwap(); |
296 controller_->delegate()->DetachInterstitialPage(); | 296 controller_->delegate()->DetachInterstitialPage(); |
297 // Let's revert to the original title if necessary. | 297 // Let's revert to the original title if necessary. |
298 NavigationEntry* entry = controller_->GetVisibleEntry(); | 298 NavigationEntry* entry = controller_->GetVisibleEntry(); |
299 if (!new_navigation_ && should_revert_web_contents_title_) { | 299 if (!new_navigation_ && should_revert_web_contents_title_) { |
300 entry->SetTitle(original_web_contents_title_); | 300 entry->SetTitle(original_web_contents_title_); |
301 controller_->delegate()->NotifyNavigationStateChanged( | 301 controller_->delegate()->NotifyNavigationStateChanged( |
302 INVALIDATE_TYPE_TITLE); | 302 INVALIDATE_TYPE_TITLE); |
303 } | 303 } |
304 | 304 |
305 InterstitialPageMap::iterator iter = | 305 InterstitialPageMap::iterator iter = |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 480 |
481 WebPreferences InterstitialPageImpl::GetWebkitPrefs() { | 481 WebPreferences InterstitialPageImpl::GetWebkitPrefs() { |
482 if (!enabled()) | 482 if (!enabled()) |
483 return WebPreferences(); | 483 return WebPreferences(); |
484 | 484 |
485 return render_view_host_->GetWebkitPrefs(url_); | 485 return render_view_host_->GetWebkitPrefs(url_); |
486 } | 486 } |
487 | 487 |
488 void InterstitialPageImpl::RenderWidgetDeleted( | 488 void InterstitialPageImpl::RenderWidgetDeleted( |
489 RenderWidgetHostImpl* render_widget_host) { | 489 RenderWidgetHostImpl* render_widget_host) { |
490 delete this; | 490 // TODO(creis): Remove this method once we verify the shutdown path is sane. |
| 491 CHECK(!web_contents_); |
491 } | 492 } |
492 | 493 |
493 bool InterstitialPageImpl::PreHandleKeyboardEvent( | 494 bool InterstitialPageImpl::PreHandleKeyboardEvent( |
494 const NativeWebKeyboardEvent& event, | 495 const NativeWebKeyboardEvent& event, |
495 bool* is_keyboard_shortcut) { | 496 bool* is_keyboard_shortcut) { |
496 if (!enabled()) | 497 if (!enabled()) |
497 return false; | 498 return false; |
498 return render_widget_host_delegate_->PreHandleKeyboardEvent( | 499 return render_widget_host_delegate_->PreHandleKeyboardEvent( |
499 event, is_keyboard_shortcut); | 500 event, is_keyboard_shortcut); |
500 } | 501 } |
(...skipping 24 matching lines...) Expand all Loading... |
525 BrowserContext* browser_context = web_contents()->GetBrowserContext(); | 526 BrowserContext* browser_context = web_contents()->GetBrowserContext(); |
526 scoped_refptr<SiteInstance> site_instance = | 527 scoped_refptr<SiteInstance> site_instance = |
527 SiteInstance::Create(browser_context); | 528 SiteInstance::Create(browser_context); |
528 DOMStorageContextWrapper* dom_storage_context = | 529 DOMStorageContextWrapper* dom_storage_context = |
529 static_cast<DOMStorageContextWrapper*>( | 530 static_cast<DOMStorageContextWrapper*>( |
530 BrowserContext::GetStoragePartition( | 531 BrowserContext::GetStoragePartition( |
531 browser_context, site_instance.get())->GetDOMStorageContext()); | 532 browser_context, site_instance.get())->GetDOMStorageContext()); |
532 session_storage_namespace_ = | 533 session_storage_namespace_ = |
533 new SessionStorageNamespaceImpl(dom_storage_context); | 534 new SessionStorageNamespaceImpl(dom_storage_context); |
534 | 535 |
535 return RenderViewHostFactory::Create(site_instance.get(), | 536 // Use the RenderViewHost from our FrameTree. |
536 this, | 537 frame_tree_.root()->render_manager()->Init( |
537 this, | 538 browser_context, site_instance.get(), MSG_ROUTING_NONE, MSG_ROUTING_NONE); |
538 this, | 539 return frame_tree_.root()->current_frame_host()->render_view_host(); |
539 MSG_ROUTING_NONE, | |
540 MSG_ROUTING_NONE, | |
541 false, | |
542 false); | |
543 } | 540 } |
544 | 541 |
545 WebContentsView* InterstitialPageImpl::CreateWebContentsView() { | 542 WebContentsView* InterstitialPageImpl::CreateWebContentsView() { |
546 if (!enabled() || !create_view_) | 543 if (!enabled() || !create_view_) |
547 return NULL; | 544 return NULL; |
548 WebContentsView* web_contents_view = web_contents()->GetView(); | 545 WebContentsView* web_contents_view = web_contents()->GetView(); |
549 WebContentsViewPort* web_contents_view_port = | 546 WebContentsViewPort* web_contents_view_port = |
550 static_cast<WebContentsViewPort*>(web_contents_view); | 547 static_cast<WebContentsViewPort*>(web_contents_view); |
551 RenderWidgetHostView* view = | 548 RenderWidgetHostView* view = |
552 web_contents_view_port->CreateViewForWidget(render_view_host_); | 549 web_contents_view_port->CreateViewForWidget(render_view_host_); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 } | 747 } |
751 | 748 |
752 FrameTree* InterstitialPageImpl::GetFrameTree() { | 749 FrameTree* InterstitialPageImpl::GetFrameTree() { |
753 return &frame_tree_; | 750 return &frame_tree_; |
754 } | 751 } |
755 | 752 |
756 void InterstitialPageImpl::Disable() { | 753 void InterstitialPageImpl::Disable() { |
757 enabled_ = false; | 754 enabled_ = false; |
758 } | 755 } |
759 | 756 |
760 void InterstitialPageImpl::Shutdown(RenderViewHostImpl* render_view_host) { | 757 void InterstitialPageImpl::Shutdown() { |
761 render_view_host->Shutdown(); | 758 delete this; |
762 // We are deleted now. | |
763 } | 759 } |
764 | 760 |
765 void InterstitialPageImpl::OnNavigatingAwayOrTabClosing() { | 761 void InterstitialPageImpl::OnNavigatingAwayOrTabClosing() { |
766 if (action_taken_ == NO_ACTION) { | 762 if (action_taken_ == NO_ACTION) { |
767 // We are navigating away from the interstitial or closing a tab with an | 763 // We are navigating away from the interstitial or closing a tab with an |
768 // interstitial. Default to DontProceed(). We don't just call Hide as | 764 // interstitial. Default to DontProceed(). We don't just call Hide as |
769 // subclasses will almost certainly override DontProceed to do some work | 765 // subclasses will almost certainly override DontProceed to do some work |
770 // (ex: close pending connections). | 766 // (ex: close pending connections). |
771 DontProceed(); | 767 DontProceed(); |
772 } else { | 768 } else { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 | 851 |
856 web_contents->GetDelegateView()->TakeFocus(reverse); | 852 web_contents->GetDelegateView()->TakeFocus(reverse); |
857 } | 853 } |
858 | 854 |
859 void InterstitialPageImpl::InterstitialPageRVHDelegateView::OnFindReply( | 855 void InterstitialPageImpl::InterstitialPageRVHDelegateView::OnFindReply( |
860 int request_id, int number_of_matches, const gfx::Rect& selection_rect, | 856 int request_id, int number_of_matches, const gfx::Rect& selection_rect, |
861 int active_match_ordinal, bool final_update) { | 857 int active_match_ordinal, bool final_update) { |
862 } | 858 } |
863 | 859 |
864 } // namespace content | 860 } // namespace content |
OLD | NEW |