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

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 dcheng 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)
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, nullptr);
imcheng 2017/01/20 20:15:43 Should this be |m_proxy.get()| here and below?
zhaobin 2017/01/23 19:38:49 Done.
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(m_url, m_id, static_cast<const uint8_t*>(
320 message->arrayBuffer->data()), 328 message->arrayBuffer->data()),
321 message->arrayBuffer->byteLength()); 329 message->arrayBuffer->byteLength(), nullptr);
322 m_messages.removeFirst(); 330 m_messages.removeFirst();
323 break; 331 break;
324 case MessageTypeBlob: 332 case MessageTypeBlob:
325 ASSERT(!m_blobLoader); 333 ASSERT(!m_blobLoader);
326 m_blobLoader = new BlobLoader(message->blobDataHandle, this); 334 m_blobLoader = new BlobLoader(message->blobDataHandle, this);
327 break; 335 break;
328 } 336 }
329 } 337 }
330 } 338 }
331 339
(...skipping 13 matching lines...) Expand all
345 m_binaryType = BinaryTypeBlob; 353 m_binaryType = BinaryTypeBlob;
346 return; 354 return;
347 } 355 }
348 if (binaryType == "arraybuffer") { 356 if (binaryType == "arraybuffer") {
349 m_binaryType = BinaryTypeArrayBuffer; 357 m_binaryType = BinaryTypeArrayBuffer;
350 return; 358 return;
351 } 359 }
352 ASSERT_NOT_REACHED(); 360 ASSERT_NOT_REACHED();
353 } 361 }
354 362
355 void PresentationConnection::didReceiveTextMessage(const String& message) { 363 void PresentationConnection::didReceiveTextMessage(const WebString& message) {
356 if (m_state != WebPresentationConnectionState::Connected) 364 if (m_state != WebPresentationConnectionState::Connected)
357 return; 365 return;
358 366
359 dispatchEvent(MessageEvent::create(message)); 367 dispatchEvent(MessageEvent::create(message));
360 } 368 }
361 369
362 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, 370 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data,
363 size_t length) { 371 size_t length) {
364 if (m_state != WebPresentationConnectionState::Connected) 372 if (m_state != WebPresentationConnectionState::Connected)
365 return; 373 return;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 m_state = WebPresentationConnectionState::Closed; 457 m_state = WebPresentationConnectionState::Closed;
450 dispatchStateChangeEvent(PresentationConnectionCloseEvent::create( 458 dispatchStateChangeEvent(PresentationConnectionCloseEvent::create(
451 EventTypeNames::close, connectionCloseReasonToString(reason), message)); 459 EventTypeNames::close, connectionCloseReasonToString(reason), message));
452 } 460 }
453 461
454 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) { 462 void PresentationConnection::didFinishLoadingBlob(DOMArrayBuffer* buffer) {
455 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); 463 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob);
456 ASSERT(buffer && buffer->buffer()); 464 ASSERT(buffer && buffer->buffer());
457 // Send the loaded blob immediately here and continue processing the queue. 465 // Send the loaded blob immediately here and continue processing the queue.
458 WebPresentationClient* client = presentationClient(getExecutionContext()); 466 WebPresentationClient* client = presentationClient(getExecutionContext());
459 if (client) 467 if (client) {
460 client->sendBlobData(m_url, m_id, 468 client->sendBlobData(m_url, m_id,
461 static_cast<const uint8_t*>(buffer->data()), 469 static_cast<const uint8_t*>(buffer->data()),
462 buffer->byteLength()); 470 buffer->byteLength(), m_proxy.get());
471 }
463 472
464 m_messages.removeFirst(); 473 m_messages.removeFirst();
465 m_blobLoader.clear(); 474 m_blobLoader.clear();
466 handleMessageQueue(); 475 handleMessageQueue();
467 } 476 }
468 477
469 void PresentationConnection::didFailLoadingBlob( 478 void PresentationConnection::didFailLoadingBlob(
470 FileError::ErrorCode errorCode) { 479 FileError::ErrorCode errorCode) {
471 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob); 480 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob);
472 // FIXME: generate error message? 481 // FIXME: generate error message?
(...skipping 21 matching lines...) Expand all
494 void PresentationConnection::tearDown() { 503 void PresentationConnection::tearDown() {
495 // Cancel current Blob loading if any. 504 // Cancel current Blob loading if any.
496 if (m_blobLoader) { 505 if (m_blobLoader) {
497 m_blobLoader->cancel(); 506 m_blobLoader->cancel();
498 m_blobLoader.clear(); 507 m_blobLoader.clear();
499 } 508 }
500 m_messages.clear(); 509 m_messages.clear();
501 } 510 }
502 511
503 } // namespace blink 512 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698