OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/extensions/api/notification_provider/notification_provi der_api.h" | |
6 | |
7 #include "base/callback.h" | |
8 #include "base/guid.h" | |
9 #include "base/rand_util.h" | |
10 #include "base/strings/string_number_conversions.h" | |
11 #include "base/strings/utf_string_conversions.h" | |
12 #include "chrome/browser/browser_process.h" | |
13 #include "chrome/common/chrome_version_info.h" | |
14 #include "extensions/browser/event_router.h" | |
15 #include "extensions/common/extension.h" | |
16 #include "extensions/common/features/feature.h" | |
17 #include "ui/base/layout.h" | |
18 #include "url/gurl.h" | |
19 | |
20 namespace extensions { | |
21 | |
22 NotificationProviderEventRouter::NotificationProviderEventRouter( | |
23 Profile* profile) | |
24 : profile_(profile) { | |
25 } | |
26 | |
27 NotificationProviderEventRouter::~NotificationProviderEventRouter() { | |
28 } | |
29 | |
30 void NotificationProviderEventRouter::CreateNotification( | |
31 const std::string& notification_provider_id, | |
32 const std::string& sender_id, | |
33 const std::string& notification_id, | |
34 const api::notifications::NotificationOptions& options) { | |
35 Create(notification_provider_id, sender_id, notification_id, options); | |
36 } | |
37 | |
38 void NotificationProviderEventRouter::UpdateNotification( | |
39 const std::string& notification_provider_id, | |
40 const std::string& sender_id, | |
41 const std::string& notification_id, | |
42 const api::notifications::NotificationOptions& options) { | |
43 Update(notification_provider_id, sender_id, notification_id, options); | |
44 } | |
45 void NotificationProviderEventRouter::ClearNotification( | |
46 const std::string& notification_provider_id, | |
47 const std::string& sender_id, | |
48 const std::string& notification_id) { | |
49 Clear(notification_provider_id, sender_id, notification_id); | |
50 } | |
51 | |
52 void NotificationProviderEventRouter::Create( | |
53 const std::string& notification_provider_id, | |
54 const std::string& sender_id, | |
55 const std::string& notification_id, | |
56 const api::notifications::NotificationOptions& options) { | |
57 scoped_ptr<base::ListValue> args = | |
58 api::notification_provider::OnCreated::Create( | |
59 sender_id, notification_id, options); | |
60 | |
61 scoped_ptr<Event> event(new Event( | |
62 api::notification_provider::OnCreated::kEventName, args.Pass())); | |
63 | |
64 EventRouter::Get(profile_) | |
65 ->DispatchEventToExtension(notification_provider_id, event.Pass()); | |
66 } | |
67 | |
68 void NotificationProviderEventRouter::Update( | |
69 const std::string& notification_provider_id, | |
70 const std::string& sender_id, | |
71 const std::string& notification_id, | |
72 const extensions::api::notifications::NotificationOptions& options) { | |
not at google - send to devlin
2014/07/30 19:24:37
extensions:: also unnecessary in this file
liyanhou
2014/07/30 22:21:51
Done.
| |
73 scoped_ptr<base::ListValue> args = | |
74 api::notification_provider::OnUpdated::Create( | |
75 sender_id, notification_id, options); | |
76 | |
77 scoped_ptr<Event> event(new Event( | |
78 api::notification_provider::OnUpdated::kEventName, args.Pass())); | |
79 | |
80 EventRouter::Get(profile_) | |
81 ->DispatchEventToExtension(notification_provider_id, event.Pass()); | |
82 } | |
83 | |
84 void NotificationProviderEventRouter::Clear( | |
85 const std::string& notification_provider_id, | |
86 const std::string& sender_id, | |
87 const std::string& notification_id) { | |
88 scoped_ptr<base::ListValue> args = | |
89 api::notification_provider::OnCleared::Create(sender_id, notification_id); | |
90 | |
91 scoped_ptr<Event> event(new Event( | |
92 api::notification_provider::OnCleared::kEventName, args.Pass())); | |
93 | |
94 EventRouter::Get(profile_) | |
95 ->DispatchEventToExtension(notification_provider_id, event.Pass()); | |
96 } | |
97 | |
98 NotificationProviderNotifyOnClearedFunction:: | |
99 NotificationProviderNotifyOnClearedFunction() { | |
100 } | |
101 | |
102 NotificationProviderNotifyOnClearedFunction:: | |
103 ~NotificationProviderNotifyOnClearedFunction() { | |
104 } | |
105 | |
106 ExtensionFunction::ResponseAction | |
107 NotificationProviderNotifyOnClearedFunction::Run() { | |
108 scoped_ptr<api::notification_provider::NotifyOnCleared::Params> params = | |
109 api::notification_provider::NotifyOnCleared::Params::Create(*args_); | |
110 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
111 | |
112 return RespondNow(ArgumentList( | |
113 api::notification_provider::NotifyOnCleared::Results::Create(true))); | |
114 } | |
115 | |
116 NotificationProviderNotifyOnClickedFunction:: | |
117 NotificationProviderNotifyOnClickedFunction() { | |
118 } | |
119 | |
120 NotificationProviderNotifyOnClickedFunction:: | |
121 ~NotificationProviderNotifyOnClickedFunction() { | |
122 } | |
123 | |
124 ExtensionFunction::ResponseAction | |
125 NotificationProviderNotifyOnClickedFunction::Run() { | |
126 scoped_ptr<api::notification_provider::NotifyOnClicked::Params> params = | |
127 api::notification_provider::NotifyOnClicked::Params::Create(*args_); | |
128 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
129 | |
130 return RespondNow(ArgumentList( | |
131 api::notification_provider::NotifyOnClicked::Results::Create(true))); | |
132 } | |
133 | |
134 NotificationProviderNotifyOnButtonClickedFunction:: | |
135 NotificationProviderNotifyOnButtonClickedFunction() { | |
136 } | |
137 | |
138 NotificationProviderNotifyOnButtonClickedFunction:: | |
139 ~NotificationProviderNotifyOnButtonClickedFunction() { | |
140 } | |
141 | |
142 ExtensionFunction::ResponseAction | |
143 NotificationProviderNotifyOnButtonClickedFunction::Run() { | |
144 scoped_ptr<api::notification_provider::NotifyOnButtonClicked::Params> params = | |
145 api::notification_provider::NotifyOnButtonClicked::Params::Create(*args_); | |
146 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
147 | |
148 return RespondNow(ArgumentList( | |
149 api::notification_provider::NotifyOnButtonClicked::Results::Create( | |
150 true))); | |
151 } | |
152 | |
153 NotificationProviderNotifyOnPermissionLevelChangedFunction:: | |
154 NotificationProviderNotifyOnPermissionLevelChangedFunction() { | |
155 } | |
156 | |
157 NotificationProviderNotifyOnPermissionLevelChangedFunction:: | |
158 ~NotificationProviderNotifyOnPermissionLevelChangedFunction() { | |
159 } | |
160 | |
161 ExtensionFunction::ResponseAction | |
162 NotificationProviderNotifyOnPermissionLevelChangedFunction::Run() { | |
163 scoped_ptr<api::notification_provider::NotifyOnPermissionLevelChanged::Params> | |
164 params = api::notification_provider::NotifyOnPermissionLevelChanged:: | |
165 Params::Create(*args_); | |
166 | |
167 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
168 | |
169 return RespondNow( | |
170 ArgumentList(api::notification_provider::NotifyOnPermissionLevelChanged:: | |
171 Results::Create(true))); | |
172 } | |
173 | |
174 NotificationProviderNotifyOnShowSettingsFunction:: | |
175 NotificationProviderNotifyOnShowSettingsFunction() { | |
176 } | |
177 | |
178 NotificationProviderNotifyOnShowSettingsFunction:: | |
179 ~NotificationProviderNotifyOnShowSettingsFunction() { | |
180 } | |
181 | |
182 ExtensionFunction::ResponseAction | |
183 NotificationProviderNotifyOnShowSettingsFunction::Run() { | |
184 scoped_ptr<api::notification_provider::NotifyOnShowSettings::Params> params = | |
185 api::notification_provider::NotifyOnShowSettings::Params::Create(*args_); | |
186 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
187 | |
188 return RespondNow(ArgumentList( | |
189 api::notification_provider::NotifyOnShowSettings::Results::Create(true))); | |
190 } | |
191 | |
192 NotificationProviderGetNotifierFunction:: | |
193 NotificationProviderGetNotifierFunction() { | |
194 } | |
195 | |
196 NotificationProviderGetNotifierFunction:: | |
197 ~NotificationProviderGetNotifierFunction() { | |
198 } | |
199 | |
200 ExtensionFunction::ResponseAction | |
201 NotificationProviderGetNotifierFunction::Run() { | |
202 extensions::api::notification_provider::Notifier notifier; | |
203 | |
204 return RespondNow(ArgumentList( | |
205 api::notification_provider::GetNotifier::Results::Create(notifier))); | |
206 } | |
207 | |
208 NotificationProviderGetAllNotifiersFunction:: | |
209 NotificationProviderGetAllNotifiersFunction() { | |
210 } | |
211 | |
212 NotificationProviderGetAllNotifiersFunction:: | |
213 ~NotificationProviderGetAllNotifiersFunction() { | |
214 } | |
215 | |
216 ExtensionFunction::ResponseAction | |
217 NotificationProviderGetAllNotifiersFunction::Run() { | |
218 std::vector<linked_ptr<extensions::api::notification_provider::Notifier> > | |
219 notifiers; | |
220 | |
221 return RespondNow(ArgumentList( | |
222 api::notification_provider::GetAllNotifiers::Results::Create(notifiers))); | |
223 } | |
224 | |
225 } // namespace extensions | |
OLD | NEW |