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