OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_MESSAGE_FILTER_H_ | |
6 #define CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_MESSAGE_FILTER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <memory> | |
11 #include <string> | |
12 | |
13 #include "base/macros.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 #include "content/common/service_worker/service_worker_status_code.h" | |
17 #include "content/public/browser/browser_message_filter.h" | |
18 #include "content/public/common/push_messaging_status.h" | |
19 #include "url/gurl.h" | |
20 | |
21 namespace content { | |
22 | |
23 class PushMessagingService; | |
24 class ServiceWorkerContextWrapper; | |
25 struct PushSubscriptionOptions; | |
26 | |
27 // Documented at definition. | |
28 extern const char kPushSenderIdServiceWorkerKey[]; | |
29 extern const char kPushRegistrationIdServiceWorkerKey[]; | |
30 | |
31 class PushMessagingMessageFilter : public BrowserMessageFilter { | |
32 public: | |
33 PushMessagingMessageFilter( | |
34 int render_process_id, | |
35 ServiceWorkerContextWrapper* service_worker_context); | |
36 | |
37 private: | |
38 struct RegisterData; | |
39 class Core; | |
40 | |
41 friend class BrowserThread; | |
42 friend class base::DeleteHelper<PushMessagingMessageFilter>; | |
43 | |
44 ~PushMessagingMessageFilter() override; | |
45 | |
46 // BrowserMessageFilter implementation. | |
47 void OnDestruct() const override; | |
48 bool OnMessageReceived(const IPC::Message& message) override; | |
49 | |
50 // Subscribe methods on IO thread -------------------------------------------- | |
51 | |
52 void OnSubscribe(int render_frame_id, | |
53 int request_id, | |
54 int64_t service_worker_registration_id, | |
55 const PushSubscriptionOptions& options); | |
56 | |
57 void DidCheckForExistingRegistration( | |
58 const RegisterData& data, | |
59 const std::vector<std::string>& push_registration_id, | |
60 ServiceWorkerStatusCode service_worker_status); | |
61 | |
62 void DidGetEncryptionKeys(const RegisterData& data, | |
63 const std::string& push_registration_id, | |
64 bool success, | |
65 const std::vector<uint8_t>& p256dh, | |
66 const std::vector<uint8_t>& auth); | |
67 | |
68 void DidGetSenderIdFromStorage(const RegisterData& data, | |
69 const std::vector<std::string>& sender_id, | |
70 ServiceWorkerStatusCode service_worker_status); | |
71 | |
72 // Called via PostTask from UI thread. | |
73 void PersistRegistrationOnIO(const RegisterData& data, | |
74 const std::string& push_registration_id, | |
75 const std::vector<uint8_t>& p256dh, | |
76 const std::vector<uint8_t>& auth); | |
77 | |
78 void DidPersistRegistrationOnIO( | |
79 const RegisterData& data, | |
80 const std::string& push_registration_id, | |
81 const std::vector<uint8_t>& p256dh, | |
82 const std::vector<uint8_t>& auth, | |
83 ServiceWorkerStatusCode service_worker_status); | |
84 | |
85 // Called both from IO thread, and via PostTask from UI thread. | |
86 void SendSubscriptionError(const RegisterData& data, | |
87 PushRegistrationStatus status); | |
88 // Called both from IO thread, and via PostTask from UI thread. | |
89 void SendSubscriptionSuccess(const RegisterData& data, | |
90 PushRegistrationStatus status, | |
91 const std::string& push_subscription_id, | |
92 const std::vector<uint8_t>& p256dh, | |
93 const std::vector<uint8_t>& auth); | |
94 | |
95 // Unsubscribe methods on IO thread ------------------------------------------ | |
96 | |
97 void OnUnsubscribe(int request_id, int64_t service_worker_registration_id); | |
98 | |
99 void UnsubscribeHavingGottenSenderId( | |
100 int request_id, | |
101 int64_t service_worker_registration_id, | |
102 const GURL& requesting_origin, | |
103 const std::vector<std::string>& sender_id, | |
104 ServiceWorkerStatusCode service_worker_status); | |
105 | |
106 // Called both from IO thread, and via PostTask from UI thread. | |
107 void DidUnregister(int request_id, | |
108 PushUnregistrationStatus unregistration_status); | |
109 | |
110 // GetSubscription methods on IO thread -------------------------------------- | |
111 | |
112 void OnGetSubscription(int request_id, | |
113 int64_t service_worker_registration_id); | |
114 | |
115 void DidGetSubscription( | |
116 int request_id, | |
117 int64_t service_worker_registration_id, | |
118 const std::vector<std::string>& push_subscription_id_and_sender_info, | |
119 ServiceWorkerStatusCode service_worker_status); | |
120 | |
121 void DidGetSubscriptionKeys(int request_id, | |
122 const GURL& endpoint, | |
123 const std::string& sender_info, | |
124 bool success, | |
125 const std::vector<uint8_t>& p256dh, | |
126 const std::vector<uint8_t>& auth); | |
127 | |
128 // GetPermission methods on IO thread ---------------------------------------- | |
129 | |
130 void OnGetPermissionStatus(int request_id, | |
131 int64_t service_worker_registration_id, | |
132 bool user_visible); | |
133 | |
134 // Helper methods on IO thread ----------------------------------------------- | |
135 | |
136 // Called via PostTask from UI thread. | |
137 void SendIPC(std::unique_ptr<IPC::Message> message); | |
138 | |
139 // Helper methods on either thread ------------------------------------------- | |
140 | |
141 // Creates an endpoint for |subscription_id| with either the default protocol, | |
142 // or the standardized Web Push Protocol, depending on |standard_protocol|. | |
143 GURL CreateEndpoint(bool standard_protocol, | |
144 const std::string& subscription_id) const; | |
145 | |
146 // Inner core of this message filter which lives on the UI thread. | |
147 std::unique_ptr<Core, BrowserThread::DeleteOnUIThread> ui_core_; | |
148 | |
149 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | |
150 | |
151 // Whether the PushMessagingService was available when constructed. | |
152 bool service_available_; | |
153 | |
154 GURL default_endpoint_; | |
155 GURL web_push_protocol_endpoint_; | |
156 | |
157 base::WeakPtrFactory<PushMessagingMessageFilter> weak_factory_io_to_io_; | |
158 | |
159 DISALLOW_COPY_AND_ASSIGN(PushMessagingMessageFilter); | |
160 }; | |
161 | |
162 } // namespace content | |
163 | |
164 #endif // CONTENT_BROWSER_PUSH_MESSAGING_PUSH_MESSAGING_MESSAGE_FILTER_H_ | |
OLD | NEW |