OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/start_page_service.h" | 5 #include "chrome/browser/ui/app_list/start_page_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/json/json_string_value_serializer.h" | 11 #include "base/json/json_string_value_serializer.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 18 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/search/hotword_service.h" | 20 #include "chrome/browser/search/hotword_service.h" |
21 #include "chrome/browser/search/hotword_service_factory.h" | 21 #include "chrome/browser/search/hotword_service_factory.h" |
| 22 #include "chrome/browser/search_engines/template_url_service_factory.h" |
22 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 23 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
23 #include "chrome/browser/ui/app_list/speech_auth_helper.h" | 24 #include "chrome/browser/ui/app_list/speech_auth_helper.h" |
24 #include "chrome/browser/ui/app_list/speech_recognizer.h" | 25 #include "chrome/browser/ui/app_list/speech_recognizer.h" |
25 #include "chrome/browser/ui/app_list/start_page_observer.h" | 26 #include "chrome/browser/ui/app_list/start_page_observer.h" |
26 #include "chrome/browser/ui/app_list/start_page_service_factory.h" | 27 #include "chrome/browser/ui/app_list/start_page_service_factory.h" |
27 #include "chrome/browser/ui/browser_navigator.h" | 28 #include "chrome/browser/ui/browser_navigator.h" |
28 #include "chrome/browser/ui/browser_tabstrip.h" | 29 #include "chrome/browser/ui/browser_tabstrip.h" |
29 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 30 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
30 #include "chrome/common/chrome_switches.h" | 31 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 34 #include "components/search_engines/template_url_prepopulate_data.h" |
| 35 #include "components/search_engines/template_url_service.h" |
33 #include "components/ui/zoom/zoom_controller.h" | 36 #include "components/ui/zoom/zoom_controller.h" |
34 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
35 #include "content/public/browser/notification_details.h" | 38 #include "content/public/browser/notification_details.h" |
36 #include "content/public/browser/notification_observer.h" | 39 #include "content/public/browser/notification_observer.h" |
37 #include "content/public/browser/notification_registrar.h" | 40 #include "content/public/browser/notification_registrar.h" |
38 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
39 #include "content/public/browser/notification_source.h" | 42 #include "content/public/browser/notification_source.h" |
40 #include "content/public/browser/speech_recognition_session_preamble.h" | 43 #include "content/public/browser/speech_recognition_session_preamble.h" |
41 #include "content/public/browser/web_contents.h" | 44 #include "content/public/browser/web_contents.h" |
42 #include "content/public/browser/web_contents_delegate.h" | 45 #include "content/public/browser/web_contents_delegate.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 // If experimental hotwording is enabled, then we're always "ready". | 275 // If experimental hotwording is enabled, then we're always "ready". |
273 // Transitioning into the "hotword recognizing" state is handled by the | 276 // Transitioning into the "hotword recognizing" state is handled by the |
274 // hotword extension. | 277 // hotword extension. |
275 if (HotwordService::IsExperimentalHotwordingEnabled()) { | 278 if (HotwordService::IsExperimentalHotwordingEnabled()) { |
276 state_ = app_list::SPEECH_RECOGNITION_READY; | 279 state_ = app_list::SPEECH_RECOGNITION_READY; |
277 } | 280 } |
278 | 281 |
279 if (app_list::switches::IsExperimentalAppListEnabled()) | 282 if (app_list::switches::IsExperimentalAppListEnabled()) |
280 LoadContents(); | 283 LoadContents(); |
281 | 284 |
| 285 TemplateURLService* template_url_service = |
| 286 TemplateURLServiceFactory::GetForProfile(profile_); |
| 287 if (template_url_service) |
| 288 template_url_service->AddObserver(this); |
| 289 |
282 network_change_observer_.reset(new NetworkChangeObserver(this)); | 290 network_change_observer_.reset(new NetworkChangeObserver(this)); |
283 } | 291 } |
284 | 292 |
285 StartPageService::~StartPageService() {} | 293 StartPageService::~StartPageService() { |
| 294 TemplateURLService* template_url_service = |
| 295 TemplateURLServiceFactory::GetForProfile(profile_); |
| 296 if (template_url_service) |
| 297 template_url_service->RemoveObserver(this); |
| 298 } |
286 | 299 |
287 void StartPageService::AddObserver(StartPageObserver* observer) { | 300 void StartPageService::AddObserver(StartPageObserver* observer) { |
288 observers_.AddObserver(observer); | 301 observers_.AddObserver(observer); |
289 } | 302 } |
290 | 303 |
291 void StartPageService::RemoveObserver(StartPageObserver* observer) { | 304 void StartPageService::RemoveObserver(StartPageObserver* observer) { |
292 observers_.RemoveObserver(observer); | 305 observers_.RemoveObserver(observer); |
293 } | 306 } |
294 | 307 |
295 void StartPageService::OnMicrophoneChanged(bool available) { | 308 void StartPageService::OnMicrophoneChanged(bool available) { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 if (service && | 500 if (service && |
488 service->IsOptedIntoAudioLogging() && | 501 service->IsOptedIntoAudioLogging() && |
489 service->IsAlwaysOnEnabled() && | 502 service->IsAlwaysOnEnabled() && |
490 !speech_auth_helper_->GetToken().empty()) { | 503 !speech_auth_helper_->GetToken().empty()) { |
491 *auth_scope = speech_auth_helper_->GetScope(); | 504 *auth_scope = speech_auth_helper_->GetScope(); |
492 *auth_token = speech_auth_helper_->GetToken(); | 505 *auth_token = speech_auth_helper_->GetToken(); |
493 } | 506 } |
494 } | 507 } |
495 } | 508 } |
496 | 509 |
| 510 void StartPageService::OnTemplateURLServiceChanged() { |
| 511 TemplateURLService* template_url_service = |
| 512 TemplateURLServiceFactory::GetForProfile(profile_); |
| 513 const TemplateURL* default_provider = |
| 514 template_url_service->GetDefaultSearchProvider(); |
| 515 bool is_google = |
| 516 TemplateURLPrepopulateData::GetEngineType( |
| 517 *default_provider, template_url_service->search_terms_data()) == |
| 518 SEARCH_ENGINE_GOOGLE; |
| 519 |
| 520 contents_->GetWebUI()->CallJavascriptFunction( |
| 521 "appList.startPage.onSearchEngineChanged", |
| 522 base::FundamentalValue(is_google)); |
| 523 |
| 524 if (is_google) |
| 525 FetchDoodleJson(); |
| 526 } |
| 527 |
497 void StartPageService::Shutdown() { | 528 void StartPageService::Shutdown() { |
498 UnloadContents(); | 529 UnloadContents(); |
499 #if defined(OS_CHROMEOS) | 530 #if defined(OS_CHROMEOS) |
500 audio_status_.reset(); | 531 audio_status_.reset(); |
501 #endif | 532 #endif |
502 | 533 |
503 speech_auth_helper_.reset(); | 534 speech_auth_helper_.reset(); |
504 network_change_observer_.reset(); | 535 network_change_observer_.reset(); |
505 } | 536 } |
506 | 537 |
(...skipping 17 matching lines...) Expand all Loading... |
524 // There's a race condition between the WebUI loading, and calling its JS | 555 // There's a race condition between the WebUI loading, and calling its JS |
525 // functions. Specifically, calling LoadContents() doesn't mean that the page | 556 // functions. Specifically, calling LoadContents() doesn't mean that the page |
526 // has loaded, but several code paths make this assumption. This function | 557 // has loaded, but several code paths make this assumption. This function |
527 // allows us to defer calling JS functions until after the page has finished | 558 // allows us to defer calling JS functions until after the page has finished |
528 // loading. | 559 // loading. |
529 webui_finished_loading_ = true; | 560 webui_finished_loading_ = true; |
530 for (const auto& cb : pending_webui_callbacks_) | 561 for (const auto& cb : pending_webui_callbacks_) |
531 cb.Run(); | 562 cb.Run(); |
532 pending_webui_callbacks_.clear(); | 563 pending_webui_callbacks_.clear(); |
533 | 564 |
534 FetchDoodleJson(); | 565 OnTemplateURLServiceChanged(); |
535 } | 566 } |
536 | 567 |
537 void StartPageService::LoadContents() { | 568 void StartPageService::LoadContents() { |
538 contents_.reset(content::WebContents::Create( | 569 contents_.reset(content::WebContents::Create( |
539 content::WebContents::CreateParams(profile_))); | 570 content::WebContents::CreateParams(profile_))); |
540 contents_delegate_.reset(new StartPageWebContentsDelegate(profile_)); | 571 contents_delegate_.reset(new StartPageWebContentsDelegate(profile_)); |
541 contents_->SetDelegate(contents_delegate_.get()); | 572 contents_->SetDelegate(contents_delegate_.get()); |
542 | 573 |
543 // The ZoomController needs to be created before the web contents is observed | 574 // The ZoomController needs to be created before the web contents is observed |
544 // by this object. Otherwise it will react to DidNavigateMainFrame after this | 575 // by this object. Otherwise it will react to DidNavigateMainFrame after this |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 | 640 |
610 // Check for a new doodle. | 641 // Check for a new doodle. |
611 content::BrowserThread::PostDelayedTask( | 642 content::BrowserThread::PostDelayedTask( |
612 content::BrowserThread::UI, FROM_HERE, | 643 content::BrowserThread::UI, FROM_HERE, |
613 base::Bind(&StartPageService::FetchDoodleJson, | 644 base::Bind(&StartPageService::FetchDoodleJson, |
614 weak_factory_.GetWeakPtr()), | 645 weak_factory_.GetWeakPtr()), |
615 recheck_delay); | 646 recheck_delay); |
616 } | 647 } |
617 | 648 |
618 } // namespace app_list | 649 } // namespace app_list |
OLD | NEW |