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

Side by Side Diff: chrome/browser/ui/webui/app_list/start_page_handler.cc

Issue 267653005: Adds HotwordPrivate API for integrating the hotword feature to AppLauncher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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"
(...skipping 17 matching lines...) Expand all
28 #include "extensions/common/extension.h" 28 #include "extensions/common/extension.h"
29 #include "extensions/common/extension_icon_set.h" 29 #include "extensions/common/extension_icon_set.h"
30 #include "ui/app_list/app_list_switches.h" 30 #include "ui/app_list/app_list_switches.h"
31 #include "ui/app_list/speech_ui_model_observer.h" 31 #include "ui/app_list/speech_ui_model_observer.h"
32 #include "ui/events/event_constants.h" 32 #include "ui/events/event_constants.h"
33 33
34 namespace app_list { 34 namespace app_list {
35 35
36 namespace { 36 namespace {
37 37
38 const char kOldHotwordExtensionVersionString[] = "0.1.1.5014_0";
39
38 scoped_ptr<base::DictionaryValue> CreateAppInfo( 40 scoped_ptr<base::DictionaryValue> CreateAppInfo(
39 const extensions::Extension* app) { 41 const extensions::Extension* app) {
40 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 42 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
41 dict->SetString("appId", app->id()); 43 dict->SetString("appId", app->id());
42 dict->SetString("textTitle", app->short_name()); 44 dict->SetString("textTitle", app->short_name());
43 dict->SetString("title", app->name()); 45 dict->SetString("title", app->name());
44 46
45 const bool grayscale = false; 47 const bool grayscale = false;
46 bool icon_exists = true; 48 bool icon_exists = true;
47 GURL icon_url = extensions::ExtensionIconSource::GetIconURL( 49 GURL icon_url = extensions::ExtensionIconSource::GetIconURL(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 for (size_t i = 0; i < recommends.size(); ++i) { 126 for (size_t i = 0; i < recommends.size(); ++i) {
125 recommended_list.Append(CreateAppInfo(recommends[i].get()).release()); 127 recommended_list.Append(CreateAppInfo(recommends[i].get()).release());
126 } 128 }
127 129
128 web_ui()->CallJavascriptFunction("appList.startPage.setRecommendedApps", 130 web_ui()->CallJavascriptFunction("appList.startPage.setRecommendedApps",
129 recommended_list); 131 recommended_list);
130 } 132 }
131 133
132 #if defined(OS_CHROMEOS) 134 #if defined(OS_CHROMEOS)
133 void StartPageHandler::OnHotwordEnabledChanged() { 135 void StartPageHandler::OnHotwordEnabledChanged() {
134 StartPageService* service = StartPageService::Get( 136 // If the hotword extension is new enough, we should use the new
135 Profile::FromWebUI(web_ui())); 137 // hotwordPrivate API to provide the feature.
136 web_ui()->CallJavascriptFunction( 138 // TODO(mukai): remove this after everything gets stable.
137 "appList.startPage.setHotwordEnabled", 139 Profile* profile = Profile::FromWebUI(web_ui());
138 base::FundamentalValue(service->HotwordEnabled())); 140 ExtensionService* extension_service =
141 extensions::ExtensionSystem::Get(profile)->extension_service();
142 if (!extension_service)
143 return;
144
145 const extensions::Extension* hotword_extension =
146 extension_service->GetExtensionById(
147 extension_misc::kHotwordExtensionId, false /* include_disabled */);
148 if (hotword_extension && hotword_extension->version()->CompareTo(
149 base::Version(kOldHotwordExtensionVersionString)) <= 0) {
150 StartPageService* service = StartPageService::Get(profile);
151 web_ui()->CallJavascriptFunction(
152 "appList.startPage.setHotwordEnabled",
153 base::FundamentalValue(service->HotwordEnabled()));
154 }
139 } 155 }
140 #endif 156 #endif
141 157
142 void StartPageHandler::HandleInitialize(const base::ListValue* args) { 158 void StartPageHandler::HandleInitialize(const base::ListValue* args) {
143 Profile* profile = Profile::FromWebUI(web_ui()); 159 Profile* profile = Profile::FromWebUI(web_ui());
144 StartPageService* service = StartPageService::Get(profile); 160 StartPageService* service = StartPageService::Get(profile);
145 if (!service) 161 if (!service)
146 return; 162 return;
147 163
148 recommended_apps_ = service->recommended_apps(); 164 recommended_apps_ = service->recommended_apps();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 else if (state_string == "STOPPING") 253 else if (state_string == "STOPPING")
238 new_state = SPEECH_RECOGNITION_STOPPING; 254 new_state = SPEECH_RECOGNITION_STOPPING;
239 255
240 StartPageService* service = 256 StartPageService* service =
241 StartPageService::Get(Profile::FromWebUI(web_ui())); 257 StartPageService::Get(Profile::FromWebUI(web_ui()));
242 if (service) 258 if (service)
243 service->OnSpeechRecognitionStateChanged(new_state); 259 service->OnSpeechRecognitionStateChanged(new_state);
244 } 260 }
245 261
246 } // namespace app_list 262 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698