OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_management_api.h" | 5 #include "chrome/browser/extensions/extension_management_api.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "chrome/browser/extensions/extension_event_names.h" | 15 #include "chrome/browser/extensions/extension_event_names.h" |
16 #include "chrome/browser/extensions/extension_event_router.h" | 16 #include "chrome/browser/extensions/extension_event_router.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/extensions/extension_updater.h" | 18 #include "chrome/browser/extensions/extension_updater.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/webui/extension_icon_source.h" | 21 #include "chrome/browser/ui/webui/extension_icon_source.h" |
| 22 #include "chrome/common/chrome_notification_types.h" |
22 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
24 #include "chrome/common/extensions/extension_error_utils.h" | 25 #include "chrome/common/extensions/extension_error_utils.h" |
25 #include "chrome/common/extensions/extension_icon_set.h" | 26 #include "chrome/common/extensions/extension_icon_set.h" |
26 #include "chrome/common/extensions/url_pattern.h" | 27 #include "chrome/common/extensions/url_pattern.h" |
27 #include "content/common/notification_service.h" | 28 #include "content/common/notification_service.h" |
28 #include "content/common/notification_type.h" | |
29 | 29 |
30 using base::IntToString; | 30 using base::IntToString; |
31 namespace events = extension_event_names; | 31 namespace events = extension_event_names; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 const char kAppLaunchUrlKey[] = "appLaunchUrl"; | 35 const char kAppLaunchUrlKey[] = "appLaunchUrl"; |
36 const char kDescriptionKey[] = "description"; | 36 const char kDescriptionKey[] = "description"; |
37 const char kEnabledKey[] = "enabled"; | 37 const char kEnabledKey[] = "enabled"; |
38 const char kHomepageURLKey[] = "homepageUrl"; | 38 const char kHomepageURLKey[] = "homepageUrl"; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 NULL); | 249 NULL); |
250 return true; | 250 return true; |
251 } | 251 } |
252 | 252 |
253 ExtensionManagementEventRouter::ExtensionManagementEventRouter(Profile* profile) | 253 ExtensionManagementEventRouter::ExtensionManagementEventRouter(Profile* profile) |
254 : profile_(profile) {} | 254 : profile_(profile) {} |
255 | 255 |
256 ExtensionManagementEventRouter::~ExtensionManagementEventRouter() {} | 256 ExtensionManagementEventRouter::~ExtensionManagementEventRouter() {} |
257 | 257 |
258 void ExtensionManagementEventRouter::Init() { | 258 void ExtensionManagementEventRouter::Init() { |
259 NotificationType::Type types[] = { | 259 int types[] = { |
260 NotificationType::EXTENSION_INSTALLED, | 260 chrome::NOTIFICATION_EXTENSION_INSTALLED, |
261 NotificationType::EXTENSION_UNINSTALLED, | 261 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
262 NotificationType::EXTENSION_LOADED, | 262 chrome::NOTIFICATION_EXTENSION_LOADED, |
263 NotificationType::EXTENSION_UNLOADED | 263 chrome::NOTIFICATION_EXTENSION_UNLOADED |
264 }; | 264 }; |
265 | 265 |
266 CHECK(registrar_.IsEmpty()); | 266 CHECK(registrar_.IsEmpty()); |
267 for (size_t i = 0; i < arraysize(types); i++) { | 267 for (size_t i = 0; i < arraysize(types); i++) { |
268 registrar_.Add(this, | 268 registrar_.Add(this, |
269 types[i], | 269 types[i], |
270 NotificationService::AllSources()); | 270 NotificationService::AllSources()); |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 void ExtensionManagementEventRouter::Observe( | 274 void ExtensionManagementEventRouter::Observe( |
275 NotificationType type, | 275 int type, |
276 const NotificationSource& source, | 276 const NotificationSource& source, |
277 const NotificationDetails& details) { | 277 const NotificationDetails& details) { |
278 const char* event_name = NULL; | 278 const char* event_name = NULL; |
279 Profile* profile = Source<Profile>(source).ptr(); | 279 Profile* profile = Source<Profile>(source).ptr(); |
280 CHECK(profile); | 280 CHECK(profile); |
281 if (!profile_->IsSameProfile(profile)) { | 281 if (!profile_->IsSameProfile(profile)) { |
282 return; | 282 return; |
283 } | 283 } |
284 | 284 |
285 switch (type.value) { | 285 switch (type) { |
286 case NotificationType::EXTENSION_INSTALLED: | 286 case chrome::NOTIFICATION_EXTENSION_INSTALLED: |
287 event_name = events::kOnExtensionInstalled; | 287 event_name = events::kOnExtensionInstalled; |
288 break; | 288 break; |
289 case NotificationType::EXTENSION_UNINSTALLED: | 289 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: |
290 event_name = events::kOnExtensionUninstalled; | 290 event_name = events::kOnExtensionUninstalled; |
291 break; | 291 break; |
292 case NotificationType::EXTENSION_LOADED: | 292 case chrome::NOTIFICATION_EXTENSION_LOADED: |
293 event_name = events::kOnExtensionEnabled; | 293 event_name = events::kOnExtensionEnabled; |
294 break; | 294 break; |
295 case NotificationType::EXTENSION_UNLOADED: | 295 case chrome::NOTIFICATION_EXTENSION_UNLOADED: |
296 event_name = events::kOnExtensionDisabled; | 296 event_name = events::kOnExtensionDisabled; |
297 break; | 297 break; |
298 default: | 298 default: |
299 NOTREACHED(); | 299 NOTREACHED(); |
300 return; | 300 return; |
301 } | 301 } |
302 | 302 |
303 ListValue args; | 303 ListValue args; |
304 if (event_name == events::kOnExtensionUninstalled) { | 304 if (event_name == events::kOnExtensionUninstalled) { |
305 const std::string& extension_id = | 305 const std::string& extension_id = |
(...skipping 11 matching lines...) Expand all Loading... |
317 bool enabled = service->GetExtensionById(extension->id(), false) != NULL; | 317 bool enabled = service->GetExtensionById(extension->id(), false) != NULL; |
318 args.Append(CreateExtensionInfo(*extension, enabled)); | 318 args.Append(CreateExtensionInfo(*extension, enabled)); |
319 } | 319 } |
320 | 320 |
321 std::string args_json; | 321 std::string args_json; |
322 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 322 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); |
323 | 323 |
324 profile->GetExtensionEventRouter()->DispatchEventToRenderers( | 324 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
325 event_name, args_json, NULL, GURL()); | 325 event_name, args_json, NULL, GURL()); |
326 } | 326 } |
OLD | NEW |