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

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

Issue 135903002: Revert 244407 "InstantExtended: remove dead code related to the ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 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: trunk/src/chrome/browser/ui/browser_instant_controller.cc
===================================================================
--- trunk/src/chrome/browser/ui/browser_instant_controller.cc (revision 244428)
+++ trunk/src/chrome/browser/ui/browser_instant_controller.cc (working copy)
@@ -16,6 +16,7 @@
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
+#include "chrome/browser/ui/search/instant_ntp.h"
#include "chrome/browser/ui/search/instant_search_prerenderer.h"
#include "chrome/browser/ui/search/search_model.h"
#include "chrome/browser/ui/search/search_tab_helper.h"
@@ -45,11 +46,13 @@
BrowserInstantController::BrowserInstantController(Browser* browser)
: browser_(browser),
- instant_(this) {
+ instant_(this),
+ instant_unload_handler_(browser) {
browser_->search_model()->AddObserver(this);
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile());
+ instant_service->OnBrowserInstantControllerCreated();
instant_service->AddObserver(this);
}
@@ -59,8 +62,64 @@
InstantService* instant_service =
InstantServiceFactory::GetForProfile(profile());
instant_service->RemoveObserver(this);
+ instant_service->OnBrowserInstantControllerDestroyed();
}
+bool BrowserInstantController::MaybeSwapInInstantNTPContents(
+ const GURL& url,
+ content::WebContents* source_contents,
+ content::WebContents** target_contents) {
+ if (url != GURL(chrome::kChromeUINewTabURL))
+ return false;
+
+ GURL extension_url(url);
+ if (ExtensionWebUI::HandleChromeURLOverride(&extension_url, profile())) {
+ // If there is an extension overriding the NTP do not use the Instant NTP.
+ return false;
+ }
+
+ InstantService* instant_service =
+ InstantServiceFactory::GetForProfile(profile());
+ scoped_ptr<content::WebContents> instant_ntp =
+ instant_service->ReleaseNTPContents();
+ if (!instant_ntp)
+ return false;
+
+ *target_contents = instant_ntp.get();
+ if (source_contents) {
+ // If the Instant NTP hasn't yet committed an entry, we can't call
+ // CopyStateFromAndPrune. Instead, load the Local NTP URL directly in the
+ // source contents.
+ // TODO(sreeram): Always using the local URL is wrong in the case of the
+ // first tab in a window where we might want to use the remote URL. Fix.
+ if (!instant_ntp->GetController().CanPruneAllButLastCommitted()) {
+ source_contents->GetController().LoadURL(chrome::GetLocalInstantURL(
+ profile()), content::Referrer(), content::PAGE_TRANSITION_GENERATED,
+ std::string());
+ *target_contents = source_contents;
+ } else {
+ instant_ntp->GetController().CopyStateFromAndPrune(
+ &source_contents->GetController(), false);
+ ReplaceWebContentsAt(
+ browser_->tab_strip_model()->GetIndexOfWebContents(source_contents),
+ instant_ntp.Pass());
+ }
+ } else {
+ // If the Instant NTP hasn't yet committed an entry, we can't call
+ // PruneAllButLastCommitted. In that case, there shouldn't be any entries
+ // to prune anyway.
+ if (instant_ntp->GetController().CanPruneAllButLastCommitted())
+ instant_ntp->GetController().PruneAllButLastCommitted();
+ else
+ CHECK(!instant_ntp->GetController().GetLastCommittedEntry());
+
+ // 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,
const GURL& url) {
// Unsupported dispositions.
@@ -97,6 +156,16 @@
return browser_->profile();
}
+void BrowserInstantController::ReplaceWebContentsAt(
+ int index,
+ scoped_ptr<content::WebContents> new_contents) {
+ DCHECK_NE(TabStripModel::kNoTab, index);
+ scoped_ptr<content::WebContents> old_contents(browser_->tab_strip_model()->
+ ReplaceWebContentsAt(index, new_contents.release()));
+ instant_unload_handler_.RunUnloadListenersOrDestroy(old_contents.Pass(),
+ index);
+}
+
content::WebContents* BrowserInstantController::GetActiveWebContents() const {
return browser_->tab_strip_model()->GetActiveWebContents();
}
« no previous file with comments | « trunk/src/chrome/browser/ui/browser_instant_controller.h ('k') | trunk/src/chrome/browser/ui/browser_navigator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698