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 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 // Preload a new Instant NTP, unless using the local NTP which is not |
| 509 // preloaded to conserve memory. | |
| 510 // | |
| 511 // Since this corresponds to a user action, give the remote page another | |
| 512 // try, even if it's blacklisted. We don't want to blacklist pages for the | |
| 513 // duration of a Browser object (for some people, that's effectively | |
| 514 // "forever"). | |
| 515 ResetNTP(true, false); | |
| 516 } | |
| 509 return ntp_contents.Pass(); | 517 return ntp_contents.Pass(); |
| 510 } | 518 } |
| 511 | 519 |
| 512 // TODO(tonyg): This method only fires when the omnibox bounds change. It also | 520 // 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). | 521 // needs to fire when the overlay bounds change (e.g.: open/close info bar). |
| 514 void InstantController::SetPopupBounds(const gfx::Rect& bounds) { | 522 void InstantController::SetPopupBounds(const gfx::Rect& bounds) { |
| 515 if (!extended_enabled_ && !instant_enabled_) | 523 if (!extended_enabled_ && !instant_enabled_) |
| 516 return; | 524 return; |
| 517 | 525 |
| 518 if (popup_bounds_ == bounds) | 526 if (popup_bounds_ == bounds) |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 void InstantController::TabDeactivated(content::WebContents* contents) { | 888 void InstantController::TabDeactivated(content::WebContents* contents) { |
| 881 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated"); | 889 LOG_INSTANT_DEBUG_EVENT(this, "TabDeactivated"); |
| 882 if (extended_enabled_ && !contents->IsBeingDestroyed()) | 890 if (extended_enabled_ && !contents->IsBeingDestroyed()) |
| 883 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); | 891 CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
| 884 | 892 |
| 885 if (GetOverlayContents()) | 893 if (GetOverlayContents()) |
| 886 HideOverlay(); | 894 HideOverlay(); |
| 887 } | 895 } |
| 888 | 896 |
| 889 void InstantController::SetInstantEnabled(bool instant_enabled, | 897 void InstantController::SetInstantEnabled(bool instant_enabled, |
| 890 bool use_local_overlay_only) { | 898 bool use_local_page_only) { |
| 891 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( | 899 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( |
| 892 "SetInstantEnabled: instant_enabled=%d, use_local_overlay_only=%d", | 900 "SetInstantEnabled: instant_enabled=%d, use_local_page_only=%d", |
| 893 instant_enabled, use_local_overlay_only)); | 901 instant_enabled, use_local_page_only)); |
| 894 | 902 |
| 895 // Non extended mode does not care about |use_local_overlay_only|. | 903 // Non extended mode does not care about |use_local_page_only|. |
| 896 if (instant_enabled == instant_enabled_ && | 904 if (instant_enabled == instant_enabled_ && |
| 897 (!extended_enabled_ || | 905 (!extended_enabled_ || |
| 898 use_local_overlay_only == use_local_overlay_only_)) { | 906 use_local_page_only == use_local_page_only_)) { |
| 899 return; | 907 return; |
| 900 } | 908 } |
| 901 | 909 |
| 902 instant_enabled_ = instant_enabled; | 910 instant_enabled_ = instant_enabled; |
| 903 use_local_overlay_only_ = use_local_overlay_only; | 911 use_local_page_only_ = use_local_page_only; |
| 904 HideInternal(); | 912 HideInternal(); |
| 905 overlay_.reset(); | 913 overlay_.reset(); |
| 906 if (extended_enabled_ || instant_enabled_) | 914 if (extended_enabled_ || instant_enabled_) |
| 907 EnsureOverlayIsCurrent(false); | 915 EnsureOverlayIsCurrent(false); |
| 908 if (extended_enabled_) | 916 if (extended_enabled_) { |
| 909 ResetNTP(false, false); | 917 // Preload the Instant NTP. But if we are using the local NTP, delete any |
| 918 // existing preloaded NTP (which we should no longer use) and don't preload | |
| 919 // the local one to conserve memory. | |
| 920 if (use_local_page_only_) | |
| 921 ntp_.reset(); | |
| 922 else | |
| 923 ResetNTP(false, false); | |
| 924 } | |
| 910 if (instant_tab_) | 925 if (instant_tab_) |
| 911 instant_tab_->SetDisplayInstantResults(instant_enabled_); | 926 instant_tab_->SetDisplayInstantResults(instant_enabled_); |
| 912 } | 927 } |
| 913 | 928 |
| 914 void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { | 929 void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { |
| 915 if (!extended_enabled_) | 930 if (!extended_enabled_) |
| 916 return; | 931 return; |
| 917 | 932 |
| 918 if (overlay_) | 933 if (overlay_) |
| 919 overlay_->SendThemeBackgroundInfo(theme_info); | 934 overlay_->SendThemeBackgroundInfo(theme_info); |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1442 DCHECK_LE(0, intersection.x()); | 1457 DCHECK_LE(0, intersection.x()); |
| 1443 DCHECK_LE(0, intersection.width()); | 1458 DCHECK_LE(0, intersection.width()); |
| 1444 DCHECK_LE(0, intersection.height()); | 1459 DCHECK_LE(0, intersection.height()); |
| 1445 | 1460 |
| 1446 overlay_->SetPopupBounds(intersection); | 1461 overlay_->SetPopupBounds(intersection); |
| 1447 } | 1462 } |
| 1448 | 1463 |
| 1449 bool InstantController::GetInstantURL(Profile* profile, | 1464 bool InstantController::GetInstantURL(Profile* profile, |
| 1450 bool ignore_blacklist, | 1465 bool ignore_blacklist, |
| 1451 std::string* instant_url) const { | 1466 std::string* instant_url) const { |
| 1452 if (extended_enabled_ && use_local_overlay_only_) | 1467 if (extended_enabled_ && use_local_page_only_) |
| 1453 return false; | 1468 return false; |
| 1454 | 1469 |
| 1455 const GURL instant_url_obj = chrome::GetInstantURL(profile, | 1470 const GURL instant_url_obj = chrome::GetInstantURL(profile, |
| 1456 omnibox_bounds_.x()); | 1471 omnibox_bounds_.x()); |
| 1457 if (!instant_url_obj.is_valid()) | 1472 if (!instant_url_obj.is_valid()) |
| 1458 return false; | 1473 return false; |
| 1459 | 1474 |
| 1460 *instant_url = instant_url_obj.spec(); | 1475 *instant_url = instant_url_obj.spec(); |
| 1461 | 1476 |
| 1462 if (!ignore_blacklist) { | 1477 if (!ignore_blacklist) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1473 } | 1488 } |
| 1474 | 1489 |
| 1475 return true; | 1490 return true; |
| 1476 } | 1491 } |
| 1477 | 1492 |
| 1478 void InstantController::BlacklistAndResetNTP() { | 1493 void InstantController::BlacklistAndResetNTP() { |
| 1479 ++blacklisted_urls_[ntp_->instant_url()]; | 1494 ++blacklisted_urls_[ntp_->instant_url()]; |
| 1480 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_ADDED_TO_BLACKLIST); | 1495 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_ADDED_TO_BLACKLIST); |
| 1481 delete ntp_->ReleaseContents().release(); | 1496 delete ntp_->ReleaseContents().release(); |
| 1482 MessageLoop::current()->DeleteSoon(FROM_HERE, ntp_.release()); | 1497 MessageLoop::current()->DeleteSoon(FROM_HERE, ntp_.release()); |
| 1483 ResetNTP(false, false); | 1498 ResetNTP(false, false); |
|
sreeram
2013/04/18 00:00:34
You should add a similar sort of "if (!use_local_p
samarth
2013/04/18 00:31:19
The only situation I can think of where we get her
| |
| 1484 } | 1499 } |
| 1485 | 1500 |
| 1486 void InstantController::BlacklistAndResetOverlay() { | 1501 void InstantController::BlacklistAndResetOverlay() { |
| 1487 ++blacklisted_urls_[overlay_->instant_url()]; | 1502 ++blacklisted_urls_[overlay_->instant_url()]; |
| 1488 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_ADDED_TO_BLACKLIST); | 1503 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_ADDED_TO_BLACKLIST); |
| 1489 HideInternal(); | 1504 HideInternal(); |
| 1490 delete overlay_->ReleaseContents().release(); | 1505 delete overlay_->ReleaseContents().release(); |
| 1491 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); | 1506 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); |
| 1492 EnsureOverlayIsCurrent(false); | 1507 EnsureOverlayIsCurrent(false); |
| 1493 } | 1508 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1640 return false; | 1655 return false; |
| 1641 | 1656 |
| 1642 // If this is not window startup, switch. | 1657 // If this is not window startup, switch. |
| 1643 // TODO(shishir): This is not completely reliable. Find a better way to detect | 1658 // TODO(shishir): This is not completely reliable. Find a better way to detect |
| 1644 // startup time. | 1659 // startup time. |
| 1645 if (browser_->GetActiveWebContents()) | 1660 if (browser_->GetActiveWebContents()) |
| 1646 return true; | 1661 return true; |
| 1647 | 1662 |
| 1648 return chrome::IsAggressiveLocalNTPFallbackEnabled(); | 1663 return chrome::IsAggressiveLocalNTPFallbackEnabled(); |
| 1649 } | 1664 } |
| OLD | NEW |