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/containers/id_map.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/synchronization/lock.h"
15 //#include "content/public/browser/desktop_notification_delegate.h"
16 #include "content/public/browser/platform_notification_service.h"
17 #include "public/ewk_notification_internal.h"
18 #include "third_party/blink/public/platform/modules/permissions/permission_status.mojom.h"
24 #if !defined(EWK_BRINGUP) // FIXME: m67 bringup
25 // DesktopNotificationDelegate is not defined
26 struct NotificationData {
27 const std::string origin_url;
28 const base::string16 replace_id;
29 std::unique_ptr<DesktopNotificationDelegate> notification_delegate;
31 NotificationData(const GURL& origin,
32 const base::string16& replaceid,
33 std::unique_ptr<DesktopNotificationDelegate> delegate)
34 : origin_url(origin.spec()),
35 replace_id(replaceid),
36 notification_delegate(std::move(delegate)) {}
38 #endif // !defined(EWK_BRINGUP)
39 class NotificationControllerEfl: public PlatformNotificationService {
41 NotificationControllerEfl();
42 ~NotificationControllerEfl();
43 #if !defined(EWK_BRINGUP) // FIXME: m67 bringup
44 // DesktopNotificationDelegate is not defined
45 // Adds a new notification received from engine to a list
46 void NotificationAdd(uint64_t notification_id, const GURL& origin,
47 const base::string16& replace_id,
48 std::unique_ptr<DesktopNotificationDelegate> delegate);
50 bool NotificationClosed(uint64_t notification_id, bool by_user);
52 void NotificationCancelled(uint64_t notification_id);
53 #if !defined(EWK_BRINGUP) // FIXME: m67 bringup
54 // DesktopNotificationDelegate is not defined
55 // Notify engine when user clicked on the notification
56 bool NotificationClicked(uint64_t notification_id);
58 // Notification engine that notification was displayed
59 bool NotificationDisplayed(uint64_t notification_id);
61 // sets the permission for a particular pending notification
62 void SetPermissionForNotification(
63 Ewk_Notification_Permission_Request* notification,
66 // Adds permission to map
67 void AddPermission(const GURL origin, bool allowed);
69 // Removes all stored permissions
70 void ClearPermissions();
72 // Removes stored permissions for given origins
73 void RemovePermissions(Eina_List* origins);
75 #if !defined(EWK_BRINGUP) // FIXME: m67 bringup
76 // DesktopNotificationDelegate is not defined
77 // Checks if the notification is already present.
78 // If present returns the notification id of the notification else false
79 bool IsNotificationPresent(const GURL& origin,
80 const base::string16& replaceid, uint64_t& notification_id);
82 void RequestPermission(WebContents* web_contents,
83 const GURL& requesting_frame,
84 const base::Callback<void(
85 blink::mojom::PermissionStatus)>& result_callback);
87 void SetNotificationCallbacks(Ewk_Notification_Show_Callback show_callback,
88 Ewk_Notification_Cancel_Callback close_callback, void* user_data);
90 /* PlatformNotificationService */
91 blink::mojom::PermissionStatus CheckPermissionOnUIThread(
92 BrowserContext* browser_context, const GURL& origin,
93 int render_process_id) override;
95 // Checks if |origin| has permission to display Web Notifications. This method
96 // exists to serve the synchronous IPC required by the Notification.permission
97 // JavaScript getter, and should not be used for other purposes. See
98 // https://crbug.com/446497 for the plan to deprecate this method.
99 // This method must only be called on the IO thread.
100 blink::mojom::PermissionStatus CheckPermissionOnIOThread(
101 ResourceContext* resource_context,
103 int render_process_id) override;
105 // Displays the notification described in |params| to the user. A closure
106 // through which the notification can be closed will be stored in the
107 // |cancel_callback| argument. This method must be called on the UI thread.
108 void DisplayNotification(
109 BrowserContext* browser_context,
110 const std::string& notification_id,
112 const PlatformNotificationData& notification_data,
113 const NotificationResources& notification_resources) override;
115 // Displays the persistent notification described in |notification_data| to
116 // the user. This method must be called on the UI thread.
117 void DisplayPersistentNotification(
118 BrowserContext* browser_context,
119 const std::string& notification_id,
120 const GURL& service_worker_origin,
122 const PlatformNotificationData& notification_data,
123 const NotificationResources& notification_resources) override;
125 // Closes the persistent notification identified by
126 // |persistent_notification_id|. This method must be called on the UI thread.
127 void ClosePersistentNotification(BrowserContext* browser_context,
128 const std::string& notification_id) override;
130 // FIXME: Removed in upstream
132 // Writes the ids of all currently displaying persistent notifications for the
133 // given |browser_context| to |displayed_notifications|. Returns whether the
134 // platform is able to provide such a set.
135 bool GetDisplayedPersistentNotifications(
136 BrowserContext* browser_context,
137 std::set<std::string>* displayed_notifications);
140 blink::mojom::PermissionStatus CheckPermissionForOrigin(
141 const GURL &origin) const;
143 // IDMap<NotificationData, IDMapOwnPointer> notifications_map_; // This stores
144 // the notifications displayed to the user
145 std::map<GURL, bool> permissions_map_;
146 mutable base::Lock permissions_mutex_;
148 Ewk_Notification_Show_Callback notification_show_callback_;
149 Ewk_Notification_Cancel_Callback notification_cancel_callback_;
150 void* notification_callback_user_data_;
152 base::WeakPtrFactory<NotificationControllerEfl> weak_factory_;
154 DISALLOW_COPY_AND_ASSIGN(NotificationControllerEfl);
159 #endif // NOTIFICATION_CONTROLLER_EFL_H