17
17
#include " mozilla/Preferences.h"
18
18
#include " mozilla/unused.h"
19
19
#include " nsGlobalWindow.h"
20
+ #include " WebSocketChannel.h"
20
21
21
22
namespace mozilla {
22
23
namespace dom {
@@ -111,6 +112,51 @@ FlyWebPublishedServer::PublishedServerStarted(nsresult aStatus)
111
112
}
112
113
}
113
114
115
+ already_AddRefed<WebSocket>
116
+ FlyWebPublishedServer::OnWebSocketAccept (InternalRequest* aConnectRequest,
117
+ const Optional<nsAString>& aProtocol,
118
+ ErrorResult& aRv)
119
+ {
120
+ MOZ_ASSERT (aConnectRequest);
121
+
122
+ LOG_I (" FlyWebPublishedServer::OnWebSocketAccept(%p)" , this );
123
+
124
+ nsCOMPtr<nsITransportProvider> provider =
125
+ OnWebSocketAcceptInternal (aConnectRequest,
126
+ aProtocol,
127
+ aRv);
128
+ if (aRv.Failed ()) {
129
+ return nullptr ;
130
+ }
131
+ MOZ_ASSERT (provider);
132
+
133
+ nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface (GetOwner ());
134
+ AutoJSContext cx;
135
+ GlobalObject global (cx, nsGlobalWindow::Cast (window)->FastGetGlobalJSObject ());
136
+
137
+ nsAutoCString extensions, negotiatedExtensions;
138
+ aConnectRequest->Headers ()->
139
+ Get (NS_LITERAL_CSTRING(" Sec-WebSocket-Extensions" ), extensions, aRv);
140
+ mozilla::net::ProcessServerWebSocketExtensions (extensions,
141
+ negotiatedExtensions);
142
+
143
+ nsCString url;
144
+ aConnectRequest->GetURL (url);
145
+ Sequence<nsString> protocols;
146
+ if (aProtocol.WasPassed () &&
147
+ !protocols.AppendElement (aProtocol.Value (), fallible)) {
148
+ aRv.Throw (NS_ERROR_OUT_OF_MEMORY);
149
+ return nullptr ;
150
+ }
151
+
152
+ return WebSocket::ConstructorCommon (global,
153
+ NS_ConvertUTF8toUTF16 (url),
154
+ protocols,
155
+ provider,
156
+ negotiatedExtensions,
157
+ aRv);
158
+ }
159
+
114
160
/* ******* FlyWebPublishedServerImpl ********/
115
161
116
162
NS_IMPL_ISUPPORTS_INHERITED0 (FlyWebPublishedServerImpl, mozilla::DOMEventTargetHelper)
@@ -166,52 +212,6 @@ FlyWebPublishedServerImpl::OnFetchResponse(InternalRequest* aRequest,
166
212
}
167
213
}
168
214
169
- already_AddRefed<WebSocket>
170
- FlyWebPublishedServerImpl::OnWebSocketAccept (InternalRequest* aConnectRequest,
171
- const Optional<nsAString>& aProtocol,
172
- ErrorResult& aRv)
173
- {
174
- MOZ_ASSERT (aConnectRequest);
175
-
176
- LOG_I (" FlyWebPublishedMDNSServer::OnWebSocketAccept(%p)" , this );
177
-
178
- if (!mHttpServer ) {
179
- aRv.Throw (NS_ERROR_UNEXPECTED);
180
- return nullptr ;
181
- }
182
-
183
- nsAutoCString negotiatedExtensions;
184
- nsCOMPtr<nsITransportProvider> provider =
185
- mHttpServer ->AcceptWebSocket (aConnectRequest,
186
- aProtocol,
187
- negotiatedExtensions,
188
- aRv);
189
- if (aRv.Failed ()) {
190
- return nullptr ;
191
- }
192
- MOZ_ASSERT (provider);
193
-
194
- nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface (GetOwner ());
195
- AutoJSContext cx;
196
- GlobalObject global (cx, nsGlobalWindow::Cast (window)->FastGetGlobalJSObject ());
197
-
198
- nsCString url;
199
- aConnectRequest->GetURL (url);
200
- Sequence<nsString> protocols;
201
- if (aProtocol.WasPassed () &&
202
- !protocols.AppendElement (aProtocol.Value (), fallible)) {
203
- aRv.Throw (NS_ERROR_OUT_OF_MEMORY);
204
- return nullptr ;
205
- }
206
-
207
- return WebSocket::ConstructorCommon (global,
208
- NS_ConvertUTF8toUTF16 (url),
209
- protocols,
210
- provider,
211
- negotiatedExtensions,
212
- aRv);
213
- }
214
-
215
215
void
216
216
FlyWebPublishedServerImpl::OnWebSocketResponse (InternalRequest* aConnectRequest,
217
217
InternalResponse* aResponse)
@@ -226,6 +226,23 @@ FlyWebPublishedServerImpl::OnWebSocketResponse(InternalRequest* aConnectRequest,
226
226
}
227
227
}
228
228
229
+ already_AddRefed<nsITransportProvider>
230
+ FlyWebPublishedServerImpl::OnWebSocketAcceptInternal (InternalRequest* aConnectRequest,
231
+ const Optional<nsAString>& aProtocol,
232
+ ErrorResult& aRv)
233
+ {
234
+ LOG_I (" FlyWebPublishedServerImpl::OnWebSocketAcceptInternal(%p)" , this );
235
+
236
+ if (!mHttpServer ) {
237
+ aRv.Throw (NS_ERROR_UNEXPECTED);
238
+ return nullptr ;
239
+ }
240
+
241
+ return mHttpServer ->AcceptWebSocket (aConnectRequest,
242
+ aProtocol,
243
+ aRv);
244
+ }
245
+
229
246
/* ******* FlyWebPublishedServerChild ********/
230
247
231
248
FlyWebPublishedServerChild::FlyWebPublishedServerChild (nsPIDOMWindowInner* aOwner,
@@ -310,12 +327,14 @@ FlyWebPublishedServerChild::OnFetchResponse(InternalRequest* aRequest,
310
327
}
311
328
}
312
329
313
- already_AddRefed<WebSocket >
314
- FlyWebPublishedServerChild::OnWebSocketAccept (InternalRequest* aConnectRequest,
315
- const Optional<nsAString>& aProtocol,
316
- ErrorResult& aRv)
330
+ already_AddRefed<nsITransportProvider >
331
+ FlyWebPublishedServerChild::OnWebSocketAcceptInternal (InternalRequest* aConnectRequest,
332
+ const Optional<nsAString>& aProtocol,
333
+ ErrorResult& aRv)
317
334
{
318
- // Send ipdl message to parent
335
+ LOG_I (" FlyWebPublishedServerChild::OnWebSocketAcceptInternal(%p)" , this );
336
+
337
+ aRv.Throw (NS_ERROR_NOT_IMPLEMENTED);
319
338
return nullptr ;
320
339
}
321
340
0 commit comments