Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: chrome/browser/extensions/api/notification_provider/notification_provider_api.cc

Issue 468813002: Add NotifyOnPermissionLevelChanged implementation of notification (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments, deleted test for notifyOnShowSettings since it's not implemented Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_);
197 EXTENSION_FUNCTION_VALIDATE(params.get());
194 198
195 EXTENSION_FUNCTION_VALIDATE(params.get()); 199 // Third party apps/extensions with notification provider API will not be able
200 // to change permission levels of web notifiers, because the list of allowed
201 // websites should only be set in Chrome Settings manually by users. But they
202 // are able to change permission levels of application type notifiers.
203 bool is_application_type =
204 (params->notifier_type ==
205 api::notification_provider::NotifierType::NOTIFIER_TYPE_APPLICATION);
206 if (is_application_type) {
207 bool enabled =
208 (params->level == api::notification_provider::NotifierPermissionLevel::
209 NOTIFIER_PERMISSION_LEVEL_GRANTED)
210 ? true
dewittj 2014/08/13 21:30:36 Can you please rewrite this statement as multiple
liyanhou 2014/08/14 16:15:24 Done.
211 : false;
212
213 DesktopNotificationService* desktop_notification_service =
214 DesktopNotificationServiceFactory::GetForProfile(GetProfile());
215 message_center::NotifierId notifier_id(
216 message_center::NotifierId::NotifierType::APPLICATION,
217 params->notifier_id);
218
219 desktop_notification_service->SetNotifierEnabled(notifier_id, enabled);
220 }
196 221
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698