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

Unified Diff: chrome/browser/extensions/api/notification/notification_api.cc

Issue 12221127: Actually prevent sending notifications from apps. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/api/notification/notification_api.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/notification/notification_api.cc
diff --git a/chrome/browser/extensions/api/notification/notification_api.cc b/chrome/browser/extensions/api/notification/notification_api.cc
index 2aea0d9343a56034c420bafe11738d831673cb40..6db3e17b56a605e94c344bf3f352e92abe06c074 100644
--- a/chrome/browser/extensions/api/notification/notification_api.cc
+++ b/chrome/browser/extensions/api/notification/notification_api.cc
@@ -11,6 +11,8 @@
#include "chrome/browser/extensions/event_names.h"
#include "chrome/browser/extensions/event_router.h"
#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/notifications/desktop_notification_service.h"
+#include "chrome/browser/notifications/desktop_notification_service_factory.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/common/extensions/extension.h"
@@ -194,6 +196,12 @@ void NotificationApiFunction::CreateNotification(
g_browser_process->notification_ui_manager()->Add(notification, profile());
}
+bool NotificationApiFunction::IsNotificationApiEnabled() {
+ DesktopNotificationService* service =
+ DesktopNotificationServiceFactory::GetForProfile(profile());
+ return service->IsExtensionEnabled(extension_->id());
+}
+
const char kNotificationPrefix[] = "extension.api.";
static uint64 next_id_ = 0;
@@ -208,6 +216,11 @@ bool NotificationCreateFunction::RunImpl() {
params_ = api::experimental_notification::Create::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
+ if (!IsNotificationApiEnabled()) {
miket_OOO 2013/02/11 23:04:20 If you think this should be enforced for all Notif
Jun Mukai 2013/02/12 01:09:02 That sounds reasonable. Fixed the code based on yo
+ SendResponse(false);
+ return true;
+ }
+
// If the caller provided a notificationId, use that. Otherwise, generate
// one. Note that there's nothing stopping an app developer from passing in
// arbitrary "extension.api.999" notificationIds that will collide with
@@ -239,6 +252,11 @@ bool NotificationUpdateFunction::RunImpl() {
params_ = api::experimental_notification::Update::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
+ if (!IsNotificationApiEnabled()) {
+ SendResponse(false);
+ return true;
+ }
+
if (g_browser_process->notification_ui_manager()->
DoesIdExist(NotificationApiDelegate::CreateScopedIdentifier(
extension_->id(), params_->notification_id))) {
@@ -263,6 +281,11 @@ bool NotificationDeleteFunction::RunImpl() {
params_ = api::experimental_notification::Delete::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
+ if (!IsNotificationApiEnabled()) {
+ SendResponse(false);
+ return true;
+ }
+
bool cancel_result = g_browser_process->notification_ui_manager()->
CancelById(NotificationApiDelegate::CreateScopedIdentifier(
extension_->id(), params_->notification_id));
« no previous file with comments | « chrome/browser/extensions/api/notification/notification_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698