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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 last_known_most_visited_items_ = items; | 83 last_known_most_visited_items_ = items; |
| 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(); |
|
samarth
2013/06/19 05:39:20
You should reset voice_search_supported_ here.
jeremycho
2013/06/19 20:11:34
Done.
| |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { | 96 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { |
| 97 bool handled = true; | 97 bool handled = true; |
| 98 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) | 98 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) |
| 99 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, | 99 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, |
| 100 OnSearchBoxShowBars) | 100 OnSearchBoxShowBars) |
| 101 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, | 101 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, |
| 102 OnSearchBoxHideBars) | 102 OnSearchBoxHideBars) |
| 103 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SetVoiceSearchSupported, | |
| 104 OnSetVoiceSearchSupported) | |
| 103 IPC_MESSAGE_UNHANDLED(handled = false) | 105 IPC_MESSAGE_UNHANDLED(handled = false) |
| 104 IPC_END_MESSAGE_MAP() | 106 IPC_END_MESSAGE_MAP() |
| 105 return handled; | 107 return handled; |
| 106 } | 108 } |
| 107 | 109 |
| 108 void SearchTabHelper::UpdateMode() { | 110 void SearchTabHelper::UpdateMode() { |
| 109 SearchMode::Type type = SearchMode::MODE_DEFAULT; | 111 SearchMode::Type type = SearchMode::MODE_DEFAULT; |
| 110 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; | 112 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; |
| 111 if (IsNTP(web_contents_)) { | 113 if (IsNTP(web_contents_)) { |
| 112 type = SearchMode::MODE_NTP; | 114 type = SearchMode::MODE_NTP; |
| 113 origin = SearchMode::ORIGIN_NTP; | 115 origin = SearchMode::ORIGIN_NTP; |
| 114 } else if (IsSearchResults(web_contents_)) { | 116 } else if (IsSearchResults(web_contents_)) { |
| 115 type = SearchMode::MODE_SEARCH_RESULTS; | 117 type = SearchMode::MODE_SEARCH_RESULTS; |
| 116 origin = SearchMode::ORIGIN_SEARCH; | 118 origin = SearchMode::ORIGIN_SEARCH; |
| 117 } | 119 } |
| 118 if (user_input_in_progress_) | 120 if (user_input_in_progress_) |
| 119 type = SearchMode::MODE_SEARCH_SUGGESTIONS; | 121 type = SearchMode::MODE_SEARCH_SUGGESTIONS; |
| 120 | 122 |
| 121 if (type == SearchMode::MODE_NTP && origin == SearchMode::ORIGIN_NTP && | 123 if (type == SearchMode::MODE_NTP && origin == SearchMode::ORIGIN_NTP && |
| 122 !popup_is_open_ && !user_text_is_empty_) { | 124 !popup_is_open_ && !user_text_is_empty_) { |
| 123 // We're switching back (|popup_is_open_| is false) to an NTP (type and | 125 // 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 | 126 // 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 | 127 // modify visibility of top bars. This specific omnibox state is set when |
| 126 // OmniboxEditModelChanged() is called from | 128 // OmniboxEditModelChanged() is called from |
| 127 // OmniboxEditModel::SetInputInProgress() which is called from | 129 // OmniboxEditModel::SetInputInProgress() which is called from |
| 128 // OmniboxEditModel::Revert(). | 130 // OmniboxEditModel::Revert(). |
| 129 model_.SetState(SearchModel::State(SearchMode(type, origin), | 131 model_.SetState(SearchModel::State(SearchMode(type, origin), |
| 130 model_.state().top_bars_visible)); | 132 model_.state().top_bars_visible, |
| 133 model_.state().voice_search_supported)); | |
| 131 } else { | 134 } else { |
| 132 model_.SetMode(SearchMode(type, origin)); | 135 model_.SetMode(SearchMode(type, origin)); |
| 133 } | 136 } |
| 134 } | 137 } |
| 135 | 138 |
| 136 void SearchTabHelper::OnSearchBoxShowBars(int page_id) { | 139 void SearchTabHelper::OnSearchBoxShowBars(int page_id) { |
| 137 if (web_contents()->IsActiveEntry(page_id)) | 140 if (web_contents()->IsActiveEntry(page_id)) |
| 138 model_.SetTopBarsVisible(true); | 141 model_.SetTopBarsVisible(true); |
| 139 } | 142 } |
| 140 | 143 |
| 141 void SearchTabHelper::OnSearchBoxHideBars(int page_id) { | 144 void SearchTabHelper::OnSearchBoxHideBars(int page_id) { |
| 142 if (web_contents()->IsActiveEntry(page_id)) { | 145 if (web_contents()->IsActiveEntry(page_id)) { |
| 143 model_.SetTopBarsVisible(false); | 146 model_.SetTopBarsVisible(false); |
| 144 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); | 147 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); |
| 145 } | 148 } |
| 146 } | 149 } |
| 150 | |
| 151 void SearchTabHelper::OnSetVoiceSearchSupported(int page_id, bool supported) { | |
| 152 if (web_contents()->IsActiveEntry(page_id)) | |
| 153 model_.SetVoiceSearchSupported(supported); | |
| 154 } | |
| OLD | NEW |