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/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_system.h" | 13 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 15 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
16 #include "chrome/browser/ui/app_list/app_list_service.h" | 16 #include "chrome/browser/ui/app_list/app_list_service.h" |
17 #include "chrome/browser/ui/app_list/recommended_apps.h" | 17 #include "chrome/browser/ui/app_list/recommended_apps.h" |
18 #include "chrome/browser/ui/app_list/start_page_service.h" | 18 #include "chrome/browser/ui/app_list/start_page_service.h" |
19 #include "chrome/browser/ui/host_desktop.h" | 19 #include "chrome/browser/ui/host_desktop.h" |
20 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 20 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
21 #include "chrome/common/extensions/extension_icon_set.h" | 21 #include "chrome/common/extensions/extension_icon_set.h" |
22 #include "content/public/browser/web_contents_view.h" | 22 #include "content/public/browser/web_contents_view.h" |
23 #include "content/public/browser/web_ui.h" | 23 #include "content/public/browser/web_ui.h" |
24 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 25 #include "ui/app_list/speech_ui_model_observer.h" |
25 #include "ui/events/event_constants.h" | 26 #include "ui/events/event_constants.h" |
26 | 27 |
27 namespace app_list { | 28 namespace app_list { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 scoped_ptr<base::DictionaryValue> CreateAppInfo( | 32 scoped_ptr<base::DictionaryValue> CreateAppInfo( |
32 const extensions::Extension* app) { | 33 const extensions::Extension* app) { |
33 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 34 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
34 dict->SetString("appId", app->id()); | 35 dict->SetString("appId", app->id()); |
(...skipping 23 matching lines...) Expand all Loading... |
58 } | 59 } |
59 | 60 |
60 void StartPageHandler::RegisterMessages() { | 61 void StartPageHandler::RegisterMessages() { |
61 web_ui()->RegisterMessageCallback( | 62 web_ui()->RegisterMessageCallback( |
62 "initialize", | 63 "initialize", |
63 base::Bind(&StartPageHandler::HandleInitialize, base::Unretained(this))); | 64 base::Bind(&StartPageHandler::HandleInitialize, base::Unretained(this))); |
64 web_ui()->RegisterMessageCallback( | 65 web_ui()->RegisterMessageCallback( |
65 "launchApp", | 66 "launchApp", |
66 base::Bind(&StartPageHandler::HandleLaunchApp, base::Unretained(this))); | 67 base::Bind(&StartPageHandler::HandleLaunchApp, base::Unretained(this))); |
67 web_ui()->RegisterMessageCallback( | 68 web_ui()->RegisterMessageCallback( |
68 "search", | 69 "speechResult", |
69 base::Bind(&StartPageHandler::HandleSearch, base::Unretained(this))); | 70 base::Bind(&StartPageHandler::HandleSpeechResult, |
| 71 base::Unretained(this))); |
| 72 web_ui()->RegisterMessageCallback( |
| 73 "speechSoundLevel", |
| 74 base::Bind(&StartPageHandler::HandleSpeechSoundLevel, |
| 75 base::Unretained(this))); |
70 web_ui()->RegisterMessageCallback( | 76 web_ui()->RegisterMessageCallback( |
71 "setSpeechRecognitionState", | 77 "setSpeechRecognitionState", |
72 base::Bind(&StartPageHandler::HandleSpeechRecognition, | 78 base::Bind(&StartPageHandler::HandleSpeechRecognition, |
73 base::Unretained(this))); | 79 base::Unretained(this))); |
74 } | 80 } |
75 | 81 |
76 void StartPageHandler::OnRecommendedAppsChanged() { | 82 void StartPageHandler::OnRecommendedAppsChanged() { |
77 SendRecommendedApps(); | 83 SendRecommendedApps(); |
78 } | 84 } |
79 | 85 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 AppListControllerDelegate* controller = AppListService::Get( | 123 AppListControllerDelegate* controller = AppListService::Get( |
118 chrome::GetHostDesktopTypeForNativeView( | 124 chrome::GetHostDesktopTypeForNativeView( |
119 web_ui()->GetWebContents()->GetView()->GetNativeView())) | 125 web_ui()->GetWebContents()->GetView()->GetNativeView())) |
120 ->GetControllerDelegate(); | 126 ->GetControllerDelegate(); |
121 controller->ActivateApp(profile, | 127 controller->ActivateApp(profile, |
122 app, | 128 app, |
123 AppListControllerDelegate::LAUNCH_FROM_APP_LIST, | 129 AppListControllerDelegate::LAUNCH_FROM_APP_LIST, |
124 ui::EF_NONE); | 130 ui::EF_NONE); |
125 } | 131 } |
126 | 132 |
127 void StartPageHandler::HandleSearch(const base::ListValue* args) { | 133 void StartPageHandler::HandleSpeechResult(const base::ListValue* args) { |
128 base::string16 query; | 134 base::string16 query; |
| 135 bool is_final = false; |
129 CHECK(args->GetString(0, &query)); | 136 CHECK(args->GetString(0, &query)); |
| 137 CHECK(args->GetBoolean(1, &is_final)); |
130 | 138 |
131 StartPageService::Get(Profile::FromWebUI(web_ui()))->OnSearch(query); | 139 StartPageService::Get(Profile::FromWebUI(web_ui()))->OnSpeechResult( |
| 140 query, is_final); |
| 141 } |
| 142 |
| 143 void StartPageHandler::HandleSpeechSoundLevel(const base::ListValue* args) { |
| 144 double level; |
| 145 CHECK(args->GetDouble(0, &level)); |
| 146 |
| 147 StartPageService* service = |
| 148 StartPageService::Get(Profile::FromWebUI(web_ui())); |
| 149 service->OnSpeechSoundLevelChanged(static_cast<int16>(level)); |
132 } | 150 } |
133 | 151 |
134 void StartPageHandler::HandleSpeechRecognition(const base::ListValue* args) { | 152 void StartPageHandler::HandleSpeechRecognition(const base::ListValue* args) { |
135 bool recognizing; | 153 std::string state_string; |
136 CHECK(args->GetBoolean(0, &recognizing)); | 154 CHECK(args->GetString(0, &state_string)); |
| 155 |
| 156 SpeechRecognitionState new_state = SPEECH_RECOGNITION_NOT_STARTED; |
| 157 if (state_string == "on") |
| 158 new_state = SPEECH_RECOGNITION_ON; |
| 159 else if (state_string == "in-speech") |
| 160 new_state = SPEECH_RECOGNITION_IN_SPEECH; |
137 | 161 |
138 StartPageService* service = | 162 StartPageService* service = |
139 StartPageService::Get(Profile::FromWebUI(web_ui())); | 163 StartPageService::Get(Profile::FromWebUI(web_ui())); |
140 service->OnSpeechRecognitionStateChanged(recognizing); | 164 service->OnSpeechRecognitionStateChanged(new_state); |
141 } | 165 } |
142 | 166 |
143 } // namespace app_list | 167 } // namespace app_list |
OLD | NEW |