| 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 "base/version.h" | 12 #include "base/version.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/search/hotword_service.h" | 14 #include "chrome/browser/search/hotword_service.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" | |
| 18 #include "chrome/browser/ui/app_list/start_page_service.h" | 17 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 19 #include "chrome/browser/ui/host_desktop.h" | 18 #include "chrome/browser/ui/host_desktop.h" |
| 20 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 19 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
| 21 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 22 #include "components/update_client/update_query_params.h" | 21 #include "components/update_client/update_query_params.h" |
| 23 #include "content/public/browser/web_ui.h" | 22 #include "content/public/browser/web_ui.h" |
| 24 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
| 25 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
| 26 #include "extensions/common/constants.h" | 25 #include "extensions/common/constants.h" |
| 27 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
| 28 #include "extensions/common/extension_icon_set.h" | 27 #include "extensions/common/extension_icon_set.h" |
| 29 #include "ui/app_list/app_list_switches.h" | 28 #include "ui/app_list/app_list_switches.h" |
| 30 #include "ui/app_list/speech_ui_model_observer.h" | 29 #include "ui/app_list/speech_ui_model_observer.h" |
| 31 #include "ui/events/event_constants.h" | 30 #include "ui/events/event_constants.h" |
| 32 | 31 |
| 33 namespace app_list { | 32 namespace app_list { |
| 34 | 33 |
| 35 namespace { | 34 namespace { |
| 36 | 35 |
| 37 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
| 38 const char kOldHotwordExtensionVersionString[] = "0.1.1.5023"; | 37 const char kOldHotwordExtensionVersionString[] = "0.1.1.5023"; |
| 39 #endif | 38 #endif |
| 40 | 39 |
| 41 scoped_ptr<base::DictionaryValue> CreateAppInfo( | |
| 42 const extensions::Extension* app) { | |
| 43 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | |
| 44 dict->SetString("appId", app->id()); | |
| 45 dict->SetString("textTitle", app->short_name()); | |
| 46 dict->SetString("title", app->name()); | |
| 47 | |
| 48 const bool grayscale = false; | |
| 49 bool icon_exists = true; | |
| 50 GURL icon_url = extensions::ExtensionIconSource::GetIconURL( | |
| 51 app, | |
| 52 extension_misc::EXTENSION_ICON_MEDIUM, | |
| 53 ExtensionIconSet::MATCH_BIGGER, | |
| 54 grayscale, | |
| 55 &icon_exists); | |
| 56 dict->SetString("iconUrl", icon_url.spec()); | |
| 57 | |
| 58 return dict.Pass(); | |
| 59 } | |
| 60 | |
| 61 } // namespace | 40 } // namespace |
| 62 | 41 |
| 63 StartPageHandler::StartPageHandler() | 42 StartPageHandler::StartPageHandler() : extension_registry_observer_(this) { |
| 64 : recommended_apps_(NULL), | |
| 65 extension_registry_observer_(this) { | |
| 66 } | 43 } |
| 67 | 44 |
| 68 StartPageHandler::~StartPageHandler() { | 45 StartPageHandler::~StartPageHandler() { |
| 69 if (recommended_apps_) | |
| 70 recommended_apps_->RemoveObserver(this); | |
| 71 } | 46 } |
| 72 | 47 |
| 73 void StartPageHandler::RegisterMessages() { | 48 void StartPageHandler::RegisterMessages() { |
| 74 web_ui()->RegisterMessageCallback( | 49 web_ui()->RegisterMessageCallback( |
| 75 "initialize", | 50 "initialize", |
| 76 base::Bind(&StartPageHandler::HandleInitialize, base::Unretained(this))); | 51 base::Bind(&StartPageHandler::HandleInitialize, base::Unretained(this))); |
| 77 web_ui()->RegisterMessageCallback( | 52 web_ui()->RegisterMessageCallback( |
| 78 "launchApp", | 53 "launchApp", |
| 79 base::Bind(&StartPageHandler::HandleLaunchApp, base::Unretained(this))); | 54 base::Bind(&StartPageHandler::HandleLaunchApp, base::Unretained(this))); |
| 80 web_ui()->RegisterMessageCallback( | 55 web_ui()->RegisterMessageCallback( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 107 const extensions::Extension* extension, | 82 const extensions::Extension* extension, |
| 108 extensions::UnloadedExtensionInfo::Reason reason) { | 83 extensions::UnloadedExtensionInfo::Reason reason) { |
| 109 #if defined(OS_CHROMEOS) | 84 #if defined(OS_CHROMEOS) |
| 110 DCHECK_EQ(Profile::FromWebUI(web_ui()), | 85 DCHECK_EQ(Profile::FromWebUI(web_ui()), |
| 111 Profile::FromBrowserContext(browser_context)); | 86 Profile::FromBrowserContext(browser_context)); |
| 112 if (extension->id() == extension_misc::kHotwordExtensionId) | 87 if (extension->id() == extension_misc::kHotwordExtensionId) |
| 113 OnHotwordEnabledChanged(); | 88 OnHotwordEnabledChanged(); |
| 114 #endif | 89 #endif |
| 115 } | 90 } |
| 116 | 91 |
| 117 void StartPageHandler::OnRecommendedAppsChanged() { | |
| 118 SendRecommendedApps(); | |
| 119 } | |
| 120 | |
| 121 void StartPageHandler::SendRecommendedApps() { | |
| 122 const RecommendedApps::Apps& recommends = recommended_apps_->apps(); | |
| 123 | |
| 124 base::ListValue recommended_list; | |
| 125 for (size_t i = 0; i < recommends.size(); ++i) { | |
| 126 recommended_list.Append(CreateAppInfo(recommends[i].get()).release()); | |
| 127 } | |
| 128 | |
| 129 web_ui()->CallJavascriptFunction("appList.startPage.setRecommendedApps", | |
| 130 recommended_list); | |
| 131 } | |
| 132 | |
| 133 #if defined(OS_CHROMEOS) | 92 #if defined(OS_CHROMEOS) |
| 134 void StartPageHandler::OnHotwordEnabledChanged() { | 93 void StartPageHandler::OnHotwordEnabledChanged() { |
| 135 // If the hotword extension is new enough, we should use the new | 94 // If the hotword extension is new enough, we should use the new |
| 136 // hotwordPrivate API to provide the feature. | 95 // hotwordPrivate API to provide the feature. |
| 137 // TODO(mukai): remove this after everything gets stable. | 96 // TODO(mukai): remove this after everything gets stable. |
| 138 Profile* profile = Profile::FromWebUI(web_ui()); | 97 Profile* profile = Profile::FromWebUI(web_ui()); |
| 139 | 98 |
| 140 extensions::ExtensionRegistry* registry = | 99 extensions::ExtensionRegistry* registry = |
| 141 extensions::ExtensionRegistry::Get(profile); | 100 extensions::ExtensionRegistry::Get(profile); |
| 142 const extensions::Extension* hotword_extension = | 101 const extensions::Extension* hotword_extension = |
| (...skipping 12 matching lines...) Expand all Loading... |
| 155 #endif | 114 #endif |
| 156 | 115 |
| 157 void StartPageHandler::HandleInitialize(const base::ListValue* args) { | 116 void StartPageHandler::HandleInitialize(const base::ListValue* args) { |
| 158 Profile* profile = Profile::FromWebUI(web_ui()); | 117 Profile* profile = Profile::FromWebUI(web_ui()); |
| 159 StartPageService* service = StartPageService::Get(profile); | 118 StartPageService* service = StartPageService::Get(profile); |
| 160 if (!service) | 119 if (!service) |
| 161 return; | 120 return; |
| 162 | 121 |
| 163 service->WebUILoaded(); | 122 service->WebUILoaded(); |
| 164 | 123 |
| 165 recommended_apps_ = service->recommended_apps(); | |
| 166 recommended_apps_->AddObserver(this); | |
| 167 | |
| 168 SendRecommendedApps(); | |
| 169 | |
| 170 #if defined(OS_CHROMEOS) | 124 #if defined(OS_CHROMEOS) |
| 171 if (app_list::switches::IsVoiceSearchEnabled() && | 125 if (app_list::switches::IsVoiceSearchEnabled() && |
| 172 HotwordService::DoesHotwordSupportLanguage(profile)) { | 126 HotwordService::DoesHotwordSupportLanguage(profile)) { |
| 173 OnHotwordEnabledChanged(); | 127 OnHotwordEnabledChanged(); |
| 174 pref_change_registrar_.Init(profile->GetPrefs()); | 128 pref_change_registrar_.Init(profile->GetPrefs()); |
| 175 pref_change_registrar_.Add( | 129 pref_change_registrar_.Add( |
| 176 prefs::kHotwordSearchEnabled, | 130 prefs::kHotwordSearchEnabled, |
| 177 base::Bind(&StartPageHandler::OnHotwordEnabledChanged, | 131 base::Bind(&StartPageHandler::OnHotwordEnabledChanged, |
| 178 base::Unretained(this))); | 132 base::Unretained(this))); |
| 179 | 133 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 else if (state_string == "NETWORK_ERROR") | 220 else if (state_string == "NETWORK_ERROR") |
| 267 new_state = SPEECH_RECOGNITION_NETWORK_ERROR; | 221 new_state = SPEECH_RECOGNITION_NETWORK_ERROR; |
| 268 | 222 |
| 269 StartPageService* service = | 223 StartPageService* service = |
| 270 StartPageService::Get(Profile::FromWebUI(web_ui())); | 224 StartPageService::Get(Profile::FromWebUI(web_ui())); |
| 271 if (service) | 225 if (service) |
| 272 service->OnSpeechRecognitionStateChanged(new_state); | 226 service->OnSpeechRecognitionStateChanged(new_state); |
| 273 } | 227 } |
| 274 | 228 |
| 275 } // namespace app_list | 229 } // namespace app_list |
| OLD | NEW |