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/webui/app_list/start_page_handler.h" | 5 #include "chrome/browser/ui/webui/app_list/start_page_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/prefs/pref_service.h" |
11 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/search/hotword_service.h" |
15 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 17 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
16 #include "chrome/browser/ui/app_list/app_list_service.h" | 18 #include "chrome/browser/ui/app_list/app_list_service.h" |
17 #include "chrome/browser/ui/app_list/recommended_apps.h" | 19 #include "chrome/browser/ui/app_list/recommended_apps.h" |
18 #include "chrome/browser/ui/app_list/start_page_service.h" | 20 #include "chrome/browser/ui/app_list/start_page_service.h" |
19 #include "chrome/browser/ui/host_desktop.h" | 21 #include "chrome/browser/ui/host_desktop.h" |
20 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 22 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
21 #include "chrome/common/extensions/extension_icon_set.h" | 23 #include "chrome/common/extensions/extension_icon_set.h" |
| 24 #include "chrome/common/pref_names.h" |
22 #include "content/public/browser/web_contents_view.h" | 25 #include "content/public/browser/web_contents_view.h" |
23 #include "content/public/browser/web_ui.h" | 26 #include "content/public/browser/web_ui.h" |
24 #include "extensions/browser/extension_system.h" | 27 #include "extensions/browser/extension_system.h" |
25 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
26 #include "ui/app_list/app_list_switches.h" | 29 #include "ui/app_list/app_list_switches.h" |
27 #include "ui/app_list/speech_ui_model_observer.h" | 30 #include "ui/app_list/speech_ui_model_observer.h" |
28 #include "ui/events/event_constants.h" | 31 #include "ui/events/event_constants.h" |
29 | 32 |
30 namespace app_list { | 33 namespace app_list { |
31 | 34 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 93 |
91 base::ListValue recommended_list; | 94 base::ListValue recommended_list; |
92 for (size_t i = 0; i < recommends.size(); ++i) { | 95 for (size_t i = 0; i < recommends.size(); ++i) { |
93 recommended_list.Append(CreateAppInfo(recommends[i].get()).release()); | 96 recommended_list.Append(CreateAppInfo(recommends[i].get()).release()); |
94 } | 97 } |
95 | 98 |
96 web_ui()->CallJavascriptFunction("appList.startPage.setRecommendedApps", | 99 web_ui()->CallJavascriptFunction("appList.startPage.setRecommendedApps", |
97 recommended_list); | 100 recommended_list); |
98 } | 101 } |
99 | 102 |
| 103 #if defined(OS_CHROMEOS) |
| 104 bool StartPageHandler::HotwordEnabled() { |
| 105 Profile* profile = Profile::FromWebUI(web_ui()); |
| 106 return HotwordService::DoesHotwordSupportLanguage(profile) && |
| 107 profile->GetPrefs()->GetBoolean(prefs::kHotwordAppListEnabled); |
| 108 } |
| 109 |
| 110 void StartPageHandler::OnHotwordEnabledChanged() { |
| 111 web_ui()->CallJavascriptFunction( |
| 112 "appList.startPage.setHotwordEnabled", |
| 113 base::FundamentalValue(HotwordEnabled())); |
| 114 } |
| 115 |
| 116 void StartPageHandler::SynchronizeHotwordEnabled() { |
| 117 Profile* profile = Profile::FromWebUI(web_ui()); |
| 118 PrefService* pref_service = profile->GetPrefs(); |
| 119 const PrefService::Preference* pref = |
| 120 pref_service->FindPreference(prefs::kHotwordSearchEnabled); |
| 121 if (!pref || pref->IsDefaultValue()) |
| 122 return; |
| 123 |
| 124 bool search_enabled = false; |
| 125 if (!pref->GetValue()->GetAsBoolean(&search_enabled)) |
| 126 return; |
| 127 |
| 128 if (pref_service->GetBoolean(prefs::kHotwordAppListEnabled) != search_enabled) |
| 129 pref_service->SetBoolean(prefs::kHotwordAppListEnabled, search_enabled); |
| 130 } |
| 131 #endif |
| 132 |
100 void StartPageHandler::HandleInitialize(const base::ListValue* args) { | 133 void StartPageHandler::HandleInitialize(const base::ListValue* args) { |
101 Profile* profile = Profile::FromWebUI(web_ui()); | 134 Profile* profile = Profile::FromWebUI(web_ui()); |
102 StartPageService* service = StartPageService::Get(profile); | 135 StartPageService* service = StartPageService::Get(profile); |
103 if (!service) | 136 if (!service) |
104 return; | 137 return; |
105 | 138 |
106 recommended_apps_ = service->recommended_apps(); | 139 recommended_apps_ = service->recommended_apps(); |
107 recommended_apps_->AddObserver(this); | 140 recommended_apps_->AddObserver(this); |
108 | 141 |
109 SendRecommendedApps(); | 142 SendRecommendedApps(); |
110 | 143 |
111 #if defined(OS_CHROMEOS) | 144 #if defined(OS_CHROMEOS) |
112 // TODO(mukai): respect the configuration of the availability of the hotword | |
113 // plugin. | |
114 if (app_list::switches::IsVoiceSearchEnabled() && | 145 if (app_list::switches::IsVoiceSearchEnabled() && |
| 146 HotwordService::DoesHotwordSupportLanguage(profile) && |
115 base::SysInfo::IsRunningOnChromeOS()) { | 147 base::SysInfo::IsRunningOnChromeOS()) { |
116 web_ui()->CallJavascriptFunction("appList.startPage.maybeInitializePlugin"); | 148 SynchronizeHotwordEnabled(); |
| 149 OnHotwordEnabledChanged(); |
| 150 pref_change_registrar_.Init(profile->GetPrefs()); |
| 151 pref_change_registrar_.Add( |
| 152 prefs::kHotwordSearchEnabled, |
| 153 base::Bind(&StartPageHandler::SynchronizeHotwordEnabled, |
| 154 base::Unretained(this))); |
| 155 pref_change_registrar_.Add( |
| 156 prefs::kHotwordAppListEnabled, |
| 157 base::Bind(&StartPageHandler::OnHotwordEnabledChanged, |
| 158 base::Unretained(this))); |
117 } | 159 } |
118 #endif | 160 #endif |
119 } | 161 } |
120 | 162 |
121 void StartPageHandler::HandleLaunchApp(const base::ListValue* args) { | 163 void StartPageHandler::HandleLaunchApp(const base::ListValue* args) { |
122 std::string app_id; | 164 std::string app_id; |
123 CHECK(args->GetString(0, &app_id)); | 165 CHECK(args->GetString(0, &app_id)); |
124 | 166 |
125 Profile* profile = Profile::FromWebUI(web_ui()); | 167 Profile* profile = Profile::FromWebUI(web_ui()); |
126 ExtensionService* service = | 168 ExtensionService* service = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 else if (state_string == "STOPPING") | 219 else if (state_string == "STOPPING") |
178 new_state = SPEECH_RECOGNITION_STOPPING; | 220 new_state = SPEECH_RECOGNITION_STOPPING; |
179 | 221 |
180 StartPageService* service = | 222 StartPageService* service = |
181 StartPageService::Get(Profile::FromWebUI(web_ui())); | 223 StartPageService::Get(Profile::FromWebUI(web_ui())); |
182 if (service) | 224 if (service) |
183 service->OnSpeechRecognitionStateChanged(new_state); | 225 service->OnSpeechRecognitionStateChanged(new_state); |
184 } | 226 } |
185 | 227 |
186 } // namespace app_list | 228 } // namespace app_list |
OLD | NEW |