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 15 matching lines...) Expand all Loading... | |
| 26 return chrome::IsInstantNTP(contents); | 26 return chrome::IsInstantNTP(contents); |
| 27 } | 27 } |
| 28 | 28 |
| 29 bool IsSearchResults(const content::WebContents* contents) { | 29 bool IsSearchResults(const content::WebContents* contents) { |
| 30 return !chrome::GetSearchTerms(contents).empty(); | 30 return !chrome::GetSearchTerms(contents).empty(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) | 35 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) |
| 36 : WebContentsObserver(web_contents), | 36 : is_search_enabled_(chrome::IsInstantExtendedAPIEnabled()), |
| 37 is_search_enabled_(chrome::IsInstantExtendedAPIEnabled()), | |
| 38 user_input_in_progress_(false), | 37 user_input_in_progress_(false), |
| 39 popup_is_open_(false), | 38 popup_is_open_(false), |
| 40 user_text_is_empty_(true), | 39 user_text_is_empty_(true), |
| 41 web_contents_(web_contents) { | 40 web_contents_(web_contents) { |
| 42 if (!is_search_enabled_) | 41 if (!is_search_enabled_) |
| 43 return; | 42 return; |
| 44 | 43 |
| 44 WebContentsObserver::Observe(web_contents); | |
|
samarth
2013/05/08 02:38:48
Ah so I made this change so that we only receive I
kmadhusu
2013/05/09 02:40:40
Reverted this change.
| |
| 45 | |
| 45 registrar_.Add( | 46 registrar_.Add( |
| 46 this, | 47 this, |
| 47 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 48 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 48 content::Source<content::NavigationController>( | 49 content::Source<content::NavigationController>( |
| 49 &web_contents->GetController())); | 50 &web_contents->GetController())); |
| 50 } | 51 } |
| 51 | 52 |
| 52 SearchTabHelper::~SearchTabHelper() { | 53 SearchTabHelper::~SearchTabHelper() { |
| 53 } | 54 } |
| 54 | 55 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 83 UpdateMode(); | 84 UpdateMode(); |
| 84 } | 85 } |
| 85 | 86 |
| 86 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { | 87 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { |
| 87 bool handled = true; | 88 bool handled = true; |
| 88 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) | 89 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) |
| 89 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, | 90 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, |
| 90 OnSearchBoxShowBars) | 91 OnSearchBoxShowBars) |
| 91 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, | 92 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, |
| 92 OnSearchBoxHideBars) | 93 OnSearchBoxHideBars) |
| 94 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, | |
| 95 OnInstantSupportDetermined) | |
| 93 IPC_MESSAGE_UNHANDLED(handled = false) | 96 IPC_MESSAGE_UNHANDLED(handled = false) |
| 94 IPC_END_MESSAGE_MAP() | 97 IPC_END_MESSAGE_MAP() |
| 95 return handled; | 98 return handled; |
| 96 } | 99 } |
| 97 | 100 |
| 101 void SearchTabHelper::DidFinishLoad( | |
| 102 int64 /* frame_id */, | |
| 103 const GURL& /* validated_url */, | |
| 104 bool is_main_frame, | |
| 105 content::RenderViewHost* /* render_view_host */) { | |
| 106 if (is_main_frame) | |
| 107 DetermineIfPageSupportsInstant(); | |
| 108 } | |
| 109 | |
| 98 void SearchTabHelper::UpdateMode() { | 110 void SearchTabHelper::UpdateMode() { |
| 99 SearchMode::Type type = SearchMode::MODE_DEFAULT; | 111 SearchMode::Type type = SearchMode::MODE_DEFAULT; |
| 100 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; | 112 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; |
| 101 if (IsNTP(web_contents_)) { | 113 if (IsNTP(web_contents_)) { |
| 102 type = SearchMode::MODE_NTP; | 114 type = SearchMode::MODE_NTP; |
| 103 origin = SearchMode::ORIGIN_NTP; | 115 origin = SearchMode::ORIGIN_NTP; |
| 104 } else if (IsSearchResults(web_contents_)) { | 116 } else if (IsSearchResults(web_contents_)) { |
| 105 type = SearchMode::MODE_SEARCH_RESULTS; | 117 type = SearchMode::MODE_SEARCH_RESULTS; |
| 106 origin = SearchMode::ORIGIN_SEARCH; | 118 origin = SearchMode::ORIGIN_SEARCH; |
| 107 } | 119 } |
| 108 if (user_input_in_progress_) | 120 if (user_input_in_progress_) |
| 109 type = SearchMode::MODE_SEARCH_SUGGESTIONS; | 121 type = SearchMode::MODE_SEARCH_SUGGESTIONS; |
| 110 | 122 |
| 111 if (type == SearchMode::MODE_NTP && origin == SearchMode::ORIGIN_NTP && | 123 if (type == SearchMode::MODE_NTP && origin == SearchMode::ORIGIN_NTP && |
| 112 !popup_is_open_ && !user_text_is_empty_) { | 124 !popup_is_open_ && !user_text_is_empty_) { |
| 113 // 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 |
| 114 // 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 |
| 115 // 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 |
| 116 // OmniboxEditModelChanged() is called from | 128 // OmniboxEditModelChanged() is called from |
| 117 // OmniboxEditModel::SetInputInProgress() which is called from | 129 // OmniboxEditModel::SetInputInProgress() which is called from |
| 118 // OmniboxEditModel::Revert(). | 130 // OmniboxEditModel::Revert(). |
| 119 model_.SetState(SearchModel::State(SearchMode(type, origin), | 131 model_.SetState(SearchModel::State(SearchMode(type, origin), |
| 120 model_.state().top_bars_visible)); | 132 model_.state().top_bars_visible)); |
| 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::OnInstantSupportDetermined(int page_id, | |
| 155 bool supports_instant) { | |
| 156 if (web_contents()->IsActiveEntry(page_id)) | |
| 157 model_.SetSupportsInstant(supports_instant); | |
| 158 } | |
| OLD | NEW |