OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/api/notification_provider/notification_provi
der_api.h" | 5 #include "chrome/browser/extensions/api/notification_provider/notification_provi
der_api.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 const std::string& sender_id, | 54 const std::string& sender_id, |
55 const std::string& notification_id) { | 55 const std::string& notification_id) { |
56 Clear(notification_provider_id, sender_id, notification_id); | 56 Clear(notification_provider_id, sender_id, notification_id); |
57 } | 57 } |
58 | 58 |
59 void NotificationProviderEventRouter::Create( | 59 void NotificationProviderEventRouter::Create( |
60 const std::string& notification_provider_id, | 60 const std::string& notification_provider_id, |
61 const std::string& sender_id, | 61 const std::string& sender_id, |
62 const std::string& notification_id, | 62 const std::string& notification_id, |
63 const api::notifications::NotificationOptions& options) { | 63 const api::notifications::NotificationOptions& options) { |
64 scoped_ptr<base::ListValue> args = | 64 std::unique_ptr<base::ListValue> args = |
65 api::notification_provider::OnCreated::Create( | 65 api::notification_provider::OnCreated::Create(sender_id, notification_id, |
66 sender_id, notification_id, options); | 66 options); |
67 | 67 |
68 scoped_ptr<Event> event(new Event( | 68 std::unique_ptr<Event> event(new Event( |
69 events::NOTIFICATION_PROVIDER_ON_CREATED, | 69 events::NOTIFICATION_PROVIDER_ON_CREATED, |
70 api::notification_provider::OnCreated::kEventName, std::move(args))); | 70 api::notification_provider::OnCreated::kEventName, std::move(args))); |
71 | 71 |
72 EventRouter::Get(profile_) | 72 EventRouter::Get(profile_) |
73 ->DispatchEventToExtension(notification_provider_id, std::move(event)); | 73 ->DispatchEventToExtension(notification_provider_id, std::move(event)); |
74 } | 74 } |
75 | 75 |
76 void NotificationProviderEventRouter::Update( | 76 void NotificationProviderEventRouter::Update( |
77 const std::string& notification_provider_id, | 77 const std::string& notification_provider_id, |
78 const std::string& sender_id, | 78 const std::string& sender_id, |
79 const std::string& notification_id, | 79 const std::string& notification_id, |
80 const api::notifications::NotificationOptions& options) { | 80 const api::notifications::NotificationOptions& options) { |
81 scoped_ptr<base::ListValue> args = | 81 std::unique_ptr<base::ListValue> args = |
82 api::notification_provider::OnUpdated::Create( | 82 api::notification_provider::OnUpdated::Create(sender_id, notification_id, |
83 sender_id, notification_id, options); | 83 options); |
84 | 84 |
85 scoped_ptr<Event> event(new Event( | 85 std::unique_ptr<Event> event(new Event( |
86 events::NOTIFICATION_PROVIDER_ON_UPDATED, | 86 events::NOTIFICATION_PROVIDER_ON_UPDATED, |
87 api::notification_provider::OnUpdated::kEventName, std::move(args))); | 87 api::notification_provider::OnUpdated::kEventName, std::move(args))); |
88 | 88 |
89 EventRouter::Get(profile_) | 89 EventRouter::Get(profile_) |
90 ->DispatchEventToExtension(notification_provider_id, std::move(event)); | 90 ->DispatchEventToExtension(notification_provider_id, std::move(event)); |
91 } | 91 } |
92 | 92 |
93 void NotificationProviderEventRouter::Clear( | 93 void NotificationProviderEventRouter::Clear( |
94 const std::string& notification_provider_id, | 94 const std::string& notification_provider_id, |
95 const std::string& sender_id, | 95 const std::string& sender_id, |
96 const std::string& notification_id) { | 96 const std::string& notification_id) { |
97 scoped_ptr<base::ListValue> args = | 97 std::unique_ptr<base::ListValue> args = |
98 api::notification_provider::OnCleared::Create(sender_id, notification_id); | 98 api::notification_provider::OnCleared::Create(sender_id, notification_id); |
99 | 99 |
100 scoped_ptr<Event> event(new Event( | 100 std::unique_ptr<Event> event(new Event( |
101 events::NOTIFICATION_PROVIDER_ON_CLEARED, | 101 events::NOTIFICATION_PROVIDER_ON_CLEARED, |
102 api::notification_provider::OnCleared::kEventName, std::move(args))); | 102 api::notification_provider::OnCleared::kEventName, std::move(args))); |
103 | 103 |
104 EventRouter::Get(profile_) | 104 EventRouter::Get(profile_) |
105 ->DispatchEventToExtension(notification_provider_id, std::move(event)); | 105 ->DispatchEventToExtension(notification_provider_id, std::move(event)); |
106 } | 106 } |
107 | 107 |
108 NotificationProviderNotifyOnClearedFunction:: | 108 NotificationProviderNotifyOnClearedFunction:: |
109 NotificationProviderNotifyOnClearedFunction() { | 109 NotificationProviderNotifyOnClearedFunction() { |
110 } | 110 } |
111 | 111 |
112 NotificationProviderNotifyOnClearedFunction:: | 112 NotificationProviderNotifyOnClearedFunction:: |
113 ~NotificationProviderNotifyOnClearedFunction() { | 113 ~NotificationProviderNotifyOnClearedFunction() { |
114 } | 114 } |
115 | 115 |
116 ExtensionFunction::ResponseAction | 116 ExtensionFunction::ResponseAction |
117 NotificationProviderNotifyOnClearedFunction::Run() { | 117 NotificationProviderNotifyOnClearedFunction::Run() { |
118 scoped_ptr<api::notification_provider::NotifyOnCleared::Params> params = | 118 std::unique_ptr<api::notification_provider::NotifyOnCleared::Params> params = |
119 api::notification_provider::NotifyOnCleared::Params::Create(*args_); | 119 api::notification_provider::NotifyOnCleared::Params::Create(*args_); |
120 EXTENSION_FUNCTION_VALIDATE(params.get()); | 120 EXTENSION_FUNCTION_VALIDATE(params.get()); |
121 | 121 |
122 const Notification* notification = | 122 const Notification* notification = |
123 g_browser_process->notification_ui_manager()->FindById( | 123 g_browser_process->notification_ui_manager()->FindById( |
124 params->notification_id, | 124 params->notification_id, |
125 NotificationUIManager::GetProfileID(GetProfile())); | 125 NotificationUIManager::GetProfileID(GetProfile())); |
126 | 126 |
127 bool found_notification = notification != NULL; | 127 bool found_notification = notification != NULL; |
128 if (found_notification) | 128 if (found_notification) |
129 notification->delegate()->Close(true); | 129 notification->delegate()->Close(true); |
130 | 130 |
131 return RespondNow( | 131 return RespondNow( |
132 ArgumentList(api::notification_provider::NotifyOnCleared::Results::Create( | 132 ArgumentList(api::notification_provider::NotifyOnCleared::Results::Create( |
133 found_notification))); | 133 found_notification))); |
134 } | 134 } |
135 | 135 |
136 NotificationProviderNotifyOnClickedFunction:: | 136 NotificationProviderNotifyOnClickedFunction:: |
137 NotificationProviderNotifyOnClickedFunction() { | 137 NotificationProviderNotifyOnClickedFunction() { |
138 } | 138 } |
139 | 139 |
140 NotificationProviderNotifyOnClickedFunction:: | 140 NotificationProviderNotifyOnClickedFunction:: |
141 ~NotificationProviderNotifyOnClickedFunction() { | 141 ~NotificationProviderNotifyOnClickedFunction() { |
142 } | 142 } |
143 | 143 |
144 ExtensionFunction::ResponseAction | 144 ExtensionFunction::ResponseAction |
145 NotificationProviderNotifyOnClickedFunction::Run() { | 145 NotificationProviderNotifyOnClickedFunction::Run() { |
146 scoped_ptr<api::notification_provider::NotifyOnClicked::Params> params = | 146 std::unique_ptr<api::notification_provider::NotifyOnClicked::Params> params = |
147 api::notification_provider::NotifyOnClicked::Params::Create(*args_); | 147 api::notification_provider::NotifyOnClicked::Params::Create(*args_); |
148 EXTENSION_FUNCTION_VALIDATE(params.get()); | 148 EXTENSION_FUNCTION_VALIDATE(params.get()); |
149 | 149 |
150 const Notification* notification = | 150 const Notification* notification = |
151 g_browser_process->notification_ui_manager()->FindById( | 151 g_browser_process->notification_ui_manager()->FindById( |
152 params->notification_id, | 152 params->notification_id, |
153 NotificationUIManager::GetProfileID(GetProfile())); | 153 NotificationUIManager::GetProfileID(GetProfile())); |
154 | 154 |
155 bool found_notification = notification != NULL; | 155 bool found_notification = notification != NULL; |
156 if (found_notification) | 156 if (found_notification) |
157 notification->delegate()->Click(); | 157 notification->delegate()->Click(); |
158 | 158 |
159 return RespondNow( | 159 return RespondNow( |
160 ArgumentList(api::notification_provider::NotifyOnClicked::Results::Create( | 160 ArgumentList(api::notification_provider::NotifyOnClicked::Results::Create( |
161 found_notification))); | 161 found_notification))); |
162 } | 162 } |
163 | 163 |
164 NotificationProviderNotifyOnButtonClickedFunction:: | 164 NotificationProviderNotifyOnButtonClickedFunction:: |
165 NotificationProviderNotifyOnButtonClickedFunction() { | 165 NotificationProviderNotifyOnButtonClickedFunction() { |
166 } | 166 } |
167 | 167 |
168 NotificationProviderNotifyOnButtonClickedFunction:: | 168 NotificationProviderNotifyOnButtonClickedFunction:: |
169 ~NotificationProviderNotifyOnButtonClickedFunction() { | 169 ~NotificationProviderNotifyOnButtonClickedFunction() { |
170 } | 170 } |
171 | 171 |
172 ExtensionFunction::ResponseAction | 172 ExtensionFunction::ResponseAction |
173 NotificationProviderNotifyOnButtonClickedFunction::Run() { | 173 NotificationProviderNotifyOnButtonClickedFunction::Run() { |
174 scoped_ptr<api::notification_provider::NotifyOnButtonClicked::Params> params = | 174 std::unique_ptr<api::notification_provider::NotifyOnButtonClicked::Params> |
175 api::notification_provider::NotifyOnButtonClicked::Params::Create(*args_); | 175 params = |
| 176 api::notification_provider::NotifyOnButtonClicked::Params::Create( |
| 177 *args_); |
176 EXTENSION_FUNCTION_VALIDATE(params.get()); | 178 EXTENSION_FUNCTION_VALIDATE(params.get()); |
177 | 179 |
178 const Notification* notification = | 180 const Notification* notification = |
179 g_browser_process->notification_ui_manager()->FindById( | 181 g_browser_process->notification_ui_manager()->FindById( |
180 params->notification_id, | 182 params->notification_id, |
181 NotificationUIManager::GetProfileID(GetProfile())); | 183 NotificationUIManager::GetProfileID(GetProfile())); |
182 | 184 |
183 bool found_notification = notification != NULL; | 185 bool found_notification = notification != NULL; |
184 if (found_notification) | 186 if (found_notification) |
185 notification->delegate()->ButtonClick(params->button_index); | 187 notification->delegate()->ButtonClick(params->button_index); |
186 | 188 |
187 return RespondNow(ArgumentList( | 189 return RespondNow(ArgumentList( |
188 api::notification_provider::NotifyOnButtonClicked::Results::Create( | 190 api::notification_provider::NotifyOnButtonClicked::Results::Create( |
189 found_notification))); | 191 found_notification))); |
190 } | 192 } |
191 | 193 |
192 NotificationProviderNotifyOnPermissionLevelChangedFunction:: | 194 NotificationProviderNotifyOnPermissionLevelChangedFunction:: |
193 NotificationProviderNotifyOnPermissionLevelChangedFunction() { | 195 NotificationProviderNotifyOnPermissionLevelChangedFunction() { |
194 } | 196 } |
195 | 197 |
196 NotificationProviderNotifyOnPermissionLevelChangedFunction:: | 198 NotificationProviderNotifyOnPermissionLevelChangedFunction:: |
197 ~NotificationProviderNotifyOnPermissionLevelChangedFunction() { | 199 ~NotificationProviderNotifyOnPermissionLevelChangedFunction() { |
198 } | 200 } |
199 | 201 |
200 ExtensionFunction::ResponseAction | 202 ExtensionFunction::ResponseAction |
201 NotificationProviderNotifyOnPermissionLevelChangedFunction::Run() { | 203 NotificationProviderNotifyOnPermissionLevelChangedFunction::Run() { |
202 scoped_ptr<api::notification_provider::NotifyOnPermissionLevelChanged::Params> | 204 std::unique_ptr< |
| 205 api::notification_provider::NotifyOnPermissionLevelChanged::Params> |
203 params = api::notification_provider::NotifyOnPermissionLevelChanged:: | 206 params = api::notification_provider::NotifyOnPermissionLevelChanged:: |
204 Params::Create(*args_); | 207 Params::Create(*args_); |
205 EXTENSION_FUNCTION_VALIDATE(params.get()); | 208 EXTENSION_FUNCTION_VALIDATE(params.get()); |
206 | 209 |
207 // Third party apps/extensions with notification provider API will not be able | 210 // Third party apps/extensions with notification provider API will not be able |
208 // to change permission levels of web notifiers, because the list of allowed | 211 // to change permission levels of web notifiers, because the list of allowed |
209 // websites should only be set in Chrome Settings manually by users. But they | 212 // websites should only be set in Chrome Settings manually by users. But they |
210 // are able to change permission levels of application type notifiers. | 213 // are able to change permission levels of application type notifiers. |
211 bool is_application_type = | 214 bool is_application_type = |
212 (params->notifier_type == | 215 (params->notifier_type == |
(...skipping 21 matching lines...) Expand all Loading... |
234 NotificationProviderNotifyOnShowSettingsFunction:: | 237 NotificationProviderNotifyOnShowSettingsFunction:: |
235 NotificationProviderNotifyOnShowSettingsFunction() { | 238 NotificationProviderNotifyOnShowSettingsFunction() { |
236 } | 239 } |
237 | 240 |
238 NotificationProviderNotifyOnShowSettingsFunction:: | 241 NotificationProviderNotifyOnShowSettingsFunction:: |
239 ~NotificationProviderNotifyOnShowSettingsFunction() { | 242 ~NotificationProviderNotifyOnShowSettingsFunction() { |
240 } | 243 } |
241 | 244 |
242 ExtensionFunction::ResponseAction | 245 ExtensionFunction::ResponseAction |
243 NotificationProviderNotifyOnShowSettingsFunction::Run() { | 246 NotificationProviderNotifyOnShowSettingsFunction::Run() { |
244 scoped_ptr<api::notification_provider::NotifyOnShowSettings::Params> params = | 247 std::unique_ptr<api::notification_provider::NotifyOnShowSettings::Params> |
245 api::notification_provider::NotifyOnShowSettings::Params::Create(*args_); | 248 params = api::notification_provider::NotifyOnShowSettings::Params::Create( |
| 249 *args_); |
246 EXTENSION_FUNCTION_VALIDATE(params.get()); | 250 EXTENSION_FUNCTION_VALIDATE(params.get()); |
247 | 251 |
248 bool has_advanced_settings; | 252 bool has_advanced_settings; |
249 // Only application type notifiers have advanced settings. | 253 // Only application type notifiers have advanced settings. |
250 if (params->notifier_type == | 254 if (params->notifier_type == |
251 api::notification_provider::NotifierType::NOTIFIER_TYPE_APPLICATION) { | 255 api::notification_provider::NotifierType::NOTIFIER_TYPE_APPLICATION) { |
252 // TODO(dewittj): Refactor NotificationUIManage API to have a getter of | 256 // TODO(dewittj): Refactor NotificationUIManage API to have a getter of |
253 // NotifierSettingsProvider, since it holds the settings provider. | 257 // NotifierSettingsProvider, since it holds the settings provider. |
254 message_center::NotifierSettingsProvider* settings_provider = | 258 message_center::NotifierSettingsProvider* settings_provider = |
255 message_center::MessageCenter::Get()->GetNotifierSettingsProvider(); | 259 message_center::MessageCenter::Get()->GetNotifierSettingsProvider(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 301 |
298 ExtensionFunction::ResponseAction | 302 ExtensionFunction::ResponseAction |
299 NotificationProviderGetAllNotifiersFunction::Run() { | 303 NotificationProviderGetAllNotifiersFunction::Run() { |
300 std::vector<api::notification_provider::Notifier> notifiers; | 304 std::vector<api::notification_provider::Notifier> notifiers; |
301 | 305 |
302 return RespondNow(ArgumentList( | 306 return RespondNow(ArgumentList( |
303 api::notification_provider::GetAllNotifiers::Results::Create(notifiers))); | 307 api::notification_provider::GetAllNotifiers::Results::Create(notifiers))); |
304 } | 308 } |
305 | 309 |
306 } // namespace extensions | 310 } // namespace extensions |
OLD | NEW |