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

Unified Diff: chrome/browser/ui/browser_instant_controller.cc

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup. Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/browser_instant_controller.cc
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc
index 7abe3aa900015a2cc93088f32a243fdf112b7983..f162b41d57e339ae54f9cf09d980de9b60f4fa32 100644
--- a/chrome/browser/ui/browser_instant_controller.cc
+++ b/chrome/browser/ui/browser_instant_controller.cc
@@ -78,6 +78,29 @@ void BrowserInstantController::RegisterUserPrefs(PrefServiceSyncable* prefs) {
PrefServiceSyncable::SYNCABLE_PREF);
}
+bool BrowserInstantController::MaybeSwapInInstantContents(
+ const GURL& url,
+ content::WebContents* source_contents,
+ content::WebContents** target_contents) {
+ if (url != GURL(chrome::kChromeUINewTabURL))
+ return false;
+
+ content::WebContents* instant_ntp = instant_.ReleaseNTPContents();
+ if (!instant_ntp)
+ return false;
+
+ instant_ntp->GetController().PruneAllButActive();
+ if (source_contents) {
+ instant_ntp->GetController().CopyStateFromAndPrune(
+ &source_contents->GetController());
+ ReplaceWebContentsAt(
+ browser_->tab_strip_model()->GetIndexOfWebContents(source_contents),
+ instant_ntp);
+ }
+ *target_contents = instant_ntp;
+ return true;
+}
+
bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) {
// Unsupported dispositions.
if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW)
@@ -101,15 +124,8 @@ void BrowserInstantController::CommitInstant(content::WebContents* preview,
instant_.last_transition_type(), TabStripModel::ADD_ACTIVE);
} else {
int index = browser_->tab_strip_model()->active_index();
- DCHECK_NE(TabStripModel::kNoTab, index);
- content::WebContents* active_tab =
- browser_->tab_strip_model()->GetWebContentsAt(index);
- // TabStripModel takes ownership of |preview|.
- browser_->tab_strip_model()->ReplaceWebContentsAt(index, preview);
- // InstantUnloadHandler takes ownership of |active_tab|.
- instant_unload_handler_.RunUnloadListenersOrDestroy(active_tab, index);
-
- GURL url = preview->GetURL();
+ ReplaceWebContentsAt(index, preview);
+ const GURL& url = preview->GetURL();
DCHECK(browser_->profile()->GetExtensionService());
if (browser_->profile()->GetExtensionService()->IsInstalledApp(url)) {
AppLauncherHandler::RecordAppLaunchType(
@@ -118,6 +134,18 @@ void BrowserInstantController::CommitInstant(content::WebContents* preview,
}
}
+void BrowserInstantController::ReplaceWebContentsAt(
+ int index,
+ content::WebContents* new_contents) {
+ DCHECK_NE(TabStripModel::kNoTab, index);
+ content::WebContents* old_contents =
+ browser_->tab_strip_model()->GetWebContentsAt(index);
+ // TabStripModel takes ownership of |new_contents|.
+ browser_->tab_strip_model()->ReplaceWebContentsAt(index, new_contents);
+ // InstantUnloadHandler takes ownership of |old_contents|.
+ instant_unload_handler_.RunUnloadListenersOrDestroy(old_contents, index);
+}
+
void BrowserInstantController::SetInstantSuggestion(
const InstantSuggestion& suggestion) {
browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion);

Powered by Google App Engine
This is Rietveld 408576698