1 // Copyright 2013 Samsung Electronics. 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 NOTIFICATION_CONTROLLER_EFL_H
6 #define NOTIFICATION_CONTROLLER_EFL_H
12 #include "base/id_map.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/synchronization/lock.h"
16 #include "content/public/browser/desktop_notification_delegate.h"
17 #include "content/public/browser/platform_notification_service.h"
18 #include "content/public/common/permission_status.mojom.h"
19 #include "public/ewk_notification.h"
25 struct NotificationData {
26 const std::string origin_url;
27 const base::string16 replace_id;
28 scoped_ptr<DesktopNotificationDelegate> notification_delegate;
30 NotificationData(const GURL& origin,
31 const base::string16& replaceid,
32 scoped_ptr<DesktopNotificationDelegate> delegate)
33 : origin_url(origin.spec()),
34 replace_id(replaceid),
35 notification_delegate(std::move(delegate)) {}
38 class NotificationControllerEfl: public PlatformNotificationService {
40 NotificationControllerEfl();
41 ~NotificationControllerEfl();
43 // Adds a new notification received from engine to a list
44 void NotificationAdd(uint64_t notification_id, const GURL& origin,
45 const base::string16& replace_id,
46 scoped_ptr<DesktopNotificationDelegate> delegate);
48 bool NotificationClosed(uint64_t notification_id, bool by_user);
50 void NotificationCancelled(uint64_t notification_id);
52 // Notify engine when user clicked on the notification
53 bool NotificationClicked(uint64_t notification_id);
55 // Notification engine that notification was displayed
56 bool NotificationDisplayed(uint64_t notification_id);
58 // sets the permission for a particular pending notification
59 void SetPermissionForNotification(
60 Ewk_Notification_Permission_Request* notification,
63 // Adds permission to map
64 void AddPermission(const GURL origin, bool allowed);
66 // Removes all stored permissions
67 void ClearPermissions();
69 // Removes stored permissions for given origins
70 void RemovePermissions(Eina_List* origins);
72 // Checks if the notification is already present.
73 // If present returns the notification id of the notification else false
74 bool IsNotificationPresent(const GURL& origin,
75 const base::string16& replaceid, uint64_t& notification_id);
77 void RequestPermission(WebContents* web_contents,
78 const GURL& requesting_frame,
79 const base::Callback<void(PermissionStatus)>& result_callback);
81 void SetNotificationCallbacks(Ewk_Notification_Show_Callback show_callback,
82 Ewk_Notification_Cancel_Callback close_callback, void* user_data);
84 /* PlatformNotificationService */
85 blink::WebNotificationPermission CheckPermissionOnUIThread(
86 BrowserContext* browser_context, const GURL& origin,
87 int render_process_id) override;
89 // Checks if |origin| has permission to display Web Notifications. This method
90 // exists to serve the synchronous IPC required by the Notification.permission
91 // JavaScript getter, and should not be used for other purposes. See
92 // https://crbug.com/446497 for the plan to deprecate this method.
93 // This method must only be called on the IO thread.
94 blink::WebNotificationPermission CheckPermissionOnIOThread(
95 ResourceContext* resource_context,
97 int render_process_id) override;
99 // Displays the notification described in |params| to the user. A closure
100 // through which the notification can be closed will be stored in the
101 // |cancel_callback| argument. This method must be called on the UI thread.
102 void DisplayNotification(
103 BrowserContext* browser_context,
105 const SkBitmap& icon,
106 const PlatformNotificationData& notification_data,
107 scoped_ptr<DesktopNotificationDelegate> delegate,
108 base::Closure* cancel_callback) override;
110 // Displays the persistent notification described in |notification_data| to
111 // the user. This method must be called on the UI thread.
112 void DisplayPersistentNotification(
113 BrowserContext* browser_context,
114 int64_t service_worker_registration_id,
116 const SkBitmap& icon,
117 const PlatformNotificationData& notification_data) override;
119 // Closes the persistent notification identified by
120 // |persistent_notification_id|. This method must be called on the UI thread.
121 void ClosePersistentNotification(
122 BrowserContext* browser_context,
123 int64_t persistent_notification_id) override;
125 // Writes the ids of all currently displaying persistent notifications for the
126 // given |browser_context| to |displayed_notifications|. Returns whether the
127 // platform is able to provide such a set.
128 bool GetDisplayedPersistentNotifications(
129 BrowserContext* browser_context,
130 std::set<std::string>* displayed_notifications) override;
133 blink::WebNotificationPermission CheckPermissionForOrigin(
134 const GURL &origin) const;
136 IDMap<NotificationData, IDMapOwnPointer> notifications_map_; // This stores the notifications displayed to the user
137 std::map<GURL, bool> permissions_map_;
138 mutable base::Lock permissions_mutex_;
140 Ewk_Notification_Show_Callback notification_show_callback_;
141 Ewk_Notification_Cancel_Callback notification_cancel_callback_;
142 void* notification_callback_user_data_;
144 base::WeakPtrFactory<NotificationControllerEfl> weak_factory_;
146 DISALLOW_COPY_AND_ASSIGN(NotificationControllerEfl);
151 #endif // NOTIFICATION_CONTROLLER_EFL_H