| 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.h" | 10 #include "base/callback.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 ServiceWorkerContext; | 19 class ServiceWorkerContext; |
| 19 | 20 |
| 20 // 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 |
| 21 // 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. |
| 22 class CONTENT_EXPORT PushMessagingService { | 23 class CONTENT_EXPORT PushMessagingService { |
| 23 public: | 24 public: |
| 24 using GetNotificationsShownCallback = | 25 using GetNotificationsShownCallback = |
| 25 base::Callback<void(const std::string& notifications_shown, | 26 base::Callback<void(const std::string& notifications_shown, |
| 26 bool success, bool not_found)>; | 27 bool success, bool not_found)>; |
| 27 | 28 |
| 28 using ResultCallback = base::Callback<void(bool success)>; | 29 using ResultCallback = base::Callback<void(bool success)>; |
| 29 | 30 |
| 30 using RegisterCallback = | 31 using RegisterCallback = |
| 31 base::Callback<void(const std::string& /* registration_id */, | 32 base::Callback<void(const std::string& /* registration_id */, |
| 32 PushRegistrationStatus /* status */)>; | 33 PushRegistrationStatus /* status */)>; |
| 33 using UnregisterCallback = base::Callback<void(PushUnregistrationStatus)>; | 34 using UnregisterCallback = base::Callback<void(PushUnregistrationStatus)>; |
| 34 | 35 |
| 35 // Provide a storage mechanism to read/write an opaque | |
| 36 // "notifications_shown_by_last_few_pushes" string associated with a Service | |
| 37 // Worker registration. Stored data is deleted when the associated | |
| 38 // registration is deleted. | |
| 39 static void GetNotificationsShownByLastFewPushes( | |
| 40 ServiceWorkerContext* service_worker_context, | |
| 41 int64 service_worker_registration_id, | |
| 42 const GetNotificationsShownCallback& callback); | |
| 43 static void SetNotificationsShownByLastFewPushes( | |
| 44 ServiceWorkerContext* service_worker_context, | |
| 45 int64 service_worker_registration_id, | |
| 46 const GURL& origin, | |
| 47 const std::string& notifications_shown, | |
| 48 const ResultCallback& callback); | |
| 49 | |
| 50 virtual ~PushMessagingService() {} | 36 virtual ~PushMessagingService() {} |
| 51 | 37 |
| 52 // 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 |
| 53 // 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 |
| 54 // origins and push registrations. | 40 // origins and push registrations. |
| 55 virtual GURL GetPushEndpoint() = 0; | 41 virtual GURL GetPushEndpoint() = 0; |
| 56 | 42 |
| 57 // Register the given |sender_id| with the push messaging service in a | 43 // Register the given |sender_id| with the push messaging service in a |
| 58 // 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 |
| 59 // to the user. | 45 // to the user. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 79 int64 service_worker_registration_id, | 65 int64 service_worker_registration_id, |
| 80 bool retry_on_failure, | 66 bool retry_on_failure, |
| 81 const UnregisterCallback& callback) = 0; | 67 const UnregisterCallback& callback) = 0; |
| 82 | 68 |
| 83 // Checks the permission status for the requesting origin. Permission is only | 69 // Checks the permission status for the requesting origin. Permission is only |
| 84 // ever granted when the requesting origin matches the top level embedding | 70 // ever granted when the requesting origin matches the top level embedding |
| 85 // origin. | 71 // origin. |
| 86 virtual blink::WebPushPermissionStatus GetPermissionStatus( | 72 virtual blink::WebPushPermissionStatus GetPermissionStatus( |
| 87 const GURL& requesting_origin, | 73 const GURL& requesting_origin, |
| 88 const GURL& embedding_origin) = 0; | 74 const GURL& embedding_origin) = 0; |
| 75 |
| 76 protected: |
| 77 // Provide a storage mechanism to read/write an opaque |
| 78 // "notifications_shown_by_last_few_pushes" string associated with a Service |
| 79 // Worker registration. Stored data is deleted when the associated |
| 80 // registration is deleted. |
| 81 static void GetNotificationsShownByLastFewPushes( |
| 82 ServiceWorkerContext* service_worker_context, |
| 83 int64 service_worker_registration_id, |
| 84 const GetNotificationsShownCallback& callback); |
| 85 static void SetNotificationsShownByLastFewPushes( |
| 86 ServiceWorkerContext* service_worker_context, |
| 87 int64 service_worker_registration_id, |
| 88 const GURL& origin, |
| 89 const std::string& notifications_shown, |
| 90 const ResultCallback& callback); |
| 91 |
| 92 // Clear the push registration id stored in the service worker with the given |
| 93 // |service_worker_registration_id| for the given |origin|. |
| 94 static void ClearPushRegistrationID(BrowserContext* browser_context, |
| 95 const GURL& origin, |
| 96 int64 service_worker_registration_id); |
| 89 }; | 97 }; |
| 90 | 98 |
| 91 } // namespace content | 99 } // namespace content |
| 92 | 100 |
| 93 #endif // CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_ | 101 #endif // CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_ |
| OLD | NEW |