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..83a4cb0d069e97aaa643b82c906c42f05612f383 100644 |
--- a/chrome/browser/instant/instant_loader.cc |
+++ b/chrome/browser/instant/instant_loader.cc |
@@ -139,6 +139,35 @@ void InstantLoader::FrameLoadObserver::Observe( |
} |
} |
+// If this is being called, something is swapping in to our preview_contents_ |
+// before we've added it to the tab strip. |
+void InstantLoader::SwapTabContents(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 15:57:36
unset it on the tabcontents, not the download help
dominich
2011/05/20 16:39:53
Both need to be done. Done.
|
+ |
+#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(); |
+} |
+ |
// TabContentsDelegateImpl ----------------------------------------------------- |
class InstantLoader::TabContentsDelegateImpl |
@@ -991,12 +1020,10 @@ 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)); |
sky
2011/05/20 15:57:36
You need to still install the delegate on the new
|
+void InstantLoader::SetupPreviewContents(TabContentsWrapper* tab_contents) { |
+ preview_contents_->set_delegate(this); |
sky
2011/05/20 15:57:36
You need to unset this some where.
dominich
2011/05/20 16:39:53
Done.
|
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. |
@@ -1004,15 +1031,9 @@ void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { |
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()); |
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 +1053,19 @@ 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)); |
+ SetupPreviewContents(tab_contents); |
+ preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); |
+ new_contents->set_delegate(preview_tab_contents_delegate_.get()); |
+ |
preview_contents_->tab_contents()->ShowContents(); |
} |