OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_ |
6 #define CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_ | 6 #define CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_ |
7 | 7 |
| 8 #include <stdint.h> |
8 #include <string> | 9 #include <string> |
| 10 #include <vector> |
9 | 11 |
10 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
11 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
12 #include "content/public/common/push_messaging_status.h" | 14 #include "content/public/common/push_messaging_status.h" |
13 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi
ssionStatus.h" | 15 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi
ssionStatus.h" |
14 #include "url/gurl.h" | 16 #include "url/gurl.h" |
15 | 17 |
16 namespace content { | 18 namespace content { |
17 | 19 |
18 class BrowserContext; | 20 class BrowserContext; |
19 class ServiceWorkerContext; | 21 class ServiceWorkerContext; |
20 | 22 |
21 // A push service-agnostic interface that the Push API uses for talking to | 23 // A push service-agnostic interface that the Push API uses for talking to |
22 // push messaging services like GCM. Must only be used on the UI thread. | 24 // push messaging services like GCM. Must only be used on the UI thread. |
23 class CONTENT_EXPORT PushMessagingService { | 25 class CONTENT_EXPORT PushMessagingService { |
24 public: | 26 public: |
25 using RegisterCallback = | 27 using RegisterCallback = |
26 base::Callback<void(const std::string& /* registration_id */, | 28 base::Callback<void(const std::string& registration_id, |
27 PushRegistrationStatus /* status */)>; | 29 const std::vector<uint8_t>& curve25519dh, |
| 30 PushRegistrationStatus status)>; |
28 using UnregisterCallback = base::Callback<void(PushUnregistrationStatus)>; | 31 using UnregisterCallback = base::Callback<void(PushUnregistrationStatus)>; |
29 | 32 |
| 33 using PublicKeyCallback = base::Callback<void( |
| 34 bool success, |
| 35 const std::vector<uint8_t>& curve25519dh)>; |
| 36 |
30 using StringCallback = base::Callback<void(const std::string& data, | 37 using StringCallback = base::Callback<void(const std::string& data, |
31 bool success, | 38 bool success, |
32 bool not_found)>; | 39 bool not_found)>; |
33 | 40 |
34 using ResultCallback = base::Callback<void(bool success)>; | 41 using ResultCallback = base::Callback<void(bool success)>; |
35 | 42 |
36 virtual ~PushMessagingService() {} | 43 virtual ~PushMessagingService() {} |
37 | 44 |
38 // Returns the absolute URL exposed by the push server where the webapp server | 45 // Returns the absolute URL exposed by the push server where the webapp server |
39 // can send push messages. This is currently assumed to be the same for all | 46 // can send push messages. This is currently assumed to be the same for all |
40 // origins and push registrations. | 47 // origins and push registrations. |
41 virtual GURL GetPushEndpoint() = 0; | 48 virtual GURL GetPushEndpoint() = 0; |
42 | 49 |
43 // Subscribe the given |sender_id| with the push messaging service in a | 50 // Subscribe the given |sender_id| with the push messaging service in a |
44 // document context. The frame is known and a permission UI may be displayed | 51 // document context. The frame is known and a permission UI may be displayed |
45 // to the user. | 52 // to the user. |
46 virtual void SubscribeFromDocument(const GURL& requesting_origin, | 53 virtual void SubscribeFromDocument(const GURL& requesting_origin, |
47 int64 service_worker_registration_id, | 54 int64_t service_worker_registration_id, |
48 const std::string& sender_id, | 55 const std::string& sender_id, |
49 int renderer_id, | 56 int renderer_id, |
50 int render_frame_id, | 57 int render_frame_id, |
51 bool user_visible, | 58 bool user_visible, |
52 const RegisterCallback& callback) = 0; | 59 const RegisterCallback& callback) = 0; |
53 | 60 |
54 // Subscribe the given |sender_id| with the push messaging service. The frame | 61 // Subscribe the given |sender_id| with the push messaging service. The frame |
55 // is not known so if permission was not previously granted by the user this | 62 // is not known so if permission was not previously granted by the user this |
56 // request should fail. | 63 // request should fail. |
57 virtual void SubscribeFromWorker(const GURL& requesting_origin, | 64 virtual void SubscribeFromWorker(const GURL& requesting_origin, |
58 int64 service_worker_registration_id, | 65 int64_t service_worker_registration_id, |
59 const std::string& sender_id, | 66 const std::string& sender_id, |
60 bool user_visible, | 67 bool user_visible, |
61 const RegisterCallback& callback) = 0; | 68 const RegisterCallback& callback) = 0; |
62 | 69 |
| 70 // Retrieves the public encryption key associated with |origin| and |
| 71 // |service_worker_registration_id|, and invokes |callback| with the result |
| 72 // when it is available. |
| 73 virtual void GetPublicEncryptionKey(const GURL& origin, |
| 74 int64_t service_worker_registration_id, |
| 75 const PublicKeyCallback& callback) = 0; |
| 76 |
63 // Unsubscribe the given |sender_id| from the push messaging service. The | 77 // Unsubscribe the given |sender_id| from the push messaging service. The |
64 // subscription will be synchronously deactivated locally, and asynchronously | 78 // subscription will be synchronously deactivated locally, and asynchronously |
65 // sent to the push service, with automatic retry. | 79 // sent to the push service, with automatic retry. |
66 virtual void Unsubscribe(const GURL& requesting_origin, | 80 virtual void Unsubscribe(const GURL& requesting_origin, |
67 int64 service_worker_registration_id, | 81 int64_t service_worker_registration_id, |
68 const std::string& sender_id, | 82 const std::string& sender_id, |
69 const UnregisterCallback& callback) = 0; | 83 const UnregisterCallback& callback) = 0; |
70 | 84 |
71 // Checks the permission status for the requesting origin. Permission is only | 85 // Checks the permission status for the requesting origin. Permission is only |
72 // ever granted when the requesting origin matches the top level embedding | 86 // ever granted when the requesting origin matches the top level embedding |
73 // origin. The |user_visible| boolean indicates whether the permission status | 87 // origin. The |user_visible| boolean indicates whether the permission status |
74 // only has to cover push messages resulting in visible effects to the user. | 88 // only has to cover push messages resulting in visible effects to the user. |
75 virtual blink::WebPushPermissionStatus GetPermissionStatus( | 89 virtual blink::WebPushPermissionStatus GetPermissionStatus( |
76 const GURL& requesting_origin, | 90 const GURL& requesting_origin, |
77 const GURL& embedding_origin, | 91 const GURL& embedding_origin, |
78 bool user_visible) = 0; | 92 bool user_visible) = 0; |
79 | 93 |
80 // Returns whether subscriptions that do not mandate user visible UI upon | 94 // Returns whether subscriptions that do not mandate user visible UI upon |
81 // receiving a push message are supported. Influences permission request and | 95 // receiving a push message are supported. Influences permission request and |
82 // permission check behaviour. | 96 // permission check behaviour. |
83 virtual bool SupportNonVisibleMessages() = 0; | 97 virtual bool SupportNonVisibleMessages() = 0; |
84 | 98 |
85 // Provide a storage mechanism to read/write an opaque | 99 // Provide a storage mechanism to read/write an opaque |
86 // "notifications_shown_by_last_few_pushes" string associated with a Service | 100 // "notifications_shown_by_last_few_pushes" string associated with a Service |
87 // Worker registration. Stored data is deleted when the associated | 101 // Worker registration. Stored data is deleted when the associated |
88 // registration is deleted. | 102 // registration is deleted. |
89 static void GetNotificationsShownByLastFewPushes( | 103 static void GetNotificationsShownByLastFewPushes( |
90 ServiceWorkerContext* service_worker_context, | 104 ServiceWorkerContext* service_worker_context, |
91 int64 service_worker_registration_id, | 105 int64_t service_worker_registration_id, |
92 const StringCallback& callback); | 106 const StringCallback& callback); |
93 static void SetNotificationsShownByLastFewPushes( | 107 static void SetNotificationsShownByLastFewPushes( |
94 ServiceWorkerContext* service_worker_context, | 108 ServiceWorkerContext* service_worker_context, |
95 int64 service_worker_registration_id, | 109 int64_t service_worker_registration_id, |
96 const GURL& origin, | 110 const GURL& origin, |
97 const std::string& notifications_shown, | 111 const std::string& notifications_shown, |
98 const ResultCallback& callback); | 112 const ResultCallback& callback); |
99 | 113 |
100 protected: | 114 protected: |
101 static void GetSenderId(BrowserContext* browser_context, | 115 static void GetSenderId(BrowserContext* browser_context, |
102 const GURL& origin, | 116 const GURL& origin, |
103 int64 service_worker_registration_id, | 117 int64_t service_worker_registration_id, |
104 const StringCallback& callback); | 118 const StringCallback& callback); |
105 | 119 |
106 // Clear the push subscription id stored in the service worker with the given | 120 // Clear the push subscription id stored in the service worker with the given |
107 // |service_worker_registration_id| for the given |origin|. | 121 // |service_worker_registration_id| for the given |origin|. |
108 static void ClearPushSubscriptionID(BrowserContext* browser_context, | 122 static void ClearPushSubscriptionID(BrowserContext* browser_context, |
109 const GURL& origin, | 123 const GURL& origin, |
110 int64 service_worker_registration_id, | 124 int64_t service_worker_registration_id, |
111 const base::Closure& callback); | 125 const base::Closure& callback); |
112 }; | 126 }; |
113 | 127 |
114 } // namespace content | 128 } // namespace content |
115 | 129 |
116 #endif // CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_ | 130 #endif // CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_ |
OLD | NEW |