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

Side by Side 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, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/search/instant_controller.h" 5 #include "chrome/browser/ui/search/instant_controller.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 LOG_INSTANT_DEBUG_EVENT(this, "ActiveTabChanged"); 926 LOG_INSTANT_DEBUG_EVENT(this, "ActiveTabChanged");
927 927
928 // When switching tabs, always hide the overlay. 928 // When switching tabs, always hide the overlay.
929 HideOverlay(); 929 HideOverlay();
930 930
931 if (extended_enabled_) 931 if (extended_enabled_)
932 ResetInstantTab(); 932 ResetInstantTab();
933 } 933 }
934 934
935 void InstantController::TabDeactivated(content::WebContents* contents) { 935 void InstantController::TabDeactivated(content::WebContents* contents) {
936 std::string instant_url;
937 if ((!instant_tab_ || !instant_tab_->supports_instant()) &&
938 GetInstantURL(browser_->profile(), false, &instant_url) &&
939 chrome::MatchesOriginAndPath(contents->GetURL(),
940 GURL(instant_url))) {
941 // 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
942 // (It probably will - likely need to check the mode or something.)
943 RedirectToLocalNTP(contents);
944 }
945
936 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated"); 946 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated");
937 if (extended_enabled_ && !contents->IsBeingDestroyed()) 947 if (extended_enabled_ && !contents->IsBeingDestroyed())
938 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); 948 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST);
939 949
940 if (GetOverlayContents()) 950 if (GetOverlayContents())
941 HideOverlay(); 951 HideOverlay();
942 } 952 }
943 953
944 void InstantController::SetInstantEnabled(bool instant_enabled, 954 void InstantController::SetInstantEnabled(bool instant_enabled,
945 bool use_local_page_only) { 955 bool use_local_page_only) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 } 1077 }
1068 1078
1069 void InstantController::UndoAllMostVisitedDeletions() { 1079 void InstantController::UndoAllMostVisitedDeletions() {
1070 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 1080 history::TopSites* top_sites = browser_->profile()->GetTopSites();
1071 if (!top_sites) 1081 if (!top_sites)
1072 return; 1082 return;
1073 1083
1074 top_sites->ClearBlacklistedURLs(); 1084 top_sites->ClearBlacklistedURLs();
1075 } 1085 }
1076 1086
1087 void InstantController::InstantPageLoadFailed(content::WebContents* contents) {
1088 GURL local_fallback_url = chrome::GetLocalInstantURL(browser_->profile());
1089
1090 if (instant_tab_ && IsContentsFrom(instant_tab(), contents)) {
1091 if (instant_tab_->IsLocal())
1092 return;
1093 SearchTabHelper::FromWebContents(contents)->RedirectingToLocal();
1094 RedirectToLocalNTP(contents);
1095 }
1096
1097 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
1098 if (ntp_->IsLocal())
1099 return;
1100 ResetNTP(false, true);
1101 }
1102
1103 if (overlay_ && IsContentsFrom(overlay(), contents)) {
1104 if (overlay_->IsLocal())
1105 return;
1106 CreateOverlay(local_fallback_url.spec(), contents);
1107 }
1108 }
1109
1077 void InstantController::Observe(int type, 1110 void InstantController::Observe(int type,
1078 const content::NotificationSource& source, 1111 const content::NotificationSource& source,
1079 const content::NotificationDetails& details) { 1112 const content::NotificationDetails& details) {
1080 DCHECK_EQ(type, chrome::NOTIFICATION_TOP_SITES_CHANGED); 1113 DCHECK_EQ(type, chrome::NOTIFICATION_TOP_SITES_CHANGED);
1081 RequestMostVisitedItems(); 1114 RequestMostVisitedItems();
1082 } 1115 }
1083 1116
1084 // TODO(shishir): We assume that the WebContent's current RenderViewHost is the 1117 // TODO(shishir): We assume that the WebContent's current RenderViewHost is the
1085 // RenderViewHost being created which is not always true. Fix this. 1118 // RenderViewHost being created which is not always true. Fix this.
1086 void InstantController::InstantPageRenderViewCreated( 1119 void InstantController::InstantPageRenderViewCreated(
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 std::string instant_url; 1732 std::string instant_url;
1700 if (!GetInstantURL(browser_->profile(), false, &instant_url) || 1733 if (!GetInstantURL(browser_->profile(), false, &instant_url) ||
1701 !chrome::MatchesOriginAndPath(GURL(ntp_->instant_url()), 1734 !chrome::MatchesOriginAndPath(GURL(ntp_->instant_url()),
1702 GURL(instant_url))) { 1735 GURL(instant_url))) {
1703 return true; 1736 return true;
1704 } 1737 }
1705 1738
1706 if (ntp_->supports_instant()) 1739 if (ntp_->supports_instant())
1707 return false; 1740 return false;
1708 1741
1709 // If this is not window startup, switch.
1710 // TODO(shishir): This is not completely reliable. Find a better way to detect
1711 // startup time.
1712 if (browser_->GetActiveWebContents())
1713 return true;
1714
1715 return chrome::IsAggressiveLocalNTPFallbackEnabled(); 1742 return chrome::IsAggressiveLocalNTPFallbackEnabled();
1716 } 1743 }
1717 1744
1718 bool InstantController::UsingLocalPage() const { 1745 bool InstantController::UsingLocalPage() const {
1719 return (instant_tab_ && instant_tab_->IsLocal()) || 1746 return (instant_tab_ && instant_tab_->IsLocal()) ||
1720 (!instant_tab_ && overlay_ && overlay_->IsLocal()); 1747 (!instant_tab_ && overlay_ && overlay_->IsLocal());
1721 } 1748 }
1749
1750 void InstantController::RedirectToLocalNTP(content::WebContents* contents) {
1751 contents->GetController().LoadURL(
1752 chrome::GetLocalInstantURL(browser_->profile()),
1753 content::Referrer(),
1754 content::PAGE_TRANSITION_SERVER_REDIRECT,
1755 std::string()); // No extra headers.
1756 // Remove extraneous history entry.
1757 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
1758 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698