| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "content/common/content_export.h" | 11 #include "content/common/content_export.h" |
| 12 #include "content/public/common/push_messaging_status.h" | 12 #include "content/public/common/push_messaging_status.h" |
| 13 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi
ssionStatus.h" | 13 #include "third_party/WebKit/public/platform/modules/push_messaging/WebPushPermi
ssionStatus.h" |
| 14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 class BrowserContext; | 18 class BrowserContext; |
| 19 class ServiceWorkerContext; | 19 class ServiceWorkerContext; |
| 20 | 20 |
| 21 // A push service-agnostic interface that the Push API uses for talking to | 21 // 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. | 22 // push messaging services like GCM. Must only be used on the UI thread. |
| 23 class CONTENT_EXPORT PushMessagingService { | 23 class CONTENT_EXPORT PushMessagingService { |
| 24 public: | 24 public: |
| 25 using RegisterCallback = | 25 using SubscribeCallback = |
| 26 base::Callback<void(const std::string& /* registration_id */, | 26 base::Callback<void(const std::string& /* subscription_id */, |
| 27 PushRegistrationStatus /* status */)>; | 27 PushSubscriptionStatus /* status */)>; |
| 28 using UnregisterCallback = base::Callback<void(PushUnregistrationStatus)>; | 28 using UnsubscribeCallback = base::Callback<void(PushUnsubscriptionStatus)>; |
| 29 | 29 |
| 30 using StringCallback = base::Callback<void(const std::string& data, | 30 using StringCallback = base::Callback<void(const std::string& data, |
| 31 bool success, | 31 bool success, |
| 32 bool not_found)>; | 32 bool not_found)>; |
| 33 | 33 |
| 34 using ResultCallback = base::Callback<void(bool success)>; | 34 using ResultCallback = base::Callback<void(bool success)>; |
| 35 | 35 |
| 36 virtual ~PushMessagingService() {} | 36 virtual ~PushMessagingService() {} |
| 37 | 37 |
| 38 // Returns the absolute URL exposed by the push server where the webapp server | 38 // 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 | 39 // can send push messages. This is currently assumed to be the same for all |
| 40 // origins and push registrations. | 40 // origins and push subscriptions. |
| 41 virtual GURL GetPushEndpoint() = 0; | 41 virtual GURL GetPushEndpoint() = 0; |
| 42 | 42 |
| 43 // Register the given |sender_id| with the push messaging service in a | 43 // 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 | 44 // document context. The frame is known and a permission UI may be displayed |
| 45 // to the user. | 45 // to the user. |
| 46 virtual void RegisterFromDocument(const GURL& requesting_origin, | 46 virtual void SubscribeFromDocument(const GURL& requesting_origin, |
| 47 int64 service_worker_registration_id, | 47 int64 service_worker_registration_id, |
| 48 const std::string& sender_id, | 48 const std::string& sender_id, |
| 49 int renderer_id, | 49 int renderer_id, |
| 50 int render_frame_id, | 50 int render_frame_id, |
| 51 bool user_visible, | 51 bool user_visible, |
| 52 const RegisterCallback& callback) = 0; | 52 const SubscribeCallback& callback) = 0; |
| 53 | 53 |
| 54 // Register the given |sender_id| with the push messaging service. The frame | 54 // 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 | 55 // is not known so if permission was not previously granted by the user this |
| 56 // request should fail. | 56 // request should fail. |
| 57 virtual void RegisterFromWorker(const GURL& requesting_origin, | 57 virtual void SubscribeFromWorker(const GURL& requesting_origin, |
| 58 int64 service_worker_registration_id, | 58 int64 service_worker_registration_id, |
| 59 const std::string& sender_id, | 59 const std::string& sender_id, |
| 60 bool user_visible, | 60 bool user_visible, |
| 61 const RegisterCallback& callback) = 0; | 61 const SubscribeCallback& callback) = 0; |
| 62 | 62 |
| 63 // Unregister the given |sender_id| from the push messaging service. The | 63 // Unsubscribe the given |sender_id| from the push messaging service. The |
| 64 // registration will be synchronously deactivated locally, and asynchronously | 64 // subscription will be synchronously deactivated locally, and asynchronously |
| 65 // sent to the push service, with automatic retry. | 65 // sent to the push service, with automatic retry. |
| 66 virtual void Unregister(const GURL& requesting_origin, | 66 virtual void Unsubscribe(const GURL& requesting_origin, |
| 67 int64 service_worker_registration_id, | 67 int64 service_worker_registration_id, |
| 68 const std::string& sender_id, | 68 const std::string& sender_id, |
| 69 const UnregisterCallback& callback) = 0; | 69 const UnsubscribeCallback& callback) = 0; |
| 70 | 70 |
| 71 // Checks the permission status for the requesting origin. Permission is only | 71 // Checks the permission status for the requesting origin. Permission is only |
| 72 // ever granted when the requesting origin matches the top level embedding | 72 // ever granted when the requesting origin matches the top level embedding |
| 73 // origin. The |user_visible| boolean indicates whether the permission status | 73 // origin. The |user_visible| boolean indicates whether the permission status |
| 74 // only has to cover push messages resulting in visible effects to the user. | 74 // only has to cover push messages resulting in visible effects to the user. |
| 75 virtual blink::WebPushPermissionStatus GetPermissionStatus( | 75 virtual blink::WebPushPermissionStatus GetPermissionStatus( |
| 76 const GURL& requesting_origin, | 76 const GURL& requesting_origin, |
| 77 const GURL& embedding_origin, | 77 const GURL& embedding_origin, |
| 78 bool user_visible) = 0; | 78 bool user_visible) = 0; |
| 79 | 79 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 91 int64 service_worker_registration_id, | 91 int64 service_worker_registration_id, |
| 92 const GURL& origin, | 92 const GURL& origin, |
| 93 const std::string& notifications_shown, | 93 const std::string& notifications_shown, |
| 94 const ResultCallback& callback); | 94 const ResultCallback& callback); |
| 95 | 95 |
| 96 static void GetSenderId(BrowserContext* browser_context, | 96 static void GetSenderId(BrowserContext* browser_context, |
| 97 const GURL& origin, | 97 const GURL& origin, |
| 98 int64 service_worker_registration_id, | 98 int64 service_worker_registration_id, |
| 99 const StringCallback& callback); | 99 const StringCallback& callback); |
| 100 | 100 |
| 101 // Clear the push registration id stored in the service worker with the given | 101 // Clear the push subscription id stored in the service worker with the given |
| 102 // |service_worker_registration_id| for the given |origin|. | 102 // |service_worker_registration_id| for the given |origin|. |
| 103 static void ClearPushRegistrationID(BrowserContext* browser_context, | 103 static void ClearPushSubscriptionID(BrowserContext* browser_context, |
| 104 const GURL& origin, | 104 const GURL& origin, |
| 105 int64 service_worker_registration_id, | 105 int64 service_worker_registration_id, |
| 106 const base::Closure& callback); | 106 const base::Closure& callback); |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 } // namespace content | 109 } // namespace content |
| 110 | 110 |
| 111 #endif // CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_ | 111 #endif // CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_ |
| OLD | NEW |