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

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

Issue 280853004: Use EventRouter::Get instead of ExtensionSystem::Get(browser_context)->event_router() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review 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
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"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/omaha_query_params/omaha_query_params.h" 13 #include "chrome/browser/omaha_query_params/omaha_query_params.h"
15 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/search/hotword_service.h" 15 #include "chrome/browser/search/hotword_service.h"
17 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
18 #include "chrome/browser/ui/app_list/app_list_service.h" 17 #include "chrome/browser/ui/app_list/app_list_service.h"
19 #include "chrome/browser/ui/app_list/recommended_apps.h" 18 #include "chrome/browser/ui/app_list/recommended_apps.h"
20 #include "chrome/browser/ui/app_list/start_page_service.h" 19 #include "chrome/browser/ui/app_list/start_page_service.h"
21 #include "chrome/browser/ui/host_desktop.h" 20 #include "chrome/browser/ui/host_desktop.h"
22 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" 21 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
23 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
24 #include "content/public/browser/notification_details.h"
25 #include "content/public/browser/notification_source.h"
26 #include "content/public/browser/web_ui.h" 23 #include "content/public/browser/web_ui.h"
24 #include "extensions/browser/extension_registry.h"
27 #include "extensions/browser/extension_system.h" 25 #include "extensions/browser/extension_system.h"
28 #include "extensions/common/extension.h" 26 #include "extensions/common/extension.h"
29 #include "extensions/common/extension_icon_set.h" 27 #include "extensions/common/extension_icon_set.h"
30 #include "ui/app_list/app_list_switches.h" 28 #include "ui/app_list/app_list_switches.h"
31 #include "ui/app_list/speech_ui_model_observer.h" 29 #include "ui/app_list/speech_ui_model_observer.h"
32 #include "ui/events/event_constants.h" 30 #include "ui/events/event_constants.h"
33 31
34 namespace app_list { 32 namespace app_list {
35 33
36 namespace { 34 namespace {
(...skipping 17 matching lines...) Expand all
54 ExtensionIconSet::MATCH_BIGGER, 52 ExtensionIconSet::MATCH_BIGGER,
55 grayscale, 53 grayscale,
56 &icon_exists); 54 &icon_exists);
57 dict->SetString("iconUrl", icon_url.spec()); 55 dict->SetString("iconUrl", icon_url.spec());
58 56
59 return dict.Pass(); 57 return dict.Pass();
60 } 58 }
61 59
62 } // namespace 60 } // namespace
63 61
64 StartPageHandler::StartPageHandler() : recommended_apps_(NULL) {} 62 StartPageHandler::StartPageHandler()
63 : recommended_apps_(NULL), extension_registry_observer_(this) {
64 }
65 65
66 StartPageHandler::~StartPageHandler() { 66 StartPageHandler::~StartPageHandler() {
67 if (recommended_apps_) 67 if (recommended_apps_)
68 recommended_apps_->RemoveObserver(this); 68 recommended_apps_->RemoveObserver(this);
69 } 69 }
70 70
71 void StartPageHandler::RegisterMessages() { 71 void StartPageHandler::RegisterMessages() {
72 web_ui()->RegisterMessageCallback( 72 web_ui()->RegisterMessageCallback(
73 "initialize", 73 "initialize",
74 base::Bind(&StartPageHandler::HandleInitialize, base::Unretained(this))); 74 base::Bind(&StartPageHandler::HandleInitialize, base::Unretained(this)));
75 web_ui()->RegisterMessageCallback( 75 web_ui()->RegisterMessageCallback(
76 "launchApp", 76 "launchApp",
77 base::Bind(&StartPageHandler::HandleLaunchApp, base::Unretained(this))); 77 base::Bind(&StartPageHandler::HandleLaunchApp, base::Unretained(this)));
78 web_ui()->RegisterMessageCallback( 78 web_ui()->RegisterMessageCallback(
79 "speechResult", 79 "speechResult",
80 base::Bind(&StartPageHandler::HandleSpeechResult, 80 base::Bind(&StartPageHandler::HandleSpeechResult,
81 base::Unretained(this))); 81 base::Unretained(this)));
82 web_ui()->RegisterMessageCallback( 82 web_ui()->RegisterMessageCallback(
83 "speechSoundLevel", 83 "speechSoundLevel",
84 base::Bind(&StartPageHandler::HandleSpeechSoundLevel, 84 base::Bind(&StartPageHandler::HandleSpeechSoundLevel,
85 base::Unretained(this))); 85 base::Unretained(this)));
86 web_ui()->RegisterMessageCallback( 86 web_ui()->RegisterMessageCallback(
87 "setSpeechRecognitionState", 87 "setSpeechRecognitionState",
88 base::Bind(&StartPageHandler::HandleSpeechRecognition, 88 base::Bind(&StartPageHandler::HandleSpeechRecognition,
89 base::Unretained(this))); 89 base::Unretained(this)));
90 } 90 }
91 91
92 void StartPageHandler::Observe(int type, 92 void StartPageHandler::OnExtensionLoaded(
93 const content::NotificationSource& source, 93 content::BrowserContext* browser_context,
94 const content::NotificationDetails& details) { 94 const extensions::Extension* extension) {
95 #if defined(OS_CHROMEOS) 95 #if defined(OS_CHROMEOS)
96 DCHECK_EQ(Profile::FromWebUI(web_ui()), 96 DCHECK_EQ(Profile::FromWebUI(web_ui()),
97 content::Source<Profile>(source).ptr()); 97 content::Source<Profile>(source).ptr());
Devlin 2014/05/16 17:34:04 This won't compile - the |source| variable is gone
98 switch (type) { 98 if (extension->id() == extension_misc::kHotwordExtensionId)
99 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { 99 OnHotwordEnabledChanged();
100 extensions::Extension* extension =
101 content::Details<extensions::Extension>(details).ptr();
102 if (extension->id() == extension_misc::kHotwordExtensionId)
103 OnHotwordEnabledChanged();
104 break;
105 }
106 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
107 extensions::UnloadedExtensionInfo* info =
108 content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
109 if (info->extension->id() == extension_misc::kHotwordExtensionId)
110 OnHotwordEnabledChanged();
111 break;
112 }
113 default:
114 NOTREACHED();
115 break;
116 }
117 #endif 100 #endif
118 } 101 }
119 102
103 void StartPageHandler::OnExtensionUnloaded(
104 content::BrowserContext* browser_context,
105 const extensions::Extension* extension,
106 extensions::UnloadedExtensionInfo::Reason reason) {
107 #if defined(OS_CHROMEOS)
108 DCHECK_EQ(Profile::FromWebUI(web_ui()),
Devlin 2014/05/16 17:34:04 same as above.
109 content::Source<Profile>(source).ptr());
110 if (extension->id() == extension_misc::kHotwordExtensionId)
111 OnHotwordEnabledChanged();
112 #endif
113 }
114
120 void StartPageHandler::OnRecommendedAppsChanged() { 115 void StartPageHandler::OnRecommendedAppsChanged() {
121 SendRecommendedApps(); 116 SendRecommendedApps();
122 } 117 }
123 118
124 void StartPageHandler::SendRecommendedApps() { 119 void StartPageHandler::SendRecommendedApps() {
125 const RecommendedApps::Apps& recommends = recommended_apps_->apps(); 120 const RecommendedApps::Apps& recommends = recommended_apps_->apps();
126 121
127 base::ListValue recommended_list; 122 base::ListValue recommended_list;
128 for (size_t i = 0; i < recommends.size(); ++i) { 123 for (size_t i = 0; i < recommends.size(); ++i) {
129 recommended_list.Append(CreateAppInfo(recommends[i].get()).release()); 124 recommended_list.Append(CreateAppInfo(recommends[i].get()).release());
130 } 125 }
131 126
132 web_ui()->CallJavascriptFunction("appList.startPage.setRecommendedApps", 127 web_ui()->CallJavascriptFunction("appList.startPage.setRecommendedApps",
133 recommended_list); 128 recommended_list);
134 } 129 }
135 130
136 #if defined(OS_CHROMEOS) 131 #if defined(OS_CHROMEOS)
137 void StartPageHandler::OnHotwordEnabledChanged() { 132 void StartPageHandler::OnHotwordEnabledChanged() {
138 // If the hotword extension is new enough, we should use the new 133 // If the hotword extension is new enough, we should use the new
139 // hotwordPrivate API to provide the feature. 134 // hotwordPrivate API to provide the feature.
140 // TODO(mukai): remove this after everything gets stable. 135 // TODO(mukai): remove this after everything gets stable.
141 Profile* profile = Profile::FromWebUI(web_ui()); 136 Profile* profile = Profile::FromWebUI(web_ui());
142 ExtensionService* extension_service = 137 ExtensionService* extension_service =
143 extensions::ExtensionSystem::Get(profile)->extension_service(); 138 extensions::ExtensionSystem::Get(profile)->extension_service();
144 if (!extension_service) 139 if (!extension_service)
145 return; 140 return;
146 141
147 const extensions::Extension* hotword_extension = 142 const extensions::Extension* hotword_extension =
148 extension_service->GetExtensionById( 143 extension_service->GetExtensionById(
Devlin 2014/05/16 17:34:04 Please change this to be ExtensionRegistry::GetExt
149 extension_misc::kHotwordExtensionId, false /* include_disabled */); 144 extension_misc::kHotwordExtensionId, false /* include_disabled */);
150 if (hotword_extension && hotword_extension->version()->CompareTo( 145 if (hotword_extension && hotword_extension->version()->CompareTo(
151 base::Version(kOldHotwordExtensionVersionString)) <= 0) { 146 base::Version(kOldHotwordExtensionVersionString)) <= 0) {
152 StartPageService* service = StartPageService::Get(profile); 147 StartPageService* service = StartPageService::Get(profile);
153 web_ui()->CallJavascriptFunction( 148 web_ui()->CallJavascriptFunction(
154 "appList.startPage.setHotwordEnabled", 149 "appList.startPage.setHotwordEnabled",
155 base::FundamentalValue(service->HotwordEnabled())); 150 base::FundamentalValue(service->HotwordEnabled()));
156 } 151 }
157 } 152 }
158 #endif 153 #endif
(...skipping 11 matching lines...) Expand all
170 165
171 #if defined(OS_CHROMEOS) 166 #if defined(OS_CHROMEOS)
172 if (app_list::switches::IsVoiceSearchEnabled() && 167 if (app_list::switches::IsVoiceSearchEnabled() &&
173 HotwordService::DoesHotwordSupportLanguage(profile)) { 168 HotwordService::DoesHotwordSupportLanguage(profile)) {
174 OnHotwordEnabledChanged(); 169 OnHotwordEnabledChanged();
175 pref_change_registrar_.Init(profile->GetPrefs()); 170 pref_change_registrar_.Init(profile->GetPrefs());
176 pref_change_registrar_.Add( 171 pref_change_registrar_.Add(
177 prefs::kHotwordSearchEnabled, 172 prefs::kHotwordSearchEnabled,
178 base::Bind(&StartPageHandler::OnHotwordEnabledChanged, 173 base::Bind(&StartPageHandler::OnHotwordEnabledChanged,
179 base::Unretained(this))); 174 base::Unretained(this)));
180 registrar_.Add(this, 175
181 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 176 extension_registry_observer_.Add(
182 content::Source<Profile>(profile)); 177 extensions::ExtensionRegistry::Get(profile));
183 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
184 content::Source<Profile>(profile));
185 } 178 }
186 #endif 179 #endif
187 180
188 web_ui()->CallJavascriptFunction( 181 web_ui()->CallJavascriptFunction(
189 "appList.startPage.setNaclArch", 182 "appList.startPage.setNaclArch",
190 base::StringValue(chrome::OmahaQueryParams::GetNaclArch())); 183 base::StringValue(chrome::OmahaQueryParams::GetNaclArch()));
191 184
192 if (!app_list::switches::IsExperimentalAppListEnabled()) { 185 if (!app_list::switches::IsExperimentalAppListEnabled()) {
193 web_ui()->CallJavascriptFunction( 186 web_ui()->CallJavascriptFunction(
194 "appList.startPage.onAppListShown", 187 "appList.startPage.onAppListShown",
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 else if (state_string == "STOPPING") 248 else if (state_string == "STOPPING")
256 new_state = SPEECH_RECOGNITION_STOPPING; 249 new_state = SPEECH_RECOGNITION_STOPPING;
257 250
258 StartPageService* service = 251 StartPageService* service =
259 StartPageService::Get(Profile::FromWebUI(web_ui())); 252 StartPageService::Get(Profile::FromWebUI(web_ui()));
260 if (service) 253 if (service)
261 service->OnSpeechRecognitionStateChanged(new_state); 254 service->OnSpeechRecognitionStateChanged(new_state);
262 } 255 }
263 256
264 } // namespace app_list 257 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698