| 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 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 // The user is on a search results page. It may be showing results for | 379 // The user is on a search results page. It may be showing results for |
| 380 // a partial query the user typed before they hit Escape. Send the | 380 // a partial query the user typed before they hit Escape. Send the |
| 381 // omnibox text to the page to restore the original results. | 381 // omnibox text to the page to restore the original results. |
| 382 // | 382 // |
| 383 // In a tab switch, |instant_tab_| won't have updated yet, so it may | 383 // In a tab switch, |instant_tab_| won't have updated yet, so it may |
| 384 // be pointing to the previous tab (which was a search results page). | 384 // be pointing to the previous tab (which was a search results page). |
| 385 // Ensure we don't send the omnibox text to a random webpage (the new | 385 // Ensure we don't send the omnibox text to a random webpage (the new |
| 386 // tab), by comparing the old and new WebContents. | 386 // tab), by comparing the old and new WebContents. |
| 387 if (escape_pressed && | 387 if (escape_pressed && |
| 388 instant_tab_->contents() == browser_->GetActiveWebContents()) { | 388 instant_tab_->contents() == browser_->GetActiveWebContents()) { |
| 389 // If the omnibox is blank, send an onchange("") instead of an | 389 // TODO(kmadhusu): If the |full_text| is not empty, send an |
| 390 // onsubmit(""). This is to avoid confusion with the onsubmit("") | 390 // onkeypress(esc) to the Instant page. Do not call |
| 391 // that we send when the user hits Enter to navigate to a URL. | 391 // onsubmit(full_text). Fix. |
| 392 // onchange("") is used for a similar situation with the overlay | |
| 393 // (when the overlay is dismissed because the user hit Escape); it | |
| 394 // does the right thing for committed tabs as well. | |
| 395 if (full_text.empty()) | 392 if (full_text.empty()) |
| 396 instant_tab_->Update(string16(), 0, 0, true); | 393 instant_tab_->EscKeyPressed(); |
| 397 else | 394 else |
| 398 instant_tab_->Submit(full_text); | 395 instant_tab_->Submit(full_text); |
| 399 } | 396 } |
| 400 } else if (!full_text.empty()) { | 397 } else if (!full_text.empty()) { |
| 401 // If |full_text| is empty, the user is on the NTP. The overlay may | 398 // If |full_text| is empty, the user is on the NTP. The overlay may |
| 402 // be showing custom NTP content; hide only if that's not the case. | 399 // be showing custom NTP content; hide only if that's not the case. |
| 403 HideOverlay(); | 400 HideOverlay(); |
| 404 } | 401 } |
| 405 } else if (full_text.empty()) { | 402 } else if (full_text.empty()) { |
| 406 // The user is typing, and backspaced away all omnibox text. Clear | 403 // The user is typing, and backspaced away all omnibox text. Clear |
| (...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1685 } | 1682 } |
| 1686 } | 1683 } |
| 1687 | 1684 |
| 1688 return false; | 1685 return false; |
| 1689 } | 1686 } |
| 1690 | 1687 |
| 1691 bool InstantController::UsingLocalPage() const { | 1688 bool InstantController::UsingLocalPage() const { |
| 1692 return (instant_tab_ && instant_tab_->IsLocal()) || | 1689 return (instant_tab_ && instant_tab_->IsLocal()) || |
| 1693 (!instant_tab_ && overlay_ && overlay_->IsLocal()); | 1690 (!instant_tab_ && overlay_ && overlay_->IsLocal()); |
| 1694 } | 1691 } |
| OLD | NEW |