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

Side by Side Diff: content/browser/tab_contents/interstitial_page_impl.cc

Issue 9473001: Extract minimal RenderViewHost interface for embedders, leaving (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to LKGR. Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
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/tab_contents/interstitial_page_impl.h" 5 #include "content/browser/tab_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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 InterstitialPageDelegate* delegate) 162 InterstitialPageDelegate* delegate)
163 : tab_(static_cast<TabContents*>(tab)), 163 : tab_(static_cast<TabContents*>(tab)),
164 url_(url), 164 url_(url),
165 new_navigation_(new_navigation), 165 new_navigation_(new_navigation),
166 should_discard_pending_nav_entry_(new_navigation), 166 should_discard_pending_nav_entry_(new_navigation),
167 reload_on_dont_proceed_(false), 167 reload_on_dont_proceed_(false),
168 enabled_(true), 168 enabled_(true),
169 action_taken_(NO_ACTION), 169 action_taken_(NO_ACTION),
170 render_view_host_(NULL), 170 render_view_host_(NULL),
171 original_child_id_(tab->GetRenderProcessHost()->GetID()), 171 original_child_id_(tab->GetRenderProcessHost()->GetID()),
172 original_rvh_id_(tab->GetRenderViewHost()->routing_id()), 172 original_rvh_id_(tab->GetRenderViewHost()->GetRoutingID()),
173 should_revert_tab_title_(false), 173 should_revert_tab_title_(false),
174 tab_was_loading_(false), 174 tab_was_loading_(false),
175 resource_dispatcher_host_notified_(false), 175 resource_dispatcher_host_notified_(false),
176 ALLOW_THIS_IN_INITIALIZER_LIST(rvh_view_delegate_( 176 ALLOW_THIS_IN_INITIALIZER_LIST(rvh_view_delegate_(
177 new InterstitialPageRVHViewDelegate(this))), 177 new InterstitialPageRVHViewDelegate(this))),
178 create_view_(true), 178 create_view_(true),
179 delegate_(delegate) { 179 delegate_(delegate) {
180 InitInterstitialPageMap(); 180 InitInterstitialPageMap();
181 // It would be inconsistent to create an interstitial with no new navigation 181 // It would be inconsistent to create an interstitial with no new navigation
182 // (which is the case when the interstitial was triggered by a sub-resource on 182 // (which is the case when the interstitial was triggered by a sub-resource on
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 entry->SetVirtualURL(url_); 233 entry->SetVirtualURL(url_);
234 entry->set_page_type(content::PAGE_TYPE_INTERSTITIAL); 234 entry->set_page_type(content::PAGE_TYPE_INTERSTITIAL);
235 235
236 // Give delegates a chance to set some states on the navigation entry. 236 // Give delegates a chance to set some states on the navigation entry.
237 delegate_->OverrideEntry(entry); 237 delegate_->OverrideEntry(entry);
238 238
239 tab_->GetControllerImpl().AddTransientEntry(entry); 239 tab_->GetControllerImpl().AddTransientEntry(entry);
240 } 240 }
241 241
242 DCHECK(!render_view_host_); 242 DCHECK(!render_view_host_);
243 render_view_host_ = CreateRenderViewHost(); 243 render_view_host_ = static_cast<RenderViewHostImpl*>(CreateRenderViewHost());
244 CreateWebContentsView(); 244 CreateWebContentsView();
245 245
246 std::string data_url = "data:text/html;charset=utf-8," + 246 std::string data_url = "data:text/html;charset=utf-8," +
247 net::EscapePath(delegate_->GetHTMLContents()); 247 net::EscapePath(delegate_->GetHTMLContents());
248 render_view_host_->NavigateToURL(GURL(data_url)); 248 render_view_host_->NavigateToURL(GURL(data_url));
249 249
250 notification_registrar_.Add(this, 250 notification_registrar_.Add(this,
251 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 251 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
252 content::Source<WebContents>(tab_)); 252 content::Source<WebContents>(tab_));
253 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 253 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
254 content::Source<NavigationController>(&tab_->GetController())); 254 content::Source<NavigationController>(&tab_->GetController()));
255 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, 255 notification_registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING,
256 content::Source<NavigationController>(&tab_->GetController())); 256 content::Source<NavigationController>(&tab_->GetController()));
257 notification_registrar_.Add( 257 notification_registrar_.Add(
258 this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, 258 this, content::NOTIFICATION_DOM_OPERATION_RESPONSE,
259 content::Source<RenderViewHost>(render_view_host_)); 259 content::Source<RenderViewHost>(render_view_host_));
260 } 260 }
261 261
262 void InterstitialPageImpl::Hide() { 262 void InterstitialPageImpl::Hide() {
263 RenderWidgetHostView* old_view = tab_->GetRenderViewHost()->view(); 263 RenderWidgetHostView* old_view = tab_->GetRenderViewHost()->GetView();
264 if (tab_->GetInterstitialPage() == this && 264 if (tab_->GetInterstitialPage() == this &&
265 old_view && !old_view->IsShowing()) { 265 old_view && !old_view->IsShowing()) {
266 // Show the original RVH since we're going away. Note it might not exist if 266 // Show the original RVH since we're going away. Note it might not exist if
267 // the renderer crashed while the interstitial was showing. 267 // the renderer crashed while the interstitial was showing.
268 // Note that it is important that we don't call Show() if the view is 268 // Note that it is important that we don't call Show() if the view is
269 // already showing. That would result in bad things (unparented HWND on 269 // already showing. That would result in bad things (unparented HWND on
270 // Windows for example) happening. 270 // Windows for example) happening.
271 old_view->Show(); 271 old_view->Show();
272 } 272 }
273 273
274 // If the focus was on the interstitial, let's keep it to the page. 274 // If the focus was on the interstitial, let's keep it to the page.
275 // (Note that in unit-tests the RVH may not have a view). 275 // (Note that in unit-tests the RVH may not have a view).
276 if (render_view_host_->view() && render_view_host_->view()->HasFocus() && 276 if (render_view_host_->GetView() &&
277 tab_->GetRenderViewHost()->view()) { 277 render_view_host_->GetView()->HasFocus() &&
278 tab_->GetRenderViewHost()->GetView()) {
278 RenderWidgetHostViewPort::FromRWHV( 279 RenderWidgetHostViewPort::FromRWHV(
279 tab_->GetRenderViewHost()->view())->Focus(); 280 tab_->GetRenderViewHost()->GetView())->Focus();
280 } 281 }
281 282
282 render_view_host_->Shutdown(); 283 render_view_host_->Shutdown();
283 render_view_host_ = NULL; 284 render_view_host_ = NULL;
284 if (tab_->GetInterstitialPage()) 285 if (tab_->GetInterstitialPage())
285 tab_->remove_interstitial_page(); 286 tab_->remove_interstitial_page();
286 // Let's revert to the original title if necessary. 287 // Let's revert to the original title if necessary.
287 NavigationEntry* entry = tab_->GetController().GetActiveEntry(); 288 NavigationEntry* entry = tab_->GetController().GetActiveEntry();
288 if (!new_navigation_ && should_revert_tab_title_) { 289 if (!new_navigation_ && should_revert_tab_title_) {
289 entry->SetTitle(original_tab_title_); 290 entry->SetTitle(original_tab_title_);
(...skipping 27 matching lines...) Expand all
317 // request won't be blocked if the same RenderViewHost was used for the 318 // request won't be blocked if the same RenderViewHost was used for the
318 // new navigation. 319 // new navigation.
319 Disable(); 320 Disable();
320 TakeActionOnResourceDispatcher(CANCEL); 321 TakeActionOnResourceDispatcher(CANCEL);
321 break; 322 break;
322 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: 323 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED:
323 if (action_taken_ == NO_ACTION) { 324 if (action_taken_ == NO_ACTION) {
324 // The RenderViewHost is being destroyed (as part of the tab being 325 // The RenderViewHost is being destroyed (as part of the tab being
325 // closed); make sure we clear the blocked requests. 326 // closed); make sure we clear the blocked requests.
326 RenderViewHost* rvh = static_cast<RenderViewHost*>( 327 RenderViewHost* rvh = static_cast<RenderViewHost*>(
327 content::Source<RenderWidgetHost>(source).ptr()); 328 static_cast<RenderViewHostImpl*>(
328 DCHECK(rvh->process()->GetID() == original_child_id_ && 329 RenderWidgetHostImpl::From(
329 rvh->routing_id() == original_rvh_id_); 330 content::Source<RenderWidgetHost>(source).ptr())));
331 DCHECK(rvh->GetProcess()->GetID() == original_child_id_ &&
332 rvh->GetRoutingID() == original_rvh_id_);
330 TakeActionOnResourceDispatcher(CANCEL); 333 TakeActionOnResourceDispatcher(CANCEL);
331 } 334 }
332 break; 335 break;
333 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: 336 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
334 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: 337 case content::NOTIFICATION_NAV_ENTRY_COMMITTED:
335 if (action_taken_ == NO_ACTION) { 338 if (action_taken_ == NO_ACTION) {
336 // We are navigating away from the interstitial or closing a tab with an 339 // We are navigating away from the interstitial or closing a tab with an
337 // interstitial. Default to DontProceed(). We don't just call Hide as 340 // interstitial. Default to DontProceed(). We don't just call Hide as
338 // subclasses will almost certainly override DontProceed to do some work 341 // subclasses will almost certainly override DontProceed to do some work
339 // (ex: close pending connections). 342 // (ex: close pending connections).
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (!enabled_) { 385 if (!enabled_) {
383 DontProceed(); 386 DontProceed();
384 return; 387 return;
385 } 388 }
386 if (params.transition == content::PAGE_TRANSITION_AUTO_SUBFRAME) { 389 if (params.transition == content::PAGE_TRANSITION_AUTO_SUBFRAME) {
387 // No need to handle navigate message from iframe in the interstitial page. 390 // No need to handle navigate message from iframe in the interstitial page.
388 return; 391 return;
389 } 392 }
390 393
391 // The RenderViewHost has loaded its contents, we can show it now. 394 // The RenderViewHost has loaded its contents, we can show it now.
392 render_view_host_->view()->Show(); 395 render_view_host_->GetView()->Show();
393 tab_->set_interstitial_page(this); 396 tab_->set_interstitial_page(this);
394 397
395 // This notification hides the bookmark bar. Note that this has to happen 398 // This notification hides the bookmark bar. Note that this has to happen
396 // after the interstitial page was registered with |tab_|, since there will be 399 // after the interstitial page was registered with |tab_|, since there will be
397 // a callback to |tab_| testing if an interstitial page is showing before 400 // a callback to |tab_| testing if an interstitial page is showing before
398 // hiding the bookmark bar. 401 // hiding the bookmark bar.
399 content::NotificationService::current()->Notify( 402 content::NotificationService::current()->Notify(
400 content::NOTIFICATION_INTERSTITIAL_ATTACHED, 403 content::NOTIFICATION_INTERSTITIAL_ATTACHED,
401 content::Source<WebContents>(tab_), 404 content::Source<WebContents>(tab_),
402 content::NotificationService::NoDetails()); 405 content::NotificationService::NoDetails());
403 406
404 RenderWidgetHostView* rwh_view = tab_->GetRenderViewHost()->view(); 407 RenderWidgetHostView* rwh_view = tab_->GetRenderViewHost()->GetView();
405 408
406 // The RenderViewHost may already have crashed before we even get here. 409 // The RenderViewHost may already have crashed before we even get here.
407 if (rwh_view) { 410 if (rwh_view) {
408 // If the page has focus, focus the interstitial. 411 // If the page has focus, focus the interstitial.
409 if (rwh_view->HasFocus()) 412 if (rwh_view->HasFocus())
410 Focus(); 413 Focus();
411 414
412 // Hide the original RVH since we're showing the interstitial instead. 415 // Hide the original RVH since we're showing the interstitial instead.
413 rwh_view->Hide(); 416 rwh_view->Hide();
414 } 417 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 void InterstitialPageImpl::HandleKeyboardEvent( 476 void InterstitialPageImpl::HandleKeyboardEvent(
474 const NativeWebKeyboardEvent& event) { 477 const NativeWebKeyboardEvent& event) {
475 return tab_->HandleKeyboardEvent(event); 478 return tab_->HandleKeyboardEvent(event);
476 } 479 }
477 480
478 WebContents* InterstitialPageImpl::tab() const { 481 WebContents* InterstitialPageImpl::tab() const {
479 return tab_; 482 return tab_;
480 } 483 }
481 484
482 RenderViewHost* InterstitialPageImpl::CreateRenderViewHost() { 485 RenderViewHost* InterstitialPageImpl::CreateRenderViewHost() {
483 RenderViewHost* render_view_host = new RenderViewHost( 486 RenderViewHostImpl* render_view_host = new RenderViewHostImpl(
484 SiteInstance::Create(tab()->GetBrowserContext()), 487 SiteInstance::Create(tab()->GetBrowserContext()),
485 this, MSG_ROUTING_NONE, kInvalidSessionStorageNamespaceId); 488 this, MSG_ROUTING_NONE, kInvalidSessionStorageNamespaceId);
486 return render_view_host; 489 return render_view_host;
487 } 490 }
488 491
489 WebContentsView* InterstitialPageImpl::CreateWebContentsView() { 492 WebContentsView* InterstitialPageImpl::CreateWebContentsView() {
490 if (!create_view_) 493 if (!create_view_)
491 return NULL; 494 return NULL;
492 WebContentsView* web_contents_view = tab()->GetView(); 495 WebContentsView* web_contents_view = tab()->GetView();
493 RenderWidgetHostView* view = 496 RenderWidgetHostView* view =
494 web_contents_view->CreateViewForWidget(render_view_host_); 497 web_contents_view->CreateViewForWidget(render_view_host_);
495 render_view_host_->SetView(view); 498 render_view_host_->SetView(view);
496 render_view_host_->AllowBindings(content::BINDINGS_POLICY_DOM_AUTOMATION); 499 render_view_host_->AllowBindings(content::BINDINGS_POLICY_DOM_AUTOMATION);
497 500
498 int32 max_page_id = 501 int32 max_page_id =
499 tab()->GetMaxPageIDForSiteInstance(render_view_host_->site_instance()); 502 tab()->GetMaxPageIDForSiteInstance(render_view_host_->GetSiteInstance());
500 render_view_host_->CreateRenderView(string16(), max_page_id); 503 render_view_host_->CreateRenderView(string16(), max_page_id);
501 view->SetSize(web_contents_view->GetContainerSize()); 504 view->SetSize(web_contents_view->GetContainerSize());
502 // Don't show the interstitial until we have navigated to it. 505 // Don't show the interstitial until we have navigated to it.
503 view->Hide(); 506 view->Hide();
504 return web_contents_view; 507 return web_contents_view;
505 } 508 }
506 509
507 void InterstitialPageImpl::Proceed() { 510 void InterstitialPageImpl::Proceed() {
508 if (action_taken_ != NO_ACTION) { 511 if (action_taken_ != NO_ACTION) {
509 NOTREACHED(); 512 NOTREACHED();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 if (new_navigation_) 583 if (new_navigation_)
581 TakeActionOnResourceDispatcher(RESUME); 584 TakeActionOnResourceDispatcher(RESUME);
582 else 585 else
583 TakeActionOnResourceDispatcher(CANCEL); 586 TakeActionOnResourceDispatcher(CANCEL);
584 } 587 }
585 588
586 void InterstitialPageImpl::SetSize(const gfx::Size& size) { 589 void InterstitialPageImpl::SetSize(const gfx::Size& size) {
587 #if !defined(OS_MACOSX) 590 #if !defined(OS_MACOSX)
588 // When a tab is closed, we might be resized after our view was NULLed 591 // When a tab is closed, we might be resized after our view was NULLed
589 // (typically if there was an info-bar). 592 // (typically if there was an info-bar).
590 if (render_view_host_->view()) 593 if (render_view_host_->GetView())
591 render_view_host_->view()->SetSize(size); 594 render_view_host_->GetView()->SetSize(size);
592 #else 595 #else
593 // TODO(port): Does Mac need to SetSize? 596 // TODO(port): Does Mac need to SetSize?
594 NOTIMPLEMENTED(); 597 NOTIMPLEMENTED();
595 #endif 598 #endif
596 } 599 }
597 600
598 void InterstitialPageImpl::Focus() { 601 void InterstitialPageImpl::Focus() {
599 // Focus the native window. 602 // Focus the native window.
600 RenderWidgetHostViewPort::FromRWHV(render_view_host_->view())->Focus(); 603 RenderWidgetHostViewPort::FromRWHV(render_view_host_->GetView())->Focus();
601 } 604 }
602 605
603 void InterstitialPageImpl::FocusThroughTabTraversal(bool reverse) { 606 void InterstitialPageImpl::FocusThroughTabTraversal(bool reverse) {
604 render_view_host_->SetInitialFocus(reverse); 607 render_view_host_->SetInitialFocus(reverse);
605 } 608 }
606 609
607 RenderViewHost* InterstitialPageImpl::GetRenderViewHostForTesting() const { 610 RenderViewHost* InterstitialPageImpl::GetRenderViewHostForTesting() const {
608 return render_view_host_; 611 return render_view_host_;
609 } 612 }
610 613
(...skipping 26 matching lines...) Expand all
637 if (resource_dispatcher_host_notified_) 640 if (resource_dispatcher_host_notified_)
638 return; 641 return;
639 resource_dispatcher_host_notified_ = true; 642 resource_dispatcher_host_notified_ = true;
640 } 643 }
641 644
642 // The tab might not have a render_view_host if it was closed (in which case, 645 // The tab might not have a render_view_host if it was closed (in which case,
643 // we have taken care of the blocked requests when processing 646 // we have taken care of the blocked requests when processing
644 // NOTIFY_RENDER_WIDGET_HOST_DESTROYED. 647 // NOTIFY_RENDER_WIDGET_HOST_DESTROYED.
645 // Also we need to test there is a ResourceDispatcherHost, as when unit-tests 648 // Also we need to test there is a ResourceDispatcherHost, as when unit-tests
646 // we don't have one. 649 // we don't have one.
647 RenderViewHost* rvh = RenderViewHost::FromID(original_child_id_, 650 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(original_child_id_,
648 original_rvh_id_); 651 original_rvh_id_);
649 if (!rvh || !ResourceDispatcherHost::Get()) 652 if (!rvh || !ResourceDispatcherHost::Get())
650 return; 653 return;
651 654
652 BrowserThread::PostTask( 655 BrowserThread::PostTask(
653 BrowserThread::IO, 656 BrowserThread::IO,
654 FROM_HERE, 657 FROM_HERE,
655 base::Bind( 658 base::Bind(
656 &ResourceRequestHelper, 659 &ResourceRequestHelper,
657 ResourceDispatcherHost::Get(), 660 ResourceDispatcherHost::Get(),
658 original_child_id_, 661 original_child_id_,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 if (!tab->GetViewDelegate()) 739 if (!tab->GetViewDelegate())
737 return; 740 return;
738 741
739 tab->GetViewDelegate()->TakeFocus(reverse); 742 tab->GetViewDelegate()->TakeFocus(reverse);
740 } 743 }
741 744
742 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::OnFindReply( 745 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::OnFindReply(
743 int request_id, int number_of_matches, const gfx::Rect& selection_rect, 746 int request_id, int number_of_matches, const gfx::Rect& selection_rect,
744 int active_match_ordinal, bool final_update) { 747 int active_match_ordinal, bool final_update) {
745 } 748 }
OLDNEW
« no previous file with comments | « content/browser/tab_contents/interstitial_page_impl.h ('k') | content/browser/tab_contents/navigation_controller_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698