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_app_api.h" | 5 #include "chrome/browser/extensions/extension_app_api.h" |
6 | 6 |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/chrome_notification_types.h" |
11 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
12 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
13 #include "content/common/notification_service.h" | 14 #include "content/common/notification_service.h" |
14 #include "content/common/notification_type.h" | |
15 | 15 |
16 | 16 |
17 const char kBodyTextKey[] = "bodyText"; | 17 const char kBodyTextKey[] = "bodyText"; |
18 const char kIconDataKey[] = "iconData"; | 18 const char kIconDataKey[] = "iconData"; |
19 const char kLinkTextKey[] = "linkText"; | 19 const char kLinkTextKey[] = "linkText"; |
20 const char kLinkUrlKey[] = "linkUrl"; | 20 const char kLinkUrlKey[] = "linkUrl"; |
21 const char kTitleKey[] = "title"; | 21 const char kTitleKey[] = "title"; |
22 | 22 |
23 const char kMissingLinkTextError[] = | 23 const char kMissingLinkTextError[] = |
24 "You must specify linkText if you use linkUrl"; | 24 "You must specify linkText if you use linkUrl"; |
25 | 25 |
26 AppNotification::AppNotification() {} | 26 AppNotification::AppNotification() {} |
27 | 27 |
28 AppNotification::~AppNotification() {} | 28 AppNotification::~AppNotification() {} |
29 | 29 |
30 AppNotificationManager::AppNotificationManager() { | 30 AppNotificationManager::AppNotificationManager() { |
31 registrar_.Add(this, | 31 registrar_.Add(this, |
32 NotificationType::EXTENSION_UNINSTALLED, | 32 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
33 NotificationService::AllSources()); | 33 NotificationService::AllSources()); |
34 } | 34 } |
35 | 35 |
36 AppNotificationManager::~AppNotificationManager() {} | 36 AppNotificationManager::~AppNotificationManager() {} |
37 | 37 |
38 void AppNotificationManager::Add(AppNotification* item) { | 38 void AppNotificationManager::Add(AppNotification* item) { |
39 CHECK(!item->extension_id.empty()); | 39 CHECK(!item->extension_id.empty()); |
40 NotificationMap::iterator found = notifications_.find(item->extension_id); | 40 NotificationMap::iterator found = notifications_.find(item->extension_id); |
41 if (found == notifications_.end()) { | 41 if (found == notifications_.end()) { |
42 notifications_[item->extension_id] = AppNotificationList(); | 42 notifications_[item->extension_id] = AppNotificationList(); |
(...skipping 19 matching lines...) Expand all Loading... |
62 const AppNotificationList& list = found->second; | 62 const AppNotificationList& list = found->second; |
63 return list.rbegin()->get(); | 63 return list.rbegin()->get(); |
64 } | 64 } |
65 | 65 |
66 void AppNotificationManager::ClearAll(const std::string& extension_id) { | 66 void AppNotificationManager::ClearAll(const std::string& extension_id) { |
67 NotificationMap::iterator found = notifications_.find(extension_id); | 67 NotificationMap::iterator found = notifications_.find(extension_id); |
68 if (found != notifications_.end()) | 68 if (found != notifications_.end()) |
69 notifications_.erase(found); | 69 notifications_.erase(found); |
70 } | 70 } |
71 | 71 |
72 void AppNotificationManager::Observe(NotificationType type, | 72 void AppNotificationManager::Observe(int type, |
73 const NotificationSource& source, | 73 const NotificationSource& source, |
74 const NotificationDetails& details) { | 74 const NotificationDetails& details) { |
75 CHECK(type == NotificationType::EXTENSION_UNINSTALLED); | 75 CHECK(type == chrome::NOTIFICATION_EXTENSION_UNINSTALLED); |
76 const std::string& id = | 76 const std::string& id = |
77 Details<UninstalledExtensionInfo>(details)->extension_id; | 77 Details<UninstalledExtensionInfo>(details)->extension_id; |
78 ClearAll(id); | 78 ClearAll(id); |
79 } | 79 } |
80 | 80 |
81 bool AppNotifyFunction::RunImpl() { | 81 bool AppNotifyFunction::RunImpl() { |
82 DictionaryValue* details; | 82 DictionaryValue* details; |
83 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); | 83 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); |
84 EXTENSION_FUNCTION_VALIDATE(details != NULL); | 84 EXTENSION_FUNCTION_VALIDATE(details != NULL); |
85 | 85 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 IPC::ReadParam(&bitmap_pickle, &iter, &bitmap)); | 118 IPC::ReadParam(&bitmap_pickle, &iter, &bitmap)); |
119 // TODO(asargent) - use the bitmap to set the NTP icon! | 119 // TODO(asargent) - use the bitmap to set the NTP icon! |
120 } | 120 } |
121 | 121 |
122 AppNotificationManager* manager = | 122 AppNotificationManager* manager = |
123 profile()->GetExtensionService()->app_notification_manager(); | 123 profile()->GetExtensionService()->app_notification_manager(); |
124 | 124 |
125 manager->Add(item.release()); | 125 manager->Add(item.release()); |
126 | 126 |
127 NotificationService::current()->Notify( | 127 NotificationService::current()->Notify( |
128 NotificationType::APP_NOTIFICATION_STATE_CHANGED, | 128 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, |
129 Source<Profile>(profile_), | 129 Source<Profile>(profile_), |
130 Details<const std::string>(&extension_id())); | 130 Details<const std::string>(&extension_id())); |
131 | 131 |
132 return true; | 132 return true; |
133 } | 133 } |
134 | 134 |
135 bool AppClearAllNotificationsFunction::RunImpl() { | 135 bool AppClearAllNotificationsFunction::RunImpl() { |
136 AppNotificationManager* manager = | 136 AppNotificationManager* manager = |
137 profile()->GetExtensionService()->app_notification_manager(); | 137 profile()->GetExtensionService()->app_notification_manager(); |
138 manager->ClearAll(extension_id()); | 138 manager->ClearAll(extension_id()); |
139 NotificationService::current()->Notify( | 139 NotificationService::current()->Notify( |
140 NotificationType::APP_NOTIFICATION_STATE_CHANGED, | 140 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, |
141 Source<Profile>(profile_), | 141 Source<Profile>(profile_), |
142 Details<const std::string>(&extension_id())); | 142 Details<const std::string>(&extension_id())); |
143 return true; | 143 return true; |
144 } | 144 } |
OLD | NEW |