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

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: rebase 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/notification_provider/basic_usage/background.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
20 #include "ui/message_center/message_center.h" 22 #include "ui/message_center/message_center.h"
21 #include "ui/message_center/notifier_settings.h" 23 #include "ui/message_center/notifier_settings.h"
22 #include "url/gurl.h" 24 #include "url/gurl.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 NotificationProviderNotifyOnPermissionLevelChangedFunction:: 189 NotificationProviderNotifyOnPermissionLevelChangedFunction::
188 ~NotificationProviderNotifyOnPermissionLevelChangedFunction() { 190 ~NotificationProviderNotifyOnPermissionLevelChangedFunction() {
189 } 191 }
190 192
191 ExtensionFunction::ResponseAction 193 ExtensionFunction::ResponseAction
192 NotificationProviderNotifyOnPermissionLevelChangedFunction::Run() { 194 NotificationProviderNotifyOnPermissionLevelChangedFunction::Run() {
193 scoped_ptr<api::notification_provider::NotifyOnPermissionLevelChanged::Params> 195 scoped_ptr<api::notification_provider::NotifyOnPermissionLevelChanged::Params>
194 params = api::notification_provider::NotifyOnPermissionLevelChanged:: 196 params = api::notification_provider::NotifyOnPermissionLevelChanged::
195 Params::Create(*args_); 197 Params::Create(*args_);
196 EXTENSION_FUNCTION_VALIDATE(params.get()); 198 EXTENSION_FUNCTION_VALIDATE(params.get());
199
200 // Third party apps/extensions with notification provider API will not be able
201 // to change permission levels of web notifiers, because the list of allowed
202 // websites should only be set in Chrome Settings manually by users. But they
203 // are able to change permission levels of application type notifiers.
204 bool is_application_type =
205 (params->notifier_type ==
206 api::notification_provider::NotifierType::NOTIFIER_TYPE_APPLICATION);
207 if (is_application_type) {
208 bool enabled =
209 (params->level == api::notification_provider::NotifierPermissionLevel::
210 NOTIFIER_PERMISSION_LEVEL_GRANTED);
211
212 DesktopNotificationService* desktop_notification_service =
213 DesktopNotificationServiceFactory::GetForProfile(GetProfile());
214 message_center::NotifierId notifier_id(
215 message_center::NotifierId::NotifierType::APPLICATION,
216 params->notifier_id);
217
218 desktop_notification_service->SetNotifierEnabled(notifier_id, enabled);
219 }
220
197 return RespondNow( 221 return RespondNow(
198 ArgumentList(api::notification_provider::NotifyOnPermissionLevelChanged:: 222 ArgumentList(api::notification_provider::NotifyOnPermissionLevelChanged::
199 Results::Create(true))); 223 Results::Create(is_application_type)));
200 } 224 }
201 225
202 NotificationProviderNotifyOnShowSettingsFunction:: 226 NotificationProviderNotifyOnShowSettingsFunction::
203 NotificationProviderNotifyOnShowSettingsFunction() { 227 NotificationProviderNotifyOnShowSettingsFunction() {
204 } 228 }
205 229
206 NotificationProviderNotifyOnShowSettingsFunction:: 230 NotificationProviderNotifyOnShowSettingsFunction::
207 ~NotificationProviderNotifyOnShowSettingsFunction() { 231 ~NotificationProviderNotifyOnShowSettingsFunction() {
208 } 232 }
209 233
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 289
266 ExtensionFunction::ResponseAction 290 ExtensionFunction::ResponseAction
267 NotificationProviderGetAllNotifiersFunction::Run() { 291 NotificationProviderGetAllNotifiersFunction::Run() {
268 std::vector<linked_ptr<api::notification_provider::Notifier> > notifiers; 292 std::vector<linked_ptr<api::notification_provider::Notifier> > notifiers;
269 293
270 return RespondNow(ArgumentList( 294 return RespondNow(ArgumentList(
271 api::notification_provider::GetAllNotifiers::Results::Create(notifiers))); 295 api::notification_provider::GetAllNotifiers::Results::Create(notifiers)));
272 } 296 }
273 297
274 } // namespace extensions 298 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/notification_provider/basic_usage/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698