OLD | NEW |
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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/content_settings/content_settings_provider.h" | 10 #include "chrome/browser/content_settings/content_settings_provider.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } else { | 110 } else { |
111 if (chrome::ShouldPrefetchSearchResults()) { | 111 if (chrome::ShouldPrefetchSearchResults()) { |
112 InstantSearchPrerenderer* prerenderer = | 112 InstantSearchPrerenderer* prerenderer = |
113 InstantSearchPrerenderer::GetForProfile(profile()); | 113 InstantSearchPrerenderer::GetForProfile(profile()); |
114 if (prerenderer) | 114 if (prerenderer) |
115 prerenderer->Prerender(suggestion); | 115 prerenderer->Prerender(suggestion); |
116 } | 116 } |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
| 120 void InstantController::InstantPageLoadFailed(content::WebContents* contents) { |
| 121 DCHECK(IsContentsFrom(instant_tab(), contents)); |
| 122 |
| 123 // Verify we're not already on a local page and that the URL precisely |
| 124 // equals the instant_url (minus the query params, as those will be filled |
| 125 // in by template values). This check is necessary to make sure we don't |
| 126 // inadvertently redirect to the local NTP if someone, say, reloads a SRP |
| 127 // while offline, as a committed results page still counts as an instant |
| 128 // url. We also check to make sure there's no forward history, as if |
| 129 // someone hits the back button a lot when offline and returns to a NTP |
| 130 // we don't want to redirect and nuke their forward history stack. |
| 131 const GURL& current_url = contents->GetURL(); |
| 132 GURL instant_url = chrome::GetInstantURL(profile(), |
| 133 chrome::kDisableStartMargin, false); |
| 134 if (instant_tab_->IsLocal() || |
| 135 !search::MatchesOriginAndPath(instant_url, current_url) || |
| 136 !current_url.ref().empty() || |
| 137 contents->GetController().CanGoForward()) |
| 138 return; |
| 139 LOG_INSTANT_DEBUG_EVENT(this, "InstantPageLoadFailed: instant_tab"); |
| 140 RedirectToLocalNTP(contents); |
| 141 } |
| 142 |
120 bool InstantController::SubmitQuery(const base::string16& search_terms) { | 143 bool InstantController::SubmitQuery(const base::string16& search_terms) { |
121 if (instant_tab_ && instant_tab_->supports_instant() && | 144 if (instant_tab_ && instant_tab_->supports_instant() && |
122 search_mode_.is_origin_search()) { | 145 search_mode_.is_origin_search()) { |
123 // Use |instant_tab_| to run the query if we're already on a search results | 146 // Use |instant_tab_| to run the query if we're already on a search results |
124 // page. (NOTE: in particular, we do not send the query to NTPs.) | 147 // page. (NOTE: in particular, we do not send the query to NTPs.) |
125 SearchTabHelper::FromWebContents(instant_tab_->contents())->Submit( | 148 SearchTabHelper::FromWebContents(instant_tab_->contents())->Submit( |
126 search_terms); | 149 search_terms); |
127 instant_tab_->contents()->GetView()->Focus(); | 150 instant_tab_->contents()->GetView()->Focus(); |
128 EnsureSearchTermsAreSet(instant_tab_->contents(), search_terms); | 151 EnsureSearchTermsAreSet(instant_tab_->contents(), search_terms); |
129 return true; | 152 return true; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 omnibox_focus_change_reason_); | 289 omnibox_focus_change_reason_); |
267 instant_tab_->sender()->SetInputInProgress(IsInputInProgress()); | 290 instant_tab_->sender()->SetInputInProgress(IsInputInProgress()); |
268 } | 291 } |
269 } | 292 } |
270 | 293 |
271 bool InstantController::IsInputInProgress() const { | 294 bool InstantController::IsInputInProgress() const { |
272 return !search_mode_.is_ntp() && | 295 return !search_mode_.is_ntp() && |
273 omnibox_focus_state_ == OMNIBOX_FOCUS_VISIBLE; | 296 omnibox_focus_state_ == OMNIBOX_FOCUS_VISIBLE; |
274 } | 297 } |
275 | 298 |
| 299 void InstantController::RedirectToLocalNTP(content::WebContents* contents) { |
| 300 contents->GetController().LoadURL( |
| 301 GURL(chrome::kChromeSearchLocalNtpUrl), |
| 302 content::Referrer(), |
| 303 content::PAGE_TRANSITION_SERVER_REDIRECT, |
| 304 std::string()); // No extra headers. |
| 305 // TODO(dcblack): Remove extraneous history entry caused by 404s. |
| 306 // Note that the base case of a 204 being returned doesn't push a history |
| 307 // entry. |
| 308 } |
| 309 |
276 InstantService* InstantController::GetInstantService() const { | 310 InstantService* InstantController::GetInstantService() const { |
277 return InstantServiceFactory::GetForProfile(profile()); | 311 return InstantServiceFactory::GetForProfile(profile()); |
278 } | 312 } |
OLD | NEW |