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 #include "modules/presentation/PresentationConnection.h" | 5 #include "modules/presentation/PresentationConnection.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "core/dom/DOMArrayBuffer.h" | 8 #include "core/dom/DOMArrayBuffer.h" |
9 #include "core/dom/DOMArrayBufferView.h" | 9 #include "core/dom/DOMArrayBufferView.h" |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 std::unique_ptr<FileReaderLoader> m_loader; | 142 std::unique_ptr<FileReaderLoader> m_loader; |
143 }; | 143 }; |
144 | 144 |
145 PresentationConnection::PresentationConnection(LocalFrame* frame, | 145 PresentationConnection::PresentationConnection(LocalFrame* frame, |
146 const String& id, | 146 const String& id, |
147 const KURL& url) | 147 const KURL& url) |
148 : DOMWindowProperty(frame), | 148 : DOMWindowProperty(frame), |
149 m_id(id), | 149 m_id(id), |
150 m_url(url), | 150 m_url(url), |
151 m_state(WebPresentationConnectionState::Connected), | 151 m_state(WebPresentationConnectionState::Connected), |
152 m_binaryType(BinaryTypeBlob) {} | 152 m_binaryType(BinaryTypeBlob), |
153 m_proxy(nullptr) {} | |
153 | 154 |
154 PresentationConnection::~PresentationConnection() { | 155 PresentationConnection::~PresentationConnection() { |
155 ASSERT(!m_blobLoader); | 156 ASSERT(!m_blobLoader); |
156 } | 157 } |
157 | 158 |
159 void PresentationConnection::SetPresentationConnectionProxy( | |
160 std::unique_ptr<WebPresentationConnectionProxy> proxy) { | |
161 DCHECK(proxy); | |
162 m_proxy = std::move(proxy); | |
163 m_proxy->SetSourceConnection(this); | |
164 } | |
165 | |
158 // static | 166 // static |
159 PresentationConnection* PresentationConnection::take( | 167 PresentationConnection* PresentationConnection::take( |
160 ScriptPromiseResolver* resolver, | 168 ScriptPromiseResolver* resolver, |
161 std::unique_ptr<WebPresentationConnectionClient> client, | 169 std::unique_ptr<WebPresentationConnectionClient> client, |
162 PresentationRequest* request) { | 170 PresentationRequest* request) { |
163 ASSERT(resolver); | 171 ASSERT(resolver); |
164 ASSERT(client); | 172 ASSERT(client); |
165 ASSERT(request); | 173 ASSERT(request); |
166 ASSERT(resolver->getExecutionContext()->isDocument()); | 174 ASSERT(resolver->getExecutionContext()->isDocument()); |
167 | 175 |
(...skipping 12 matching lines...) Expand all Loading... | |
180 // static | 188 // static |
181 PresentationConnection* PresentationConnection::take( | 189 PresentationConnection* PresentationConnection::take( |
182 PresentationController* controller, | 190 PresentationController* controller, |
183 std::unique_ptr<WebPresentationConnectionClient> client, | 191 std::unique_ptr<WebPresentationConnectionClient> client, |
184 PresentationRequest* request) { | 192 PresentationRequest* request) { |
185 ASSERT(controller); | 193 ASSERT(controller); |
186 ASSERT(request); | 194 ASSERT(request); |
187 | 195 |
188 PresentationConnection* connection = new PresentationConnection( | 196 PresentationConnection* connection = new PresentationConnection( |
189 controller->frame(), client->getId(), client->getUrl()); | 197 controller->frame(), client->getId(), client->getUrl()); |
198 | |
199 if (auto proxy = client->takeProxy()) | |
imcheng
2016/11/01 17:20:30
this check is not needed? std::move should work on
zhaobin
2016/11/02 03:55:48
Done.
| |
200 connection->SetPresentationConnectionProxy(std::move(proxy)); | |
201 | |
190 controller->registerConnection(connection); | 202 controller->registerConnection(connection); |
191 request->dispatchEvent(PresentationConnectionAvailableEvent::create( | 203 request->dispatchEvent(PresentationConnectionAvailableEvent::create( |
192 EventTypeNames::connectionavailable, connection)); | 204 EventTypeNames::connectionavailable, connection)); |
193 | 205 |
194 return connection; | 206 return connection; |
195 } | 207 } |
196 | 208 |
197 // static | 209 // static |
198 PresentationConnection* PresentationConnection::take( | 210 PresentationConnection* PresentationConnection::take( |
199 PresentationReceiver* receiver, | 211 PresentationReceiver* receiver, |
200 std::unique_ptr<WebPresentationConnectionClient> client) { | 212 std::unique_ptr<WebPresentationConnectionClient> client) { |
201 DCHECK(receiver); | 213 DCHECK(receiver); |
202 DCHECK(client); | 214 DCHECK(client); |
203 | 215 |
204 PresentationConnection* connection = new PresentationConnection( | 216 PresentationConnection* connection = new PresentationConnection( |
205 receiver->frame(), client->getId(), client->getUrl()); | 217 receiver->frame(), client->getId(), client->getUrl()); |
218 | |
219 if (auto proxy = client->takeProxy()) | |
imcheng
2016/11/01 17:20:30
this should always be non-null, right?
zhaobin
2016/11/02 03:55:48
Done.
| |
220 connection->SetPresentationConnectionProxy(std::move(proxy)); | |
221 | |
206 receiver->registerConnection(connection); | 222 receiver->registerConnection(connection); |
207 | 223 |
208 return connection; | 224 return connection; |
209 } | 225 } |
210 | 226 |
211 const AtomicString& PresentationConnection::interfaceName() const { | 227 const AtomicString& PresentationConnection::interfaceName() const { |
212 return EventTargetNames::PresentationConnection; | 228 return EventTargetNames::PresentationConnection; |
213 } | 229 } |
214 | 230 |
215 ExecutionContext* PresentationConnection::getExecutionContext() const { | 231 ExecutionContext* PresentationConnection::getExecutionContext() const { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 | 313 |
298 void PresentationConnection::handleMessageQueue() { | 314 void PresentationConnection::handleMessageQueue() { |
299 WebPresentationClient* client = presentationClient(getExecutionContext()); | 315 WebPresentationClient* client = presentationClient(getExecutionContext()); |
300 if (!client) | 316 if (!client) |
301 return; | 317 return; |
302 | 318 |
303 while (!m_messages.isEmpty() && !m_blobLoader) { | 319 while (!m_messages.isEmpty() && !m_blobLoader) { |
304 Message* message = m_messages.first().get(); | 320 Message* message = m_messages.first().get(); |
305 switch (message->type) { | 321 switch (message->type) { |
306 case MessageTypeText: | 322 case MessageTypeText: |
307 client->sendString(m_url, m_id, message->text); | 323 if (m_proxy) |
324 m_proxy->SendString(message->text); | |
325 else | |
326 client->sendString(m_url, m_id, message->text); | |
308 m_messages.removeFirst(); | 327 m_messages.removeFirst(); |
309 break; | 328 break; |
310 case MessageTypeArrayBuffer: | 329 case MessageTypeArrayBuffer: |
311 client->sendArrayBuffer(m_url, m_id, static_cast<const uint8_t*>( | 330 if (m_proxy) { |
312 message->arrayBuffer->data()), | 331 m_proxy->SendArrayBuffer( |
313 message->arrayBuffer->byteLength()); | 332 static_cast<const uint8_t*>(message->arrayBuffer->data()), |
333 message->arrayBuffer->byteLength()); | |
334 } else { | |
335 client->sendArrayBuffer( | |
336 m_url, m_id, | |
337 static_cast<const uint8_t*>(message->arrayBuffer->data()), | |
338 message->arrayBuffer->byteLength()); | |
339 } | |
314 m_messages.removeFirst(); | 340 m_messages.removeFirst(); |
315 break; | 341 break; |
316 case MessageTypeBlob: | 342 case MessageTypeBlob: |
317 ASSERT(!m_blobLoader); | 343 ASSERT(!m_blobLoader); |
318 m_blobLoader = new BlobLoader(message->blobDataHandle, this); | 344 m_blobLoader = new BlobLoader(message->blobDataHandle, this); |
319 break; | 345 break; |
320 } | 346 } |
321 } | 347 } |
322 } | 348 } |
323 | 349 |
(...skipping 13 matching lines...) Expand all Loading... | |
337 m_binaryType = BinaryTypeBlob; | 363 m_binaryType = BinaryTypeBlob; |
338 return; | 364 return; |
339 } | 365 } |
340 if (binaryType == "arraybuffer") { | 366 if (binaryType == "arraybuffer") { |
341 m_binaryType = BinaryTypeArrayBuffer; | 367 m_binaryType = BinaryTypeArrayBuffer; |
342 return; | 368 return; |
343 } | 369 } |
344 ASSERT_NOT_REACHED(); | 370 ASSERT_NOT_REACHED(); |
345 } | 371 } |
346 | 372 |
347 void PresentationConnection::didReceiveTextMessage(const String& message) { | 373 void PresentationConnection::didReceiveTextMessage(const WebString& message) { |
348 if (m_state != WebPresentationConnectionState::Connected) | 374 if (m_state != WebPresentationConnectionState::Connected) |
349 return; | 375 return; |
350 | 376 |
351 dispatchEvent(MessageEvent::create(message)); | 377 dispatchEvent(MessageEvent::create(message)); |
352 } | 378 } |
353 | 379 |
354 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, | 380 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, |
355 size_t length) { | 381 size_t length) { |
356 if (m_state != WebPresentationConnectionState::Connected) | 382 if (m_state != WebPresentationConnectionState::Connected) |
357 return; | 383 return; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 void PresentationConnection::tearDown() { | 484 void PresentationConnection::tearDown() { |
459 // Cancel current Blob loading if any. | 485 // Cancel current Blob loading if any. |
460 if (m_blobLoader) { | 486 if (m_blobLoader) { |
461 m_blobLoader->cancel(); | 487 m_blobLoader->cancel(); |
462 m_blobLoader.clear(); | 488 m_blobLoader.clear(); |
463 } | 489 } |
464 m_messages.clear(); | 490 m_messages.clear(); |
465 } | 491 } |
466 | 492 |
467 } // namespace blink | 493 } // namespace blink |
OLD | NEW |