Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: chrome/browser/ui/search/search_tab_helper.cc

Issue 14911005: Move instant support to SearchTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed instant support code from InstantPage Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 12 matching lines...) Expand all
23 if (entry && entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL)) 23 if (entry && entry->GetVirtualURL() == GURL(chrome::kChromeUINewTabURL))
24 return true; 24 return true;
25 25
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 // TODO(kmadhusu): Move this helper from anonymous namespace to chrome
34 // namespace and remove InstantPage::IsLocal().
35 bool IsLocal(const content::WebContents* contents) {
36 return contents &&
37 (contents->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) ||
38 contents->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl));
39 }
40
33 } // namespace 41 } // namespace
34 42
35 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents) 43 SearchTabHelper::SearchTabHelper(content::WebContents* web_contents)
36 : WebContentsObserver(web_contents), 44 : WebContentsObserver(web_contents),
37 is_search_enabled_(chrome::IsInstantExtendedAPIEnabled()), 45 is_search_enabled_(chrome::IsInstantExtendedAPIEnabled()),
38 user_input_in_progress_(false), 46 user_input_in_progress_(false),
39 popup_is_open_(false), 47 popup_is_open_(false),
40 user_text_is_empty_(true), 48 user_text_is_empty_(true),
41 web_contents_(web_contents) { 49 web_contents_(web_contents) {
42 if (!is_search_enabled_) 50 if (!is_search_enabled_)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 UpdateMode(); 91 UpdateMode();
84 } 92 }
85 93
86 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) { 94 bool SearchTabHelper::OnMessageReceived(const IPC::Message& message) {
87 bool handled = true; 95 bool handled = true;
88 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message) 96 IPC_BEGIN_MESSAGE_MAP(SearchTabHelper, message)
89 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars, 97 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxShowBars,
90 OnSearchBoxShowBars) 98 OnSearchBoxShowBars)
91 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars, 99 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxHideBars,
92 OnSearchBoxHideBars) 100 OnSearchBoxHideBars)
101 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantSupportDetermined,
102 OnInstantSupportDeterminedMsgReceived)
93 IPC_MESSAGE_UNHANDLED(handled = false) 103 IPC_MESSAGE_UNHANDLED(handled = false)
94 IPC_END_MESSAGE_MAP() 104 IPC_END_MESSAGE_MAP()
95 return handled; 105 return handled;
96 } 106 }
97 107
108 void SearchTabHelper::DidFinishLoad(
109 int64 /* frame_id */,
110 const GURL& /* validated_url */,
111 bool is_main_frame,
112 content::RenderViewHost* /* render_view_host */) {
113 if (is_main_frame)
114 DetermineIfPageSupportsInstant();
115 }
116
98 void SearchTabHelper::UpdateMode() { 117 void SearchTabHelper::UpdateMode() {
99 SearchMode::Type type = SearchMode::MODE_DEFAULT; 118 SearchMode::Type type = SearchMode::MODE_DEFAULT;
100 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT; 119 SearchMode::Origin origin = SearchMode::ORIGIN_DEFAULT;
101 if (IsNTP(web_contents_)) { 120 if (IsNTP(web_contents_)) {
102 type = SearchMode::MODE_NTP; 121 type = SearchMode::MODE_NTP;
103 origin = SearchMode::ORIGIN_NTP; 122 origin = SearchMode::ORIGIN_NTP;
104 } else if (IsSearchResults(web_contents_)) { 123 } else if (IsSearchResults(web_contents_)) {
105 type = SearchMode::MODE_SEARCH_RESULTS; 124 type = SearchMode::MODE_SEARCH_RESULTS;
106 origin = SearchMode::ORIGIN_SEARCH; 125 origin = SearchMode::ORIGIN_SEARCH;
107 } 126 }
108 if (user_input_in_progress_) 127 if (user_input_in_progress_)
109 type = SearchMode::MODE_SEARCH_SUGGESTIONS; 128 type = SearchMode::MODE_SEARCH_SUGGESTIONS;
110 129
111 if (type == SearchMode::MODE_NTP && origin == SearchMode::ORIGIN_NTP && 130 if (type == SearchMode::MODE_NTP && origin == SearchMode::ORIGIN_NTP &&
112 !popup_is_open_ && !user_text_is_empty_) { 131 !popup_is_open_ && !user_text_is_empty_) {
113 // We're switching back (|popup_is_open_| is false) to an NTP (type and 132 // 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 133 // 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 134 // modify visibility of top bars. This specific omnibox state is set when
116 // OmniboxEditModelChanged() is called from 135 // OmniboxEditModelChanged() is called from
117 // OmniboxEditModel::SetInputInProgress() which is called from 136 // OmniboxEditModel::SetInputInProgress() which is called from
118 // OmniboxEditModel::Revert(). 137 // OmniboxEditModel::Revert().
119 model_.SetState(SearchModel::State(SearchMode(type, origin), 138 model_.SetState(SearchModel::State(SearchMode(type, origin),
120 model_.state().top_bars_visible)); 139 model_.state().top_bars_visible,
140 model_.instant_support()));
121 } else { 141 } else {
122 model_.SetMode(SearchMode(type, origin)); 142 model_.SetMode(SearchMode(type, origin));
123 } 143 }
124 } 144 }
125 145
146 void SearchTabHelper::DetermineIfPageSupportsInstant() {
147 if (IsLocal(web_contents_)) {
148 // Local pages always support Instant. That's why we keep them around.
149 int page_id = web_contents_->GetController().GetActiveEntry()->GetPageID();
150 OnInstantSupportDeterminedMsgReceived(page_id, true);
151 } else {
152 Send(new ChromeViewMsg_DetermineIfPageSupportsInstant(routing_id()));
153 }
154 }
155
126 void SearchTabHelper::OnSearchBoxShowBars(int page_id) { 156 void SearchTabHelper::OnSearchBoxShowBars(int page_id) {
127 if (web_contents()->IsActiveEntry(page_id)) 157 if (web_contents()->IsActiveEntry(page_id))
128 model_.SetTopBarsVisible(true); 158 model_.SetTopBarsVisible(true);
129 } 159 }
130 160
131 void SearchTabHelper::OnSearchBoxHideBars(int page_id) { 161 void SearchTabHelper::OnSearchBoxHideBars(int page_id) {
132 if (web_contents()->IsActiveEntry(page_id)) { 162 if (web_contents()->IsActiveEntry(page_id)) {
133 model_.SetTopBarsVisible(false); 163 model_.SetTopBarsVisible(false);
134 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id())); 164 Send(new ChromeViewMsg_SearchBoxBarsHidden(routing_id()));
135 } 165 }
136 } 166 }
167
168 void SearchTabHelper::OnInstantSupportDeterminedMsgReceived(
169 int page_id,
170 bool supports_instant) {
171 if (web_contents()->IsActiveEntry(page_id))
172 model_.SetSupportsInstant(supports_instant);
173 }
OLDNEW
« chrome/browser/ui/search/search_tab_helper.h ('K') | « chrome/browser/ui/search/search_tab_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698