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

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: Fix terrible flag guarding logic 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 734223f576163de72022b539f28ce94622af602d..3b15c1e4a6521ad1084fb26245a79c9644606222 100644
--- a/chrome/browser/ui/search/instant_controller.cc
+++ b/chrome/browser/ui/search/instant_controller.cc
@@ -677,6 +677,39 @@ void InstantController::OmniboxNavigateToURL() {
instant_tab_->Submit(string16());
}
+void InstantController::InstantPageLoadFailed(content::WebContents* contents) {
+ if (!chrome::ShouldPreferRemoteNTPOnStartup()) {
+ // We only need to fall back on errors if we're showing the online page
+ // at startup, as otherwise we fall back correctly when trying to show
+ // a page that hasn't yet indicated that it supports the InstantExtended
+ // API.
+ return;
+ }
+
+ GURL local_fallback_url = chrome::GetLocalInstantURL(browser_->profile());
samarth 2013/05/02 21:57:18 not used anymore
David Black 2013/05/02 23:30:01 Done.
+
+ if (IsContentsFrom(instant_tab(), contents)) {
+ std::string instant_url = GetInstantURL();
samarth 2013/05/02 21:57:18 const std::string&
David Black 2013/05/02 23:30:01 Bloody c++ and its inability to have a basic strin
+ if (instant_tab_->IsLocal() || contents->GetURL() != GURL(instant_url))
+ return;
+ RedirectToLocalNTP(contents);
samarth 2013/05/02 21:57:18 Please add a comment explaining why we only redire
David Black 2013/05/02 23:30:01 You're talking about the url != url condition abov
+ }
+
+ if (IsContentsFrom(ntp(), contents)) {
+ if (ntp_->IsLocal())
samarth 2013/05/02 21:57:18 I don't see how a local page would ever fail, but
David Black 2013/05/02 23:30:01 Done.
+ return;
+ DeletePageSoon(ntp_.Pass());
+ ResetNTP(GetLocalInstantURL());
+ }
+
+ if (IsContentsFrom(overlay(), contents)) {
+ if (overlay_->IsLocal())
+ return;
+ DeletePageSoon(overlay_.Pass());
+ ResetOverlay(GetLocalInstantURL());
+ }
+}
+
content::WebContents* InstantController::GetOverlayContents() const {
return overlay_ ? overlay_->contents() : NULL;
}
@@ -1137,29 +1170,35 @@ void InstantController::InstantPageRenderViewGone(
void InstantController::InstantPageAboutToNavigateMainFrame(
const content::WebContents* contents,
const GURL& url) {
- DCHECK(IsContentsFrom(overlay(), contents));
-
- // If the page does not yet support Instant, we allow redirects and other
- // navigations to go through since the Instant URL can redirect - e.g. to
- // country specific pages.
- if (!overlay_->supports_instant())
- return;
+ if (IsContentsFrom(overlay(), contents)) {
+ // If the page does not yet support Instant, we allow redirects and other
+ // navigations to go through since the Instant URL can redirect - e.g. to
+ // country specific pages.
+ if (!overlay_->supports_instant())
+ return;
- GURL instant_url(overlay_->instant_url());
+ GURL instant_url(overlay_->instant_url());
- // If we are navigating to the Instant URL, do nothing.
- if (url == instant_url)
- return;
+ // If we are navigating to the Instant URL, do nothing.
+ if (url == instant_url)
+ return;
- // Commit the navigation if either:
- // - The page is in NTP mode (so it could only navigate on a user click) or
- // - The page is not in NTP mode and we are navigating to a URL with a
- // different host or path than the Instant URL. This enables the instant
- // page when it is showing search results to change the query parameters
- // and fragments of the URL without it navigating.
- if (model_.mode().is_ntp() ||
- (url.host() != instant_url.host() || url.path() != instant_url.path())) {
- CommitIfPossible(INSTANT_COMMIT_NAVIGATED);
+ // Commit the navigation if either:
+ // - The page is in NTP mode (so it could only navigate on a user click) or
+ // - The page is not in NTP mode and we are navigating to a URL with a
+ // different host or path than the Instant URL. This enables the instant
+ // page when it is showing search results to change the query parameters
+ // and fragments of the URL without it navigating.
+ if (model_.mode().is_ntp() ||
+ (url.host() != instant_url.host() ||
+ url.path() != instant_url.path())) {
+ CommitIfPossible(INSTANT_COMMIT_NAVIGATED);
+ }
+ } else if (IsContentsFrom(instant_tab(), contents)) {
+ // The Instant tab loaded. Send it the data it needs to display properly.
samarth 2013/05/02 21:57:18 nit: The Instant tab navigated.
David Black 2013/05/02 23:30:01 AARG. THAT MAKES THE LINE 81 CHARS LONG. Done.
+ UpdateInfoForInstantTab();
+ } else {
+ NOTREACHED();
}
}
@@ -1447,14 +1486,7 @@ void InstantController::ResetInstantTab() {
if (!instant_tab_ || active_tab != instant_tab_->contents()) {
instant_tab_.reset(new InstantTab(this));
instant_tab_->Init(active_tab);
- // Update theme info for this tab.
- browser_->UpdateThemeInfo();
- instant_tab_->SetDisplayInstantResults(instant_enabled_);
- instant_tab_->SetOmniboxBounds(omnibox_bounds_);
- instant_tab_->InitializeFonts();
- StartListeningToMostVisitedChanges();
- instant_tab_->KeyCaptureChanged(
- omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
+ UpdateInfoForInstantTab();
}
// Hide the |overlay_| since we are now using |instant_tab_| instead.
@@ -1464,6 +1496,18 @@ void InstantController::ResetInstantTab() {
}
}
+void InstantController::UpdateInfoForInstantTab() {
+ if (instant_tab_) {
+ browser_->UpdateThemeInfo();
+ instant_tab_->SetDisplayInstantResults(instant_enabled_);
+ instant_tab_->SetOmniboxBounds(omnibox_bounds_);
+ instant_tab_->InitializeFonts();
+ StartListeningToMostVisitedChanges();
+ instant_tab_->KeyCaptureChanged(
+ omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
+ }
+}
+
void InstantController::HideOverlay() {
HideInternal();
ReloadOverlayIfStale();
@@ -1687,3 +1731,12 @@ 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.
+ // TODO(dcblack): Remove extraneous history entry.
+}

Powered by Google App Engine
This is Rietveld 408576698