1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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:
~NotificationProviderNotifyOnClearedFunction() override;
private:
DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnCleared",
NOTIFICATIONPROVIDER_NOTIFYONCLEARED);
// UIThreadExtensionFunction implementation.
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:
~NotificationProviderNotifyOnClickedFunction() override;
private:
DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnClicked",
NOTIFICATIONPROVIDER_NOTIFYONCLICKED);
// UIThreadExtensionFunction implementation.
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:
~NotificationProviderNotifyOnButtonClickedFunction() override;
private:
DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnButtonClicked",
NOTIFICATIONPROVIDER_NOTIFYONBUTTONCLICKED);
// UIThreadExtensionFunction implementation.
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:
~NotificationProviderNotifyOnPermissionLevelChangedFunction() override;
private:
DECLARE_EXTENSION_FUNCTION(
"notificationProvider.notifyOnPermissionLevelChanged",
NOTIFICATIONPROVIDER_NOTIFYONPERMISSIONLEVELCHANGED);
// UIThreadExtensionFunction implementation.
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:
~NotificationProviderNotifyOnShowSettingsFunction() override;
private:
DECLARE_EXTENSION_FUNCTION("notificationProvider.notifyOnShowSettings",
NOTIFICATIONPROVIDER_NOTIFYONSHOWSETTINGS);
// UIThreadExtensionFunction implementation.
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:
~NotificationProviderGetNotifierFunction() override;
private:
DECLARE_EXTENSION_FUNCTION("notificationProvider.getNotifier",
NOTIFICATIONPROVIDER_GETNOTIFIER);
// UIThreadExtensionFunction implementation.
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:
~NotificationProviderGetAllNotifiersFunction() override;
private:
DECLARE_EXTENSION_FUNCTION("notificationProvider.getAllNotifiers",
NOTIFICATIONPROVIDER_GETALLNOTIFIERS);
// UIThreadExtensionFunction implementation.
ExtensionFunction::ResponseAction Run() override;
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_NOTIFICATION_PROVIDER_NOTIFICATION_PROVIDER_API_H_
|