Chromium Code Reviews| 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 | 455 |
| 456 if (!UseInstantTabToShowSuggestions()) { | 456 if (!UseInstantTabToShowSuggestions()) { |
| 457 if (first_interaction_time_.is_null()) | 457 if (first_interaction_time_.is_null()) |
| 458 first_interaction_time_ = base::Time::Now(); | 458 first_interaction_time_ = base::Time::Now(); |
| 459 allow_overlay_to_show_search_suggestions_ = true; | 459 allow_overlay_to_show_search_suggestions_ = true; |
| 460 | 460 |
| 461 // For extended mode, if the loader is not ready at this point, switch over | 461 // For extended mode, if the loader is not ready at this point, switch over |
| 462 // to a backup loader. | 462 // to a backup loader. |
| 463 if (extended_enabled_ && !overlay_->supports_instant() && | 463 if (extended_enabled_ && !overlay_->supports_instant() && |
| 464 !overlay_->IsLocalOverlay() && browser_->GetActiveWebContents()) { | 464 !overlay_->IsLocalOverlay() && browser_->GetActiveWebContents()) { |
| 465 CreateOverlay(chrome::kChromeSearchLocalOmniboxPopupURL, | 465 CreateOverlay(chrome::kChromeSearchLocalNtpUrl, |
|
samarth
2013/04/15 19:01:34
Replace this (and below) with a GetLocalInstantURL
jeremycho
2013/04/16 01:42:37
Done.
| |
| 466 browser_->GetActiveWebContents()); | 466 browser_->GetActiveWebContents()); |
| 467 } | 467 } |
| 468 | 468 |
| 469 overlay_->Update(extended_enabled_ ? user_text : full_text, | 469 overlay_->Update(extended_enabled_ ? user_text : full_text, |
| 470 selection_start, selection_end, verbatim); | 470 selection_start, selection_end, verbatim); |
| 471 } | 471 } |
| 472 | 472 |
| 473 content::NotificationService::current()->Notify( | 473 content::NotificationService::current()->Notify( |
| 474 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, | 474 chrome::NOTIFICATION_INSTANT_CONTROLLER_UPDATED, |
| 475 content::Source<InstantController>(this), | 475 content::Source<InstantController>(this), |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 663 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| 664 "CommitIfPossible: type=%d last_omnibox_text_='%s' " | 664 "CommitIfPossible: type=%d last_omnibox_text_='%s' " |
| 665 "last_match_was_search_=%d instant_tab_=%d", type, | 665 "last_match_was_search_=%d instant_tab_=%d", type, |
| 666 UTF16ToUTF8(last_omnibox_text_).c_str(), last_match_was_search_, | 666 UTF16ToUTF8(last_omnibox_text_).c_str(), last_match_was_search_, |
| 667 instant_tab_ != NULL)); | 667 instant_tab_ != NULL)); |
| 668 | 668 |
| 669 // If we are on an already committed search results page, send a submit event | 669 // If we are on an already committed search results page, send a submit event |
| 670 // to the page, but otherwise, nothing else to do. | 670 // to the page, but otherwise, nothing else to do. |
| 671 if (UseInstantTabToShowSuggestions()) { | 671 if (UseInstantTabToShowSuggestions()) { |
| 672 if (type == INSTANT_COMMIT_PRESSED_ENTER && | 672 if (type == INSTANT_COMMIT_PRESSED_ENTER && |
| 673 !instant_tab_->IsLocalNTP() && | |
| 673 (last_match_was_search_ || | 674 (last_match_was_search_ || |
| 674 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)) { | 675 last_suggestion_.behavior == INSTANT_COMPLETE_NEVER)) { |
| 675 last_suggestion_.text.clear(); | 676 last_suggestion_.text.clear(); |
| 676 instant_tab_->Submit(last_omnibox_text_); | 677 instant_tab_->Submit(last_omnibox_text_); |
| 677 instant_tab_->contents()->GetView()->Focus(); | 678 instant_tab_->contents()->GetView()->Focus(); |
| 678 EnsureSearchTermsAreSet(instant_tab_->contents(), last_omnibox_text_); | 679 EnsureSearchTermsAreSet(instant_tab_->contents(), last_omnibox_text_); |
| 679 return true; | 680 return true; |
| 680 } | 681 } |
| 681 return false; | 682 return false; |
| 682 } | 683 } |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 922 #if defined(USE_AURA) | 923 #if defined(USE_AURA) |
| 923 // On aura the omnibox only receives a focus lost if we initiate the focus | 924 // On aura the omnibox only receives a focus lost if we initiate the focus |
| 924 // change. This does that. | 925 // change. This does that. |
| 925 if (!model_.mode().is_default()) | 926 if (!model_.mode().is_default()) |
| 926 browser_->InstantOverlayFocused(); | 927 browser_->InstantOverlayFocused(); |
| 927 #endif | 928 #endif |
| 928 } | 929 } |
| 929 | 930 |
| 930 void InstantController::ReloadOverlayIfStale() { | 931 void InstantController::ReloadOverlayIfStale() { |
| 931 // The local overlay is never stale. | 932 // The local overlay is never stale. |
| 932 if (overlay_ && overlay_->IsLocalOverlay()) | 933 if (overlay_ && overlay_->IsLocalOverlay()) |
|
samarth
2013/04/15 19:01:34
Replace all instances of IsLocalOverlay with IsLoc
jeremycho
2013/04/16 01:42:37
Done. Will do the rename in a followup.
| |
| 933 return; | 934 return; |
| 934 | 935 |
| 935 // If the overlay is showing or the omnibox has focus, don't delete the | 936 // If the overlay is showing or the omnibox has focus, don't delete the |
| 936 // overlay. It will get refreshed the next time the overlay is hidden or the | 937 // overlay. It will get refreshed the next time the overlay is hidden or the |
| 937 // omnibox loses focus. | 938 // omnibox loses focus. |
| 938 if ((!overlay_ || overlay_->is_stale()) && | 939 if ((!overlay_ || overlay_->is_stale()) && |
| 939 omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && | 940 omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && |
| 940 model_.mode().is_default()) { | 941 model_.mode().is_default()) { |
| 941 overlay_.reset(); | 942 overlay_.reset(); |
| 942 EnsureOverlayIsCurrent(false); | 943 EnsureOverlayIsCurrent(false); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1261 else if (!IsViewInContents(GetViewGainingFocus(view_gaining_focus), | 1262 else if (!IsViewInContents(GetViewGainingFocus(view_gaining_focus), |
| 1262 overlay_->contents())) | 1263 overlay_->contents())) |
| 1263 HideOverlay(); | 1264 HideOverlay(); |
| 1264 #endif | 1265 #endif |
| 1265 } | 1266 } |
| 1266 | 1267 |
| 1267 void InstantController::ResetNTP(bool ignore_blacklist, bool use_local_ntp) { | 1268 void InstantController::ResetNTP(bool ignore_blacklist, bool use_local_ntp) { |
| 1268 std::string instant_url; | 1269 std::string instant_url; |
| 1269 if (use_local_ntp || | 1270 if (use_local_ntp || |
| 1270 !GetInstantURL(browser_->profile(), ignore_blacklist, &instant_url)) | 1271 !GetInstantURL(browser_->profile(), ignore_blacklist, &instant_url)) |
| 1271 instant_url = chrome::kChromeSearchLocalNtpUrl; | 1272 instant_url = chrome::kChromeSearchLocalNtpUrl; |
|
samarth
2013/04/15 19:01:34
Use the GetLocalInstantURL() function here too.
jeremycho
2013/04/16 01:42:37
Done.
| |
| 1272 ntp_.reset(new InstantNTP(this, instant_url)); | 1273 ntp_.reset(new InstantNTP(this, instant_url)); |
| 1273 ntp_->InitContents(browser_->profile(), browser_->GetActiveWebContents(), | 1274 ntp_->InitContents(browser_->profile(), browser_->GetActiveWebContents(), |
| 1274 base::Bind(&InstantController::ResetNTP, | 1275 base::Bind(&InstantController::ResetNTP, |
| 1275 base::Unretained(this), false, false)); | 1276 base::Unretained(this), false, false)); |
| 1276 } | 1277 } |
| 1277 | 1278 |
| 1278 bool InstantController::EnsureOverlayIsCurrent(bool ignore_blacklist) { | 1279 bool InstantController::EnsureOverlayIsCurrent(bool ignore_blacklist) { |
| 1279 // If there's no active tab, the browser is closing. | 1280 // If there's no active tab, the browser is closing. |
| 1280 const content::WebContents* active_tab = browser_->GetActiveWebContents(); | 1281 const content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 1281 if (!active_tab) | 1282 if (!active_tab) |
| 1282 return false; | 1283 return false; |
| 1283 | 1284 |
| 1284 Profile* profile = Profile::FromBrowserContext( | 1285 Profile* profile = Profile::FromBrowserContext( |
| 1285 active_tab->GetBrowserContext()); | 1286 active_tab->GetBrowserContext()); |
| 1286 std::string instant_url; | 1287 std::string instant_url; |
| 1287 if (!GetInstantURL(profile, ignore_blacklist, &instant_url)) { | 1288 if (!GetInstantURL(profile, ignore_blacklist, &instant_url)) { |
| 1288 // If we are in extended mode, fallback to the local overlay. | 1289 // If we are in extended mode, fallback to the local overlay. |
| 1289 if (extended_enabled_) | 1290 if (extended_enabled_) |
| 1290 instant_url = chrome::kChromeSearchLocalOmniboxPopupURL; | 1291 instant_url = chrome::kChromeSearchLocalNtpUrl; |
|
samarth
2013/04/15 19:01:34
Use the GetLocalInstantURL() function here too.
jeremycho
2013/04/16 01:42:37
Done.
| |
| 1291 else | 1292 else |
| 1292 return false; | 1293 return false; |
| 1293 } | 1294 } |
| 1294 | 1295 |
| 1295 if (!overlay_ || overlay_->instant_url() != instant_url) | 1296 if (!overlay_ || overlay_->instant_url() != instant_url) |
| 1296 CreateOverlay(instant_url, active_tab); | 1297 CreateOverlay(instant_url, active_tab); |
| 1297 | 1298 |
| 1298 return true; | 1299 return true; |
| 1299 } | 1300 } |
| 1300 | 1301 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1607 // suggest 'nstant'. Otherwise, the user text really isn't a prefix, so | 1608 // suggest 'nstant'. Otherwise, the user text really isn't a prefix, so |
| 1608 // suggest nothing. | 1609 // suggest nothing. |
| 1609 // TODO(samarth|jered): revisit this logic. http://crbug.com/196572. | 1610 // TODO(samarth|jered): revisit this logic. http://crbug.com/196572. |
| 1610 return true; | 1611 return true; |
| 1611 } | 1612 } |
| 1612 } | 1613 } |
| 1613 | 1614 |
| 1614 return false; | 1615 return false; |
| 1615 } | 1616 } |
| 1616 | 1617 |
| 1617 bool InstantController::UseInstantTabToShowSuggestions() const { | 1618 bool InstantController::UseInstantTabToShowSuggestions() const { |
|
samarth
2013/04/15 19:01:34
You can just inline this check wherever this funct
jeremycho
2013/04/16 01:42:37
Done.
| |
| 1618 return instant_tab_ && !instant_tab_->IsLocalNTP(); | 1619 return instant_tab_; |
| 1619 } | 1620 } |
| 1620 | 1621 |
| 1621 bool InstantController::ShouldSwitchToLocalNTP() const { | 1622 bool InstantController::ShouldSwitchToLocalNTP() const { |
| 1622 // If there is no Instant URL or the NTP is stale, switch. | 1623 // If there is no Instant URL or the NTP is stale, switch. |
| 1623 std::string instant_url; | 1624 std::string instant_url; |
| 1624 if (!GetInstantURL(browser_->profile(), false, &instant_url) || | 1625 if (!GetInstantURL(browser_->profile(), false, &instant_url) || |
| 1625 !chrome::MatchesOriginAndPath(GURL(ntp_->instant_url()), | 1626 !chrome::MatchesOriginAndPath(GURL(ntp_->instant_url()), |
| 1626 GURL(instant_url))) { | 1627 GURL(instant_url))) { |
| 1627 return true; | 1628 return true; |
| 1628 } | 1629 } |
| 1629 | 1630 |
| 1630 if (ntp_->supports_instant()) | 1631 if (ntp_->supports_instant()) |
| 1631 return false; | 1632 return false; |
| 1632 | 1633 |
| 1633 // If this is not window startup, switch. | 1634 // If this is not window startup, switch. |
| 1634 // TODO(shishir): This is not completely reliable. Find a better way to detect | 1635 // TODO(shishir): This is not completely reliable. Find a better way to detect |
| 1635 // startup time. | 1636 // startup time. |
| 1636 if (browser_->GetActiveWebContents()) | 1637 if (browser_->GetActiveWebContents()) |
| 1637 return true; | 1638 return true; |
| 1638 | 1639 |
| 1639 return chrome::IsAggressiveLocalNTPFallbackEnabled(); | 1640 return chrome::IsAggressiveLocalNTPFallbackEnabled(); |
| 1640 } | 1641 } |
| OLD | NEW |