| 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 web_contents_(web_contents) { | 38 web_contents_(web_contents) { |
| 40 if (!is_search_enabled_) | 39 if (!is_search_enabled_) |
| 41 return; | 40 return; |
| 42 | 41 |
| 42 WebContentsObserver::Observe(web_contents); |
| 43 |
| 43 registrar_.Add( | 44 registrar_.Add( |
| 44 this, | 45 this, |
| 45 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 46 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 46 content::Source<content::NavigationController>( | 47 content::Source<content::NavigationController>( |
| 47 &web_contents->GetController())); | 48 &web_contents->GetController())); |
| 48 } | 49 } |
| 49 | 50 |
| 50 SearchTabHelper::~SearchTabHelper() { | 51 SearchTabHelper::~SearchTabHelper() { |
| 51 } | 52 } |
| 52 | 53 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 77 UpdateMode(); | 78 UpdateMode(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { | 81 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { |
| 81 bool handled = true; | 82 bool handled = true; |
| 82 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) | 83 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) |
| 83 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, | 84 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, |
| 84 OnSearchBoxShowBars) | 85 OnSearchBoxShowBars) |
| 85 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, | 86 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, |
| 86 OnSearchBoxHideBars) | 87 OnSearchBoxHideBars) |
| 88 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined, |
| 89 OnInstantSupportDetermined); |
| 87 IPC_MESSAGE_UNHANDLED(handled = false) | 90 IPC_MESSAGE_UNHANDLED(handled = false) |
| 88 IPC_END_MESSAGE_MAP() | 91 IPC_END_MESSAGE_MAP() |
| 89 return handled; | 92 return handled; |
| 90 } | 93 } |
| 91 | 94 |
| 95 void SearchTabHelper::DidFinishLoad( |
| 96 int64 /* frame_id */, |
| 97 const GURL& /* validated_url */, |
| 98 bool is_main_frame, |
| 99 content::RenderViewHost* /* render_view_host */) { |
| 100 if (is_main_frame) |
| 101 DetermineIfPageSupportsInstant(); |
| 102 } |
| 103 |
| 92 void SearchTabHelper::UpdateMode() { | 104 void SearchTabHelper::UpdateMode() { |
| 93 SearchMode::Type type = SearchMode::MODE_DEFAULT; | 105 SearchMode::Type type = SearchMode::MODE_DEFAULT; |
| 94 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; | 106 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; |
| 95 if (IsNTP(web_contents_)) { | 107 if (IsNTP(web_contents_)) { |
| 96 type = SearchMode::MODE_NTP; | 108 type = SearchMode::MODE_NTP; |
| 97 origin = SearchMode::ORIGIN_NTP; | 109 origin = SearchMode::ORIGIN_NTP; |
| 98 } else if (IsSearchResults(web_contents_)) { | 110 } else if (IsSearchResults(web_contents_)) { |
| 99 type = SearchMode::MODE_SEARCH_RESULTS; | 111 type = SearchMode::MODE_SEARCH_RESULTS; |
| 100 origin = SearchMode::ORIGIN_SEARCH; | 112 origin = SearchMode::ORIGIN_SEARCH; |
| 101 } | 113 } |
| 102 if (user_input_in_progress_) | 114 if (user_input_in_progress_) |
| 103 type = SearchMode::MODE_SEARCH_SUGGESTIONS; | 115 type = SearchMode::MODE_SEARCH_SUGGESTIONS; |
| 104 model_.SetMode(SearchMode(type, origin)); | 116 model_.SetMode(SearchMode(type, origin)); |
| 105 } | 117 } |
| 106 | 118 |
| 119 void SearchTabHelper::DetermineIfPageSupportsInstant() { |
| 120 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id())); |
| 121 } |
| 122 |
| 107 void SearchTabHelper::OnSearchBoxShowBars(int page_id) { | 123 void SearchTabHelper::OnSearchBoxShowBars(int page_id) { |
| 108 if (web_contents()->IsActiveEntry(page_id)) | 124 if (web_contents()->IsActiveEntry(page_id)) |
| 109 model_.SetTopBarsVisible(true); | 125 model_.SetTopBarsVisible(true); |
| 110 } | 126 } |
| 111 | 127 |
| 112 void SearchTabHelper::OnSearchBoxHideBars(int page_id) { | 128 void SearchTabHelper::OnSearchBoxHideBars(int page_id) { |
| 113 if (web_contents()->IsActiveEntry(page_id)) { | 129 if (web_contents()->IsActiveEntry(page_id)) { |
| 114 model_.SetTopBarsVisible(false); | 130 model_.SetTopBarsVisible(false); |
| 115 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); | 131 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); |
| 116 } | 132 } |
| 117 } | 133 } |
| 134 |
| 135 void SearchTabHelper::OnInstantSupportDetermined(int page_id, |
| 136 bool supports_instant) { |
| 137 if (web_contents()->IsActiveEntry(page_id)) |
| 138 model_.SetSupportsInstant(supports_instant); |
| 139 } |
| OLD | NEW |