Implement WebPushProvider.unregister() in Chromium.
[chromium-blink-merge.git] / content / public / browser / push_messaging_service.h
blob624efb11a0cf08a20fc745f0d9a96c5bc56daf6c
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_
6 #define CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_
8 #include <string>
10 #include "base/callback.h"
11 #include "content/common/content_export.h"
12 #include "content/public/common/push_messaging_status.h"
13 #include "third_party/WebKit/public/platform/WebPushPermissionStatus.h"
14 #include "url/gurl.h"
16 namespace content {
18 // A push service-agnostic interface that the Push API uses for talking to
19 // push messaging services like GCM. Must only be used on the UI thread.
20 class CONTENT_EXPORT PushMessagingService {
21 public:
22 using RegisterCallback =
23 base::Callback<void(const std::string& /* registration_id */,
24 PushRegistrationStatus /* status */)>;
25 using UnregisterCallback = base::Callback<void(PushUnregistrationStatus)>;
27 virtual ~PushMessagingService() {}
29 // Returns the absolute URL exposed by the push server where the webapp server
30 // can send push messages. This is currently assumed to be the same for all
31 // origins and push registrations.
32 virtual GURL GetPushEndpoint() = 0;
34 // Register the given |sender_id| with the push messaging service in a
35 // document context. The frame is known and a permission UI may be displayed
36 // to the user.
37 virtual void RegisterFromDocument(const GURL& requesting_origin,
38 int64 service_worker_registration_id,
39 const std::string& sender_id,
40 int renderer_id,
41 int render_frame_id,
42 bool user_visible_only,
43 const RegisterCallback& callback) = 0;
45 // Register the given |sender_id| with the push messaging service. The frame
46 // is not known so if permission was not previously granted by the user this
47 // request should fail.
48 virtual void RegisterFromWorker(const GURL& requesting_origin,
49 int64 service_worker_registration_id,
50 const std::string& sender_id,
51 const RegisterCallback& callback) = 0;
53 // Unregister an origin and its associated service worker registration id from
54 // the push service.
55 virtual void Unregister(const GURL& requesting_origin,
56 int64 service_worker_registration_id,
57 const UnregisterCallback& callback) = 0;
59 // Check whether the requester has permission to register for Push
60 // Messages
61 // TODO(mvanouwerkerk): Delete once the Push API flows through platform.
62 // https://crbug.com/389194
63 virtual blink::WebPushPermissionStatus GetPermissionStatus(
64 const GURL& requesting_origin,
65 int renderer_id,
66 int render_frame_id) = 0;
68 // Checks the permission status for the requesting origin. Permission is only
69 // ever granted when the requesting origin matches the top level embedding
70 // origin.
71 virtual blink::WebPushPermissionStatus GetPermissionStatus(
72 const GURL& requesting_origin,
73 const GURL& embedding_origin) = 0;
76 } // namespace content
78 #endif // CONTENT_PUBLIC_BROWSER_PUSH_MESSAGING_SERVICE_H_