Chromium Code Reviews| Index: chrome/browser/instant/instant_loader.cc |
| diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc |
| index f686ecb88928eca1229c996078012340a2a1c702..104253ae4279b96444107190ad7215c28f76bb73 100644 |
| --- a/chrome/browser/instant/instant_loader.cc |
| +++ b/chrome/browser/instant/instant_loader.cc |
| @@ -35,6 +35,7 @@ |
| #include "content/browser/tab_contents/tab_contents.h" |
| #include "content/browser/tab_contents/tab_contents_delegate.h" |
| #include "content/browser/tab_contents/tab_contents_view.h" |
| +#include "content/common/content_constants.h" |
| #include "content/common/notification_details.h" |
| #include "content/common/notification_observer.h" |
| #include "content/common/notification_registrar.h" |
| @@ -143,6 +144,7 @@ void InstantLoader::FrameLoadObserver::Observe( |
| class InstantLoader::TabContentsDelegateImpl |
| : public TabContentsDelegate, |
| + public TabContentsWrapperDelegate, |
| public NotificationObserver, |
| public TabContentsObserver, |
| public DownloadTabHelperDelegate { |
| @@ -219,6 +221,10 @@ class InstantLoader::TabContentsDelegateImpl |
| NavigationType::Type navigation_type) OVERRIDE; |
| virtual bool ShouldShowHungRendererDialog() OVERRIDE; |
| + // TabContentsWrapperDelegate: |
| + virtual void SwapTabContents(TabContentsWrapper* old_tc, |
| + TabContentsWrapper* new_tc) OVERRIDE; |
| + |
| // TabContentsObserver: |
| virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| @@ -550,6 +556,15 @@ bool InstantLoader::TabContentsDelegateImpl::ShouldShowHungRendererDialog() { |
| return false; |
| } |
| +// If this is being called, something is swapping in to our preview_contents_ |
| +// before we've added it to the tab strip. |
| +void InstantLoader::TabContentsDelegateImpl::SwapTabContents( |
| + TabContentsWrapper* old_tc, |
| + TabContentsWrapper* new_tc) { |
| + loader_->ReplacePreviewContents(old_tc, new_tc); |
| +} |
| + |
| + |
| bool InstantLoader::TabContentsDelegateImpl::OnMessageReceived( |
| const IPC::Message& message) { |
| bool handled = true; |
| @@ -991,28 +1006,51 @@ void InstantLoader::SendBoundsToPage(bool force_if_waiting) { |
| } |
| } |
| -void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { |
| - TabContents* new_contents = |
| - new TabContents( |
| - tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
| - preview_contents_.reset(new TabContentsWrapper(new_contents)); |
| +void InstantLoader::ReplacePreviewContents(TabContentsWrapper* old_tc, |
| + TabContentsWrapper* new_tc) { |
| + DCHECK(old_tc == preview_contents_); |
| + // We release here without deleting so that the caller still has reponsibility |
| + // for deleting the TabContentsWrapper. |
| + ignore_result(preview_contents_.release()); |
| + preview_contents_.reset(new_tc); |
| + |
| + // Make sure the new preview contents acts like the old one. |
| + SetupPreviewContents(old_tc); |
| + |
| + // Cleanup the old preview contents. |
| + old_tc->download_tab_helper()->set_delegate(NULL); |
|
sky
2011/05/20 18:54:19
Why do you need to reset the download_tab_helper d
dominich
2011/05/20 23:22:34
It's set to the preview_tab_contents_delegate_ and
sky
2011/05/20 23:38:33
I see it. Sorry.
|
| + old_tc->tab_contents()->set_delegate(NULL); |
| + old_tc->set_delegate(NULL); |
| + |
| +#if defined(OS_MACOSX) |
| + registrar_.Remove(this, |
| + NotificationType::RENDER_VIEW_HOST_CHANGED, |
| + Source<NavigationController>(&old_tc->controller())); |
| +#endif |
| + registrar_.Remove(this, |
| + NotificationType::NAV_ENTRY_COMMITTED, |
| + Source<NavigationController>(&old_tc->controller())); |
| + |
| + // We prerendered so we should be ready to show. |
| + ShowPreview(); |
|
sky
2011/05/20 18:54:19
If the tabcontents was already showing then the Sh
sky
2011/05/20 19:45:09
To deal with this you'll likely want to add a new
dominich
2011/05/20 23:22:34
When would this happen though? If we're swapping i
sky
2011/05/20 23:38:33
Is that always the case? Lets say foo.com is prere
|
| +} |
| + |
| +void InstantLoader::SetupPreviewContents(TabContentsWrapper* tab_contents) { |
| + preview_contents_->set_delegate(preview_tab_contents_delegate_.get()); |
| + preview_contents_->tab_contents()->set_delegate( |
| + preview_tab_contents_delegate_.get()); |
| preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); |
| - // Propagate the max page id. That way if we end up merging the two |
| - // NavigationControllers (which happens if we commit) none of the page ids |
| - // will overlap. |
| - int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID(); |
| - if (max_page_id != -1) |
| - preview_contents_->controller().set_max_restored_page_id(max_page_id + 1); |
| - preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); |
| - new_contents->set_delegate(preview_tab_contents_delegate_.get()); |
| + // Set the max page id to one greater than the largest we can ever have. |
| + // That way if we end up merging the two NavigationControllers (which happens |
| + // if we commit) none of the page ids will overlap irregardless of how many |
| + // tabs have been opened in the mean-time. |
| + preview_contents_->controller().set_max_restored_page_id( |
| + content::kMaxSessionHistoryEntries + 1); |
| + |
| preview_contents_->download_tab_helper()->set_delegate( |
| preview_tab_contents_delegate_.get()); |
| - gfx::Rect tab_bounds; |
| - tab_contents->view()->GetContainerBounds(&tab_bounds); |
| - preview_contents_->view()->SizeContents(tab_bounds.size()); |
| - |
| #if defined(OS_MACOSX) |
| // If |preview_contents_| does not currently have a RWHV, we will call |
| // SetTakesFocusOnlyOnMouseDown() as a result of the |
| @@ -1032,5 +1070,18 @@ void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { |
| NotificationType::NAV_ENTRY_COMMITTED, |
| Source<NavigationController>(&preview_contents_->controller())); |
| + gfx::Rect tab_bounds; |
| + tab_contents->view()->GetContainerBounds(&tab_bounds); |
| + preview_contents_->view()->SizeContents(tab_bounds.size()); |
| +} |
| + |
| +void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { |
| + TabContents* new_contents = |
| + new TabContents( |
| + tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
| + preview_contents_.reset(new TabContentsWrapper(new_contents)); |
| + preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); |
| + SetupPreviewContents(tab_contents); |
| + |
| preview_contents_->tab_contents()->ShowContents(); |
| } |