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

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: remove search_tab_helper changes 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 210c2f0a0a6e01295f82438db3c44dc0b8b9ab6c..023782a6898a09080af259454b960dd6b3278ca3 100644
--- a/chrome/browser/ui/search/instant_controller.cc
+++ b/chrome/browser/ui/search/instant_controller.cc
@@ -709,6 +709,34 @@ void InstantController::OmniboxNavigateToURL() {
instant_tab_->Submit(string16());
}
+void InstantController::InstantPageLoadFailed(content::WebContents* contents) {
+ GURL local_fallback_url = chrome::GetLocalInstantURL(browser_->profile());
+
+ if (instant_tab_ && IsContentsFrom(instant_tab(), contents)) {
samarth 2013/05/02 03:12:56 IsContentsFrom already checks that the page is not
David Black 2013/05/02 05:02:49 Done.
+ std::string instant_url;
+ bool has_online_url = GetInstantURL(
+ browser_->profile(), true, &instant_url);
+ if (instant_tab_->IsLocal() || !has_online_url ||
+ contents->GetURL() != GURL(instant_url))
+ return;
+ RedirectToLocalNTP(contents);
+ }
+
+ if (ntp_ && IsContentsFrom(ntp(), contents)) {
+ if (ntp_->IsLocal())
+ return;
+ MessageLoop::current()->DeleteSoon(FROM_HERE, ntp_.release());
samarth 2013/05/02 03:12:56 It's best to also delete the contents held by ntp_
David Black 2013/05/02 05:02:49 Ok. That'll require a bunch of rebasing on my par
+ ResetNTP(false, true);
+ }
+
+ if (overlay_ && IsContentsFrom(overlay(), contents)) {
+ if (overlay_->IsLocal())
+ return;
+ MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release());
+ CreateOverlay(local_fallback_url.spec(), contents);
+ }
+}
+
content::WebContents* InstantController::GetOverlayContents() const {
return overlay_ ? overlay_->contents() : NULL;
}
@@ -1156,29 +1184,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.
+ UpdateInfoForInstantTab();
+ } else {
+ NOTREACHED();
}
}
@@ -1396,14 +1430,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.
@@ -1413,6 +1440,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();
@@ -1719,3 +1758,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