Chromium Code Reviews| 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/desktop_notification_service.h" | |
| 14 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | |
| 13 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" | 
| 14 #include "chrome/browser/notifications/notification_ui_manager.h" | 16 #include "chrome/browser/notifications/notification_ui_manager.h" | 
| 15 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" | 
| 16 #include "extensions/browser/event_router.h" | 18 #include "extensions/browser/event_router.h" | 
| 17 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" | 
| 18 #include "extensions/common/features/feature.h" | 20 #include "extensions/common/features/feature.h" | 
| 19 #include "ui/base/layout.h" | 21 #include "ui/base/layout.h" | 
| 22 #include "ui/message_center/notifier_settings.h" | |
| 20 #include "url/gurl.h" | 23 #include "url/gurl.h" | 
| 21 | 24 | 
| 22 namespace extensions { | 25 namespace extensions { | 
| 23 | 26 | 
| 24 NotificationProviderEventRouter::NotificationProviderEventRouter( | 27 NotificationProviderEventRouter::NotificationProviderEventRouter( | 
| 25 Profile* profile) | 28 Profile* profile) | 
| 26 : profile_(profile) { | 29 : profile_(profile) { | 
| 27 } | 30 } | 
| 28 | 31 | 
| 29 NotificationProviderEventRouter::~NotificationProviderEventRouter() { | 32 NotificationProviderEventRouter::~NotificationProviderEventRouter() { | 
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 | 187 | 
| 185 NotificationProviderNotifyOnPermissionLevelChangedFunction:: | 188 NotificationProviderNotifyOnPermissionLevelChangedFunction:: | 
| 186 ~NotificationProviderNotifyOnPermissionLevelChangedFunction() { | 189 ~NotificationProviderNotifyOnPermissionLevelChangedFunction() { | 
| 187 } | 190 } | 
| 188 | 191 | 
| 189 ExtensionFunction::ResponseAction | 192 ExtensionFunction::ResponseAction | 
| 190 NotificationProviderNotifyOnPermissionLevelChangedFunction::Run() { | 193 NotificationProviderNotifyOnPermissionLevelChangedFunction::Run() { | 
| 191 scoped_ptr<api::notification_provider::NotifyOnPermissionLevelChanged::Params> | 194 scoped_ptr<api::notification_provider::NotifyOnPermissionLevelChanged::Params> | 
| 192 params = api::notification_provider::NotifyOnPermissionLevelChanged:: | 195 params = api::notification_provider::NotifyOnPermissionLevelChanged:: | 
| 193 Params::Create(*args_); | 196 Params::Create(*args_); | 
| 194 | |
| 195 EXTENSION_FUNCTION_VALIDATE(params.get()); | 197 EXTENSION_FUNCTION_VALIDATE(params.get()); | 
| 196 | 198 | 
| 199 bool is_application_type = | |
| 
 
Pete Williamson
2014/08/13 19:54:01
Let's add a comment about why we only check applic
 
liyanhou
2014/08/14 16:15:24
Done.
 
 | |
| 200 (params->notifier_type == | |
| 201 api::notification_provider::NotifierType::NOTIFIER_TYPE_APPLICATION); | |
| 202 if (is_application_type) { | |
| 203 bool enabled = | |
| 204 (params->level == api::notification_provider::NotifierPermissionLevel:: | |
| 205 NOTIFIER_PERMISSION_LEVEL_GRANTED) | |
| 206 ? true | |
| 207 : false; | |
| 208 | |
| 209 DesktopNotificationService* desktop_notification_service = | |
| 210 DesktopNotificationServiceFactory::GetForProfile(GetProfile()); | |
| 211 message_center::NotifierId notifier_id( | |
| 212 message_center::NotifierId::NotifierType::APPLICATION, | |
| 213 params->notifier_id); | |
| 214 | |
| 215 desktop_notification_service->SetNotifierEnabled(notifier_id, enabled); | |
| 216 } | |
| 217 | |
| 218 // Third party apps/extensions with notification provider API will not be able | |
| 219 // to change permission levels of web notifiers. Because the list of allowed | |
| 220 // websites should only be set in Chrome Settings manually by users. They can | |
| 221 // can change permission levels of application type notifiers. | |
| 
 
Pete Williamson
2014/08/13 19:54:01
nit: notifiers. Because -> notifiers, because
 
liyanhou
2014/08/14 16:15:24
Done.
 
 | |
| 197 return RespondNow( | 222 return RespondNow( | 
| 198 ArgumentList(api::notification_provider::NotifyOnPermissionLevelChanged:: | 223 ArgumentList(api::notification_provider::NotifyOnPermissionLevelChanged:: | 
| 199 Results::Create(true))); | 224 Results::Create(is_application_type))); | 
| 200 } | 225 } | 
| 201 | 226 | 
| 202 NotificationProviderNotifyOnShowSettingsFunction:: | 227 NotificationProviderNotifyOnShowSettingsFunction:: | 
| 203 NotificationProviderNotifyOnShowSettingsFunction() { | 228 NotificationProviderNotifyOnShowSettingsFunction() { | 
| 204 } | 229 } | 
| 205 | 230 | 
| 206 NotificationProviderNotifyOnShowSettingsFunction:: | 231 NotificationProviderNotifyOnShowSettingsFunction:: | 
| 207 ~NotificationProviderNotifyOnShowSettingsFunction() { | 232 ~NotificationProviderNotifyOnShowSettingsFunction() { | 
| 208 } | 233 } | 
| 209 | 234 | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 | 268 | 
| 244 ExtensionFunction::ResponseAction | 269 ExtensionFunction::ResponseAction | 
| 245 NotificationProviderGetAllNotifiersFunction::Run() { | 270 NotificationProviderGetAllNotifiersFunction::Run() { | 
| 246 std::vector<linked_ptr<api::notification_provider::Notifier> > notifiers; | 271 std::vector<linked_ptr<api::notification_provider::Notifier> > notifiers; | 
| 247 | 272 | 
| 248 return RespondNow(ArgumentList( | 273 return RespondNow(ArgumentList( | 
| 249 api::notification_provider::GetAllNotifiers::Results::Create(notifiers))); | 274 api::notification_provider::GetAllNotifiers::Results::Create(notifiers))); | 
| 250 } | 275 } | 
| 251 | 276 | 
| 252 } // namespace extensions | 277 } // namespace extensions | 
| OLD | NEW |