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

Side by Side Diff: chrome/browser/instant/instant_loader.cc

Issue 7034043: Prerender/Instant interopability. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup and consolidate code Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/instant/instant_loader.h" 5 #include "chrome/browser/instant/instant_loader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 host->Send(new ViewMsg_DetermineIfPageSupportsInstant( 132 host->Send(new ViewMsg_DetermineIfPageSupportsInstant(
133 host->routing_id(), text_, verbatim_, text_length, text_length)); 133 host->routing_id(), text_, verbatim_, text_length, text_length));
134 break; 134 break;
135 } 135 }
136 default: 136 default:
137 NOTREACHED(); 137 NOTREACHED();
138 break; 138 break;
139 } 139 }
140 } 140 }
141 141
142 // If this is being called, something is swapping in to our preview_contents_
143 // before we've added it to the tab strip.
144 void InstantLoader::SwapTabContents(TabContentsWrapper* old_tc,
145 TabContentsWrapper* new_tc) {
146 DCHECK(old_tc == preview_contents_);
147 // We release here without deleting so that the caller still has reponsibility
148 // for deleting the TabContentsWrapper.
149 ignore_result(preview_contents_.release());
150 preview_contents_.reset(new_tc);
151
152 // Make sure the new preview contents acts like the old one.
153 SetupPreviewContents(old_tc);
154
155 // Cleanup the old preview contents.
156 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.
157
158 #if defined(OS_MACOSX)
159 registrar_.Remove(this,
160 NotificationType::RENDER_VIEW_HOST_CHANGED,
161 Source<NavigationController>(&old_tc->controller()));
162 #endif
163 registrar_.Remove(this,
164 NotificationType::NAV_ENTRY_COMMITTED,
165 Source<NavigationController>(&old_tc->controller()));
166
167 // We prerendered so we should be ready to show.
168 ShowPreview();
169 }
170
142 // TabContentsDelegateImpl ----------------------------------------------------- 171 // TabContentsDelegateImpl -----------------------------------------------------
143 172
144 class InstantLoader::TabContentsDelegateImpl 173 class InstantLoader::TabContentsDelegateImpl
145 : public TabContentsDelegate, 174 : public TabContentsDelegate,
146 public NotificationObserver, 175 public NotificationObserver,
147 public TabContentsObserver, 176 public TabContentsObserver,
148 public DownloadTabHelperDelegate { 177 public DownloadTabHelperDelegate {
149 public: 178 public:
150 explicit TabContentsDelegateImpl(InstantLoader* loader); 179 explicit TabContentsDelegateImpl(InstantLoader* loader);
151 180
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 1013
985 if (preview_contents_.get() && is_showing_instant() && 1014 if (preview_contents_.get() && is_showing_instant() &&
986 (force_if_waiting || !is_waiting_for_load())) { 1015 (force_if_waiting || !is_waiting_for_load())) {
987 last_omnibox_bounds_ = omnibox_bounds_; 1016 last_omnibox_bounds_ = omnibox_bounds_;
988 RenderViewHost* host = preview_contents_->render_view_host(); 1017 RenderViewHost* host = preview_contents_->render_view_host();
989 host->Send(new ViewMsg_SearchBoxResize( 1018 host->Send(new ViewMsg_SearchBoxResize(
990 host->routing_id(), GetOmniboxBoundsInTermsOfPreview())); 1019 host->routing_id(), GetOmniboxBoundsInTermsOfPreview()));
991 } 1020 }
992 } 1021 }
993 1022
994 void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) { 1023 void InstantLoader::SetupPreviewContents(TabContentsWrapper* tab_contents) {
995 TabContents* new_contents = 1024 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.
996 new TabContents(
997 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
998 preview_contents_.reset(new TabContentsWrapper(new_contents));
sky 2011/05/20 15:57:36 You need to still install the delegate on the new
999 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true); 1025 preview_contents_->blocked_content_tab_helper()->SetAllContentsBlocked(true);
1026
1000 // Propagate the max page id. That way if we end up merging the two 1027 // Propagate the max page id. That way if we end up merging the two
1001 // NavigationControllers (which happens if we commit) none of the page ids 1028 // NavigationControllers (which happens if we commit) none of the page ids
1002 // will overlap. 1029 // will overlap.
1003 int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID(); 1030 int32 max_page_id = tab_contents->tab_contents()->GetMaxPageID();
1004 if (max_page_id != -1) 1031 if (max_page_id != -1)
1005 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1); 1032 preview_contents_->controller().set_max_restored_page_id(max_page_id + 1);
1006 1033
1007 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this));
1008 new_contents->set_delegate(preview_tab_contents_delegate_.get());
1009 preview_contents_->download_tab_helper()->set_delegate( 1034 preview_contents_->download_tab_helper()->set_delegate(
1010 preview_tab_contents_delegate_.get()); 1035 preview_tab_contents_delegate_.get());
1011 1036
1012 gfx::Rect tab_bounds;
1013 tab_contents->view()->GetContainerBounds(&tab_bounds);
1014 preview_contents_->view()->SizeContents(tab_bounds.size());
1015
1016 #if defined(OS_MACOSX) 1037 #if defined(OS_MACOSX)
1017 // If |preview_contents_| does not currently have a RWHV, we will call 1038 // If |preview_contents_| does not currently have a RWHV, we will call
1018 // SetTakesFocusOnlyOnMouseDown() as a result of the 1039 // SetTakesFocusOnlyOnMouseDown() as a result of the
1019 // RENDER_VIEW_HOST_CHANGED notification. 1040 // RENDER_VIEW_HOST_CHANGED notification.
1020 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) { 1041 if (preview_contents_->tab_contents()->GetRenderWidgetHostView()) {
1021 preview_contents_->tab_contents()->GetRenderWidgetHostView()-> 1042 preview_contents_->tab_contents()->GetRenderWidgetHostView()->
1022 SetTakesFocusOnlyOnMouseDown(true); 1043 SetTakesFocusOnlyOnMouseDown(true);
1023 } 1044 }
1024 registrar_.Add( 1045 registrar_.Add(
1025 this, 1046 this,
1026 NotificationType::RENDER_VIEW_HOST_CHANGED, 1047 NotificationType::RENDER_VIEW_HOST_CHANGED,
1027 Source<NavigationController>(&preview_contents_->controller())); 1048 Source<NavigationController>(&preview_contents_->controller()));
1028 #endif 1049 #endif
1029 1050
1030 registrar_.Add( 1051 registrar_.Add(
1031 this, 1052 this,
1032 NotificationType::NAV_ENTRY_COMMITTED, 1053 NotificationType::NAV_ENTRY_COMMITTED,
1033 Source<NavigationController>(&preview_contents_->controller())); 1054 Source<NavigationController>(&preview_contents_->controller()));
1034 1055
1056 gfx::Rect tab_bounds;
1057 tab_contents->view()->GetContainerBounds(&tab_bounds);
1058 preview_contents_->view()->SizeContents(tab_bounds.size());
1059 }
1060
1061 void InstantLoader::CreatePreviewContents(TabContentsWrapper* tab_contents) {
1062 TabContents* new_contents =
1063 new TabContents(
1064 tab_contents->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
1065 preview_contents_.reset(new TabContentsWrapper(new_contents));
1066 SetupPreviewContents(tab_contents);
1067 preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this));
1068 new_contents->set_delegate(preview_tab_contents_delegate_.get());
1069
1035 preview_contents_->tab_contents()->ShowContents(); 1070 preview_contents_->tab_contents()->ShowContents();
1036 } 1071 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698