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/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/app_notification_manager.h" | 8 #include "chrome/browser/extensions/app_notification_manager.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/chrome_notification_types.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 #include "content/public/browser/notification_service.h" |
13 | 14 |
14 const char kBodyTextKey[] = "bodyText"; | 15 const char kBodyTextKey[] = "bodyText"; |
15 const char kExtensionIdKey[] = "extensionId"; | 16 const char kExtensionIdKey[] = "extensionId"; |
16 const char kLinkTextKey[] = "linkText"; | 17 const char kLinkTextKey[] = "linkText"; |
17 const char kLinkUrlKey[] = "linkUrl"; | 18 const char kLinkUrlKey[] = "linkUrl"; |
18 const char kTitleKey[] = "title"; | 19 const char kTitleKey[] = "title"; |
19 | 20 |
20 const char kInvalidExtensionIdError[] = | 21 const char kInvalidExtensionIdError[] = |
21 "Invalid extension id"; | 22 "Invalid extension id"; |
22 const char kMissingLinkTextError[] = | 23 const char kMissingLinkTextError[] = |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkTextKey, | 64 EXTENSION_FUNCTION_VALIDATE(details->GetString(kLinkTextKey, |
64 &link_text)); | 65 &link_text)); |
65 item->set_link_text(link_text); | 66 item->set_link_text(link_text); |
66 } | 67 } |
67 | 68 |
68 AppNotificationManager* manager = | 69 AppNotificationManager* manager = |
69 profile()->GetExtensionService()->app_notification_manager(); | 70 profile()->GetExtensionService()->app_notification_manager(); |
70 | 71 |
71 manager->Add(id, item.release()); | 72 manager->Add(id, item.release()); |
72 | 73 |
73 NotificationService::current()->Notify( | 74 content::NotificationService::current()->Notify( |
74 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, | 75 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, |
75 content::Source<Profile>(profile_), | 76 content::Source<Profile>(profile_), |
76 content::Details<const std::string>(&id)); | 77 content::Details<const std::string>(&id)); |
77 | 78 |
78 return true; | 79 return true; |
79 } | 80 } |
80 | 81 |
81 bool AppClearAllNotificationsFunction::RunImpl() { | 82 bool AppClearAllNotificationsFunction::RunImpl() { |
82 std::string id = extension_id(); | 83 std::string id = extension_id(); |
83 DictionaryValue* details = NULL; | 84 DictionaryValue* details = NULL; |
84 if (args_->GetDictionary(0, &details) && details->HasKey(kExtensionIdKey)) { | 85 if (args_->GetDictionary(0, &details) && details->HasKey(kExtensionIdKey)) { |
85 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); | 86 EXTENSION_FUNCTION_VALIDATE(details->GetString(kExtensionIdKey, &id)); |
86 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { | 87 if (!profile()->GetExtensionService()->GetExtensionById(id, true)) { |
87 error_ = kInvalidExtensionIdError; | 88 error_ = kInvalidExtensionIdError; |
88 return false; | 89 return false; |
89 } | 90 } |
90 } | 91 } |
91 | 92 |
92 AppNotificationManager* manager = | 93 AppNotificationManager* manager = |
93 profile()->GetExtensionService()->app_notification_manager(); | 94 profile()->GetExtensionService()->app_notification_manager(); |
94 manager->ClearAll(id); | 95 manager->ClearAll(id); |
95 NotificationService::current()->Notify( | 96 content::NotificationService::current()->Notify( |
96 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, | 97 chrome::NOTIFICATION_APP_NOTIFICATION_STATE_CHANGED, |
97 content::Source<Profile>(profile_), | 98 content::Source<Profile>(profile_), |
98 content::Details<const std::string>(&id)); | 99 content::Details<const std::string>(&id)); |
99 return true; | 100 return true; |
100 } | 101 } |
OLD | NEW |