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

Unified Diff: chrome/browser/ui/search/instant_controller.cc

Issue 14043009: Fall back to local page if online NTP fails to load. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 7 years, 8 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/search/instant_controller.cc
diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc
index f63aeab6c07470428821cdb5c2a6fbee6c264dc8..a3d6b91fdb1d85bc40e6861dd08b5e9e4bfe8c26 100644
--- a/chrome/browser/ui/search/instant_controller.cc
+++ b/chrome/browser/ui/search/instant_controller.cc
@@ -933,6 +933,16 @@ void InstantController::ActiveTabChanged() {
}
void InstantController::TabDeactivated(content::WebContents* contents) {
+ std::string instant_url;
+ if ((!instant_tab_ || !instant_tab_->supports_instant()) &&
+ GetInstantURL(browser_->profile(), false, &instant_url) &&
+ chrome::MatchesOriginAndPath(contents->GetURL(),
+ GURL(instant_url))) {
+ // TODO(dcblack): verify this won't nuke loading SRPs and the like.
samarth 2013/04/30 17:10:33 This definitely will. In general, I don't think we
David Black 2013/04/30 23:09:08 As I mentioned in person, this is also necessary t
+ // (It probably will - likely need to check the mode or something.)
+ RedirectToLocalNTP(contents);
+ }
+
LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated");
if (extended_enabled_ && !contents->IsBeingDestroyed())
CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
@@ -1074,6 +1084,29 @@ void InstantController::UndoAllMostVisitedDeletions() {
top_sites->ClearBlacklistedURLs();
}
+void InstantController::InstantPageLoadFailed(content::WebContents* contents) {
+ GURL local_fallback_url = chrome::GetLocalInstantURL(browser_->profile());
+
+ if (instant_tab_ && IsContentsFrom(instant_tab(), contents)) {
+ if (instant_tab_->IsLocal())
+ return;
+ SearchTabHelper::FromWebContents(contents)->RedirectingToLocal();
+ RedirectToLocalNTP(contents);
+ }
+
+ if (ntp_ && IsContentsFrom(ntp(), contents)) {
samarth 2013/04/30 17:10:33 Shouldn't this get handled normally via InstantSup
David Black 2013/04/30 23:09:08 Whether it *should* or not is not something I'm su
+ if (ntp_->IsLocal())
+ return;
+ ResetNTP(false, true);
+ }
+
+ if (overlay_ && IsContentsFrom(overlay(), contents)) {
+ if (overlay_->IsLocal())
+ return;
+ CreateOverlay(local_fallback_url.spec(), contents);
+ }
+}
+
void InstantController::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
@@ -1706,12 +1739,6 @@ bool InstantController::ShouldSwitchToLocalNTP() const {
if (ntp_->supports_instant())
return false;
- // If this is not window startup, switch.
- // TODO(shishir): This is not completely reliable. Find a better way to detect
- // startup time.
- if (browser_->GetActiveWebContents())
- return true;
-
return chrome::IsAggressiveLocalNTPFallbackEnabled();
}
@@ -1719,3 +1746,13 @@ bool InstantController::UsingLocalPage() const {
return (instant_tab_ && instant_tab_->IsLocal()) ||
(!instant_tab_ && overlay_ && overlay_->IsLocal());
}
+
+void InstantController::RedirectToLocalNTP(content::WebContents* contents) {
+ contents->GetController().LoadURL(
+ chrome::GetLocalInstantURL(browser_->profile()),
+ content::Referrer(),
+ content::PAGE_TRANSITION_SERVER_REDIRECT,
+ std::string()); // No extra headers.
+ // Remove extraneous history entry.
+ contents->GetController().PruneAllButActive();
samarth 2013/04/30 17:10:33 This isn't right in the general case. For example
David Black 2013/04/30 23:09:08 Yes, I know. However, I was unable to find a way
+}

Powered by Google App Engine
This is Rietveld 408576698