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

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

Issue 17132011: Add setVoiceSearchSupported to the searchbox API. This will be used to determine whether to show a … (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Move listener to SearchTabHelper. Created 7 years, 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
samarth 2013/06/19 05:39:20 Why do you need any changes in this file at all?
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/instant_page.h" 5 #include "chrome/browser/ui/search/instant_page.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/search/search_tab_helper.h"
8 #include "chrome/common/render_messages.h" 9 #include "chrome/common/render_messages.h"
9 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
10 #include "content/public/browser/navigation_controller.h" 11 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/navigation_details.h" 12 #include "content/public/browser/navigation_details.h"
12 #include "content/public/browser/navigation_entry.h" 13 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/frame_navigate_params.h" 15 #include "content/public/common/frame_navigate_params.h"
15 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/font.h" 17 #include "ui/gfx/font.h"
17 18
18 InstantPage::Delegate::~Delegate() { 19 InstantPage::Delegate::~Delegate() {
19 } 20 }
20 21
21 InstantPage::~InstantPage() { 22 InstantPage::~InstantPage() {
23 if (contents())
24 GetSearchModel()->RemoveObserver(this);
22 } 25 }
23 26
24 bool InstantPage::supports_instant() const { 27 bool InstantPage::supports_instant() const {
25 return supports_instant_; 28 return supports_instant_;
26 } 29 }
27 30
28 bool InstantPage::IsLocal() const { 31 bool InstantPage::IsLocal() const {
29 return contents() && 32 return contents() &&
30 (contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) || 33 (contents()->GetURL() == GURL(chrome::kChromeSearchLocalNtpUrl) ||
31 contents()->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); 34 contents()->GetURL() == GURL(chrome::kChromeSearchLocalGoogleNtpUrl));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id())); 134 Send(new ChromeViewMsg_SearchBoxToggleVoiceSearch(routing_id()));
132 } 135 }
133 136
134 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url) 137 InstantPage::InstantPage(Delegate* delegate, const std::string& instant_url)
135 : delegate_(delegate), 138 : delegate_(delegate),
136 instant_url_(instant_url), 139 instant_url_(instant_url),
137 supports_instant_(false), 140 supports_instant_(false),
138 instant_support_determined_(false) { 141 instant_support_determined_(false) {
139 } 142 }
140 143
141 void InstantPage::SetContents(content::WebContents* contents) { 144 void InstantPage::SetContents(content::WebContents* web_contents) {
142 Observe(contents); 145 if (contents())
146 GetSearchModel()->RemoveObserver(this);
147
148 Observe(web_contents);
149
150 if (!web_contents)
151 return;
152
153 SearchModel* model = GetSearchModel();
154 model->AddObserver(this);
143 } 155 }
144 156
145 bool InstantPage::ShouldProcessRenderViewCreated() { 157 bool InstantPage::ShouldProcessRenderViewCreated() {
146 return false; 158 return false;
147 } 159 }
148 160
149 bool InstantPage::ShouldProcessRenderViewGone() { 161 bool InstantPage::ShouldProcessRenderViewGone() {
150 return false; 162 return false;
151 } 163 }
152 164
153 bool InstantPage::ShouldProcessAboutToNavigateMainFrame() { 165 bool InstantPage::ShouldProcessAboutToNavigateMainFrame() {
154 return false; 166 return false;
155 } 167 }
156 168
157 bool InstantPage::ShouldProcessSetSuggestions() { 169 bool InstantPage::ShouldProcessSetSuggestions() {
158 return false; 170 return false;
159 } 171 }
160 172
173 bool InstantPage::ShouldProcessSetVoiceSearchSupported() {
174 return false;
175 }
176
161 bool InstantPage::ShouldProcessShowInstantOverlay() { 177 bool InstantPage::ShouldProcessShowInstantOverlay() {
162 return false; 178 return false;
163 } 179 }
164 180
165 bool InstantPage::ShouldProcessFocusOmnibox() { 181 bool InstantPage::ShouldProcessFocusOmnibox() {
166 return false; 182 return false;
167 } 183 }
168 184
169 bool InstantPage::ShouldProcessNavigateToURL() { 185 bool InstantPage::ShouldProcessNavigateToURL() {
170 return false; 186 return false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 int64 /* frame_id */, 263 int64 /* frame_id */,
248 bool is_main_frame, 264 bool is_main_frame,
249 const GURL& /* validated_url */, 265 const GURL& /* validated_url */,
250 int /* error_code */, 266 int /* error_code */,
251 const string16& /* error_description */, 267 const string16& /* error_description */,
252 content::RenderViewHost* /* render_view_host */) { 268 content::RenderViewHost* /* render_view_host */) {
253 if (is_main_frame) 269 if (is_main_frame)
254 delegate_->InstantPageLoadFailed(contents()); 270 delegate_->InstantPageLoadFailed(contents());
255 } 271 }
256 272
273 void InstantPage::ModelChanged(const SearchModel::State& old_state,
274 const SearchModel::State& new_state) {
275 if (ShouldProcessSetVoiceSearchSupported() &&
276 old_state.voice_search_supported != new_state.voice_search_supported)
277 delegate_->SetVoiceSearchSupported(
278 contents(), new_state.voice_search_supported);
279 }
280
281 SearchModel* InstantPage::GetSearchModel() {
282 return contents() ?
283 SearchTabHelper::FromWebContents(contents())->model() : NULL;
284 }
285
257 void InstantPage::OnSetSuggestions( 286 void InstantPage::OnSetSuggestions(
258 int page_id, 287 int page_id,
259 const std::vector<InstantSuggestion>& suggestions) { 288 const std::vector<InstantSuggestion>& suggestions) {
260 if (!contents()->IsActiveEntry(page_id)) 289 if (!contents()->IsActiveEntry(page_id))
261 return; 290 return;
262 291
263 OnInstantSupportDetermined(page_id, true); 292 OnInstantSupportDetermined(page_id, true);
264 if (!ShouldProcessSetSuggestions()) 293 if (!ShouldProcessSetSuggestions())
265 return; 294 return;
266 295
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 void InstantPage::OnUndoAllMostVisitedDeletions(int page_id) { 378 void InstantPage::OnUndoAllMostVisitedDeletions(int page_id) {
350 if (!contents()->IsActiveEntry(page_id)) 379 if (!contents()->IsActiveEntry(page_id))
351 return; 380 return;
352 381
353 OnInstantSupportDetermined(page_id, true); 382 OnInstantSupportDetermined(page_id, true);
354 if (!ShouldProcessUndoAllMostVisitedDeletions()) 383 if (!ShouldProcessUndoAllMostVisitedDeletions())
355 return; 384 return;
356 385
357 delegate_->UndoAllMostVisitedDeletions(); 386 delegate_->UndoAllMostVisitedDeletions();
358 } 387 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698