Index: chrome/browser/instant/instant_controller.cc |
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc |
index 175fef2ad24763f3f98c3bcb17ca4f063e2f7c9e..2ededbe70fb922ff5fdc854c1910e6ef35d48e7d 100644 |
--- a/chrome/browser/instant/instant_controller.cc |
+++ b/chrome/browser/instant/instant_controller.cc |
@@ -13,7 +13,8 @@ |
#include "chrome/browser/history/history.h" |
#include "chrome/browser/history/history_service_factory.h" |
#include "chrome/browser/history/history_tab_helper.h" |
-#include "chrome/browser/instant/instant_loader.h" |
+#include "chrome/browser/instant/instant_ntp.h" |
+#include "chrome/browser/instant/instant_overlay.h" |
#include "chrome/browser/instant/instant_tab.h" |
#include "chrome/browser/platform_util.h" |
#include "chrome/browser/search_engines/template_url_service.h" |
@@ -46,7 +47,7 @@ const int kMaxInstantSupportFailures = 10; |
// If an Instant page has not been used in these many milliseconds, it is |
// reloaded so that the page does not become stale. |
-const int kStaleLoaderTimeoutMS = 3 * 3600 * 1000; |
+const int kStalePageTimeoutMS = 3 * 3600 * 1000; |
// For reporting events of interest. |
enum InstantControllerEvent { |
@@ -215,7 +216,7 @@ bool InstantController::Update(const AutocompleteMatch& match, |
if (instant_tab_) |
instant_tab_->Update(string16(), 0, 0, true); |
else |
- HideLoader(); |
+ HideOverlay(); |
last_match_was_search_ = false; |
return false; |
} |
@@ -237,21 +238,21 @@ bool InstantController::Update(const AutocompleteMatch& match, |
// The preview is being clicked and will commit soon. Don't change anything. |
// TODO(sreeram): Add a browser test for this. |
- if (loader_ && loader_->is_pointer_down_from_activate()) |
+ if (overlay_ && overlay_->is_pointer_down_from_activate()) |
return false; |
// In non-extended mode, SearchModeChanged() is never called, so fake it. The |
// mode is set to "disallow suggestions" here, so that if one of the early |
// "return false" conditions is hit, suggestions will be disallowed. If the |
- // query is sent to the loader, the mode is set to "allow" further below. |
+ // query is sent to the overlay, the mode is set to "allow" further below. |
if (!extended_enabled_) |
search_mode_.mode = chrome::search::Mode::MODE_DEFAULT; |
last_match_was_search_ = AutocompleteMatch::IsSearchType(match.type) && |
!user_text.empty(); |
- if (!ResetLoaderForMatch(match)) { |
- HideLoader(); |
+ if (!ResetOverlayForMatch(match)) { |
+ HideOverlay(); |
return false; |
} |
@@ -276,7 +277,7 @@ bool InstantController::Update(const AutocompleteMatch& match, |
} else if (!full_text.empty()) { |
// If |full_text| is empty, the user is on the NTP. The preview may |
// be showing custom NTP content; hide only if that's not the case. |
- HideLoader(); |
+ HideOverlay(); |
} |
} else if (full_text.empty()) { |
// The user is typing, and backspaced away all omnibox text. Clear |
@@ -289,13 +290,13 @@ bool InstantController::Update(const AutocompleteMatch& match, |
} else if (search_mode_.is_origin_ntp()) { |
// On the NTP, tell the preview to clear old results. Don't hide the |
// preview so it can show a blank page or logo if it wants. |
- loader_->Update(string16(), 0, 0, true); |
+ overlay_->Update(string16(), 0, 0, true); |
} else { |
- HideLoader(); |
+ HideOverlay(); |
} |
} else { |
// The user switched to a tab with partial text already in the omnibox. |
- HideLoader(); |
+ HideOverlay(); |
// The new tab may or may not be a search results page; we don't know |
// since SearchModeChanged() hasn't been called yet. If it later turns |
@@ -314,15 +315,15 @@ bool InstantController::Update(const AutocompleteMatch& match, |
if (instant_tab_) |
instant_tab_->Update(string16(), 0, 0, true); |
else if (search_mode_.is_origin_ntp()) |
- loader_->Update(string16(), 0, 0, true); |
+ overlay_->Update(string16(), 0, 0, true); |
else |
- HideLoader(); |
+ HideOverlay(); |
return false; |
} |
} else if (!omnibox_popup_is_open || full_text.empty()) { |
// In the non-extended case, hide the preview as long as the user isn't |
// actively typing a non-empty query. |
- HideLoader(); |
+ HideOverlay(); |
return false; |
} |
@@ -371,7 +372,7 @@ bool InstantController::Update(const AutocompleteMatch& match, |
if (first_interaction_time_.is_null()) |
first_interaction_time_ = base::Time::Now(); |
allow_preview_to_show_search_suggestions_ = true; |
- loader_->Update(extended_enabled_ ? user_text : full_text, |
+ overlay_->Update(extended_enabled_ ? user_text : full_text, |
selection_start, selection_end, verbatim); |
} |
@@ -390,6 +391,16 @@ bool InstantController::Update(const AutocompleteMatch& match, |
return last_match_was_search_; |
} |
+content::WebContents* InstantController::ReleaseNTPContents() { |
+ if (!extended_enabled_ || !ntp_) |
+ return NULL; |
+ |
+ content::WebContents* ntp_contents = ntp_->ReleaseContents(); |
+ ntp_.reset(); |
+ ResetNTP(); |
+ return ntp_contents; |
+} |
+ |
// TODO(tonyg): This method only fires when the omnibox bounds change. It also |
// needs to fire when the preview bounds change (e.g.: open/close info bar). |
void InstantController::SetPopupBounds(const gfx::Rect& bounds) { |
@@ -416,8 +427,10 @@ void InstantController::SetMarginSize(int start, int end) { |
start_margin_ = start; |
end_margin_ = end; |
- if (loader_) |
- loader_->SetMarginSize(start_margin_, end_margin_); |
+ if (overlay_) |
+ overlay_->SetMarginSize(start_margin_, end_margin_); |
+ if (ntp_) |
+ ntp_->SetMarginSize(start_margin_, end_margin_); |
if (instant_tab_) |
instant_tab_->SetMarginSize(start_margin_, end_margin_); |
} |
@@ -427,7 +440,7 @@ void InstantController::HandleAutocompleteResults( |
if (!extended_enabled_) |
return; |
- if (!instant_tab_ && !loader_) |
+ if (!instant_tab_ && !overlay_) |
return; |
DVLOG(1) << "AutocompleteResults:"; |
@@ -453,26 +466,26 @@ void InstantController::HandleAutocompleteResults( |
if (instant_tab_) |
instant_tab_->SendAutocompleteResults(results); |
else |
- loader_->SendAutocompleteResults(results); |
+ overlay_->SendAutocompleteResults(results); |
} |
bool InstantController::OnUpOrDownKeyPressed(int count) { |
if (!extended_enabled_) |
return false; |
- if (!instant_tab_ && !loader_) |
+ if (!instant_tab_ && !overlay_) |
return false; |
if (instant_tab_) |
instant_tab_->UpOrDownKeyPressed(count); |
else |
- loader_->UpOrDownKeyPressed(count); |
+ overlay_->UpOrDownKeyPressed(count); |
return true; |
} |
content::WebContents* InstantController::GetPreviewContents() const { |
- return loader_ ? loader_->contents() : NULL; |
+ return overlay_ ? overlay_->contents() : NULL; |
} |
bool InstantController::IsPreviewingSearchResults() const { |
@@ -504,21 +517,21 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { |
// There may re-entrance here, from the call to browser_->CommitInstant below, |
// which can cause a TabDeactivated notification which gets back here. |
- // In this case, loader_->ReleaseContents() was called already. |
+ // In this case, overlay_->ReleaseContents() was called already. |
if (!GetPreviewContents()) |
return false; |
// Never commit the local omnibox. |
- if (loader_->IsUsingLocalPreview()) |
+ if (overlay_->IsUsingLocalPreview()) |
return false; |
if (type == INSTANT_COMMIT_FOCUS_LOST) |
- loader_->Cancel(last_omnibox_text_); |
+ overlay_->Cancel(last_omnibox_text_); |
else if (type != INSTANT_COMMIT_NAVIGATED && |
type != INSTANT_COMMIT_CLICKED_QUERY_SUGGESTION) |
- loader_->Submit(last_omnibox_text_); |
+ overlay_->Submit(last_omnibox_text_); |
- content::WebContents* preview = loader_->ReleaseContents(); |
+ content::WebContents* preview = overlay_->ReleaseContents(); |
if (extended_enabled_) { |
// Consider what's happening: |
@@ -556,11 +569,11 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { |
// the navigation to history ourselves. Else, the page will navigate after |
// commit, and it will be added to history in the usual manner. |
const history::HistoryAddPageArgs& last_navigation = |
- loader_->last_navigation(); |
+ overlay_->last_navigation(); |
if (!last_navigation.url.is_empty()) { |
content::NavigationEntry* entry = preview->GetController().GetActiveEntry(); |
- // The last navigation should be the same as the active entry if the loader |
+ // The last navigation should be the same as the active entry if the overlay |
// is in search mode. During navigation, the active entry could have |
// changed since DidCommitProvisionalLoadForFrame is called after the entry |
// is changed. |
@@ -606,15 +619,15 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { |
content::Source<content::WebContents>(preview), |
content::NotificationService::NoDetails()); |
- // Hide explicitly. See comments in HideLoader() for why. |
+ // Hide explicitly. See comments in HideOverlay() for why. |
model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); |
- // Delay deletion as we could've gotten here from an InstantLoader method. |
- MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); |
+ // Delay deletion as we could've gotten here from an InstantOverlay method. |
+ MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); |
- // Try to create another loader immediately so that it is ready for the next |
+ // Try to create another overlay immediately so that it is ready for the next |
// user interaction. |
- CreateDefaultLoader(); |
+ CreateDefaultOverlay(); |
return true; |
} |
@@ -640,14 +653,20 @@ void InstantController::OmniboxFocusChanged( |
// have no way of telling whether the keycapturechange happened because of |
// some actual user action or just because they started typing.) |
if (extended_enabled_ && GetPreviewContents() && |
- reason != OMNIBOX_FOCUS_CHANGE_TYPING) |
- loader_->KeyCaptureChanged(omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); |
+ reason != OMNIBOX_FOCUS_CHANGE_TYPING) { |
+ const bool is_key_capture_enabled = |
+ omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE; |
+ if (overlay_) |
+ overlay_->KeyCaptureChanged(is_key_capture_enabled); |
+ if (instant_tab_) |
+ instant_tab_->KeyCaptureChanged(is_key_capture_enabled); |
+ } |
// If focus went from outside the omnibox to the omnibox, preload the default |
// search engine, in anticipation of the user typing a query. If the reverse |
// happened, commit or discard the preview. |
if (state != OMNIBOX_FOCUS_NONE && old_focus_state == OMNIBOX_FOCUS_NONE) |
- CreateDefaultLoader(); |
+ CreateDefaultOverlay(); |
else if (state == OMNIBOX_FOCUS_NONE && old_focus_state != OMNIBOX_FOCUS_NONE) |
OmniboxLostFocus(view_gaining_focus); |
} |
@@ -664,10 +683,10 @@ void InstantController::SearchModeChanged( |
search_mode_ = new_mode; |
if (!new_mode.is_search_suggestions()) |
- HideLoader(); |
+ HideOverlay(); |
- if (loader_) |
- loader_->SearchModeChanged(new_mode); |
+ if (overlay_) |
+ overlay_->SearchModeChanged(new_mode); |
ResetInstantTab(); |
} |
@@ -678,10 +697,8 @@ void InstantController::ActiveTabChanged() { |
DVLOG(1) << "ActiveTabChanged"; |
- // When switching tabs, always hide the preview, except if it's showing NTP |
- // content, and the new tab is also an NTP. |
- if (!search_mode_.is_ntp() || !model_.mode().is_ntp()) |
- HideLoader(); |
+ // When switching tabs, always hide the preview. |
+ HideOverlay(); |
if (extended_enabled_) |
ResetInstantTab(); |
@@ -697,9 +714,11 @@ void InstantController::SetInstantEnabled(bool instant_enabled) { |
DVLOG(1) << "SetInstantEnabled: " << instant_enabled; |
instant_enabled_ = instant_enabled; |
HideInternal(); |
- loader_.reset(); |
+ overlay_.reset(); |
if (extended_enabled_ || instant_enabled_) |
- CreateDefaultLoader(); |
+ CreateDefaultOverlay(); |
+ if (extended_enabled_) |
+ ResetNTP(); |
if (instant_tab_) |
instant_tab_->SetDisplayInstantResults(instant_enabled_); |
} |
@@ -708,16 +727,20 @@ void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { |
if (!extended_enabled_) |
return; |
- if (loader_) |
- loader_->SendThemeBackgroundInfo(theme_info); |
+ if (overlay_) |
+ overlay_->SendThemeBackgroundInfo(theme_info); |
+ if (ntp_) |
+ ntp_->SendThemeBackgroundInfo(theme_info); |
} |
void InstantController::ThemeAreaHeightChanged(int height) { |
if (!extended_enabled_) |
return; |
- if (loader_) |
- loader_->SendThemeAreaHeight(height); |
+ if (overlay_) |
+ overlay_->SendThemeAreaHeight(height); |
+ if (ntp_) |
+ ntp_->SendThemeAreaHeight(height); |
} |
void InstantController::SetSuggestions( |
@@ -729,7 +752,7 @@ void InstantController::SetSuggestions( |
if (instant_tab_) { |
if (instant_tab_->contents() != contents) |
return; |
- } else if (!loader_ || loader_->contents() != contents || |
+ } else if (!overlay_ || overlay_->contents() != contents || |
!allow_preview_to_show_search_suggestions_) { |
return; |
} |
@@ -809,9 +832,9 @@ void InstantController::SetSuggestions( |
} |
} |
- // Extended mode pages will call ShowLoader() when they are ready. |
+ // Extended mode pages will call ShowOverlay() when they are ready. |
if (!extended_enabled_) |
- ShowLoader(INSTANT_SHOWN_QUERY_SUGGESTIONS, 100, INSTANT_SIZE_PERCENT); |
+ ShowOverlay(INSTANT_SHOWN_QUERY_SUGGESTIONS, 100, INSTANT_SIZE_PERCENT); |
} |
void InstantController::InstantSupportDetermined( |
@@ -823,19 +846,34 @@ void InstantController::InstantSupportDetermined( |
return; |
} |
- if (loader_ && loader_->contents() == contents) { |
+ if (ntp_ && ntp_->contents() == contents) { |
if (supports_instant) { |
- if (blacklisted_urls_.erase(loader_->instant_url())) { |
+ if (blacklisted_urls_.erase(ntp_->instant_url())) { |
RecordEventHistogram( |
INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); |
} |
} else { |
- ++blacklisted_urls_[loader_->instant_url()]; |
+ ++blacklisted_urls_[ntp_->instant_url()]; |
+ RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_ADDED_TO_BLACKLIST); |
+ delete ntp_->ReleaseContents(); |
+ MessageLoop::current()->DeleteSoon(FROM_HERE, ntp_.release()); |
+ ResetNTP(); |
+ } |
+ } |
+ |
+ if (overlay_ && overlay_->contents() == contents) { |
+ if (supports_instant) { |
+ if (blacklisted_urls_.erase(overlay_->instant_url())) { |
+ RecordEventHistogram( |
+ INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); |
+ } |
+ } else { |
+ ++blacklisted_urls_[overlay_->instant_url()]; |
RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_ADDED_TO_BLACKLIST); |
HideInternal(); |
- delete loader_->ReleaseContents(); |
- MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); |
- CreateDefaultLoader(); |
+ delete overlay_->ReleaseContents(); |
+ MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); |
+ CreateDefaultOverlay(); |
} |
content::NotificationService::current()->Notify( |
chrome::NOTIFICATION_INSTANT_SUPPORT_DETERMINED, |
@@ -848,28 +886,43 @@ void InstantController::ShowInstantPreview(InstantShownReason reason, |
int height, |
InstantSizeUnits units) { |
if (extended_enabled_) |
- ShowLoader(reason, height, units); |
+ ShowOverlay(reason, height, units); |
} |
-void InstantController::StartCapturingKeyStrokes() { |
- // Ignore unless the loader is active and on the NTP. |
- if (extended_enabled_ && !instant_tab_ && model_.mode().is_ntp()) |
+void InstantController::StartCapturingKeyStrokes( |
+ content::WebContents* contents) { |
+ if (!extended_enabled_) |
+ return; |
+ |
+ // Only honor the call if it comes from an active InstantTab or from an |
+ // InstantOverlay that is being shown. |
+ if ((instant_tab_ && instant_tab_->contents() == contents) || |
+ (overlay_ && overlay_->contents() == contents && |
+ !model_.mode().is_default())) { |
browser_->FocusOmniboxInvisibly(); |
+ } |
} |
-void InstantController::StopCapturingKeyStrokes() { |
- // Ignore unless the loader is active and on the NTP, and the omnibox has |
- // invisible focus. |
- if (extended_enabled_ && !instant_tab_ && model_.mode().is_ntp() && |
- omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE) |
- loader_->contents()->Focus(); |
+void InstantController::StopCapturingKeyStrokes( |
+ content::WebContents* contents) { |
+ // Nothing to do if omnibox doesn't have invisible focus. |
+ if (!extended_enabled_ || omnibox_focus_state_ != OMNIBOX_FOCUS_INVISIBLE) |
+ return; |
+ |
+ // Only honor the call if it comes from an active InstantTab or from an |
+ // InstantOverlay that is being shown. |
+ if ((instant_tab_ && instant_tab_->contents() == contents) || |
+ (overlay_ && overlay_->contents() == contents && |
+ !model_.mode().is_default())) { |
+ contents->Focus(); |
+ } |
} |
-void InstantController::SwappedWebContents() { |
+void InstantController::SwappedOverlayWebContents() { |
model_.SetPreviewContents(GetPreviewContents()); |
} |
-void InstantController::InstantLoaderContentsFocused() { |
+void InstantController::InstantOverlayContentsFocused() { |
#if defined(USE_AURA) |
// On aura the omnibox only receives a focus lost if we initiate the focus |
// change. This does that. |
@@ -878,23 +931,32 @@ void InstantController::InstantLoaderContentsFocused() { |
#endif |
} |
-void InstantController::InstantLoaderRenderViewGone() { |
- ++blacklisted_urls_[loader_->instant_url()]; |
+void InstantController::InstantOverlayRenderViewGone() { |
+ ++blacklisted_urls_[overlay_->instant_url()]; |
HideInternal(); |
- delete loader_->ReleaseContents(); |
- // Delay deletion as we have gotten here from an InstantLoader method. |
- MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); |
- CreateDefaultLoader(); |
+ delete overlay_->ReleaseContents(); |
+ // Delay deletion as we have gotten here from an InstantOverlay method. |
+ MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); |
+ CreateDefaultOverlay(); |
+} |
+ |
+void InstantController::InstantNTPRenderViewGone() { |
+ ++blacklisted_urls_[ntp_->instant_url()]; |
+ delete ntp_->ReleaseContents(); |
+ // Delay deletion as we have gotten here from an InstantNTP method. |
+ MessageLoop::current()->DeleteSoon(FROM_HERE, ntp_.release()); |
+ ResetNTP(); |
} |
-void InstantController::InstantLoaderAboutToNavigateMainFrame(const GURL& url) { |
+void InstantController::InstantOverlayAboutToNavigateMainFrame( |
+ const GURL& url) { |
// If the page does not yet support instant, we allow redirects and other |
// navigations to go through since the instant URL can redirect - e.g. to |
// country specific pages. |
- if (!loader_->supports_instant()) |
+ if (!overlay_->supports_instant()) |
return; |
- GURL instant_url(loader_->instant_url()); |
+ GURL instant_url(overlay_->instant_url()); |
// If we are navigating to the instant URL, do nothing. |
if (url == instant_url) |
@@ -920,7 +982,7 @@ void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { |
// If the preview is not showing at all, recreate it if it's stale. |
if (model_.mode().is_default()) { |
- OnStaleLoader(); |
+ OnStaleOverlay(); |
return; |
} |
@@ -931,14 +993,14 @@ void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { |
#if defined(OS_MACOSX) |
// TODO(sreeram): See if Mac really needs this special treatment. |
- if (!loader_->is_pointer_down_from_activate()) |
- HideLoader(); |
+ if (!overlay_->is_pointer_down_from_activate()) |
+ HideOverlay(); |
#else |
if (IsViewInContents(GetViewGainingFocus(view_gaining_focus), |
- loader_->contents())) |
+ overlay_->contents())) |
CommitIfPossible(INSTANT_COMMIT_FOCUS_LOST); |
else |
- HideLoader(); |
+ HideOverlay(); |
#endif |
} |
@@ -946,14 +1008,14 @@ void InstantController::NavigateToURL(const GURL& url, |
content::PageTransition transition) { |
if (!extended_enabled_) |
return; |
- if (loader_) |
- HideLoader(); |
+ if (overlay_) |
+ HideOverlay(); |
browser_->OpenURLInCurrentTab(url, transition); |
} |
-bool InstantController::ResetLoader(const TemplateURL* template_url, |
- const content::WebContents* active_tab, |
- bool fallback_to_local) { |
+bool InstantController::ResetOverlay(const TemplateURL* template_url, |
+ const content::WebContents* active_tab, |
+ bool fallback_to_local) { |
std::string instant_url; |
if (!GetInstantURL(template_url, &instant_url)) { |
if (!fallback_to_local || !extended_enabled_) |
@@ -963,32 +1025,58 @@ bool InstantController::ResetLoader(const TemplateURL* template_url, |
instant_url = kLocalOmniboxPopupURL; |
} |
- if (loader_ && loader_->instant_url() == instant_url) |
+ if (overlay_ && overlay_->instant_url() == instant_url) |
return true; |
HideInternal(); |
- loader_.reset(new InstantLoader(this, instant_url)); |
- loader_->InitContents(active_tab); |
+ overlay_.reset(new InstantOverlay(this, instant_url)); |
+ overlay_->InitContents(browser_->profile(), active_tab); |
// Ensure the searchbox API has the correct initial state. |
if (extended_enabled_) { |
browser_->UpdateThemeInfoForPreview(); |
- loader_->SetDisplayInstantResults(instant_enabled_); |
- loader_->SearchModeChanged(search_mode_); |
- loader_->KeyCaptureChanged(omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); |
- loader_->SetMarginSize(start_margin_, end_margin_); |
+ overlay_->SetDisplayInstantResults(instant_enabled_); |
+ overlay_->SearchModeChanged(search_mode_); |
+ overlay_->KeyCaptureChanged( |
+ omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); |
+ overlay_->SetMarginSize(start_margin_, end_margin_); |
} |
- // Restart the stale loader timer. |
- stale_loader_timer_.Start(FROM_HERE, |
- base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, |
- &InstantController::OnStaleLoader); |
+ // Restart the stale overlay timer. |
+ stale_overlay_timer_.Start(FROM_HERE, |
+ base::TimeDelta::FromMilliseconds(kStalePageTimeoutMS), this, |
+ &InstantController::OnStaleOverlay); |
return true; |
} |
-bool InstantController::CreateDefaultLoader() { |
- // If there's no active tab, the browser is closing. |
+bool InstantController::ResetNTP() { |
+ const TemplateURL* template_url = TemplateURLServiceFactory::GetForProfile( |
+ browser_->profile())->GetDefaultSearchProvider(); |
+ std::string instant_url; |
+ if (!GetInstantURL(template_url, &instant_url)) |
+ return false; |
+ |
+ ntp_.reset(new InstantNTP(this, instant_url)); |
+ ntp_->InitContents(browser_->profile(), browser_->GetActiveWebContents()); |
+ |
+ // Ensure the searchbox API has the correct initial state. |
+ if (extended_enabled_) { |
+ browser_->UpdateThemeInfoForPreview(); |
+ ntp_->SetDisplayInstantResults(instant_enabled_); |
+ ntp_->SetMarginSize(start_margin_, end_margin_); |
+ } |
+ |
+ // Restart the stale NTP timer. |
+ stale_ntp_timer_.Start(FROM_HERE, |
+ base::TimeDelta::FromMilliseconds(kStalePageTimeoutMS), this, |
+ &InstantController::OnStaleNTP); |
+ |
+ return true; |
+} |
+ |
+bool InstantController::CreateDefaultOverlay() { |
+ // If there's no active tab, the browser is opening or closing. |
const content::WebContents* active_tab = browser_->GetActiveWebContents(); |
if (!active_tab) |
return false; |
@@ -997,46 +1085,55 @@ bool InstantController::CreateDefaultLoader() { |
Profile::FromBrowserContext(active_tab->GetBrowserContext()))-> |
GetDefaultSearchProvider(); |
- return ResetLoader(template_url, active_tab, true); |
+ return ResetOverlay(template_url, active_tab, true); |
} |
-void InstantController::OnStaleLoader() { |
+void InstantController::OnStaleOverlay() { |
// The local popup is never stale. |
- if (loader_ && loader_->IsUsingLocalPreview()) |
+ if (overlay_ && overlay_->IsUsingLocalPreview()) |
return; |
// If the preview is showing or the omnibox has focus, don't delete the |
- // loader. It will get refreshed the next time the preview is hidden or the |
+ // overlay. It will get refreshed the next time the preview is hidden or the |
// omnibox loses focus. |
- if (!stale_loader_timer_.IsRunning() && |
+ if (!stale_overlay_timer_.IsRunning() && |
omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && |
model_.mode().is_default()) { |
- loader_.reset(); |
- CreateDefaultLoader(); |
+ overlay_.reset(); |
+ CreateDefaultOverlay(); |
+ } |
+} |
+ |
+void InstantController::OnStaleNTP() { |
+ if (!stale_ntp_timer_.IsRunning()) { |
+ ntp_.reset(); |
+ ResetNTP(); |
} |
} |
void InstantController::ResetInstantTab() { |
// Do not wire up the InstantTab if instant should only use local previews, to |
// prevent it from sending data to the page. |
- if (search_mode_.is_origin_search() && !use_local_preview_only_) { |
+ if (!search_mode_.is_origin_default() && !use_local_preview_only_) { |
content::WebContents* active_tab = browser_->GetActiveWebContents(); |
if (!instant_tab_ || active_tab != instant_tab_->contents()) { |
instant_tab_.reset(new InstantTab(this, active_tab)); |
instant_tab_->Init(); |
instant_tab_->SetDisplayInstantResults(instant_enabled_); |
instant_tab_->SetMarginSize(start_margin_, end_margin_); |
+ instant_tab_->KeyCaptureChanged( |
+ omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); |
} |
- // Hide the |loader_| since we are now using |instant_tab_| instead. |
- HideLoader(); |
+ // Hide the |overlay_| since we are now using |instant_tab_| instead. |
+ HideOverlay(); |
} else { |
instant_tab_.reset(); |
} |
} |
-bool InstantController::ResetLoaderForMatch(const AutocompleteMatch& match) { |
- // If we are on a search results page, we'll use that instead of a loader. |
+bool InstantController::ResetOverlayForMatch(const AutocompleteMatch& match) { |
+ // If we are on a search results page, we'll use that instead of a overlay. |
// TODO(sreeram): If |instant_tab_|'s URL is not the same as the instant_url |
// of |match|, we shouldn't use the committed tab. |
if (instant_tab_) |
@@ -1047,16 +1144,16 @@ bool InstantController::ResetLoaderForMatch(const AutocompleteMatch& match) { |
if (!active_tab) |
return false; |
- // Try to create a loader for the instant_url in the TemplateURL of |match|. |
+ // Try to create a overlay for the instant_url in the TemplateURL of |match|. |
// Do not fallback to the local preview because if the keyword specific |
// instant URL fails, we want to first try the default instant URL which |
- // happens in the CreateDefaultLoader call below. |
+ // happens in the CreateDefaultOverlay call below. |
const TemplateURL* template_url = match.GetTemplateURL( |
Profile::FromBrowserContext(active_tab->GetBrowserContext()), false); |
- if (ResetLoader(template_url, active_tab, false)) |
+ if (ResetOverlay(template_url, active_tab, false)) |
return true; |
- // In non-extended mode, stop if we couldn't get a loader for the |match|. |
+ // In non-extended mode, stop if we couldn't get a overlay for the |match|. |
if (!extended_enabled_) |
return false; |
@@ -1065,12 +1162,12 @@ bool InstantController::ResetLoaderForMatch(const AutocompleteMatch& match) { |
return false; |
// The match is a URL, or a blank query. Try the default search engine. |
- return CreateDefaultLoader(); |
+ return CreateDefaultOverlay(); |
} |
-void InstantController::HideLoader() { |
+void InstantController::HideOverlay() { |
HideInternal(); |
- OnStaleLoader(); |
+ OnStaleOverlay(); |
} |
void InstantController::HideInternal() { |
@@ -1085,35 +1182,36 @@ void InstantController::HideInternal() { |
allow_preview_to_show_search_suggestions_ = false; |
// Send a message asking the preview to clear out old results. |
- loader_->Update(string16(), 0, 0, true); |
+ overlay_->Update(string16(), 0, 0, true); |
} |
// Clear the first interaction timestamp for later use. |
first_interaction_time_ = base::Time(); |
} |
-void InstantController::ShowLoader(InstantShownReason reason, |
- int height, |
- InstantSizeUnits units) { |
- // If we are on a committed search results page, the |loader_| is not in use. |
+void InstantController::ShowOverlay(InstantShownReason reason, |
+ int height, |
+ InstantSizeUnits units) { |
+ // If we are on a committed search results page, the |overlay_| is not in use. |
if (instant_tab_) |
return; |
DVLOG(1) << "Show: reason=" << reason << " height=" << height << " units=" |
<< units; |
- // Must be on NTP to show NTP content. |
- if (reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT && !search_mode_.is_ntp()) |
+ // INSTANT_SHOWN_CUSTOM_NTP_CONTENT is no longer supported. |
+ // TODO(samarth): remove once the server has been updated. |
+ if (reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT) |
return; |
- // Must have updated omnibox after the last HideLoader() to show suggestions. |
+ // Must have updated omnibox after the last HideOverlay() to show suggestions. |
if ((reason == INSTANT_SHOWN_QUERY_SUGGESTIONS || |
reason == INSTANT_SHOWN_CLICKED_QUERY_SUGGESTION) && |
!allow_preview_to_show_search_suggestions_) |
return; |
// The page is trying to hide itself. Hide explicitly (i.e., don't use |
- // HideLoader()) so that it can change its mind. |
+ // HideOverlay()) so that it can change its mind. |
if (height == 0) { |
model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); |
return; |
@@ -1132,7 +1230,7 @@ void InstantController::ShowLoader(InstantShownReason reason, |
// - The page wants to show custom NTP content. |
// - The page is over a website other than search or an NTP, and is not |
// already showing at 100% height. |
- if (loader_->IsUsingLocalPreview() || !instant_enabled_ || |
+ if (overlay_->IsUsingLocalPreview() || !instant_enabled_ || |
reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT || |
(search_mode_.is_origin_default() && !IsFullHeight(model_))) |
model_.SetPreviewState(search_mode_, height, units); |
@@ -1148,8 +1246,8 @@ void InstantController::ShowLoader(InstantShownReason reason, |
} |
void InstantController::SendPopupBoundsToPage() { |
- if (last_popup_bounds_ == popup_bounds_ || !loader_ || |
- loader_->is_pointer_down_from_activate()) |
+ if (last_popup_bounds_ == popup_bounds_ || !overlay_ || |
+ overlay_->is_pointer_down_from_activate()) |
return; |
last_popup_bounds_ = popup_bounds_; |
@@ -1171,7 +1269,7 @@ void InstantController::SendPopupBoundsToPage() { |
DCHECK_LE(0, intersection.width()); |
DCHECK_LE(0, intersection.height()); |
- loader_->SetPopupBounds(intersection); |
+ overlay_->SetPopupBounds(intersection); |
} |
bool InstantController::GetInstantURL(const TemplateURL* template_url, |