| 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 4118de59b0de8e390a68fa3136e01b1275fbafad..73df0bdeb7a47ce6814a2cf6cb94f0987391ac6c 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"
|
| @@ -95,6 +96,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)
|
| @@ -110,23 +138,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();
|
| + ReplaceWebContentsAt(index, preview.Pass());
|
| DCHECK(browser_->profile()->GetExtensionService());
|
| if (browser_->profile()->GetExtensionService()->IsInstalledApp(url)) {
|
| AppLauncherHandler::RecordAppLaunchType(
|
| @@ -135,6 +161,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);
|
|
|