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

Unified Diff: chrome/browser/ui/search/instant_controller.cc

Issue 13905008: Merge local_omnibox_popup into local_ntp. Render the Google logo and fakebox if Google is the sear… (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Address Samarth's comments. 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
« no previous file with comments | « chrome/browser/ui/search/instant_controller.h ('k') | chrome/browser/ui/search/instant_page.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 83f1e345833a15ef85e88f0bd2df06d9dfbae3a5..2ed8c2e9da64fe3f79825878a9e0c7f21bc77d57 100644
--- a/chrome/browser/ui/search/instant_controller.cc
+++ b/chrome/browser/ui/search/instant_controller.cc
@@ -268,7 +268,7 @@ bool InstantController::Update(const AutocompleteMatch& match,
// DCHECKs below because |user_text| and |full_text| have different semantics
// when keyword search is in effect.
if (is_keyword_search) {
- if (UseInstantTabToShowSuggestions())
+ if (instant_tab_)
instant_tab_->Update(string16(), 0, 0, true);
else
HideOverlay();
@@ -321,8 +321,7 @@ bool InstantController::Update(const AutocompleteMatch& match,
// If we have an |instant_tab_| use it, else ensure we have an overlay that is
// current or is using the local overlay.
- if (!UseInstantTabToShowSuggestions() &&
- !(overlay_ && overlay_->IsLocalOverlay()) &&
+ if (!instant_tab_ && !(overlay_ && overlay_->IsLocal()) &&
!EnsureOverlayIsCurrent(false)) {
HideOverlay();
return false;
@@ -333,7 +332,7 @@ bool InstantController::Update(const AutocompleteMatch& match,
if (!user_input_in_progress) {
// If the user isn't typing and the omnibox popup is closed, it means a
// regular navigation, tab-switch or the user hitting Escape.
- if (UseInstantTabToShowSuggestions()) {
+ if (instant_tab_) {
// The user is on a search results page. It may be showing results for
// a partial query the user typed before they hit Escape. Send the
// omnibox text to the page to restore the original results.
@@ -357,7 +356,7 @@ bool InstantController::Update(const AutocompleteMatch& match,
last_omnibox_text_.clear();
last_user_text_.clear();
last_suggestion_ = InstantSuggestion();
- if (UseInstantTabToShowSuggestions()) {
+ if (instant_tab_) {
// On a search results page, tell it to clear old results.
instant_tab_->Update(string16(), 0, 0, true);
} else if (search_mode_.is_origin_ntp()) {
@@ -387,7 +386,7 @@ bool InstantController::Update(const AutocompleteMatch& match,
last_omnibox_text_.clear();
last_user_text_.clear();
last_suggestion_ = InstantSuggestion();
- if (UseInstantTabToShowSuggestions())
+ if (instant_tab_)
instant_tab_->Update(string16(), 0, 0, true);
else if (search_mode_.is_origin_ntp())
overlay_->Update(string16(), 0, 0, true);
@@ -442,7 +441,7 @@ bool InstantController::Update(const AutocompleteMatch& match,
if (!extended_enabled_)
search_mode_.mode = SearchMode::MODE_SEARCH_SUGGESTIONS;
- if (UseInstantTabToShowSuggestions()) {
+ if (instant_tab_) {
// If we have an |instant_tab_| but it doesn't support Instant yet, sever
// the connection to it so we use the overlay instead. This ensures that the
// user interaction will be responsive and handles cases where
@@ -453,7 +452,7 @@ bool InstantController::Update(const AutocompleteMatch& match,
instant_tab_.reset();
}
- if (!UseInstantTabToShowSuggestions()) {
+ if (!instant_tab_) {
if (first_interaction_time_.is_null())
first_interaction_time_ = base::Time::Now();
allow_overlay_to_show_search_suggestions_ = true;
@@ -461,8 +460,8 @@ bool InstantController::Update(const AutocompleteMatch& match,
// For extended mode, if the loader is not ready at this point, switch over
// to a backup loader.
if (extended_enabled_ && !overlay_->supports_instant() &&
- !overlay_->IsLocalOverlay() && browser_->GetActiveWebContents()) {
- CreateOverlay(chrome::kChromeSearchLocalOmniboxPopupURL,
+ !overlay_->IsLocal() && browser_->GetActiveWebContents()) {
+ CreateOverlay(chrome::GetLocalInstantURL(browser_->profile()).spec(),
browser_->GetActiveWebContents());
}
@@ -489,8 +488,8 @@ scoped_ptr<content::WebContents> InstantController::ReleaseNTPContents() {
LOG_INSTANT_DEBUG_EVENT(this, "ReleaseNTPContents");
- // Switch to the local NTP unless we're already using one.
- if (!ntp_ || (ShouldSwitchToLocalNTP() && !ntp_->IsLocalNTP()))
+ // Switch to the local NTP unless its URL hasn't changed.
+ if (!ntp_ || ShouldSwitchToLocalNTP())
samarth 2013/04/17 17:24:59 A few more comments here actually: 1) Please also
jeremycho 2013/04/17 20:14:33 Done. Left a TODO for the test.
ResetNTP(false, true);
scoped_ptr<content::WebContents> ntp_contents = ntp_->ReleaseContents();
@@ -552,10 +551,11 @@ void InstantController::HandleAutocompleteResults(
provider != providers.end(); ++provider) {
const bool from_search_provider =
(*provider)->type() == AutocompleteProvider::TYPE_SEARCH;
- // Unless we are talking to the local overlay, skip SearchProvider, since
- // it only echoes suggestions.
- if (from_search_provider &&
- (UseInstantTabToShowSuggestions() || !overlay_->IsLocalOverlay()))
+ const bool using_local_page =
+ (instant_tab_ && instant_tab_->IsLocal()) || overlay_->IsLocal();
+ // Unless we are talking to a local page, skip SearchProvider, since it only
+ // echoes suggestions.
+ if (from_search_provider && !using_local_page)
continue;
// Only send autocomplete results when all the providers are done. Skip
// this check for the SearchProvider, since it isn't done until the page
@@ -587,7 +587,7 @@ void InstantController::HandleAutocompleteResults(
"HandleAutocompleteResults: total_results=%d",
static_cast<int>(results.size())));
- if (UseInstantTabToShowSuggestions())
+ if (instant_tab_)
instant_tab_->SendAutocompleteResults(results);
else
overlay_->SendAutocompleteResults(results);
@@ -600,7 +600,7 @@ bool InstantController::OnUpOrDownKeyPressed(int count) {
if (!instant_tab_ && !overlay_)
return false;
- if (UseInstantTabToShowSuggestions())
+ if (instant_tab_)
instant_tab_->UpOrDownKeyPressed(count);
else
overlay_->UpOrDownKeyPressed(count);
@@ -629,7 +629,7 @@ void InstantController::OnCancel(const AutocompleteMatch& match,
// inline autocompletion is "zon.com"; so the selection should span from
// user_text.size() to full_text.size(). The selection bounds are inverted
// because the caret is at the end of |user_text|, not |full_text|.
- if (UseInstantTabToShowSuggestions()) {
+ if (instant_tab_) {
instant_tab_->CancelSelection(user_text, full_text.size(), user_text.size(),
last_verbatim_);
} else {
@@ -668,8 +668,9 @@ bool InstantController::CommitIfPossible(InstantCommitType type) {
// If we are on an already committed search results page, send a submit event
// to the page, but otherwise, nothing else to do.
- if (UseInstantTabToShowSuggestions()) {
+ if (instant_tab_) {
if (type == INSTANT_COMMIT_PRESSED_ENTER &&
+ !instant_tab_->IsLocal() &&
(last_match_was_search_ ||
last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)) {
last_suggestion_.text.clear();
@@ -697,7 +698,7 @@ bool InstantController::CommitIfPossible(InstantCommitType type) {
return false;
// Never commit the local overlay.
- if (overlay_->IsLocalOverlay())
+ if (overlay_->IsLocal())
return false;
if (type == INSTANT_COMMIT_FOCUS_LOST) {
@@ -929,7 +930,7 @@ void InstantController::FocusedOverlayContents() {
void InstantController::ReloadOverlayIfStale() {
// The local overlay is never stale.
- if (overlay_ && overlay_->IsLocalOverlay())
+ if (overlay_ && overlay_->IsLocal())
return;
// If the overlay is showing or the omnibox has focus, don't delete the
@@ -1119,8 +1120,7 @@ void InstantController::SetSuggestions(
// Ignore if the message is from an unexpected source.
if (IsContentsFrom(ntp(), contents))
return;
- if (UseInstantTabToShowSuggestions() &&
- !IsContentsFrom(instant_tab(), contents))
+ if (instant_tab_ && !IsContentsFrom(instant_tab(), contents))
return;
if (IsContentsFrom(overlay(), contents) &&
!allow_overlay_to_show_search_suggestions_)
@@ -1132,8 +1132,7 @@ void InstantController::SetSuggestions(
// TODO(samarth): allow InstantTabs to call SetSuggestions() from the NTP once
// that is better supported.
- bool can_use_instant_tab = UseInstantTabToShowSuggestions() &&
- search_mode_.is_search();
+ bool can_use_instant_tab = instant_tab_ && search_mode_.is_search();
bool can_use_overlay = search_mode_.is_search_suggestions() &&
!last_omnibox_text_.empty();
if (!can_use_instant_tab && !can_use_overlay)
@@ -1268,7 +1267,7 @@ void InstantController::ResetNTP(bool ignore_blacklist, bool use_local_ntp) {
std::string instant_url;
if (use_local_ntp ||
!GetInstantURL(browser_->profile(), ignore_blacklist, &instant_url))
- instant_url = chrome::kChromeSearchLocalNtpUrl;
+ instant_url = chrome::GetLocalInstantURL(browser_->profile()).spec();
ntp_.reset(new InstantNTP(this, instant_url));
ntp_->InitContents(browser_->profile(), browser_->GetActiveWebContents(),
base::Bind(&InstantController::ResetNTP,
@@ -1287,7 +1286,7 @@ bool InstantController::EnsureOverlayIsCurrent(bool ignore_blacklist) {
if (!GetInstantURL(profile, ignore_blacklist, &instant_url)) {
// If we are in extended mode, fallback to the local overlay.
if (extended_enabled_)
- instant_url = chrome::kChromeSearchLocalOmniboxPopupURL;
+ instant_url = chrome::GetLocalInstantURL(browser_->profile()).spec();
else
return false;
}
@@ -1369,7 +1368,7 @@ void InstantController::HideInternal() {
void InstantController::ShowOverlay(int height, InstantSizeUnits units) {
// If we are on a committed search results page, the |overlay_| is not in use.
- if (UseInstantTabToShowSuggestions())
+ if (instant_tab_)
return;
LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
@@ -1398,7 +1397,7 @@ void InstantController::ShowOverlay(int height, InstantSizeUnits units) {
// - Instant is disabled. The page needs to be able to show only a dropdown.
// - The page is over a website other than search or an NTP, and is not
// already showing at 100% height.
- if (overlay_->IsLocalOverlay() || !instant_enabled_ ||
+ if (overlay_->IsLocal() || !instant_enabled_ ||
(search_mode_.is_origin_default() && !IsFullHeight(model_)))
model_.SetOverlayState(search_mode_, height, units);
else
@@ -1614,17 +1613,17 @@ bool InstantController::FixSuggestion(InstantSuggestion* suggestion) const {
return false;
}
-bool InstantController::UseInstantTabToShowSuggestions() const {
- return instant_tab_ && !instant_tab_->IsLocalNTP();
-}
-
bool InstantController::ShouldSwitchToLocalNTP() const {
+ bool localNtpUrlChanged =
samarth 2013/04/17 16:24:11 This was really confusing for me to reason about.
jeremycho 2013/04/17 20:14:33 Done.
+ (ntp_->instant_url() != chrome::GetLocalInstantURL(
+ browser_->profile()).spec());
+
// If there is no Instant URL or the NTP is stale, switch.
std::string instant_url;
if (!GetInstantURL(browser_->profile(), false, &instant_url) ||
!chrome::MatchesOriginAndPath(GURL(ntp_->instant_url()),
GURL(instant_url))) {
- return true;
+ return localNtpUrlChanged;
}
if (ntp_->supports_instant())
@@ -1634,7 +1633,7 @@ bool InstantController::ShouldSwitchToLocalNTP() const {
// TODO(shishir): This is not completely reliable. Find a better way to detect
// startup time.
if (browser_->GetActiveWebContents())
- return true;
+ return localNtpUrlChanged;
- return chrome::IsAggressiveLocalNTPFallbackEnabled();
+ return chrome::IsAggressiveLocalNTPFallbackEnabled() && localNtpUrlChanged;
}
« no previous file with comments | « chrome/browser/ui/search/instant_controller.h ('k') | chrome/browser/ui/search/instant_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698