diff options
6 files changed, 39 insertions, 40 deletions
diff --git a/chrome/browser/ui/omnibox/omnibox_current_page_delegate.h b/chrome/browser/ui/omnibox/omnibox_current_page_delegate.h index 560b2c3..5674f78 100644 --- a/chrome/browser/ui/omnibox/omnibox_current_page_delegate.h +++ b/chrome/browser/ui/omnibox/omnibox_current_page_delegate.h @@ -54,10 +54,8 @@ class OmniboxCurrentPageDelegate { const AutocompleteMatch& match, WindowOpenDisposition disposition) = 0; - // Notifies the SearchTabHelper, if one exists, of relevant changes to the - // omnibox state. - virtual void NotifySearchTabHelper(bool user_input_in_progress, - bool cancelling) = 0; + // Called to notify clients that the omnibox input state has changed. + virtual void OnInputStateChanged() = 0; // Performs prerendering for |match|. virtual void DoPrerender(const AutocompleteMatch& match) = 0; diff --git a/chrome/browser/ui/omnibox/omnibox_current_page_delegate_impl.cc b/chrome/browser/ui/omnibox/omnibox_current_page_delegate_impl.cc index 4d744b1..d3708a8 100644 --- a/chrome/browser/ui/omnibox/omnibox_current_page_delegate_impl.cc +++ b/chrome/browser/ui/omnibox/omnibox_current_page_delegate_impl.cc @@ -82,14 +82,11 @@ bool OmniboxCurrentPageDelegateImpl::ProcessExtensionKeyword( return true; } -void OmniboxCurrentPageDelegateImpl::NotifySearchTabHelper( - bool user_input_in_progress, - bool cancelling) { +void OmniboxCurrentPageDelegateImpl::OnInputStateChanged() { if (!controller_->GetWebContents()) return; SearchTabHelper::FromWebContents( - controller_->GetWebContents())->OmniboxEditModelChanged( - user_input_in_progress, cancelling); + controller_->GetWebContents())->OmniboxInputStateChanged(); } void OmniboxCurrentPageDelegateImpl::DoPrerender( diff --git a/chrome/browser/ui/omnibox/omnibox_current_page_delegate_impl.h b/chrome/browser/ui/omnibox/omnibox_current_page_delegate_impl.h index 9f5b024..78e4682 100644 --- a/chrome/browser/ui/omnibox/omnibox_current_page_delegate_impl.h +++ b/chrome/browser/ui/omnibox/omnibox_current_page_delegate_impl.h @@ -30,8 +30,7 @@ class OmniboxCurrentPageDelegateImpl : public OmniboxCurrentPageDelegate { TemplateURL* template_url, const AutocompleteMatch& match, WindowOpenDisposition disposition) OVERRIDE; - virtual void NotifySearchTabHelper(bool user_input_in_progress, - bool cancelling) OVERRIDE; + virtual void OnInputStateChanged() OVERRIDE; virtual void DoPrerender(const AutocompleteMatch& match) OVERRIDE; private: diff --git a/chrome/browser/ui/omnibox/omnibox_edit_model.cc b/chrome/browser/ui/omnibox/omnibox_edit_model.cc index d5da5ae..830fae8 100644 --- a/chrome/browser/ui/omnibox/omnibox_edit_model.cc +++ b/chrome/browser/ui/omnibox/omnibox_edit_model.cc @@ -515,7 +515,8 @@ void OmniboxEditModel::SetInputInProgress(bool in_progress) { controller_->GetToolbarModel()->set_input_in_progress(in_progress); controller_->Update(NULL); - delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); + if (user_input_in_progress_ || !in_revert_) + delegate_->OnInputStateChanged(); } void OmniboxEditModel::Revert() { @@ -869,7 +870,9 @@ bool OmniboxEditModel::AcceptKeyword(EnteredKeywordModeMethod entered_method) { void OmniboxEditModel::AcceptTemporaryTextAsUserText() { InternalSetUserText(UserTextFromDisplayText(view_->GetText())); has_temporary_text_ = false; - delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); + + if (user_input_in_progress_ || !in_revert_) + delegate_->OnInputStateChanged(); } void OmniboxEditModel::ClearKeyword(const base::string16& visible_text) { @@ -927,7 +930,8 @@ void OmniboxEditModel::OnSetFocus(bool control_down) { permanent_text_); } - delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); + if (user_input_in_progress_ || !in_revert_) + delegate_->OnInputStateChanged(); } void OmniboxEditModel::SetCaretVisibility(bool visible) { @@ -948,7 +952,9 @@ void OmniboxEditModel::OnWillKillFocus(gfx::NativeView view_gaining_focus) { // TODO(jered): Rip this out along with StartZeroSuggest. autocomplete_controller()->StopZeroSuggest(); - delegate_->NotifySearchTabHelper(user_input_in_progress_, !in_revert_); + + if (user_input_in_progress_ || !in_revert_) + delegate_->OnInputStateChanged(); } void OmniboxEditModel::OnKillFocus() { diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc index 133b9d1..b6e6b30 100644 --- a/chrome/browser/ui/search/search_tab_helper.cc +++ b/chrome/browser/ui/search/search_tab_helper.cc @@ -137,12 +137,24 @@ void RecordNewTabLoadTime(content::WebContents* contents) { core_tab_helper->set_new_tab_start_time(base::TimeTicks()); } +// Returns the OmniboxView for |contents| or NULL if not available. +OmniboxView* GetOmniboxView(content::WebContents* contents) { + if (!contents) + return NULL; + + // iOS and Android don't use the Instant framework. +#if !defined(OS_IOS) && !defined(OS_ANDROID) + Browser* browser = chrome::FindBrowserWithWebContents(contents); + return browser ? browser->window()->GetLocationBar()->GetOmniboxView() : NULL; +#endif + return NULL; +} + } // namespace SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) : WebContentsObserver(web_contents), is_search_enabled_(chrome::IsInstantExtendedAPIEnabled()), - user_input_in_progress_(false), web_contents_(web_contents), ipc_router_(web_contents, this, make_scoped_ptr(new SearchIPCRouterPolicyImpl(web_contents)) @@ -167,15 +179,10 @@ void SearchTabHelper::InitForPreloadedNTP() { UpdateMode(true, true); } -void SearchTabHelper::OmniboxEditModelChanged(bool user_input_in_progress, - bool cancelling) { +void SearchTabHelper::OmniboxInputStateChanged() { if (!is_search_enabled_) return; - user_input_in_progress_ = user_input_in_progress; - if (!user_input_in_progress && !cancelling) - return; - UpdateMode(false, false); } @@ -422,13 +429,10 @@ void SearchTabHelper::MaybeRemoveMostVisitedItems( } void SearchTabHelper::FocusOmnibox(OmniboxFocusState state) { -// iOS and Android don't use the Instant framework. -#if !defined(OS_IOS) && !defined(OS_ANDROID) - Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); - if (!browser) + OmniboxView* omnibox = GetOmniboxView(web_contents()); + if (!omnibox) return; - OmniboxView* omnibox = browser->window()->GetLocationBar()->GetOmniboxView(); // Do not add a default case in the switch block for the following reasons: // (1) Explicitly handle the new states. If new states are added in the // OmniboxFocusState, the compiler will warn the developer to handle the new @@ -460,7 +464,6 @@ void SearchTabHelper::FocusOmnibox(OmniboxFocusState state) { web_contents()->GetView()->Focus(); break; } -#endif } void SearchTabHelper::NavigateToURL(const GURL& url, @@ -522,13 +525,10 @@ void SearchTabHelper::OnLogImpression(int position, } void SearchTabHelper::PasteIntoOmnibox(const base::string16& text) { -// iOS and Android don't use the Instant framework. -#if !defined(OS_IOS) && !defined(OS_ANDROID) - Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); - if (!browser) + OmniboxView* omnibox = GetOmniboxView(web_contents()); + if (!omnibox) return; - OmniboxView* omnibox = browser->window()->GetLocationBar()->GetOmniboxView(); // The first case is for right click to paste, where the text is retrieved // from the clipboard already sanitized. The second case is needed to handle // drag-and-drop value and it has to be sanitazed before setting it into the @@ -546,7 +546,6 @@ void SearchTabHelper::PasteIntoOmnibox(const base::string16& text) { omnibox->model()->OnPaste(); omnibox->SetUserText(text_to_paste); omnibox->OnAfterPossibleChange(); -#endif } void SearchTabHelper::OnChromeIdentityCheck(const base::string16& identity) { @@ -571,8 +570,11 @@ void SearchTabHelper::UpdateMode(bool update_origin, bool is_preloaded_ntp) { } if (!update_origin) origin = model_.mode().origin; - if (user_input_in_progress_) + + OmniboxView* omnibox = GetOmniboxView(web_contents()); + if (omnibox && omnibox->model()->user_input_in_progress()) type = SearchMode::MODE_SEARCH_SUGGESTIONS; + model_.SetMode(SearchMode(type, origin)); } diff --git a/chrome/browser/ui/search/search_tab_helper.h b/chrome/browser/ui/search/search_tab_helper.h index db05376..50f9a58 100644 --- a/chrome/browser/ui/search/search_tab_helper.h +++ b/chrome/browser/ui/search/search_tab_helper.h @@ -51,9 +51,9 @@ class SearchTabHelper : public content::WebContentsObserver, // Sets up the initial state correctly for a preloaded NTP. void InitForPreloadedNTP(); - // Invoked when the OmniboxEditModel changes state in some way that might + // Invoked when the omnibox input state is changed in some way that might // affect the search mode. - void OmniboxEditModelChanged(bool user_input_in_progress, bool cancelling); + void OmniboxInputStateChanged(); // Invoked when the active navigation entry is updated in some way that might // affect the search mode. This is used by Instant when it "fixes up" the @@ -201,9 +201,6 @@ class SearchTabHelper : public content::WebContentsObserver, const bool is_search_enabled_; - // Tracks the last value passed to OmniboxEditModelChanged(). - bool user_input_in_progress_; - // Model object for UI that cares about search state. SearchModel model_; |