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 "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/guid.h" | 8 #include "base/guid.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/notifications/notification.h" | 13 #include "chrome/browser/notifications/notification.h" |
14 #include "chrome/browser/notifications/notification_ui_manager.h" | 14 #include "chrome/browser/notifications/notification_ui_manager.h" |
15 #include "chrome/common/chrome_version_info.h" | 15 #include "chrome/common/chrome_version_info.h" |
16 #include "extensions/browser/event_router.h" | 16 #include "extensions/browser/event_router.h" |
17 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
18 #include "extensions/common/features/feature.h" | 18 #include "extensions/common/features/feature.h" |
19 #include "ui/base/layout.h" | 19 #include "ui/base/layout.h" |
| 20 #include "ui/message_center/message_center.h" |
| 21 #include "ui/message_center/notifier_settings.h" |
20 #include "url/gurl.h" | 22 #include "url/gurl.h" |
21 | 23 |
22 namespace extensions { | 24 namespace extensions { |
23 | 25 |
24 NotificationProviderEventRouter::NotificationProviderEventRouter( | 26 NotificationProviderEventRouter::NotificationProviderEventRouter( |
25 Profile* profile) | 27 Profile* profile) |
26 : profile_(profile) { | 28 : profile_(profile) { |
27 } | 29 } |
28 | 30 |
29 NotificationProviderEventRouter::~NotificationProviderEventRouter() { | 31 NotificationProviderEventRouter::~NotificationProviderEventRouter() { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 186 |
185 NotificationProviderNotifyOnPermissionLevelChangedFunction:: | 187 NotificationProviderNotifyOnPermissionLevelChangedFunction:: |
186 ~NotificationProviderNotifyOnPermissionLevelChangedFunction() { | 188 ~NotificationProviderNotifyOnPermissionLevelChangedFunction() { |
187 } | 189 } |
188 | 190 |
189 ExtensionFunction::ResponseAction | 191 ExtensionFunction::ResponseAction |
190 NotificationProviderNotifyOnPermissionLevelChangedFunction::Run() { | 192 NotificationProviderNotifyOnPermissionLevelChangedFunction::Run() { |
191 scoped_ptr<api::notification_provider::NotifyOnPermissionLevelChanged::Params> | 193 scoped_ptr<api::notification_provider::NotifyOnPermissionLevelChanged::Params> |
192 params = api::notification_provider::NotifyOnPermissionLevelChanged:: | 194 params = api::notification_provider::NotifyOnPermissionLevelChanged:: |
193 Params::Create(*args_); | 195 Params::Create(*args_); |
194 | |
195 EXTENSION_FUNCTION_VALIDATE(params.get()); | 196 EXTENSION_FUNCTION_VALIDATE(params.get()); |
196 | |
197 return RespondNow( | 197 return RespondNow( |
198 ArgumentList(api::notification_provider::NotifyOnPermissionLevelChanged:: | 198 ArgumentList(api::notification_provider::NotifyOnPermissionLevelChanged:: |
199 Results::Create(true))); | 199 Results::Create(true))); |
200 } | 200 } |
201 | 201 |
202 NotificationProviderNotifyOnShowSettingsFunction:: | 202 NotificationProviderNotifyOnShowSettingsFunction:: |
203 NotificationProviderNotifyOnShowSettingsFunction() { | 203 NotificationProviderNotifyOnShowSettingsFunction() { |
204 } | 204 } |
205 | 205 |
206 NotificationProviderNotifyOnShowSettingsFunction:: | 206 NotificationProviderNotifyOnShowSettingsFunction:: |
207 ~NotificationProviderNotifyOnShowSettingsFunction() { | 207 ~NotificationProviderNotifyOnShowSettingsFunction() { |
208 } | 208 } |
209 | 209 |
210 ExtensionFunction::ResponseAction | 210 ExtensionFunction::ResponseAction |
211 NotificationProviderNotifyOnShowSettingsFunction::Run() { | 211 NotificationProviderNotifyOnShowSettingsFunction::Run() { |
212 scoped_ptr<api::notification_provider::NotifyOnShowSettings::Params> params = | 212 scoped_ptr<api::notification_provider::NotifyOnShowSettings::Params> params = |
213 api::notification_provider::NotifyOnShowSettings::Params::Create(*args_); | 213 api::notification_provider::NotifyOnShowSettings::Params::Create(*args_); |
214 EXTENSION_FUNCTION_VALIDATE(params.get()); | 214 EXTENSION_FUNCTION_VALIDATE(params.get()); |
215 | 215 |
| 216 bool has_advanced_settings; |
| 217 // Only application type notifiers have advanced settings. |
| 218 if (params->notifier_type == |
| 219 api::notification_provider::NotifierType::NOTIFIER_TYPE_APPLICATION) { |
| 220 // TODO(dewittj): Refactor NotificationUIManage API to have a getter of |
| 221 // NotifierSettingsProvider, since it holds the settings provider. |
| 222 message_center::NotifierSettingsProvider* settings_provider = |
| 223 message_center::MessageCenter::Get()->GetNotifierSettingsProvider(); |
| 224 |
| 225 message_center::NotifierId notifier_id( |
| 226 message_center::NotifierId::NotifierType::APPLICATION, |
| 227 params->notifier_id); |
| 228 |
| 229 has_advanced_settings = |
| 230 settings_provider->NotifierHasAdvancedSettings(notifier_id); |
| 231 if (has_advanced_settings) |
| 232 settings_provider->OnNotifierAdvancedSettingsRequested(notifier_id, NULL); |
| 233 } else { |
| 234 has_advanced_settings = false; |
| 235 } |
| 236 |
216 return RespondNow(ArgumentList( | 237 return RespondNow(ArgumentList( |
217 api::notification_provider::NotifyOnShowSettings::Results::Create(true))); | 238 api::notification_provider::NotifyOnShowSettings::Results::Create( |
| 239 has_advanced_settings))); |
218 } | 240 } |
219 | 241 |
220 NotificationProviderGetNotifierFunction:: | 242 NotificationProviderGetNotifierFunction:: |
221 NotificationProviderGetNotifierFunction() { | 243 NotificationProviderGetNotifierFunction() { |
222 } | 244 } |
223 | 245 |
224 NotificationProviderGetNotifierFunction:: | 246 NotificationProviderGetNotifierFunction:: |
225 ~NotificationProviderGetNotifierFunction() { | 247 ~NotificationProviderGetNotifierFunction() { |
226 } | 248 } |
227 | 249 |
(...skipping 15 matching lines...) Expand all Loading... |
243 | 265 |
244 ExtensionFunction::ResponseAction | 266 ExtensionFunction::ResponseAction |
245 NotificationProviderGetAllNotifiersFunction::Run() { | 267 NotificationProviderGetAllNotifiersFunction::Run() { |
246 std::vector<linked_ptr<api::notification_provider::Notifier> > notifiers; | 268 std::vector<linked_ptr<api::notification_provider::Notifier> > notifiers; |
247 | 269 |
248 return RespondNow(ArgumentList( | 270 return RespondNow(ArgumentList( |
249 api::notification_provider::GetAllNotifiers::Results::Create(notifiers))); | 271 api::notification_provider::GetAllNotifiers::Results::Create(notifiers))); |
250 } | 272 } |
251 | 273 |
252 } // namespace extensions | 274 } // namespace extensions |
OLD | NEW |