1 // Copyright (c) 2012 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_NOTIFICATIONS_NOTIFICATIONS_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_
10 #include "base/memory/ref_counted.h"
11 #include "chrome/browser/extensions/chrome_extension_function.h"
12 #include "chrome/common/extensions/api/notifications.h"
13 #include "extensions/browser/extension_function.h"
14 #include "ui/message_center/notification_types.h"
18 namespace extensions
{
20 class NotificationsApiFunction
: public ChromeAsyncExtensionFunction
{
22 // Whether the current extension and channel allow the API. Public for
24 bool IsNotificationsApiAvailable();
27 NotificationsApiFunction();
28 ~NotificationsApiFunction() override
;
30 bool CreateNotification(const std::string
& id
,
31 api::notifications::NotificationOptions
* options
);
32 bool UpdateNotification(const std::string
& id
,
33 api::notifications::NotificationOptions
* options
,
34 Notification
* notification
);
36 bool IsNotificationsApiEnabled() const;
38 bool AreExtensionNotificationsAllowed() const;
40 // Returns true if the API function is still allowed to run even when the
41 // notifications for a notifier have been disabled.
42 virtual bool CanRunWhileDisabled() const;
44 // Called inside of RunAsync.
45 virtual bool RunNotificationsApi() = 0;
47 // UITHreadExtensionFunction:
48 bool RunAsync() override
;
50 message_center::NotificationType
MapApiTemplateTypeToType(
51 api::notifications::TemplateType type
);
54 class NotificationsCreateFunction
: public NotificationsApiFunction
{
56 NotificationsCreateFunction();
58 // NotificationsApiFunction:
59 bool RunNotificationsApi() override
;
62 ~NotificationsCreateFunction() override
;
65 scoped_ptr
<api::notifications::Create::Params
> params_
;
67 DECLARE_EXTENSION_FUNCTION("notifications.create", NOTIFICATIONS_CREATE
)
70 class NotificationsUpdateFunction
: public NotificationsApiFunction
{
72 NotificationsUpdateFunction();
74 // NotificationsApiFunction:
75 bool RunNotificationsApi() override
;
78 ~NotificationsUpdateFunction() override
;
81 scoped_ptr
<api::notifications::Update::Params
> params_
;
83 DECLARE_EXTENSION_FUNCTION("notifications.update", NOTIFICATIONS_UPDATE
)
86 class NotificationsClearFunction
: public NotificationsApiFunction
{
88 NotificationsClearFunction();
90 // NotificationsApiFunction:
91 bool RunNotificationsApi() override
;
94 ~NotificationsClearFunction() override
;
97 scoped_ptr
<api::notifications::Clear::Params
> params_
;
99 DECLARE_EXTENSION_FUNCTION("notifications.clear", NOTIFICATIONS_CLEAR
)
102 class NotificationsGetAllFunction
: public NotificationsApiFunction
{
104 NotificationsGetAllFunction();
106 // NotificationsApiFunction:
107 bool RunNotificationsApi() override
;
110 ~NotificationsGetAllFunction() override
;
113 DECLARE_EXTENSION_FUNCTION("notifications.getAll", NOTIFICATIONS_GET_ALL
)
116 class NotificationsGetPermissionLevelFunction
117 : public NotificationsApiFunction
{
119 NotificationsGetPermissionLevelFunction();
121 // NotificationsApiFunction:
122 bool CanRunWhileDisabled() const override
;
123 bool RunNotificationsApi() override
;
126 ~NotificationsGetPermissionLevelFunction() override
;
129 DECLARE_EXTENSION_FUNCTION("notifications.getPermissionLevel",
130 NOTIFICATIONS_GET_ALL
)
133 } // namespace extensions
135 #endif // CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_