summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorliyanhou@chromium.org <liyanhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-02 05:45:34 +0000
committerliyanhou@chromium.org <liyanhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-02 05:45:34 +0000
commit0a0e32150f1f3bfce3d0ecd082da4a6f11b0101f (patch)
tree0836e554b154a4b96c14877718aac60db6795265
parent0916270fe2e7cf0b4d308c48dbd5c02fb961d9bd (diff)
downloadchromium_src-0a0e32150f1f3bfce3d0ecd082da4a6f11b0101f.zip
chromium_src-0a0e32150f1f3bfce3d0ecd082da4a6f11b0101f.tar.gz
chromium_src-0a0e32150f1f3bfce3d0ecd082da4a6f11b0101f.tar.bz2
Notification Provider API
The Notification provider API will reroute the notifications that are supposed to be sent to the Chrome Notification Center, so an app can get the notifications and have its own implementation of notification center. BUG=397197 Review URL: https://codereview.chromium.org/356673003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287155 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/api/notification_provider/notification_provider_api.cc224
-rw-r--r--chrome/browser/extensions/api/notification_provider/notification_provider_api.h191
-rw-r--r--chrome/browser/extensions/api/notification_provider/notification_provider_apitest.cc43
-rw-r--r--chrome/chrome_browser_extensions.gypi2
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/common/extensions/api/_api_features.json4
-rw-r--r--chrome/common/extensions/api/_permission_features.json4
-rw-r--r--chrome/common/extensions/api/api.gyp1
-rw-r--r--chrome/common/extensions/api/notification_provider.idl132
-rw-r--r--chrome/common/extensions/permissions/chrome_api_permissions.cc1
-rw-r--r--chrome/common/extensions/permissions/permission_set_unittest.cc1
-rw-r--r--chrome/test/data/extensions/api_test/notification_provider/events/manifest.json13
-rw-r--r--chrome/test/data/extensions/api_test/notification_provider/events/test.js24
-rw-r--r--extensions/browser/extension_function_histogram_value.h8
-rw-r--r--extensions/common/permissions/api_permission.h1
-rw-r--r--tools/metrics/histograms/histograms.xml7
16 files changed, 657 insertions, 0 deletions
diff --git a/chrome/browser/extensions/api/notification_provider/notification_provider_api.cc b/chrome/browser/extensions/api/notification_provider/notification_provider_api.cc
new file mode 100644
index 0000000..6b71abd
--- /dev/null
+++ b/chrome/browser/extensions/api/notification_provider/notification_provider_api.cc
@@ -0,0 +1,224 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/notification_provider/notification_provider_api.h"
+
+#include "base/callback.h"
+#include "base/guid.h"
+#include "base/rand_util.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/common/chrome_version_info.h"
+#include "extensions/browser/event_router.h"
+#include "extensions/common/extension.h"
+#include "extensions/common/features/feature.h"
+#include "ui/base/layout.h"
+#include "url/gurl.h"
+
+namespace extensions {
+
+NotificationProviderEventRouter::NotificationProviderEventRouter(
+ Profile* profile)
+ : profile_(profile) {
+}
+
+NotificationProviderEventRouter::~NotificationProviderEventRouter() {
+}
+
+void NotificationProviderEventRouter::CreateNotification(
+ const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notification_id,
+ const api::notifications::NotificationOptions& options) {
+ Create(notification_provider_id, sender_id, notification_id, options);
+}
+
+void NotificationProviderEventRouter::UpdateNotification(
+ const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notification_id,
+ const api::notifications::NotificationOptions& options) {
+ Update(notification_provider_id, sender_id, notification_id, options);
+}
+void NotificationProviderEventRouter::ClearNotification(
+ const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notification_id) {
+ Clear(notification_provider_id, sender_id, notification_id);
+}
+
+void NotificationProviderEventRouter::Create(
+ const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notification_id,
+ const api::notifications::NotificationOptions& options) {
+ scoped_ptr<base::ListValue> args =
+ api::notification_provider::OnCreated::Create(
+ sender_id, notification_id, options);
+
+ scoped_ptr<Event> event(new Event(
+ api::notification_provider::OnCreated::kEventName, args.Pass()));
+
+ EventRouter::Get(profile_)
+ ->DispatchEventToExtension(notification_provider_id, event.Pass());
+}
+
+void NotificationProviderEventRouter::Update(
+ const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notification_id,
+ const api::notifications::NotificationOptions& options) {
+ scoped_ptr<base::ListValue> args =
+ api::notification_provider::OnUpdated::Create(
+ sender_id, notification_id, options);
+
+ scoped_ptr<Event> event(new Event(
+ api::notification_provider::OnUpdated::kEventName, args.Pass()));
+
+ EventRouter::Get(profile_)
+ ->DispatchEventToExtension(notification_provider_id, event.Pass());
+}
+
+void NotificationProviderEventRouter::Clear(
+ const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notification_id) {
+ scoped_ptr<base::ListValue> args =
+ api::notification_provider::OnCleared::Create(sender_id, notification_id);
+
+ scoped_ptr<Event> event(new Event(
+ api::notification_provider::OnCleared::kEventName, args.Pass()));
+
+ EventRouter::Get(profile_)
+ ->DispatchEventToExtension(notification_provider_id, event.Pass());
+}
+
+NotificationProviderNotifyOnClearedFunction::
+ NotificationProviderNotifyOnClearedFunction() {
+}
+
+NotificationProviderNotifyOnClearedFunction::
+ ~NotificationProviderNotifyOnClearedFunction() {
+}
+
+ExtensionFunction::ResponseAction
+NotificationProviderNotifyOnClearedFunction::Run() {
+ scoped_ptr<api::notification_provider::NotifyOnCleared::Params> params =
+ api::notification_provider::NotifyOnCleared::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ return RespondNow(ArgumentList(
+ api::notification_provider::NotifyOnCleared::Results::Create(true)));
+}
+
+NotificationProviderNotifyOnClickedFunction::
+ NotificationProviderNotifyOnClickedFunction() {
+}
+
+NotificationProviderNotifyOnClickedFunction::
+ ~NotificationProviderNotifyOnClickedFunction() {
+}
+
+ExtensionFunction::ResponseAction
+NotificationProviderNotifyOnClickedFunction::Run() {
+ scoped_ptr<api::notification_provider::NotifyOnClicked::Params> params =
+ api::notification_provider::NotifyOnClicked::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ return RespondNow(ArgumentList(
+ api::notification_provider::NotifyOnClicked::Results::Create(true)));
+}
+
+NotificationProviderNotifyOnButtonClickedFunction::
+ NotificationProviderNotifyOnButtonClickedFunction() {
+}
+
+NotificationProviderNotifyOnButtonClickedFunction::
+ ~NotificationProviderNotifyOnButtonClickedFunction() {
+}
+
+ExtensionFunction::ResponseAction
+NotificationProviderNotifyOnButtonClickedFunction::Run() {
+ scoped_ptr<api::notification_provider::NotifyOnButtonClicked::Params> params =
+ api::notification_provider::NotifyOnButtonClicked::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ return RespondNow(ArgumentList(
+ api::notification_provider::NotifyOnButtonClicked::Results::Create(
+ true)));
+}
+
+NotificationProviderNotifyOnPermissionLevelChangedFunction::
+ NotificationProviderNotifyOnPermissionLevelChangedFunction() {
+}
+
+NotificationProviderNotifyOnPermissionLevelChangedFunction::
+ ~NotificationProviderNotifyOnPermissionLevelChangedFunction() {
+}
+
+ExtensionFunction::ResponseAction
+NotificationProviderNotifyOnPermissionLevelChangedFunction::Run() {
+ scoped_ptr<api::notification_provider::NotifyOnPermissionLevelChanged::Params>
+ params = api::notification_provider::NotifyOnPermissionLevelChanged::
+ Params::Create(*args_);
+
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ return RespondNow(
+ ArgumentList(api::notification_provider::NotifyOnPermissionLevelChanged::
+ Results::Create(true)));
+}
+
+NotificationProviderNotifyOnShowSettingsFunction::
+ NotificationProviderNotifyOnShowSettingsFunction() {
+}
+
+NotificationProviderNotifyOnShowSettingsFunction::
+ ~NotificationProviderNotifyOnShowSettingsFunction() {
+}
+
+ExtensionFunction::ResponseAction
+NotificationProviderNotifyOnShowSettingsFunction::Run() {
+ scoped_ptr<api::notification_provider::NotifyOnShowSettings::Params> params =
+ api::notification_provider::NotifyOnShowSettings::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ return RespondNow(ArgumentList(
+ api::notification_provider::NotifyOnShowSettings::Results::Create(true)));
+}
+
+NotificationProviderGetNotifierFunction::
+ NotificationProviderGetNotifierFunction() {
+}
+
+NotificationProviderGetNotifierFunction::
+ ~NotificationProviderGetNotifierFunction() {
+}
+
+ExtensionFunction::ResponseAction
+NotificationProviderGetNotifierFunction::Run() {
+ api::notification_provider::Notifier notifier;
+
+ return RespondNow(ArgumentList(
+ api::notification_provider::GetNotifier::Results::Create(notifier)));
+}
+
+NotificationProviderGetAllNotifiersFunction::
+ NotificationProviderGetAllNotifiersFunction() {
+}
+
+NotificationProviderGetAllNotifiersFunction::
+ ~NotificationProviderGetAllNotifiersFunction() {
+}
+
+ExtensionFunction::ResponseAction
+NotificationProviderGetAllNotifiersFunction::Run() {
+ std::vector<linked_ptr<api::notification_provider::Notifier> > notifiers;
+
+ return RespondNow(ArgumentList(
+ api::notification_provider::GetAllNotifiers::Results::Create(notifiers)));
+}
+
+} // namespace extensions
diff --git a/chrome/browser/extensions/api/notification_provider/notification_provider_api.h b/chrome/browser/extensions/api/notification_provider/notification_provider_api.h
new file mode 100644
index 0000000..88f2d2e
--- /dev/null
+++ b/chrome/browser/extensions/api/notification_provider/notification_provider_api.h
@@ -0,0 +1,191 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_NOTIFICATION_PROVIDER_NOTIFICATION_PROVIDER_API_H_
+#define CHROME_BROWSER_EXTENSIONS_API_NOTIFICATION_PROVIDER_NOTIFICATION_PROVIDER_API_H_
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "chrome/browser/extensions/chrome_extension_function.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/api/notification_provider.h"
+#include "extensions/browser/extension_function.h"
+#include "ui/message_center/notification_types.h"
+
+namespace extensions {
+
+// Send events to the client. This will send events onCreated, onUpdated and
+// onCleared to extensions/apps using this API.
+class NotificationProviderEventRouter {
+ public:
+ explicit NotificationProviderEventRouter(Profile* profile);
+ virtual ~NotificationProviderEventRouter();
+
+ void CreateNotification(
+ const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notification_id,
+ const api::notifications::NotificationOptions& options);
+ void UpdateNotification(
+ const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notificaiton_id,
+ const api::notifications::NotificationOptions& options);
+ void ClearNotification(const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notification_id);
+
+ private:
+ void Create(const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notification_id,
+ const api::notifications::NotificationOptions& options);
+ void Update(const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notification_id,
+ const api::notifications::NotificationOptions& options);
+ void Clear(const std::string& notification_provider_id,
+ const std::string& sender_id,
+ const std::string& notification_id);
+
+ Profile* profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(NotificationProviderEventRouter);
+};
+
+// Implememtation of NotifyOnCleared function of the API. It will inform the
+// notifier that the user cleared a notification sent from that notifier.
+class NotificationProviderNotifyOnClearedFunction
+ : public ChromeUIThreadExtensionFunction {
+ public:
+ NotificationProviderNotifyOnClearedFunction();
+
+ protected:
+ virtual ~NotificationProviderNotifyOnClearedFunction();
+
+ private:
+ DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnCleared",
+ NOTIFICATIONPROVIDER_NOTIFYONCLEARED);
+
+ // UIThreadExtensionFunction implementation.
+ virtual ExtensionFunction::ResponseAction Run() OVERRIDE;
+};
+
+// Implememtation of NotifyOnClicked function of the API. It will inform the
+// notifier that the user clicked in a non-button area of a notification sent
+// from that notifier.
+class NotificationProviderNotifyOnClickedFunction
+ : public ChromeUIThreadExtensionFunction {
+ public:
+ NotificationProviderNotifyOnClickedFunction();
+
+ protected:
+ virtual ~NotificationProviderNotifyOnClickedFunction();
+
+ private:
+ DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnClicked",
+ NOTIFICATIONPROVIDER_NOTIFYONCLICKED);
+
+ // UIThreadExtensionFunction implementation.
+ virtual ExtensionFunction::ResponseAction Run() OVERRIDE;
+};
+
+// Implememtation of NotifyOnButtonClicked function of the API. It will inform
+// the
+// notifier that the user pressed a button in the notification sent from that
+// notifier.
+class NotificationProviderNotifyOnButtonClickedFunction
+ : public ChromeUIThreadExtensionFunction {
+ public:
+ NotificationProviderNotifyOnButtonClickedFunction();
+
+ protected:
+ virtual ~NotificationProviderNotifyOnButtonClickedFunction();
+
+ private:
+ DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnButtonClicked",
+ NOTIFICATIONPROVIDER_NOTIFYONBUTTONCLICKED);
+
+ // UIThreadExtensionFunction implementation.
+ virtual ExtensionFunction::ResponseAction Run() OVERRIDE;
+};
+
+// Implememtation of NotifyOnPermissionLevelChanged function of the API. It will
+// inform the notifier that the user changed the permission level of that
+// notifier.
+class NotificationProviderNotifyOnPermissionLevelChangedFunction
+ : public ChromeUIThreadExtensionFunction {
+ public:
+ NotificationProviderNotifyOnPermissionLevelChangedFunction();
+
+ protected:
+ virtual ~NotificationProviderNotifyOnPermissionLevelChangedFunction();
+
+ private:
+ DECLARE_EXTENSION_FUNCTION(
+ "notificationProvider.notifyOnPermissionLevelChanged",
+ NOTIFICATIONPROVIDER_NOTIFYONPERMISSIONLEVELCHANGED);
+
+ // UIThreadExtensionFunction implementation.
+ virtual ExtensionFunction::ResponseAction Run() OVERRIDE;
+};
+
+// Implememtation of NotifyOnShowSettings function of the API. It will inform
+// the notifier that the user clicked on advanced settings of that notifier.
+class NotificationProviderNotifyOnShowSettingsFunction
+ : public ChromeUIThreadExtensionFunction {
+ public:
+ NotificationProviderNotifyOnShowSettingsFunction();
+
+ protected:
+ virtual ~NotificationProviderNotifyOnShowSettingsFunction();
+
+ private:
+ DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnShowSettings",
+ NOTIFICATIONPROVIDER_NOTIFYONSHOWSETTINGS);
+
+ // UIThreadExtensionFunction implementation.
+ virtual ExtensionFunction::ResponseAction Run() OVERRIDE;
+};
+
+// Implememtation of GetNotifier function of the API. It will get the notifier
+// object that corresponds to the notifier ID.
+class NotificationProviderGetNotifierFunction
+ : public ChromeUIThreadExtensionFunction {
+ public:
+ NotificationProviderGetNotifierFunction();
+
+ protected:
+ virtual ~NotificationProviderGetNotifierFunction();
+
+ private:
+ DECLARE_EXTENSION_FUNCTION("notificationProvider.getNotifier",
+ NOTIFICATIONPROVIDER_GETNOTIFIER);
+
+ // UIThreadExtensionFunction implementation.
+ virtual ExtensionFunction::ResponseAction Run() OVERRIDE;
+};
+
+// Implememtation of GetAllNotifiers function of the API. It will get all the
+// notifiers that would send notifications.
+class NotificationProviderGetAllNotifiersFunction
+ : public ChromeUIThreadExtensionFunction {
+ public:
+ NotificationProviderGetAllNotifiersFunction();
+
+ protected:
+ virtual ~NotificationProviderGetAllNotifiersFunction();
+
+ private:
+ DECLARE_EXTENSION_FUNCTION("notificationProvider.getAllNotifiers",
+ NOTIFICATIONPROVIDER_GETALLNOTIFIERS);
+
+ // UIThreadExtensionFunction implementation.
+ virtual ExtensionFunction::ResponseAction Run() OVERRIDE;
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_NOTIFICATION_PROVIDER_NOTIFICATION_PROVIDER_API_H_
diff --git a/chrome/browser/extensions/api/notification_provider/notification_provider_apitest.cc b/chrome/browser/extensions/api/notification_provider/notification_provider_apitest.cc
new file mode 100644
index 0000000..d5f0031
--- /dev/null
+++ b/chrome/browser/extensions/api/notification_provider/notification_provider_apitest.cc
@@ -0,0 +1,43 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/notification_provider/notification_provider_api.h"
+#include "chrome/browser/extensions/chrome_extension_function.h"
+#include "chrome/browser/extensions/extension_apitest.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/api/notification_provider.h"
+
+typedef ExtensionApiTest NotificationProviderApiTest;
+
+IN_PROC_BROWSER_TEST_F(NotificationProviderApiTest, Events) {
+ std::string sender_id1 = "SenderId1";
+ std::string notification_id1 = "NotificationId1";
+
+ extensions::api::notifications::NotificationOptions options;
+ options.type = extensions::api::notifications::ParseTemplateType("basic");
+ options.icon_url = scoped_ptr<std::string>(new std::string("icon.png"));
+ options.title = scoped_ptr<std::string>(new std::string("Title"));
+ options.message =
+ scoped_ptr<std::string>(new std::string("Here goes the message"));
+
+ ResultCatcher catcher;
+ catcher.RestrictToProfile(browser()->profile());
+
+ // Test notification provider extension
+ const extensions::Extension* extension =
+ LoadExtension(test_data_dir_.AppendASCII("notification_provider/events"));
+ ASSERT_TRUE(extension);
+
+ extensions::NotificationProviderEventRouter* event_router =
+ new extensions::NotificationProviderEventRouter(browser()->profile());
+
+ event_router->CreateNotification(
+ extension->id(), sender_id1, notification_id1, options);
+ event_router->UpdateNotification(
+ extension->id(), sender_id1, notification_id1, options);
+ event_router->ClearNotification(
+ extension->id(), sender_id1, notification_id1);
+
+ EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
+}
diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi
index 104ac87..880ead1 100644
--- a/chrome/chrome_browser_extensions.gypi
+++ b/chrome/chrome_browser_extensions.gypi
@@ -700,6 +700,8 @@
'browser/extensions/api/networking_private/networking_private_event_router_factory.h',
'browser/extensions/api/networking_private/networking_private_factory_chromeos.cc',
'browser/extensions/api/networking_private/networking_private_factory_chromeos.h',
+ 'browser/extensions/api/notification_provider/notification_provider_api.cc',
+ 'browser/extensions/api/notification_provider/notification_provider_api.h',
'browser/extensions/api/notifications/notifications_api.cc',
'browser/extensions/api/notifications/notifications_api.h',
'browser/extensions/api/omnibox/omnibox_api.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index fead9e3..6a586b7 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1115,6 +1115,7 @@
'browser/extensions/api/metrics_private/metrics_apitest.cc',
'browser/extensions/api/module/module_apitest.cc',
'browser/extensions/api/music_manager_private/music_manager_private_browsertest.cc',
+ 'browser/extensions/api/notification_provider/notification_provider_apitest.cc',
'browser/extensions/api/notifications/notifications_apitest.cc',
'browser/extensions/api/omnibox/omnibox_api_browsertest.cc',
'browser/extensions/api/page_capture/page_capture_apitest.cc',
diff --git a/chrome/common/extensions/api/_api_features.json b/chrome/common/extensions/api/_api_features.json
index 4ab66016..eb3047d 100644
--- a/chrome/common/extensions/api/_api_features.json
+++ b/chrome/common/extensions/api/_api_features.json
@@ -563,6 +563,10 @@
"dependencies": ["permission:networkingPrivate"],
"contexts": ["blessed_extension"]
},
+ "notificationProvider": {
+ "dependencies": ["permission:notificationProvider"],
+ "contexts": ["blessed_extension"]
+ },
"notifications": {
"dependencies": ["permission:notifications"],
"contexts": ["blessed_extension"]
diff --git a/chrome/common/extensions/api/_permission_features.json b/chrome/common/extensions/api/_permission_features.json
index 3a3b943..a3e8662 100644
--- a/chrome/common/extensions/api/_permission_features.json
+++ b/chrome/common/extensions/api/_permission_features.json
@@ -801,6 +801,10 @@
"75E3CFFFC530582C583E4690EF97C70B9C8423B7" // CCD Release
]
},
+ "notificationProvider": {
+ "channel": "trunk",
+ "extension_types": ["extension", "platform_app"]
+ },
"notifications": {
// The chrome.notifications functionality listed in notifications.idl is
// available only to extension/platform_app types. The implementation of
diff --git a/chrome/common/extensions/api/api.gyp b/chrome/common/extensions/api/api.gyp
index aaddab8..5965415 100644
--- a/chrome/common/extensions/api/api.gyp
+++ b/chrome/common/extensions/api/api.gyp
@@ -82,6 +82,7 @@
'media_galleries_private.idl',
'metrics_private.json',
'networking_private.json',
+ 'notification_provider.idl',
'notifications.idl',
'omnibox.json',
'page_capture.json',
diff --git a/chrome/common/extensions/api/notification_provider.idl b/chrome/common/extensions/api/notification_provider.idl
new file mode 100644
index 0000000..4220f40
--- /dev/null
+++ b/chrome/common/extensions/api/notification_provider.idl
@@ -0,0 +1,132 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Use the <code>chrome.notificationProvider</code> API to intercept
+// notifications that would otherwise go into the Chrome Notification Center,
+// get notifiers' information, and inform notifiers about users' actions on the
+// notifications.
+namespace notificationProvider {
+
+ // TODO(liyanhou): Use notifications.PermissionLevel everywhere and delete
+ // this type. See http://crbug.com/398266.
+
+ // whether notifications from this notifier is permitted or blocked.
+ enum NotifierPermissionLevel {
+ // User has elected to show notifications from the notifier.
+ // This is the default at install time.
+ granted,
+
+ // User has elected not to show notifications from the notifier.
+ denied
+ };
+
+ dictionary Notifier {
+ // Name of the notifier.
+ DOMString name;
+
+ // Icon of the notifier.
+ notifications.NotificationBitmap notifierIcon;
+
+ // Permission level of the notifier.
+ NotifierPermissionLevel permissionLevel;
+
+ // If a notifier has advanced settings.
+ boolean hasSettings;
+ };
+
+ callback NotifyOnClearedCallback = void (boolean wasCleared);
+
+ callback NotifyOnClickedCallback = void (boolean matchExists);
+
+ callback NotifyOnButtonClickedCallback = void (boolean matchExists);
+
+ callback NotifyOnPermissionLevelChangedCallback =
+ void (boolean notifierExists);
+
+ callback NotifyOnShowSettingsCallback = void (boolean notifierExists);
+
+ callback GetNotifierCallback = void (Notifier notifier);
+
+ callback GetAllNotifiersCallback = void (Notifier[] notifiers);
+
+ interface Functions {
+ // Inform the notifier that the user cleared a notification sent from that
+ // notifier.
+ // |notifierId|: The id of the notifier that sent the notification.
+ // |notificationId|: The id of the notification that was closed.
+ // |callback|: Called to indicate whether a matching notification existed.
+ static void notifyOnCleared(DOMString notifierId,
+ DOMString notificationId,
+ NotifyOnClearedCallback callback);
+
+ // Inform the notifier that the user clicked in a non-button area of a
+ // notification sent from that notifier.
+ // |notifierId|: The id of the notifier that sent the notification.
+ // |notificationId|: The id of the notification that was clicked on.
+ // |callback|: Called to indicate whether a matching notification existed.
+ static void notifyOnClicked(DOMString notifierId,
+ DOMString notificationId,
+ NotifyOnClickedCallback callback);
+
+ // Inform the notifier that the user pressed a button in the notification
+ // sent from that notifier.
+ // |notifierId|: The id of the notifier that sent the notification.
+ // |notificationId|: The id of the notification that was clicked on its
+ // button.
+ // |buttonIndex|: The index of the button that was clicked.
+ // |callback|: Called to indicate whether a matching notification existed.
+ static void notifyOnButtonClicked(DOMString notifierId,
+ DOMString notificationId,
+ long buttonIndex,
+ NotifyOnButtonClickedCallback callback);
+
+ // Inform the notifier that the user changed the permission level of that
+ // notifier.
+ // |notifierId|: The id of the notifier that sent the notification.
+ // |level|: The perission level of the notifier
+ // |callback|: Called to indicate whether the notifier existed.
+ static void notifyOnPermissionLevelChanged(
+ DOMString notifierId,
+ NotifierPermissionLevel level,
+ NotifyOnPermissionLevelChangedCallback callback);
+
+ // Inform the notifier that the user chose to see advanced settings of that
+ // notifier.
+ // |notifierId|: The id of the notifier that sent the notification.
+ // |callback|: Called to indicate whether a matching notifier existed.
+ static void notifyOnShowSettings(DOMString notifierId,
+ NotifyOnShowSettingsCallback callback);
+
+ // To get a notifier from it's notifier ID.
+ // |callback|: Returns the notifier object of the given ID.
+ static void getNotifier(GetNotifierCallback callback);
+
+ // To get all the notifiers that could send notifications.
+ // |callback|: Returns the set of notifiers currently in the system.
+ static void getAllNotifiers(GetAllNotifiersCallback callback);
+ };
+
+ interface Events {
+ // A new notification is created.
+ // |notifierId|: The id of the notifier that sent the new notification.
+ // |notificationId|: The id of the newly created notification.
+ // |options|: The content of the notification: type, title, message etc.
+ static void onCreated(DOMString notifierId,
+ DOMString notificationId,
+ notifications.NotificationOptions options);
+
+ // A notification is updated by the notifier.
+ // |notifierId|: The id of the notifier that sent the updated notification.
+ // |notificationId|: The id of the updated notification.
+ // |options|: The content of the notification: type, title, message etc.
+ static void onUpdated(DOMString notifierId,
+ DOMString notificationId,
+ notifications.NotificationOptions options);
+
+ // A notification is cleared by the notifier.
+ // |notifierId|: The id of the notifier that cleared the notification.
+ // |notificationId|: The id of the cleared notification.
+ static void onCleared(DOMString notifierId, DOMString notificationId);
+ };
+};
diff --git a/chrome/common/extensions/permissions/chrome_api_permissions.cc b/chrome/common/extensions/permissions/chrome_api_permissions.cc
index 6a7fe37..64258b8 100644
--- a/chrome/common/extensions/permissions/chrome_api_permissions.cc
+++ b/chrome/common/extensions/permissions/chrome_api_permissions.cc
@@ -83,6 +83,7 @@ std::vector<APIPermissionInfo*> ChromeAPIPermissions::GetAllPermissions()
APIPermissionInfo::kFlagCannotBeOptional},
{APIPermission::kGcdPrivate, "gcdPrivate"},
{APIPermission::kGcm, "gcm"},
+ {APIPermission::kNotificationProvider, "notificationProvider"},
// Register extension permissions.
{APIPermission::kAccessibilityFeaturesModify,
diff --git a/chrome/common/extensions/permissions/permission_set_unittest.cc b/chrome/common/extensions/permissions/permission_set_unittest.cc
index 3ec38f5..3c5a3c5 100644
--- a/chrome/common/extensions/permissions/permission_set_unittest.cc
+++ b/chrome/common/extensions/permissions/permission_set_unittest.cc
@@ -656,6 +656,7 @@ TEST(PermissionsTest, PermissionMessages) {
skip.insert(APIPermission::kLedger);
skip.insert(APIPermission::kLogPrivate);
skip.insert(APIPermission::kNotifications);
+ skip.insert(APIPermission::kNotificationProvider);
skip.insert(APIPermission::kOverrideEscFullscreen);
skip.insert(APIPermission::kPointerLock);
skip.insert(APIPermission::kPower);
diff --git a/chrome/test/data/extensions/api_test/notification_provider/events/manifest.json b/chrome/test/data/extensions/api_test/notification_provider/events/manifest.json
new file mode 100644
index 0000000..7c058e3
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/notification_provider/events/manifest.json
@@ -0,0 +1,13 @@
+{
+ "name": "chrome.notificationProvider",
+ "version": "0.1",
+ "description": "Tests chrome.notificationProvider API events",
+ "app": {
+ "background": {
+ "scripts": ["test.js"]
+ }
+ },
+ "permissions": [
+ "notificationProvider"
+ ]
+} \ No newline at end of file
diff --git a/chrome/test/data/extensions/api_test/notification_provider/events/test.js b/chrome/test/data/extensions/api_test/notification_provider/events/test.js
new file mode 100644
index 0000000..215699d
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/notification_provider/events/test.js
@@ -0,0 +1,24 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+var testEvents = function() {
+
+ chrome.notificationProvider.onCreated.addListener(function(senderId,
+ notificationId,
+ options) {
+ chrome.test.succeed();
+ });
+
+ chrome.notificationProvider.onUpdated.addListener(function(senderId,
+ notificationId,
+ options) {
+ chrome.test.succeed();
+ });
+
+ chrome.notificationProvider.onCleared.addListener(function(senderId,
+ notificationId) {
+ chrome.test.succeed();
+ });
+};
+
+chrome.test.runTests([ testEvents ]); \ No newline at end of file
diff --git a/extensions/browser/extension_function_histogram_value.h b/extensions/browser/extension_function_histogram_value.h
index d904948..402970f 100644
--- a/extensions/browser/extension_function_histogram_value.h
+++ b/extensions/browser/extension_function_histogram_value.h
@@ -912,6 +912,14 @@ enum HistogramValue {
EXPERIENCESAMPLINGPRIVATE_GETBROWSERINFO,
EASYUNLOCKPRIVATE_SEEKBLUETOOTHDEVICEBYADDRESS,
EASYUNLOCKPRIVATE_GETSTRINGS,
+ NOTIFICATIONPROVIDER_SENDONCLEAR,
+ NOTIFICATIONPROVIDER_NOTIFYONCLEARED,
+ NOTIFICATIONPROVIDER_NOTIFYONCLICKED,
+ NOTIFICATIONPROVIDER_NOTIFYONBUTTONCLICKED,
+ NOTIFICATIONPROVIDER_NOTIFYONPERMISSIONLEVELCHANGED,
+ NOTIFICATIONPROVIDER_NOTIFYONSHOWSETTINGS,
+ NOTIFICATIONPROVIDER_GETNOTIFIER,
+ NOTIFICATIONPROVIDER_GETALLNOTIFIERS,
// Last entry: Add new entries above and ensure to update
// tools/metrics/histograms/histograms/histograms.xml.
ENUM_BOUNDARY
diff --git a/extensions/common/permissions/api_permission.h b/extensions/common/permissions/api_permission.h
index 458df8b..2ca8e45 100644
--- a/extensions/common/permissions/api_permission.h
+++ b/extensions/common/permissions/api_permission.h
@@ -123,6 +123,7 @@ class APIPermission {
kMusicManagerPrivate,
kNativeMessaging,
kNetworkingPrivate,
+ kNotificationProvider,
kNotifications,
kOverrideEscFullscreen,
kPageCapture,
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 4f986de..a0bf846 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -39462,6 +39462,13 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="851" label="EXPERIENCESAMPLINGPRIVATE_GETBROWSERINFO"/>
<int value="852" label="EASYUNLOCKPRIVATE_SEEKBLUETOOTHDEVICEBYADDRESS"/>
<int value="853" label="EASYUNLOCKPRIVATE_GETSTRINGS"/>
+ <int value="854" label="NOTIFICATIONPROVIDER_NOTIFYONCLEARED"/>
+ <int value="855" label="NOTIFICATIONPROVIDER_NOTIFYONCLICKED"/>
+ <int value="856" label="NOTIFICATIONPROVIDER_NOTIFYONBUTTONCLICKED"/>
+ <int value="857" label="NOTIFICATIONPROVIDER_NOTIFYONPERMISSIONLEVELCHANGED"/>
+ <int value="858" label="NOTIFICATIONPROVIDER_NOTIFYONSHOWSETTINGS"/>
+ <int value="859" label="NOTIFICATIONPROVIDER_GETNOTIFIER"/>
+ <int value="860" label="NOTIFICATIONPROVIDER_GETALLNOTIFIERS"/>
</enum>
<enum name="ExtensionInstallCause" type="int">