| 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/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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // The user is on a search results page. It may be showing results for | 372 // The user is on a search results page. It may be showing results for |
| 373 // a partial query the user typed before they hit Escape. Send the | 373 // a partial query the user typed before they hit Escape. Send the |
| 374 // omnibox text to the page to restore the original results. | 374 // omnibox text to the page to restore the original results. |
| 375 // | 375 // |
| 376 // In a tab switch, |instant_tab_| won't have updated yet, so it may | 376 // In a tab switch, |instant_tab_| won't have updated yet, so it may |
| 377 // be pointing to the previous tab (which was a search results page). | 377 // be pointing to the previous tab (which was a search results page). |
| 378 // Ensure we don't send the omnibox text to a random webpage (the new | 378 // Ensure we don't send the omnibox text to a random webpage (the new |
| 379 // tab), by comparing the old and new WebContents. | 379 // tab), by comparing the old and new WebContents. |
| 380 if (escape_pressed && | 380 if (escape_pressed && |
| 381 instant_tab_->contents() == browser_->GetActiveWebContents()) { | 381 instant_tab_->contents() == browser_->GetActiveWebContents()) { |
| 382 // If the omnibox is blank, send an onchange("") instead of an | 382 // TODO(kmadhusu): If the |full_text| is not empty, send an |
| 383 // onsubmit(""). This is to avoid confusion with the onsubmit("") | 383 // onkeypress(esc) to the Instant page. Do not call |
| 384 // that we send when the user hits Enter to navigate to a URL. | 384 // onsubmit(full_text). Fix. |
| 385 // onchange("") is used for a similar situation with the overlay | 385 if (full_text.empty()) { |
| 386 // (when the overlay is dismissed because the user hit Escape); it | 386 // Call onchange("") to clear the query for the page. |
| 387 // does the right thing for committed tabs as well. | |
| 388 if (full_text.empty()) | |
| 389 instant_tab_->Update(string16(), 0, 0, true); | 387 instant_tab_->Update(string16(), 0, 0, true); |
| 390 else | 388 instant_tab_->EscKeyPressed(); |
| 389 } else { |
| 391 instant_tab_->Submit(full_text); | 390 instant_tab_->Submit(full_text); |
| 391 } |
| 392 } | 392 } |
| 393 } else if (!full_text.empty()) { | 393 } else if (!full_text.empty()) { |
| 394 // If |full_text| is empty, the user is on the NTP. The overlay may | 394 // If |full_text| is empty, the user is on the NTP. The overlay may |
| 395 // be showing custom NTP content; hide only if that's not the case. | 395 // be showing custom NTP content; hide only if that's not the case. |
| 396 HideOverlay(); | 396 HideOverlay(); |
| 397 } | 397 } |
| 398 } else if (full_text.empty()) { | 398 } else if (full_text.empty()) { |
| 399 // The user is typing, and backspaced away all omnibox text. Clear | 399 // The user is typing, and backspaced away all omnibox text. Clear |
| 400 // |last_omnibox_text_| so that we don't attempt to set suggestions. | 400 // |last_omnibox_text_| so that we don't attempt to set suggestions. |
| 401 last_omnibox_text_.clear(); | 401 last_omnibox_text_.clear(); |
| (...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 void InstantController::RedirectToLocalNTP(content::WebContents* contents) { | 1776 void InstantController::RedirectToLocalNTP(content::WebContents* contents) { |
| 1777 contents->GetController().LoadURL( | 1777 contents->GetController().LoadURL( |
| 1778 chrome::GetLocalInstantURL(browser_->profile()), | 1778 chrome::GetLocalInstantURL(browser_->profile()), |
| 1779 content::Referrer(), | 1779 content::Referrer(), |
| 1780 content::PAGE_TRANSITION_SERVER_REDIRECT, | 1780 content::PAGE_TRANSITION_SERVER_REDIRECT, |
| 1781 std::string()); // No extra headers. | 1781 std::string()); // No extra headers. |
| 1782 // TODO(dcblack): Remove extraneous history entry caused by 404s. | 1782 // TODO(dcblack): Remove extraneous history entry caused by 404s. |
| 1783 // Note that the base case of a 204 being returned doesn't push a history | 1783 // Note that the base case of a 204 being returned doesn't push a history |
| 1784 // entry. | 1784 // entry. |
| 1785 } | 1785 } |
| OLD | NEW |