Commit cab66ce0 authored by mukai@chromium.org's avatar mukai@chromium.org

Actually prevent sending notifications from apps.

It looks up the current preference through DesktopNotificationService
and reports failures when it's stopped.

BUG=161094


Review URL: https://chromiumcodereview.appspot.com/12221127

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182138 0039d316-1c4b-4281-b951-d872f2087c98
parent 511edc1c
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "chrome/browser/extensions/event_names.h" #include "chrome/browser/extensions/event_names.h"
#include "chrome/browser/extensions/event_router.h" #include "chrome/browser/extensions/event_router.h"
#include "chrome/browser/extensions/extension_system.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.h"
#include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/common/extensions/extension.h" #include "chrome/common/extensions/extension.h"
...@@ -194,6 +196,21 @@ void NotificationApiFunction::CreateNotification( ...@@ -194,6 +196,21 @@ void NotificationApiFunction::CreateNotification(
g_browser_process->notification_ui_manager()->Add(notification, profile()); g_browser_process->notification_ui_manager()->Add(notification, profile());
} }
bool NotificationApiFunction::IsNotificationApiEnabled() {
DesktopNotificationService* service =
DesktopNotificationServiceFactory::GetForProfile(profile());
return service->IsExtensionEnabled(extension_->id());
}
bool NotificationApiFunction::RunImpl() {
if (!IsNotificationApiEnabled()) {
SendResponse(false);
return true;
}
return RunNotificationApi();
}
const char kNotificationPrefix[] = "extension.api."; const char kNotificationPrefix[] = "extension.api.";
static uint64 next_id_ = 0; static uint64 next_id_ = 0;
...@@ -204,7 +221,7 @@ NotificationCreateFunction::NotificationCreateFunction() { ...@@ -204,7 +221,7 @@ NotificationCreateFunction::NotificationCreateFunction() {
NotificationCreateFunction::~NotificationCreateFunction() { NotificationCreateFunction::~NotificationCreateFunction() {
} }
bool NotificationCreateFunction::RunImpl() { bool NotificationCreateFunction::RunNotificationApi() {
params_ = api::experimental_notification::Create::Params::Create(*args_); params_ = api::experimental_notification::Create::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get()); EXTENSION_FUNCTION_VALIDATE(params_.get());
...@@ -235,7 +252,7 @@ NotificationUpdateFunction::NotificationUpdateFunction() { ...@@ -235,7 +252,7 @@ NotificationUpdateFunction::NotificationUpdateFunction() {
NotificationUpdateFunction::~NotificationUpdateFunction() { NotificationUpdateFunction::~NotificationUpdateFunction() {
} }
bool NotificationUpdateFunction::RunImpl() { bool NotificationUpdateFunction::RunNotificationApi() {
params_ = api::experimental_notification::Update::Params::Create(*args_); params_ = api::experimental_notification::Update::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get()); EXTENSION_FUNCTION_VALIDATE(params_.get());
...@@ -259,7 +276,7 @@ NotificationDeleteFunction::NotificationDeleteFunction() { ...@@ -259,7 +276,7 @@ NotificationDeleteFunction::NotificationDeleteFunction() {
NotificationDeleteFunction::~NotificationDeleteFunction() { NotificationDeleteFunction::~NotificationDeleteFunction() {
} }
bool NotificationDeleteFunction::RunImpl() { bool NotificationDeleteFunction::RunNotificationApi() {
params_ = api::experimental_notification::Delete::Params::Create(*args_); params_ = api::experimental_notification::Delete::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get()); EXTENSION_FUNCTION_VALIDATE(params_.get());
......
...@@ -22,6 +22,14 @@ class NotificationApiFunction : public ApiFunction { ...@@ -22,6 +22,14 @@ class NotificationApiFunction : public ApiFunction {
void CreateNotification( void CreateNotification(
const std::string& id, const std::string& id,
api::experimental_notification::NotificationOptions* options); api::experimental_notification::NotificationOptions* options);
bool IsNotificationApiEnabled();
// Called inside of RunImpl.
virtual bool RunNotificationApi() = 0;
// UITHreadExtensionFunction:
virtual bool RunImpl() OVERRIDE;
}; };
class NotificationCreateFunction : public NotificationApiFunction { class NotificationCreateFunction : public NotificationApiFunction {
...@@ -29,7 +37,7 @@ class NotificationCreateFunction : public NotificationApiFunction { ...@@ -29,7 +37,7 @@ class NotificationCreateFunction : public NotificationApiFunction {
NotificationCreateFunction(); NotificationCreateFunction();
// UIThreadExtensionFunction: // UIThreadExtensionFunction:
virtual bool RunImpl() OVERRIDE; virtual bool RunNotificationApi() OVERRIDE;
protected: protected:
virtual ~NotificationCreateFunction(); virtual ~NotificationCreateFunction();
...@@ -46,7 +54,7 @@ class NotificationUpdateFunction : public NotificationApiFunction { ...@@ -46,7 +54,7 @@ class NotificationUpdateFunction : public NotificationApiFunction {
NotificationUpdateFunction(); NotificationUpdateFunction();
// UIThreadExtensionFunction: // UIThreadExtensionFunction:
virtual bool RunImpl() OVERRIDE; virtual bool RunNotificationApi() OVERRIDE;
protected: protected:
virtual ~NotificationUpdateFunction(); virtual ~NotificationUpdateFunction();
...@@ -63,7 +71,7 @@ class NotificationDeleteFunction : public NotificationApiFunction { ...@@ -63,7 +71,7 @@ class NotificationDeleteFunction : public NotificationApiFunction {
NotificationDeleteFunction(); NotificationDeleteFunction();
// UIThreadExtensionFunction: // UIThreadExtensionFunction:
virtual bool RunImpl() OVERRIDE; virtual bool RunNotificationApi() OVERRIDE;
protected: protected:
virtual ~NotificationDeleteFunction(); virtual ~NotificationDeleteFunction();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment