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

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: Ready for initial review. 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 content::Source<RenderWidgetHost>(source).ptr()->AsRWHImpl()));
329 rvh->routing_id() == original_rvh_id_); 330 DCHECK(rvh->GetProcess()->GetID() == original_child_id_ &&
331 rvh->GetRoutingID() == original_rvh_id_);
330 TakeActionOnResourceDispatcher(CANCEL); 332 TakeActionOnResourceDispatcher(CANCEL);
331 } 333 }
332 break; 334 break;
333 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: 335 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
334 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: 336 case content::NOTIFICATION_NAV_ENTRY_COMMITTED:
335 if (action_taken_ == NO_ACTION) { 337 if (action_taken_ == NO_ACTION) {
336 // We are navigating away from the interstitial or closing a tab with an 338 // 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 339 // interstitial. Default to DontProceed(). We don't just call Hide as
338 // subclasses will almost certainly override DontProceed to do some work 340 // subclasses will almost certainly override DontProceed to do some work
339 // (ex: close pending connections). 341 // (ex: close pending connections).
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (!enabled_) { 384 if (!enabled_) {
383 DontProceed(); 385 DontProceed();
384 return; 386 return;
385 } 387 }
386 if (params.transition == content::PAGE_TRANSITION_AUTO_SUBFRAME) { 388 if (params.transition == content::PAGE_TRANSITION_AUTO_SUBFRAME) {
387 // No need to handle navigate message from iframe in the interstitial page. 389 // No need to handle navigate message from iframe in the interstitial page.
388 return; 390 return;
389 } 391 }
390 392
391 // The RenderViewHost has loaded its contents, we can show it now. 393 // The RenderViewHost has loaded its contents, we can show it now.
392 render_view_host_->view()->Show(); 394 render_view_host_->GetView()->Show();
393 tab_->set_interstitial_page(this); 395 tab_->set_interstitial_page(this);
394 396
395 // This notification hides the bookmark bar. Note that this has to happen 397 // 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 398 // 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 399 // a callback to |tab_| testing if an interstitial page is showing before
398 // hiding the bookmark bar. 400 // hiding the bookmark bar.
399 content::NotificationService::current()->Notify( 401 content::NotificationService::current()->Notify(
400 content::NOTIFICATION_INTERSTITIAL_ATTACHED, 402 content::NOTIFICATION_INTERSTITIAL_ATTACHED,
401 content::Source<WebContents>(tab_), 403 content::Source<WebContents>(tab_),
402 content::NotificationService::NoDetails()); 404 content::NotificationService::NoDetails());
403 405
404 RenderWidgetHostView* rwh_view = tab_->GetRenderViewHost()->view(); 406 RenderWidgetHostView* rwh_view = tab_->GetRenderViewHost()->GetView();
405 407
406 // The RenderViewHost may already have crashed before we even get here. 408 // The RenderViewHost may already have crashed before we even get here.
407 if (rwh_view) { 409 if (rwh_view) {
408 // If the page has focus, focus the interstitial. 410 // If the page has focus, focus the interstitial.
409 if (rwh_view->HasFocus()) 411 if (rwh_view->HasFocus())
410 Focus(); 412 Focus();
411 413
412 // Hide the original RVH since we're showing the interstitial instead. 414 // Hide the original RVH since we're showing the interstitial instead.
413 rwh_view->Hide(); 415 rwh_view->Hide();
414 } 416 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 void InterstitialPageImpl::HandleKeyboardEvent( 475 void InterstitialPageImpl::HandleKeyboardEvent(
474 const NativeWebKeyboardEvent& event) { 476 const NativeWebKeyboardEvent& event) {
475 return tab_->HandleKeyboardEvent(event); 477 return tab_->HandleKeyboardEvent(event);
476 } 478 }
477 479
478 WebContents* InterstitialPageImpl::tab() const { 480 WebContents* InterstitialPageImpl::tab() const {
479 return tab_; 481 return tab_;
480 } 482 }
481 483
482 RenderViewHost* InterstitialPageImpl::CreateRenderViewHost() { 484 RenderViewHost* InterstitialPageImpl::CreateRenderViewHost() {
483 RenderViewHost* render_view_host = new RenderViewHost( 485 RenderViewHostImpl* render_view_host = new RenderViewHostImpl(
484 SiteInstance::Create(tab()->GetBrowserContext()), 486 SiteInstance::Create(tab()->GetBrowserContext()),
485 this, MSG_ROUTING_NONE, kInvalidSessionStorageNamespaceId); 487 this, MSG_ROUTING_NONE, kInvalidSessionStorageNamespaceId);
486 return render_view_host; 488 return render_view_host;
487 } 489 }
488 490
489 WebContentsView* InterstitialPageImpl::CreateWebContentsView() { 491 WebContentsView* InterstitialPageImpl::CreateWebContentsView() {
490 if (!create_view_) 492 if (!create_view_)
491 return NULL; 493 return NULL;
492 WebContentsView* web_contents_view = tab()->GetView(); 494 WebContentsView* web_contents_view = tab()->GetView();
493 RenderWidgetHostView* view = 495 RenderWidgetHostView* view =
494 web_contents_view->CreateViewForWidget(render_view_host_); 496 web_contents_view->CreateViewForWidget(render_view_host_);
495 render_view_host_->SetView(view); 497 render_view_host_->SetView(view);
496 render_view_host_->AllowBindings(content::BINDINGS_POLICY_DOM_AUTOMATION); 498 render_view_host_->AllowBindings(content::BINDINGS_POLICY_DOM_AUTOMATION);
497 499
498 int32 max_page_id = 500 int32 max_page_id =
499 tab()->GetMaxPageIDForSiteInstance(render_view_host_->site_instance()); 501 tab()->GetMaxPageIDForSiteInstance(render_view_host_->GetSiteInstance());
500 render_view_host_->CreateRenderView(string16(), max_page_id); 502 render_view_host_->CreateRenderView(string16(), max_page_id);
501 view->SetSize(web_contents_view->GetContainerSize()); 503 view->SetSize(web_contents_view->GetContainerSize());
502 // Don't show the interstitial until we have navigated to it. 504 // Don't show the interstitial until we have navigated to it.
503 view->Hide(); 505 view->Hide();
504 return web_contents_view; 506 return web_contents_view;
505 } 507 }
506 508
507 void InterstitialPageImpl::Proceed() { 509 void InterstitialPageImpl::Proceed() {
508 if (action_taken_ != NO_ACTION) { 510 if (action_taken_ != NO_ACTION) {
509 NOTREACHED(); 511 NOTREACHED();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 if (new_navigation_) 582 if (new_navigation_)
581 TakeActionOnResourceDispatcher(RESUME); 583 TakeActionOnResourceDispatcher(RESUME);
582 else 584 else
583 TakeActionOnResourceDispatcher(CANCEL); 585 TakeActionOnResourceDispatcher(CANCEL);
584 } 586 }
585 587
586 void InterstitialPageImpl::SetSize(const gfx::Size& size) { 588 void InterstitialPageImpl::SetSize(const gfx::Size& size) {
587 #if !defined(OS_MACOSX) 589 #if !defined(OS_MACOSX)
588 // When a tab is closed, we might be resized after our view was NULLed 590 // When a tab is closed, we might be resized after our view was NULLed
589 // (typically if there was an info-bar). 591 // (typically if there was an info-bar).
590 if (render_view_host_->view()) 592 if (render_view_host_->GetView())
591 render_view_host_->view()->SetSize(size); 593 render_view_host_->GetView()->SetSize(size);
592 #else 594 #else
593 // TODO(port): Does Mac need to SetSize? 595 // TODO(port): Does Mac need to SetSize?
594 NOTIMPLEMENTED(); 596 NOTIMPLEMENTED();
595 #endif 597 #endif
596 } 598 }
597 599
598 void InterstitialPageImpl::Focus() { 600 void InterstitialPageImpl::Focus() {
599 // Focus the native window. 601 // Focus the native window.
600 RenderWidgetHostViewPort::FromRWHV(render_view_host_->view())->Focus(); 602 RenderWidgetHostViewPort::FromRWHV(render_view_host_->GetView())->Focus();
601 } 603 }
602 604
603 void InterstitialPageImpl::FocusThroughTabTraversal(bool reverse) { 605 void InterstitialPageImpl::FocusThroughTabTraversal(bool reverse) {
604 render_view_host_->SetInitialFocus(reverse); 606 render_view_host_->SetInitialFocus(reverse);
605 } 607 }
606 608
607 RenderViewHost* InterstitialPageImpl::GetRenderViewHostForTesting() const { 609 RenderViewHost* InterstitialPageImpl::GetRenderViewHostForTesting() const {
608 return render_view_host_; 610 return render_view_host_;
609 } 611 }
610 612
(...skipping 26 matching lines...) Expand all
637 if (resource_dispatcher_host_notified_) 639 if (resource_dispatcher_host_notified_)
638 return; 640 return;
639 resource_dispatcher_host_notified_ = true; 641 resource_dispatcher_host_notified_ = true;
640 } 642 }
641 643
642 // The tab might not have a render_view_host if it was closed (in which case, 644 // 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 645 // we have taken care of the blocked requests when processing
644 // NOTIFY_RENDER_WIDGET_HOST_DESTROYED. 646 // NOTIFY_RENDER_WIDGET_HOST_DESTROYED.
645 // Also we need to test there is a ResourceDispatcherHost, as when unit-tests 647 // Also we need to test there is a ResourceDispatcherHost, as when unit-tests
646 // we don't have one. 648 // we don't have one.
647 RenderViewHost* rvh = RenderViewHost::FromID(original_child_id_, 649 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(original_child_id_,
648 original_rvh_id_); 650 original_rvh_id_);
649 if (!rvh || !ResourceDispatcherHost::Get()) 651 if (!rvh || !ResourceDispatcherHost::Get())
650 return; 652 return;
651 653
652 BrowserThread::PostTask( 654 BrowserThread::PostTask(
653 BrowserThread::IO, 655 BrowserThread::IO,
654 FROM_HERE, 656 FROM_HERE,
655 base::Bind( 657 base::Bind(
656 &ResourceRequestHelper, 658 &ResourceRequestHelper,
657 ResourceDispatcherHost::Get(), 659 ResourceDispatcherHost::Get(),
658 original_child_id_, 660 original_child_id_,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 if (!tab->GetViewDelegate()) 738 if (!tab->GetViewDelegate())
737 return; 739 return;
738 740
739 tab->GetViewDelegate()->TakeFocus(reverse); 741 tab->GetViewDelegate()->TakeFocus(reverse);
740 } 742 }
741 743
742 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::OnFindReply( 744 void InterstitialPageImpl::InterstitialPageRVHViewDelegate::OnFindReply(
743 int request_id, int number_of_matches, const gfx::Rect& selection_rect, 745 int request_id, int number_of_matches, const gfx::Rect& selection_rect,
744 int active_match_ordinal, bool final_update) { 746 int active_match_ordinal, bool final_update) {
745 } 747 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698