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