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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 return true; | 213 return true; |
214 } | 214 } |
215 | 215 |
216 } // namespace | 216 } // namespace |
217 | 217 |
218 InstantController::InstantController(BrowserInstantController* browser, | 218 InstantController::InstantController(BrowserInstantController* browser, |
219 bool extended_enabled) | 219 bool extended_enabled) |
220 : browser_(browser), | 220 : browser_(browser), |
221 extended_enabled_(extended_enabled), | 221 extended_enabled_(extended_enabled), |
222 instant_enabled_(false), | 222 instant_enabled_(false), |
223 use_local_overlay_only_(true), | 223 use_local_page_only_(true), |
224 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 224 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
225 last_omnibox_text_has_inline_autocompletion_(false), | 225 last_omnibox_text_has_inline_autocompletion_(false), |
226 last_verbatim_(false), | 226 last_verbatim_(false), |
227 last_transition_type_(content::PAGE_TRANSITION_LINK), | 227 last_transition_type_(content::PAGE_TRANSITION_LINK), |
228 last_match_was_search_(false), | 228 last_match_was_search_(false), |
229 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), | 229 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), |
230 omnibox_bounds_(-1, -1, 0, 0), | 230 omnibox_bounds_(-1, -1, 0, 0), |
231 allow_overlay_to_show_search_suggestions_(false), | 231 allow_overlay_to_show_search_suggestions_(false), |
232 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 232 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
233 | 233 |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
497 return scoped_ptr<content::WebContents>(NULL); | 497 return scoped_ptr<content::WebContents>(NULL); |
498 | 498 |
499 LOG_INSTANT_DEBUG_EVENT(this, "ReleaseNTPContents"); | 499 LOG_INSTANT_DEBUG_EVENT(this, "ReleaseNTPContents"); |
500 | 500 |
501 // Switch to the local NTP unless we're already using one. | 501 // Switch to the local NTP unless we're already using one. |
502 if (!ntp_ || (ShouldSwitchToLocalNTP() && !ntp_->IsLocalNTP())) | 502 if (!ntp_ || (ShouldSwitchToLocalNTP() && !ntp_->IsLocalNTP())) |
503 ResetNTP(false, true); | 503 ResetNTP(false, true); |
504 | 504 |
505 scoped_ptr<content::WebContents> ntp_contents = ntp_->ReleaseContents(); | 505 scoped_ptr<content::WebContents> ntp_contents = ntp_->ReleaseContents(); |
506 | 506 |
507 // Override the blacklist on an explicit user action. | 507 if (!use_local_page_only_) { |
508 ResetNTP(true, false); | 508 // Don't preload the local NTP. Override the blacklist on an explicit user |
Jered
2013/04/17 22:42:06
How about:
// Preload a new Instant NTP for the ne
Jered
2013/04/17 22:42:06
Update the comment to explain why the blacklist is
samarth
2013/04/17 23:28:15
Done.
samarth
2013/04/17 23:28:15
Done. How does this sound?
| |
509 // action. | |
510 ResetNTP(true, false); | |
511 } | |
509 return ntp_contents.Pass(); | 512 return ntp_contents.Pass(); |
510 } | 513 } |
511 | 514 |
512 // TODO(tonyg): This method only fires when the omnibox bounds change. It also | 515 // TODO(tonyg): This method only fires when the omnibox bounds change. It also |
513 // needs to fire when the overlay bounds change (e.g.: open/close info bar). | 516 // needs to fire when the overlay bounds change (e.g.: open/close info bar). |
514 void InstantController::SetPopupBounds(const gfx::Rect& bounds) { | 517 void InstantController::SetPopupBounds(const gfx::Rect& bounds) { |
515 if (!extended_enabled_ && !instant_enabled_) | 518 if (!extended_enabled_ && !instant_enabled_) |
516 return; | 519 return; |
517 | 520 |
518 if (popup_bounds_ == bounds) | 521 if (popup_bounds_ == bounds) |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
880 void InstantController::TabDeactivated(content::WebContents* contents) { | 883 void InstantController::TabDeactivated(content::WebContents* contents) { |
881 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated"); | 884 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated"); |
882 if (extended_enabled_ && !contents->IsBeingDestroyed()) | 885 if (extended_enabled_ && !contents->IsBeingDestroyed()) |
883 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); | 886 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
884 | 887 |
885 if (GetOverlayContents()) | 888 if (GetOverlayContents()) |
886 HideOverlay(); | 889 HideOverlay(); |
887 } | 890 } |
888 | 891 |
889 void InstantController::SetInstantEnabled(bool instant_enabled, | 892 void InstantController::SetInstantEnabled(bool instant_enabled, |
890 bool use_local_overlay_only) { | 893 bool use_local_page_only) { |
891 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 894 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
892 "SetInstantEnabled: instant_enabled=%d, use_local_overlay_only=%d", | 895 "SetInstantEnabled: instant_enabled=%d, use_local_page_only=%d", |
893 instant_enabled, use_local_overlay_only)); | 896 instant_enabled, use_local_page_only)); |
894 | 897 |
895 // Non extended mode does not care about |use_local_overlay_only|. | 898 // Non extended mode does not care about |use_local_page_only|. |
896 if (instant_enabled == instant_enabled_ && | 899 if (instant_enabled == instant_enabled_ && |
897 (!extended_enabled_ || | 900 (!extended_enabled_ || |
898 use_local_overlay_only == use_local_overlay_only_)) { | 901 use_local_page_only == use_local_page_only_)) { |
899 return; | 902 return; |
900 } | 903 } |
901 | 904 |
902 instant_enabled_ = instant_enabled; | 905 instant_enabled_ = instant_enabled; |
903 use_local_overlay_only_ = use_local_overlay_only; | 906 use_local_page_only_ = use_local_page_only; |
904 HideInternal(); | 907 HideInternal(); |
905 overlay_.reset(); | 908 overlay_.reset(); |
906 if (extended_enabled_ || instant_enabled_) | 909 if (extended_enabled_ || instant_enabled_) |
907 EnsureOverlayIsCurrent(false); | 910 EnsureOverlayIsCurrent(false); |
908 if (extended_enabled_) | 911 if (extended_enabled_) { |
909 ResetNTP(false, false); | 912 // Preload the Instant NTP unless we are using the local NTP. |
Jered
2013/04/17 22:42:06
Why not? Why do we want to reset it otherwise?
samarth
2013/04/17 23:28:15
Done.
| |
913 if (use_local_page_only_) | |
914 ntp_.reset(); | |
915 else | |
916 ResetNTP(false, false); | |
917 } | |
910 if (instant_tab_) | 918 if (instant_tab_) |
911 instant_tab_->SetDisplayInstantResults(instant_enabled_); | 919 instant_tab_->SetDisplayInstantResults(instant_enabled_); |
912 } | 920 } |
913 | 921 |
914 void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { | 922 void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { |
915 if (!extended_enabled_) | 923 if (!extended_enabled_) |
916 return; | 924 return; |
917 | 925 |
918 if (overlay_) | 926 if (overlay_) |
919 overlay_->SendThemeBackgroundInfo(theme_info); | 927 overlay_->SendThemeBackgroundInfo(theme_info); |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1442 DCHECK_LE(0, intersection.x()); | 1450 DCHECK_LE(0, intersection.x()); |
1443 DCHECK_LE(0, intersection.width()); | 1451 DCHECK_LE(0, intersection.width()); |
1444 DCHECK_LE(0, intersection.height()); | 1452 DCHECK_LE(0, intersection.height()); |
1445 | 1453 |
1446 overlay_->SetPopupBounds(intersection); | 1454 overlay_->SetPopupBounds(intersection); |
1447 } | 1455 } |
1448 | 1456 |
1449 bool InstantController::GetInstantURL(Profile* profile, | 1457 bool InstantController::GetInstantURL(Profile* profile, |
1450 bool ignore_blacklist, | 1458 bool ignore_blacklist, |
1451 std::string* instant_url) const { | 1459 std::string* instant_url) const { |
1452 if (extended_enabled_ && use_local_overlay_only_) | 1460 if (extended_enabled_ && use_local_page_only_) |
1453 return false; | 1461 return false; |
1454 | 1462 |
1455 const GURL instant_url_obj = chrome::GetInstantURL(profile, | 1463 const GURL instant_url_obj = chrome::GetInstantURL(profile, |
1456 omnibox_bounds_.x()); | 1464 omnibox_bounds_.x()); |
1457 if (!instant_url_obj.is_valid()) | 1465 if (!instant_url_obj.is_valid()) |
1458 return false; | 1466 return false; |
1459 | 1467 |
1460 *instant_url = instant_url_obj.spec(); | 1468 *instant_url = instant_url_obj.spec(); |
1461 | 1469 |
1462 if (!ignore_blacklist) { | 1470 if (!ignore_blacklist) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1640 return false; | 1648 return false; |
1641 | 1649 |
1642 // If this is not window startup, switch. | 1650 // If this is not window startup, switch. |
1643 // TODO(shishir): This is not completely reliable. Find a better way to detect | 1651 // TODO(shishir): This is not completely reliable. Find a better way to detect |
1644 // startup time. | 1652 // startup time. |
1645 if (browser_->GetActiveWebContents()) | 1653 if (browser_->GetActiveWebContents()) |
1646 return true; | 1654 return true; |
1647 | 1655 |
1648 return chrome::IsAggressiveLocalNTPFallbackEnabled(); | 1656 return chrome::IsAggressiveLocalNTPFallbackEnabled(); |
1649 } | 1657 } |
OLD | NEW |