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/search_tab_helper.h" | 5 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 6 | 6 |
| 7 #include "chrome/browser/search/search.h" | 7 #include "chrome/browser/search/search.h" |
| 8 #include "chrome/common/render_messages.h" | 8 #include "chrome/common/render_messages.h" |
| 9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
| 10 #include "content/public/browser/navigation_entry.h" | 10 #include "content/public/browser/navigation_entry.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 | 86 |
| 87 void SearchTabHelper::Observe( | 87 void SearchTabHelper::Observe( |
| 88 int type, | 88 int type, |
| 89 const content::NotificationSource& source, | 89 const content::NotificationSource& source, |
| 90 const content::NotificationDetails& details) { | 90 const content::NotificationDetails& details) { |
| 91 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); | 91 DCHECK_EQ(content::NOTIFICATION_NAV_ENTRY_COMMITTED, type); |
| 92 UpdateMode(); | 92 UpdateMode(); |
| 93 last_known_most_visited_items_.clear(); | 93 last_known_most_visited_items_.clear(); |
| 94 model_.SetVoiceSearchSupported(false); | |
|
samarth
2013/06/19 22:55:16
Sorry, this is a bit more subtle. You should do th
jeremycho
2013/06/20 19:35:52
Done.
| |
| 94 } | 95 } |
| 95 | 96 |
| 96 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { | 97 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { |
| 97 bool handled = true; | 98 bool handled = true; |
| 98 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) | 99 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) |
| 99 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, | 100 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, |
| 100 OnSearchBoxShowBars) | 101 OnSearchBoxShowBars) |
| 101 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, | 102 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, |
| 102 OnSearchBoxHideBars) | 103 OnSearchBoxHideBars) |
| 104 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetVoiceSearchSupported, | |
| 105 OnSetVoiceSearchSupported) | |
| 103 IPC_MESSAGE_UNHANDLED(handled = false) | 106 IPC_MESSAGE_UNHANDLED(handled = false) |
| 104 IPC_END_MESSAGE_MAP() | 107 IPC_END_MESSAGE_MAP() |
| 105 return handled; | 108 return handled; |
| 106 } | 109 } |
| 107 | 110 |
| 108 void SearchTabHelper::UpdateMode() { | 111 void SearchTabHelper::UpdateMode() { |
| 109 SearchMode::Type type = SearchMode::MODE_DEFAULT; | 112 SearchMode::Type type = SearchMode::MODE_DEFAULT; |
| 110 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; | 113 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; |
| 111 if (IsNTP(web_contents_)) { | 114 if (IsNTP(web_contents_)) { |
| 112 type = SearchMode::MODE_NTP; | 115 type = SearchMode::MODE_NTP; |
| 113 origin = SearchMode::ORIGIN_NTP; | 116 origin = SearchMode::ORIGIN_NTP; |
| 114 } else if (IsSearchResults(web_contents_)) { | 117 } else if (IsSearchResults(web_contents_)) { |
| 115 type = SearchMode::MODE_SEARCH_RESULTS; | 118 type = SearchMode::MODE_SEARCH_RESULTS; |
| 116 origin = SearchMode::ORIGIN_SEARCH; | 119 origin = SearchMode::ORIGIN_SEARCH; |
| 117 } | 120 } |
| 118 if (user_input_in_progress_) | 121 if (user_input_in_progress_) |
| 119 type = SearchMode::MODE_SEARCH_SUGGESTIONS; | 122 type = SearchMode::MODE_SEARCH_SUGGESTIONS; |
| 120 | 123 |
| 121 if (type == SearchMode::MODE_NTP && origin == SearchMode::ORIGIN_NTP && | 124 if (type == SearchMode::MODE_NTP && origin == SearchMode::ORIGIN_NTP && |
| 122 !popup_is_open_ && !user_text_is_empty_) { | 125 !popup_is_open_ && !user_text_is_empty_) { |
| 123 // We're switching back (|popup_is_open_| is false) to an NTP (type and | 126 // We're switching back (|popup_is_open_| is false) to an NTP (type and |
| 124 // mode are |NTP|) with suggestions (|user_text_is_empty_| is false), don't | 127 // mode are |NTP|) with suggestions (|user_text_is_empty_| is false), don't |
| 125 // modify visibility of top bars. This specific omnibox state is set when | 128 // modify visibility of top bars or voice search support. This specific |
| 126 // OmniboxEditModelChanged() is called from | 129 // omnibox state is set when OmniboxEditModelChanged() is called from |
| 127 // OmniboxEditModel::SetInputInProgress() which is called from | 130 // OmniboxEditModel::SetInputInProgress() which is called from |
| 128 // OmniboxEditModel::Revert(). | 131 // OmniboxEditModel::Revert(). |
| 129 model_.SetState(SearchModel::State(SearchMode(type, origin), | 132 model_.SetState(SearchModel::State(SearchMode(type, origin), |
| 130 model_.state().top_bars_visible)); | 133 model_.state().top_bars_visible, |
| 134 model_.state().voice_search_supported)); | |
| 131 } else { | 135 } else { |
| 132 model_.SetMode(SearchMode(type, origin)); | 136 model_.SetMode(SearchMode(type, origin)); |
| 133 } | 137 } |
| 134 } | 138 } |
| 135 | 139 |
| 136 void SearchTabHelper::OnSearchBoxShowBars(int page_id) { | 140 void SearchTabHelper::OnSearchBoxShowBars(int page_id) { |
| 137 if (web_contents()->IsActiveEntry(page_id)) | 141 if (web_contents()->IsActiveEntry(page_id)) |
| 138 model_.SetTopBarsVisible(true); | 142 model_.SetTopBarsVisible(true); |
| 139 } | 143 } |
| 140 | 144 |
| 141 void SearchTabHelper::OnSearchBoxHideBars(int page_id) { | 145 void SearchTabHelper::OnSearchBoxHideBars(int page_id) { |
| 142 if (web_contents()->IsActiveEntry(page_id)) { | 146 if (web_contents()->IsActiveEntry(page_id)) { |
| 143 model_.SetTopBarsVisible(false); | 147 model_.SetTopBarsVisible(false); |
| 144 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); | 148 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); |
| 145 } | 149 } |
| 146 } | 150 } |
| 151 | |
| 152 void SearchTabHelper::OnSetVoiceSearchSupported(int page_id, bool supported) { | |
| 153 if (web_contents()->IsActiveEntry(page_id)) | |
| 154 model_.SetVoiceSearchSupported(supported); | |
| 155 } | |
| OLD | NEW |