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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_NOTIFICATION_PROVIDER_NOTIFICATION_PROVIDER_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_NOTIFICATION_PROVIDER_NOTIFICATION_PROVIDER_API_H_
10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/extensions/chrome_extension_function.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/extensions/api/notification_provider.h"
14 #include "extensions/browser/extension_function.h"
15 #include "ui/message_center/notification_types.h"
17 namespace extensions
{
19 // Send events to the client. This will send events onCreated, onUpdated and
20 // onCleared to extensions/apps using this API.
21 class NotificationProviderEventRouter
{
23 explicit NotificationProviderEventRouter(Profile
* profile
);
24 virtual ~NotificationProviderEventRouter();
26 void CreateNotification(
27 const std::string
& notification_provider_id
,
28 const std::string
& sender_id
,
29 const std::string
& notification_id
,
30 const api::notifications::NotificationOptions
& options
);
31 void UpdateNotification(
32 const std::string
& notification_provider_id
,
33 const std::string
& sender_id
,
34 const std::string
& notificaiton_id
,
35 const api::notifications::NotificationOptions
& options
);
36 void ClearNotification(const std::string
& notification_provider_id
,
37 const std::string
& sender_id
,
38 const std::string
& notification_id
);
41 void Create(const std::string
& notification_provider_id
,
42 const std::string
& sender_id
,
43 const std::string
& notification_id
,
44 const api::notifications::NotificationOptions
& options
);
45 void Update(const std::string
& notification_provider_id
,
46 const std::string
& sender_id
,
47 const std::string
& notification_id
,
48 const api::notifications::NotificationOptions
& options
);
49 void Clear(const std::string
& notification_provider_id
,
50 const std::string
& sender_id
,
51 const std::string
& notification_id
);
55 DISALLOW_COPY_AND_ASSIGN(NotificationProviderEventRouter
);
58 // Implememtation of NotifyOnCleared function of the API. It will inform the
59 // notifier that the user cleared a notification sent from that notifier.
60 class NotificationProviderNotifyOnClearedFunction
61 : public ChromeUIThreadExtensionFunction
{
63 NotificationProviderNotifyOnClearedFunction();
66 ~NotificationProviderNotifyOnClearedFunction() override
;
69 DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnCleared",
70 NOTIFICATIONPROVIDER_NOTIFYONCLEARED
);
72 // UIThreadExtensionFunction implementation.
73 ExtensionFunction::ResponseAction
Run() override
;
76 // Implememtation of NotifyOnClicked function of the API. It will inform the
77 // notifier that the user clicked in a non-button area of a notification sent
78 // from that notifier.
79 class NotificationProviderNotifyOnClickedFunction
80 : public ChromeUIThreadExtensionFunction
{
82 NotificationProviderNotifyOnClickedFunction();
85 ~NotificationProviderNotifyOnClickedFunction() override
;
88 DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnClicked",
89 NOTIFICATIONPROVIDER_NOTIFYONCLICKED
);
91 // UIThreadExtensionFunction implementation.
92 ExtensionFunction::ResponseAction
Run() override
;
95 // Implememtation of NotifyOnButtonClicked function of the API. It will inform
97 // notifier that the user pressed a button in the notification sent from that
99 class NotificationProviderNotifyOnButtonClickedFunction
100 : public ChromeUIThreadExtensionFunction
{
102 NotificationProviderNotifyOnButtonClickedFunction();
105 ~NotificationProviderNotifyOnButtonClickedFunction() override
;
108 DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnButtonClicked",
109 NOTIFICATIONPROVIDER_NOTIFYONBUTTONCLICKED
);
111 // UIThreadExtensionFunction implementation.
112 ExtensionFunction::ResponseAction
Run() override
;
115 // Implememtation of NotifyOnPermissionLevelChanged function of the API. It will
116 // inform the notifier that the user changed the permission level of that
118 class NotificationProviderNotifyOnPermissionLevelChangedFunction
119 : public ChromeUIThreadExtensionFunction
{
121 NotificationProviderNotifyOnPermissionLevelChangedFunction();
124 ~NotificationProviderNotifyOnPermissionLevelChangedFunction() override
;
127 DECLARE_EXTENSION_FUNCTION(
128 "notificationProvider.notifyOnPermissionLevelChanged",
129 NOTIFICATIONPROVIDER_NOTIFYONPERMISSIONLEVELCHANGED
);
131 // UIThreadExtensionFunction implementation.
132 ExtensionFunction::ResponseAction
Run() override
;
135 // Implememtation of NotifyOnShowSettings function of the API. It will inform
136 // the notifier that the user clicked on advanced settings of that notifier.
137 class NotificationProviderNotifyOnShowSettingsFunction
138 : public ChromeUIThreadExtensionFunction
{
140 NotificationProviderNotifyOnShowSettingsFunction();
143 ~NotificationProviderNotifyOnShowSettingsFunction() override
;
146 DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnShowSettings",
147 NOTIFICATIONPROVIDER_NOTIFYONSHOWSETTINGS
);
149 // UIThreadExtensionFunction implementation.
150 ExtensionFunction::ResponseAction
Run() override
;
153 // Implememtation of GetNotifier function of the API. It will get the notifier
154 // object that corresponds to the notifier ID.
155 class NotificationProviderGetNotifierFunction
156 : public ChromeUIThreadExtensionFunction
{
158 NotificationProviderGetNotifierFunction();
161 ~NotificationProviderGetNotifierFunction() override
;
164 DECLARE_EXTENSION_FUNCTION("notificationProvider.getNotifier",
165 NOTIFICATIONPROVIDER_GETNOTIFIER
);
167 // UIThreadExtensionFunction implementation.
168 ExtensionFunction::ResponseAction
Run() override
;
171 // Implememtation of GetAllNotifiers function of the API. It will get all the
172 // notifiers that would send notifications.
173 class NotificationProviderGetAllNotifiersFunction
174 : public ChromeUIThreadExtensionFunction
{
176 NotificationProviderGetAllNotifiersFunction();
179 ~NotificationProviderGetAllNotifiersFunction() override
;
182 DECLARE_EXTENSION_FUNCTION("notificationProvider.getAllNotifiers",
183 NOTIFICATIONPROVIDER_GETALLNOTIFIERS
);
185 // UIThreadExtensionFunction implementation.
186 ExtensionFunction::ResponseAction
Run() override
;
189 } // namespace extensions
191 #endif // CHROME_BROWSER_EXTENSIONS_API_NOTIFICATION_PROVIDER_NOTIFICATION_PROVIDER_API_H_