| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_contents/interstitial_page_impl.h" | 5 #include "content/browser/web_contents/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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 if (iter == g_web_contents_to_interstitial_page->end()) | 128 if (iter == g_web_contents_to_interstitial_page->end()) |
| 129 return NULL; | 129 return NULL; |
| 130 | 130 |
| 131 return iter->second; | 131 return iter->second; |
| 132 } | 132 } |
| 133 | 133 |
| 134 InterstitialPageImpl::InterstitialPageImpl(WebContents* web_contents, | 134 InterstitialPageImpl::InterstitialPageImpl(WebContents* web_contents, |
| 135 bool new_navigation, | 135 bool new_navigation, |
| 136 const GURL& url, | 136 const GURL& url, |
| 137 InterstitialPageDelegate* delegate) | 137 InterstitialPageDelegate* delegate) |
| 138 : web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 138 : WebContentsObserver(web_contents), |
| 139 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
| 139 url_(url), | 140 url_(url), |
| 140 new_navigation_(new_navigation), | 141 new_navigation_(new_navigation), |
| 141 should_discard_pending_nav_entry_(new_navigation), | 142 should_discard_pending_nav_entry_(new_navigation), |
| 142 reload_on_dont_proceed_(false), | 143 reload_on_dont_proceed_(false), |
| 143 enabled_(true), | 144 enabled_(true), |
| 144 action_taken_(NO_ACTION), | 145 action_taken_(NO_ACTION), |
| 145 render_view_host_(NULL), | 146 render_view_host_(NULL), |
| 146 original_child_id_(web_contents->GetRenderProcessHost()->GetID()), | 147 original_child_id_(web_contents->GetRenderProcessHost()->GetID()), |
| 147 original_rvh_id_(web_contents->GetRenderViewHost()->GetRoutingID()), | 148 original_rvh_id_(web_contents->GetRenderViewHost()->GetRoutingID()), |
| 148 should_revert_web_contents_title_(false), | 149 should_revert_web_contents_title_(false), |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 218 } |
| 218 | 219 |
| 219 DCHECK(!render_view_host_); | 220 DCHECK(!render_view_host_); |
| 220 render_view_host_ = static_cast<RenderViewHostImpl*>(CreateRenderViewHost()); | 221 render_view_host_ = static_cast<RenderViewHostImpl*>(CreateRenderViewHost()); |
| 221 CreateWebContentsView(); | 222 CreateWebContentsView(); |
| 222 | 223 |
| 223 std::string data_url = "data:text/html;charset=utf-8," + | 224 std::string data_url = "data:text/html;charset=utf-8," + |
| 224 net::EscapePath(delegate_->GetHTMLContents()); | 225 net::EscapePath(delegate_->GetHTMLContents()); |
| 225 render_view_host_->NavigateToURL(GURL(data_url)); | 226 render_view_host_->NavigateToURL(GURL(data_url)); |
| 226 | 227 |
| 227 notification_registrar_.Add(this, | |
| 228 NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
| 229 Source<WebContents>(web_contents_)); | |
| 230 notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_COMMITTED, | 228 notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 231 Source<NavigationController>(&web_contents_->GetController())); | 229 Source<NavigationController>(&web_contents_->GetController())); |
| 232 notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_PENDING, | 230 notification_registrar_.Add(this, NOTIFICATION_NAV_ENTRY_PENDING, |
| 233 Source<NavigationController>(&web_contents_->GetController())); | 231 Source<NavigationController>(&web_contents_->GetController())); |
| 234 notification_registrar_.Add( | 232 notification_registrar_.Add( |
| 235 this, NOTIFICATION_DOM_OPERATION_RESPONSE, | 233 this, NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 236 Source<RenderViewHost>(render_view_host_)); | 234 Source<RenderViewHost>(render_view_host_)); |
| 237 } | 235 } |
| 238 | 236 |
| 239 void InterstitialPageImpl::Hide() { | 237 void InterstitialPageImpl::Hide() { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 // closed); make sure we clear the blocked requests. | 315 // closed); make sure we clear the blocked requests. |
| 318 RenderViewHost* rvh = static_cast<RenderViewHost*>( | 316 RenderViewHost* rvh = static_cast<RenderViewHost*>( |
| 319 static_cast<RenderViewHostImpl*>( | 317 static_cast<RenderViewHostImpl*>( |
| 320 RenderWidgetHostImpl::From( | 318 RenderWidgetHostImpl::From( |
| 321 Source<RenderWidgetHost>(source).ptr()))); | 319 Source<RenderWidgetHost>(source).ptr()))); |
| 322 DCHECK(rvh->GetProcess()->GetID() == original_child_id_ && | 320 DCHECK(rvh->GetProcess()->GetID() == original_child_id_ && |
| 323 rvh->GetRoutingID() == original_rvh_id_); | 321 rvh->GetRoutingID() == original_rvh_id_); |
| 324 TakeActionOnResourceDispatcher(CANCEL); | 322 TakeActionOnResourceDispatcher(CANCEL); |
| 325 } | 323 } |
| 326 break; | 324 break; |
| 327 case NOTIFICATION_WEB_CONTENTS_DESTROYED: | |
| 328 case NOTIFICATION_NAV_ENTRY_COMMITTED: | 325 case NOTIFICATION_NAV_ENTRY_COMMITTED: |
| 329 if (action_taken_ == NO_ACTION) { | 326 OnNavigatingAwayOrTabClosing(); |
| 330 // We are navigating away from the interstitial or closing a tab with an | |
| 331 // interstitial. Default to DontProceed(). We don't just call Hide as | |
| 332 // subclasses will almost certainly override DontProceed to do some work | |
| 333 // (ex: close pending connections). | |
| 334 DontProceed(); | |
| 335 } else { | |
| 336 // User decided to proceed and either the navigation was committed or | |
| 337 // the tab was closed before that. | |
| 338 Hide(); | |
| 339 } | |
| 340 break; | 327 break; |
| 341 case NOTIFICATION_DOM_OPERATION_RESPONSE: | 328 case NOTIFICATION_DOM_OPERATION_RESPONSE: |
| 342 if (enabled()) { | 329 if (enabled()) { |
| 343 Details<DomOperationNotificationDetails> dom_op_details( | 330 Details<DomOperationNotificationDetails> dom_op_details( |
| 344 details); | 331 details); |
| 345 delegate_->CommandReceived(dom_op_details->json); | 332 delegate_->CommandReceived(dom_op_details->json); |
| 346 } | 333 } |
| 347 break; | 334 break; |
| 348 default: | 335 default: |
| 349 NOTREACHED(); | 336 NOTREACHED(); |
| 350 } | 337 } |
| 351 } | 338 } |
| 352 | 339 |
| 340 void InterstitialPageImpl::WebContentsDestroyed(WebContents* web_contents) { |
| 341 OnNavigatingAwayOrTabClosing(); |
| 342 } |
| 343 |
| 353 RenderViewHostDelegateView* InterstitialPageImpl::GetDelegateView() { | 344 RenderViewHostDelegateView* InterstitialPageImpl::GetDelegateView() { |
| 354 return rvh_delegate_view_.get(); | 345 return rvh_delegate_view_.get(); |
| 355 } | 346 } |
| 356 | 347 |
| 357 const GURL& InterstitialPageImpl::GetURL() const { | 348 const GURL& InterstitialPageImpl::GetURL() const { |
| 358 return url_; | 349 return url_; |
| 359 } | 350 } |
| 360 | 351 |
| 361 void InterstitialPageImpl::RenderViewTerminated( | 352 void InterstitialPageImpl::RenderViewTerminated( |
| 362 RenderViewHost* render_view_host, | 353 RenderViewHost* render_view_host, |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 | 705 |
| 715 void InterstitialPageImpl::Disable() { | 706 void InterstitialPageImpl::Disable() { |
| 716 enabled_ = false; | 707 enabled_ = false; |
| 717 } | 708 } |
| 718 | 709 |
| 719 void InterstitialPageImpl::Shutdown(RenderViewHostImpl* render_view_host) { | 710 void InterstitialPageImpl::Shutdown(RenderViewHostImpl* render_view_host) { |
| 720 render_view_host->Shutdown(); | 711 render_view_host->Shutdown(); |
| 721 // We are deleted now. | 712 // We are deleted now. |
| 722 } | 713 } |
| 723 | 714 |
| 715 void InterstitialPageImpl::OnNavigatingAwayOrTabClosing() { |
| 716 if (action_taken_ == NO_ACTION) { |
| 717 // We are navigating away from the interstitial or closing a tab with an |
| 718 // interstitial. Default to DontProceed(). We don't just call Hide as |
| 719 // subclasses will almost certainly override DontProceed to do some work |
| 720 // (ex: close pending connections). |
| 721 DontProceed(); |
| 722 } else { |
| 723 // User decided to proceed and either the navigation was committed or |
| 724 // the tab was closed before that. |
| 725 Hide(); |
| 726 } |
| 727 } |
| 728 |
| 724 void InterstitialPageImpl::TakeActionOnResourceDispatcher( | 729 void InterstitialPageImpl::TakeActionOnResourceDispatcher( |
| 725 ResourceRequestAction action) { | 730 ResourceRequestAction action) { |
| 726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)) << | 731 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)) << |
| 727 "TakeActionOnResourceDispatcher should be called on the main thread."; | 732 "TakeActionOnResourceDispatcher should be called on the main thread."; |
| 728 | 733 |
| 729 if (action == CANCEL || action == RESUME) { | 734 if (action == CANCEL || action == RESUME) { |
| 730 if (resource_dispatcher_host_notified_) | 735 if (resource_dispatcher_host_notified_) |
| 731 return; | 736 return; |
| 732 resource_dispatcher_host_notified_ = true; | 737 resource_dispatcher_host_notified_ = true; |
| 733 } | 738 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 | 805 |
| 801 web_contents->GetDelegateView()->TakeFocus(reverse); | 806 web_contents->GetDelegateView()->TakeFocus(reverse); |
| 802 } | 807 } |
| 803 | 808 |
| 804 void InterstitialPageImpl::InterstitialPageRVHDelegateView::OnFindReply( | 809 void InterstitialPageImpl::InterstitialPageRVHDelegateView::OnFindReply( |
| 805 int request_id, int number_of_matches, const gfx::Rect& selection_rect, | 810 int request_id, int number_of_matches, const gfx::Rect& selection_rect, |
| 806 int active_match_ordinal, bool final_update) { | 811 int active_match_ordinal, bool final_update) { |
| 807 } | 812 } |
| 808 | 813 |
| 809 } // namespace content | 814 } // namespace content |
| OLD | NEW |