Chromium Code Reviews| 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 49d93dab257173ca9a7c3a87b2a7f47b0f378fef..46525f79d8e36637d31d151c3004371a26a8f935 100644 |
| --- a/chrome/browser/ui/browser_instant_controller.cc |
| +++ b/chrome/browser/ui/browser_instant_controller.cc |
| @@ -19,6 +19,7 @@ |
| #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| #include "chrome/common/chrome_notification_types.h" |
| #include "chrome/common/pref_names.h" |
| +#include "chrome/common/url_constants.h" |
| #include "content/public/browser/notification_service.h" |
| #include "grit/theme_resources.h" |
| #include "ui/gfx/color_utils.h" |
| @@ -98,6 +99,33 @@ void BrowserInstantController::RegisterUserPrefs(PrefServiceSyncable* prefs) { |
| PrefServiceSyncable::SYNCABLE_PREF); |
| } |
| +bool BrowserInstantController::MaybeSwapInInstantNTPContents( |
| + const GURL& url, |
| + content::WebContents* source_contents, |
| + content::WebContents** target_contents) { |
| + if (url != GURL(chrome::kChromeUINewTabURL)) |
| + return false; |
| + |
| + scoped_ptr<content::WebContents> instant_ntp = instant_.ReleaseNTPContents(); |
| + if (!instant_ntp) |
| + return false; |
| + |
| + *target_contents = instant_ntp.get(); |
| + instant_ntp->GetController().PruneAllButActive(); |
| + if (source_contents) { |
| + instant_ntp->GetController().CopyStateFromAndPrune( |
| + &source_contents->GetController()); |
| + ReplaceWebContentsAt( |
| + browser_->tab_strip_model()->GetIndexOfWebContents(source_contents), |
| + instant_ntp.Pass()); |
| + } else { |
| + // If |source_contents| is NULL, then the caller is responsible for |
| + // inserting instant_ntp into the tabstrip and will take ownership. |
| + ignore_result(instant_ntp.release()); |
| + } |
| + return true; |
| +} |
| + |
| bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) { |
| // Unsupported dispositions. |
| if (disposition == NEW_BACKGROUND_TAB || disposition == NEW_WINDOW) |
| @@ -113,23 +141,21 @@ bool BrowserInstantController::OpenInstant(WindowOpenDisposition disposition) { |
| INSTANT_COMMIT_PRESSED_ENTER : INSTANT_COMMIT_PRESSED_ALT_ENTER); |
| } |
| -void BrowserInstantController::CommitInstant(content::WebContents* preview, |
| - bool in_new_tab) { |
| +Profile* BrowserInstantController::profile() const { |
| + return browser_->profile(); |
| +} |
| + |
| +void BrowserInstantController::CommitInstant( |
| + scoped_ptr<content::WebContents> preview, |
| + bool in_new_tab) { |
| if (in_new_tab) { |
| // TabStripModel takes ownership of |preview|. |
| - browser_->tab_strip_model()->AddWebContents(preview, -1, |
| + browser_->tab_strip_model()->AddWebContents(preview.release(), -1, |
| 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(); |
| + const GURL& url = preview->GetURL(); |
|
sreeram
2013/02/07 21:17:50
GURL url = preview->GetURL();
Because, given prev
samarth
2013/02/07 22:11:55
Done.
|
| + ReplaceWebContentsAt(index, preview.Pass()); |
|
sreeram
2013/02/07 21:17:50
Nit: ReplaceWebContentsAt(browser_->tab_strip_mode
samarth
2013/02/07 22:11:55
Done.
|
| DCHECK(browser_->profile()->GetExtensionService()); |
| if (browser_->profile()->GetExtensionService()->IsInstalledApp(url)) { |
| AppLauncherHandler::RecordAppLaunchType( |
| @@ -138,6 +164,21 @@ void BrowserInstantController::CommitInstant(content::WebContents* preview, |
| } |
| } |
| +void BrowserInstantController::ReplaceWebContentsAt( |
| + int index, |
| + scoped_ptr<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.release()); |
| + // TODO(samarth): use scoped_ptr instead of comments to document ownership |
| + // transfer. |
| + // InstantUnloadHandler takes ownership of |old_contents|. |
| + instant_unload_handler_.RunUnloadListenersOrDestroy(old_contents, index); |
| +} |
| + |
| void BrowserInstantController::SetInstantSuggestion( |
| const InstantSuggestion& suggestion) { |
| browser_->window()->GetLocationBar()->SetInstantSuggestion(suggestion); |