| 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 UpdateMode(); | 83 UpdateMode(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { | 86 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { |
| 87 bool handled = true; | 87 bool handled = true; |
| 88 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) | 88 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) |
| 89 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, | 89 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, |
| 90 OnSearchBoxShowBars) | 90 OnSearchBoxShowBars) |
| 91 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, | 91 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, |
| 92 OnSearchBoxHideBars) | 92 OnSearchBoxHideBars) |
| 93 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, |
| 94 OnInstantSupportDeterminedMsgReceived) |
| 93 IPC_MESSAGE_UNHANDLED(handled = false) | 95 IPC_MESSAGE_UNHANDLED(handled = false) |
| 94 IPC_END_MESSAGE_MAP() | 96 IPC_END_MESSAGE_MAP() |
| 95 return handled; | 97 return handled; |
| 96 } | 98 } |
| 97 | 99 |
| 100 void SearchTabHelper::DidFinishLoad( |
| 101 int64 /* frame_id */, |
| 102 const GURL& /* validated_url */, |
| 103 bool is_main_frame, |
| 104 content::RenderViewHost* /* render_view_host */) { |
| 105 if (is_main_frame) |
| 106 DetermineIfPageSupportsInstant(); |
| 107 } |
| 108 |
| 98 void SearchTabHelper::UpdateMode() { | 109 void SearchTabHelper::UpdateMode() { |
| 99 SearchMode::Type type = SearchMode::MODE_DEFAULT; | 110 SearchMode::Type type = SearchMode::MODE_DEFAULT; |
| 100 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; | 111 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; |
| 101 if (IsNTP(web_contents_)) { | 112 if (IsNTP(web_contents_)) { |
| 102 type = SearchMode::MODE_NTP; | 113 type = SearchMode::MODE_NTP; |
| 103 origin = SearchMode::ORIGIN_NTP; | 114 origin = SearchMode::ORIGIN_NTP; |
| 104 } else if (IsSearchResults(web_contents_)) { | 115 } else if (IsSearchResults(web_contents_)) { |
| 105 type = SearchMode::MODE_SEARCH_RESULTS; | 116 type = SearchMode::MODE_SEARCH_RESULTS; |
| 106 origin = SearchMode::ORIGIN_SEARCH; | 117 origin = SearchMode::ORIGIN_SEARCH; |
| 107 } | 118 } |
| 108 if (user_input_in_progress_) | 119 if (user_input_in_progress_) |
| 109 type = SearchMode::MODE_SEARCH_SUGGESTIONS; | 120 type = SearchMode::MODE_SEARCH_SUGGESTIONS; |
| 110 | 121 |
| 111 if (type == SearchMode::MODE_NTP && origin == SearchMode::ORIGIN_NTP && | 122 if (type == SearchMode::MODE_NTP && origin == SearchMode::ORIGIN_NTP && |
| 112 !popup_is_open_ && !user_text_is_empty_) { | 123 !popup_is_open_ && !user_text_is_empty_) { |
| 113 // We're switching back (|popup_is_open_| is false) to an NTP (type and | 124 // We're switching back (|popup_is_open_| is false) to an NTP (type and |
| 114 // mode are |NTP|) with suggestions (|user_text_is_empty_| is false), don't | 125 // mode are |NTP|) with suggestions (|user_text_is_empty_| is false), don't |
| 115 // modify visibility of top bars. This specific omnibox state is set when | 126 // modify visibility of top bars. This specific omnibox state is set when |
| 116 // OmniboxEditModelChanged() is called from | 127 // OmniboxEditModelChanged() is called from |
| 117 // OmniboxEditModel::SetInputInProgress() which is called from | 128 // OmniboxEditModel::SetInputInProgress() which is called from |
| 118 // OmniboxEditModel::Revert(). | 129 // OmniboxEditModel::Revert(). |
| 119 model_.SetState(SearchModel::State(SearchMode(type, origin), | 130 model_.SetState(SearchModel::State(SearchMode(type, origin), |
| 120 model_.state().top_bars_visible)); | 131 model_.state().top_bars_visible, |
| 132 model_.instant_support())); |
| 121 } else { | 133 } else { |
| 122 model_.SetMode(SearchMode(type, origin)); | 134 model_.SetMode(SearchMode(type, origin)); |
| 123 } | 135 } |
| 124 } | 136 } |
| 125 | 137 |
| 138 void SearchTabHelper::DetermineIfPageSupportsInstant() { |
| 139 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); |
| 140 } |
| 141 |
| 126 void SearchTabHelper::OnSearchBoxShowBars(int page_id) { | 142 void SearchTabHelper::OnSearchBoxShowBars(int page_id) { |
| 127 if (web_contents()->IsActiveEntry(page_id)) | 143 if (web_contents()->IsActiveEntry(page_id)) |
| 128 model_.SetTopBarsVisible(true); | 144 model_.SetTopBarsVisible(true); |
| 129 } | 145 } |
| 130 | 146 |
| 131 void SearchTabHelper::OnSearchBoxHideBars(int page_id) { | 147 void SearchTabHelper::OnSearchBoxHideBars(int page_id) { |
| 132 if (web_contents()->IsActiveEntry(page_id)) { | 148 if (web_contents()->IsActiveEntry(page_id)) { |
| 133 model_.SetTopBarsVisible(false); | 149 model_.SetTopBarsVisible(false); |
| 134 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); | 150 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); |
| 135 } | 151 } |
| 136 } | 152 } |
| 153 |
| 154 void SearchTabHelper::OnInstantSupportDeterminedMsgReceived( |
| 155 int page_id, |
| 156 bool supports_instant) { |
| 157 if (web_contents()->IsActiveEntry(page_id)) |
| 158 model_.SetSupportsInstant(supports_instant); |
| 159 } |
| OLD | NEW |