Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Side by Side Diff: third_party/WebKit/Source/modules/presentation/PresentationConnection.cpp

Issue 2471263003: [Presentation API] (4th)(1-UA blink side) Add WebPresentationConnection and WebPresentationConnecti… (Closed)
Patch Set: resolve code review comments from Derek and Mark Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 std::unique_ptr<FileReaderLoader> m_loader; 146 std::unique_ptr<FileReaderLoader> m_loader;
147 }; 147 };
148 148
149 PresentationConnection::PresentationConnection(LocalFrame* frame, 149 PresentationConnection::PresentationConnection(LocalFrame* frame,
150 const String& id, 150 const String& id,
151 const KURL& url) 151 const KURL& url)
152 : ContextClient(frame), 152 : ContextClient(frame),
153 m_id(id), 153 m_id(id),
154 m_url(url), 154 m_url(url),
155 m_state(WebPresentationConnectionState::Connecting), 155 m_state(WebPresentationConnectionState::Connecting),
156 m_binaryType(BinaryTypeBlob) {} 156 m_binaryType(BinaryTypeBlob),
157 m_proxy(nullptr) {}
157 158
158 PresentationConnection::~PresentationConnection() { 159 PresentationConnection::~PresentationConnection() {
159 ASSERT(!m_blobLoader); 160 ASSERT(!m_blobLoader);
160 } 161 }
161 162
163 void PresentationConnection::bindProxy(
164 std::unique_ptr<WebPresentationConnectionProxy> proxy) {
165 DCHECK(proxy);
166 DCHECK(!m_proxy);
167 m_proxy = std::move(proxy);
168 }
169
162 // static 170 // static
163 PresentationConnection* PresentationConnection::take( 171 PresentationConnection* PresentationConnection::take(
164 ScriptPromiseResolver* resolver, 172 ScriptPromiseResolver* resolver,
165 const WebPresentationSessionInfo& sessionInfo, 173 const WebPresentationSessionInfo& sessionInfo,
166 PresentationRequest* request) { 174 PresentationRequest* request) {
167 ASSERT(resolver); 175 ASSERT(resolver);
168 ASSERT(request); 176 ASSERT(request);
169 ASSERT(resolver->getExecutionContext()->isDocument()); 177 ASSERT(resolver->getExecutionContext()->isDocument());
170 178
171 Document* document = toDocument(resolver->getExecutionContext()); 179 Document* document = toDocument(resolver->getExecutionContext());
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 throwPresentationDisconnectedError(exceptionState); 306 throwPresentationDisconnectedError(exceptionState);
299 return false; 307 return false;
300 } 308 }
301 309
302 // The connection can send a message if there is a client available. 310 // The connection can send a message if there is a client available.
303 return !!presentationClient(getExecutionContext()); 311 return !!presentationClient(getExecutionContext());
304 } 312 }
305 313
306 void PresentationConnection::handleMessageQueue() { 314 void PresentationConnection::handleMessageQueue() {
307 WebPresentationClient* client = presentationClient(getExecutionContext()); 315 WebPresentationClient* client = presentationClient(getExecutionContext());
308 if (!client) 316 if (!client || !m_proxy)
309 return; 317 return;
310 318
311 while (!m_messages.isEmpty() && !m_blobLoader) { 319 while (!m_messages.isEmpty() && !m_blobLoader) {
312 Message* message = m_messages.first().get(); 320 Message* message = m_messages.first().get();
313 switch (message->type) { 321 switch (message->type) {
314 case MessageTypeText: 322 case MessageTypeText:
315 client->sendString(m_url, m_id, message->text); 323 client->sendString(m_url, m_id, message->text, m_proxy.get());
316 m_messages.removeFirst(); 324 m_messages.removeFirst();
317 break; 325 break;
318 case MessageTypeArrayBuffer: 326 case MessageTypeArrayBuffer:
319 client->sendArrayBuffer(m_url, m_id, static_cast<const uint8_t*>( 327 client->sendArrayBuffer(
320 message->arrayBuffer->data()), 328 m_url, m_id,
321 message->arrayBuffer->byteLength()); 329 static_cast<const uint8_t*>(message->arrayBuffer->data()),
330 message->arrayBuffer->byteLength(), m_proxy.get());
322 m_messages.removeFirst(); 331 m_messages.removeFirst();
323 break; 332 break;
324 case MessageTypeBlob: 333 case MessageTypeBlob:
325 ASSERT(!m_blobLoader); 334 ASSERT(!m_blobLoader);
326 m_blobLoader = new BlobLoader(message->blobDataHandle, this); 335 m_blobLoader = new BlobLoader(message->blobDataHandle, this);
327 break; 336 break;
328 } 337 }
329 } 338 }
330 } 339 }
331 340
(...skipping 13 matching lines...) Expand all
345 m_binaryType = BinaryTypeBlob; 354 m_binaryType = BinaryTypeBlob;
346 return; 355 return;
347 } 356 }
348 if (binaryType == "arraybuffer") { 357 if (binaryType == "arraybuffer") {
349 m_binaryType = BinaryTypeArrayBuffer; 358 m_binaryType = BinaryTypeArrayBuffer;
350 return; 359 return;
351 } 360 }
352 ASSERT_NOT_REACHED(); 361 ASSERT_NOT_REACHED();
353 } 362 }
354 363
355 void PresentationConnection::didReceiveTextMessage(const String& message) { 364 void PresentationConnection::didReceiveTextMessage(const WebString& message) {
356 if (m_state != WebPresentationConnectionState::Connected) 365 if (m_state != WebPresentationConnectionState::Connected)
357 return; 366 return;
358 367
359 dispatchEvent(MessageEvent::create(message)); 368 dispatchEvent(MessageEvent::create(message));
360 } 369 }
361 370
362 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, 371 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data,
363 size_t length) { 372 size_t length) {
364 if (m_state != WebPresentationConnectionState::Connected) 373 if (m_state != WebPresentationConnectionState::Connected)
365 return; 374 return;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 m_state = WebPresentationConnectionState::Closed; 458 m_state = WebPresentationConnectionState::Closed;
450 dispatchStateChangeEvent(PresentationConnectionCloseEvent::create( 459 dispatchStateChangeEvent(PresentationConnectionCloseEvent::create(
451 EventTypeNames::close, connectionCloseReasonToString(reason), message)); 460 EventTypeNames::close, connectionCloseReasonToString(reason), message));
452 } 461 }
453 462
454 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) { 463 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) {
455 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); 464 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob);
456 ASSERT(buffer && buffer->buffer()); 465 ASSERT(buffer && buffer->buffer());
457 // Send the loaded blob immediately here and continue processing the queue. 466 // Send the loaded blob immediately here and continue processing the queue.
458 WebPresentationClient* client = presentationClient(getExecutionContext()); 467 WebPresentationClient* client = presentationClient(getExecutionContext());
459 if (client) 468 if (client) {
460 client->sendBlobData(m_url, m_id, 469 client->sendBlobData(m_url, m_id,
461 static_cast<const uint8_t*>(buffer->data()), 470 static_cast<const uint8_t*>(buffer->data()),
462 buffer->byteLength()); 471 buffer->byteLength(), m_proxy.get());
472 }
463 473
464 m_messages.removeFirst(); 474 m_messages.removeFirst();
465 m_blobLoader.clear(); 475 m_blobLoader.clear();
466 handleMessageQueue(); 476 handleMessageQueue();
467 } 477 }
468 478
469 void PresentationConnection::didFailLoadingBlob( 479 void PresentationConnection::didFailLoadingBlob(
470 FileError::ErrorCode errorCode) { 480 FileError::ErrorCode errorCode) {
471 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); 481 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob);
472 // FIXME: generate error message? 482 // FIXME: generate error message?
(...skipping 21 matching lines...) Expand all
494 void PresentationConnection::tearDown() { 504 void PresentationConnection::tearDown() {
495 // Cancel current Blob loading if any. 505 // Cancel current Blob loading if any.
496 if (m_blobLoader) { 506 if (m_blobLoader) {
497 m_blobLoader->cancel(); 507 m_blobLoader->cancel();
498 m_blobLoader.clear(); 508 m_blobLoader.clear();
499 } 509 }
500 m_messages.clear(); 510 m_messages.clear();
501 } 511 }
502 512
503 } // namespace blink 513 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698