OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/app_list/app_list_view_delegate.h" | 5 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 urls->push_back(extension->GetResourceURL(info->page)); | 101 urls->push_back(extension->GetResourceURL(info->page)); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 } // namespace | 105 } // namespace |
106 | 106 |
107 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) | 107 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) |
108 : controller_(controller), | 108 : controller_(controller), |
109 profile_(NULL), | 109 profile_(NULL), |
110 model_(NULL), | 110 model_(NULL), |
111 is_voice_query_(false), | |
112 template_url_service_observer_(this) { | 111 template_url_service_observer_(this) { |
113 CHECK(controller_); | 112 CHECK(controller_); |
114 speech_ui_.reset(new app_list::SpeechUIModel); | 113 speech_ui_.reset(new app_list::SpeechUIModel); |
115 | 114 |
116 #if defined(GOOGLE_CHROME_BUILD) | 115 #if defined(GOOGLE_CHROME_BUILD) |
117 gfx::ImageSkia* image; | 116 gfx::ImageSkia* image; |
118 { | 117 { |
119 // TODO(tapted): Remove ScopedTracker below once crbug.com/431326 is fixed. | 118 // TODO(tapted): Remove ScopedTracker below once crbug.com/431326 is fixed. |
120 tracked_objects::ScopedTracker tracking_profile( | 119 tracked_objects::ScopedTracker tracking_profile( |
121 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 GetImageSkiaNamed()")); | 120 FROM_HERE_WITH_EXPLICIT_FUNCTION("431326 GetImageSkiaNamed()")); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 search_answer_delegate_ = | 191 search_answer_delegate_ = |
193 base::MakeUnique<app_list::SearchAnswerWebContentsDelegate>(profile_, | 192 base::MakeUnique<app_list::SearchAnswerWebContentsDelegate>(profile_, |
194 model_); | 193 model_); |
195 | 194 |
196 SetUpSearchUI(); | 195 SetUpSearchUI(); |
197 SetUpCustomLauncherPages(); | 196 SetUpCustomLauncherPages(); |
198 OnTemplateURLServiceChanged(); | 197 OnTemplateURLServiceChanged(); |
199 } | 198 } |
200 | 199 |
201 // Clear search query. | 200 // Clear search query. |
202 model_->search_box()->SetText(base::string16()); | 201 model_->search_box()->Update(base::string16(), false); |
203 } | 202 } |
204 | 203 |
205 void AppListViewDelegate::SetUpSearchUI() { | 204 void AppListViewDelegate::SetUpSearchUI() { |
206 app_list::StartPageService* start_page_service = | 205 app_list::StartPageService* start_page_service = |
207 app_list::StartPageService::Get(profile_); | 206 app_list::StartPageService::Get(profile_); |
208 if (start_page_service) | 207 if (start_page_service) |
209 start_page_service->AddObserver(this); | 208 start_page_service->AddObserver(this); |
210 | 209 |
211 speech_ui_->SetSpeechRecognitionState(start_page_service | 210 speech_ui_->SetSpeechRecognitionState(start_page_service |
212 ? start_page_service->state() | 211 ? start_page_service->state() |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 app_list::AppListModel* AppListViewDelegate::GetModel() { | 269 app_list::AppListModel* AppListViewDelegate::GetModel() { |
271 return model_; | 270 return model_; |
272 } | 271 } |
273 | 272 |
274 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() { | 273 app_list::SpeechUIModel* AppListViewDelegate::GetSpeechUI() { |
275 return speech_ui_.get(); | 274 return speech_ui_.get(); |
276 } | 275 } |
277 | 276 |
278 void AppListViewDelegate::StartSearch() { | 277 void AppListViewDelegate::StartSearch() { |
279 if (search_controller_) { | 278 if (search_controller_) { |
280 search_controller_->Start(is_voice_query_); | 279 search_controller_->Start(); |
281 controller_->OnSearchStarted(); | 280 controller_->OnSearchStarted(); |
282 } | 281 } |
283 if (search_answer_delegate_) | 282 if (search_answer_delegate_) |
284 search_answer_delegate_->Update(); | 283 search_answer_delegate_->Update(); |
285 } | 284 } |
286 | 285 |
287 void AppListViewDelegate::StopSearch() { | 286 void AppListViewDelegate::StopSearch() { |
288 if (search_controller_) | 287 if (search_controller_) |
289 search_controller_->Stop(); | 288 search_controller_->Stop(); |
290 } | 289 } |
291 | 290 |
292 void AppListViewDelegate::OpenSearchResult( | 291 void AppListViewDelegate::OpenSearchResult( |
293 app_list::SearchResult* result, | 292 app_list::SearchResult* result, |
294 bool auto_launch, | 293 bool auto_launch, |
295 int event_flags) { | 294 int event_flags) { |
296 if (auto_launch) | 295 if (auto_launch) |
297 base::RecordAction(base::UserMetricsAction("AppList_AutoLaunched")); | 296 base::RecordAction(base::UserMetricsAction("AppList_AutoLaunched")); |
298 search_controller_->OpenResult(result, event_flags); | 297 search_controller_->OpenResult(result, event_flags); |
299 is_voice_query_ = false; | |
300 } | 298 } |
301 | 299 |
302 void AppListViewDelegate::InvokeSearchResultAction( | 300 void AppListViewDelegate::InvokeSearchResultAction( |
303 app_list::SearchResult* result, | 301 app_list::SearchResult* result, |
304 int action_index, | 302 int action_index, |
305 int event_flags) { | 303 int event_flags) { |
306 search_controller_->InvokeResultAction(result, action_index, event_flags); | 304 search_controller_->InvokeResultAction(result, action_index, event_flags); |
307 } | 305 } |
308 | 306 |
309 base::TimeDelta AppListViewDelegate::GetAutoLaunchTimeout() { | 307 base::TimeDelta AppListViewDelegate::GetAutoLaunchTimeout() { |
310 return auto_launch_timeout_; | 308 return auto_launch_timeout_; |
311 } | 309 } |
312 | 310 |
313 void AppListViewDelegate::AutoLaunchCanceled() { | 311 void AppListViewDelegate::AutoLaunchCanceled() { |
314 if (is_voice_query_) { | 312 if (model_ && model_->search_box()->is_voice_query()) { |
315 base::RecordAction(base::UserMetricsAction("AppList_AutoLaunchCanceled")); | 313 base::RecordAction(base::UserMetricsAction("AppList_AutoLaunchCanceled")); |
316 // Cancelling the auto launch means we are no longer in a voice query. | |
317 is_voice_query_ = false; | |
318 } | 314 } |
319 auto_launch_timeout_ = base::TimeDelta(); | 315 auto_launch_timeout_ = base::TimeDelta(); |
320 } | 316 } |
321 | 317 |
322 void AppListViewDelegate::ViewInitialized() { | 318 void AppListViewDelegate::ViewInitialized() { |
323 app_list::StartPageService* service = | 319 app_list::StartPageService* service = |
324 app_list::StartPageService::Get(profile_); | 320 app_list::StartPageService::Get(profile_); |
325 if (service) { | 321 if (service) { |
326 service->AppListShown(); | 322 service->AppListShown(); |
327 if (service->HotwordEnabled()) { | 323 if (service->HotwordEnabled()) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 hotword_service->StopHotwordSession(this); | 410 hotword_service->StopHotwordSession(this); |
415 } | 411 } |
416 } | 412 } |
417 | 413 |
418 void AppListViewDelegate::OnSpeechResult(const base::string16& result, | 414 void AppListViewDelegate::OnSpeechResult(const base::string16& result, |
419 bool is_final) { | 415 bool is_final) { |
420 speech_ui_->SetSpeechResult(result, is_final); | 416 speech_ui_->SetSpeechResult(result, is_final); |
421 if (is_final) { | 417 if (is_final) { |
422 auto_launch_timeout_ = base::TimeDelta::FromMilliseconds( | 418 auto_launch_timeout_ = base::TimeDelta::FromMilliseconds( |
423 kAutoLaunchDefaultTimeoutMilliSec); | 419 kAutoLaunchDefaultTimeoutMilliSec); |
424 is_voice_query_ = true; | 420 model_->search_box()->Update(result, true); |
425 model_->search_box()->SetText(result); | |
426 } | 421 } |
427 } | 422 } |
428 | 423 |
429 void AppListViewDelegate::OnSpeechSoundLevelChanged(int16_t level) { | 424 void AppListViewDelegate::OnSpeechSoundLevelChanged(int16_t level) { |
430 speech_ui_->UpdateSoundLevel(level); | 425 speech_ui_->UpdateSoundLevel(level); |
431 } | 426 } |
432 | 427 |
433 void AppListViewDelegate::OnSpeechRecognitionStateChanged( | 428 void AppListViewDelegate::OnSpeechRecognitionStateChanged( |
434 app_list::SpeechRecognitionState new_state) { | 429 app_list::SpeechRecognitionState new_state) { |
435 speech_ui_->SetSpeechRecognitionState(new_state, false); | 430 speech_ui_->SetSpeechRecognitionState(new_state, false); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 app_list::StartPageService* service = | 513 app_list::StartPageService* service = |
519 app_list::StartPageService::Get(profile_); | 514 app_list::StartPageService::Get(profile_); |
520 return service && service->GetSpeechRecognitionContents(); | 515 return service && service->GetSpeechRecognitionContents(); |
521 } | 516 } |
522 | 517 |
523 void AppListViewDelegate::OnTemplateURLServiceChanged() { | 518 void AppListViewDelegate::OnTemplateURLServiceChanged() { |
524 TemplateURLService* template_url_service = | 519 TemplateURLService* template_url_service = |
525 TemplateURLServiceFactory::GetForProfile(profile_); | 520 TemplateURLServiceFactory::GetForProfile(profile_); |
526 const TemplateURL* default_provider = | 521 const TemplateURL* default_provider = |
527 template_url_service->GetDefaultSearchProvider(); | 522 template_url_service->GetDefaultSearchProvider(); |
528 bool is_google = | 523 bool is_google = |
xiyuan
2017/05/01 21:16:31
nit: const , since you are here... :)
vadimt
2017/05/10 22:55:48
Done.
| |
529 default_provider->GetEngineType( | 524 default_provider->GetEngineType( |
530 template_url_service->search_terms_data()) == | 525 template_url_service->search_terms_data()) == |
531 SEARCH_ENGINE_GOOGLE; | 526 SEARCH_ENGINE_GOOGLE; |
532 | 527 |
533 model_->SetSearchEngineIsGoogle(is_google); | 528 if (model_->search_engine_is_google() != is_google) { |
xiyuan
2017/05/01 21:16:31
nit: Move this test to AppListModel::SetSearchEngi
vadimt
2017/05/10 22:55:49
Done.
| |
534 search_answer_delegate_->Update(); | 529 model_->SetSearchEngineIsGoogle(is_google); |
530 search_answer_delegate_->Update(); | |
531 } | |
535 | 532 |
536 app_list::StartPageService* start_page_service = | 533 app_list::StartPageService* start_page_service = |
537 app_list::StartPageService::Get(profile_); | 534 app_list::StartPageService::Get(profile_); |
538 if (start_page_service) | 535 if (start_page_service) |
539 start_page_service->set_search_engine_is_google(is_google); | 536 start_page_service->set_search_engine_is_google(is_google); |
540 } | 537 } |
541 | 538 |
542 void AppListViewDelegate::Observe(int type, | 539 void AppListViewDelegate::Observe(int type, |
543 const content::NotificationSource& source, | 540 const content::NotificationSource& source, |
544 const content::NotificationDetails& details) { | 541 const content::NotificationDetails& details) { |
545 DCHECK_EQ(chrome::NOTIFICATION_APP_TERMINATING, type); | 542 DCHECK_EQ(chrome::NOTIFICATION_APP_TERMINATING, type); |
546 | 543 |
547 SetProfile(nullptr); // Ensures launcher page web contents are torn down. | 544 SetProfile(nullptr); // Ensures launcher page web contents are torn down. |
548 } | 545 } |
OLD | NEW |