| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace | 89 } // namespace |
| 90 | 90 |
| 91 class PresentationConnection::BlobLoader final : public GarbageCollectedFinalize
d<PresentationConnection::BlobLoader>, public FileReaderLoaderClient { | 91 class PresentationConnection::BlobLoader final : public GarbageCollectedFinalize
d<PresentationConnection::BlobLoader>, public FileReaderLoaderClient { |
| 92 public: | 92 public: |
| 93 BlobLoader(PassRefPtr<BlobDataHandle> blobDataHandle, PresentationConnection
* PresentationConnection) | 93 BlobLoader(PassRefPtr<BlobDataHandle> blobDataHandle, PresentationConnection
* PresentationConnection) |
| 94 : m_PresentationConnection(PresentationConnection) | 94 : m_PresentationConnection(PresentationConnection) |
| 95 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this) | 95 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this) |
| 96 { | 96 { |
| 97 m_loader.start(m_PresentationConnection->executionContext(), blobDataHan
dle); | 97 m_loader.start(m_PresentationConnection->getExecutionContext(), blobData
Handle); |
| 98 } | 98 } |
| 99 ~BlobLoader() override { } | 99 ~BlobLoader() override { } |
| 100 | 100 |
| 101 // FileReaderLoaderClient functions. | 101 // FileReaderLoaderClient functions. |
| 102 void didStartLoading() override { } | 102 void didStartLoading() override { } |
| 103 void didReceiveData() override { } | 103 void didReceiveData() override { } |
| 104 void didFinishLoading() override | 104 void didFinishLoading() override |
| 105 { | 105 { |
| 106 m_PresentationConnection->didFinishLoadingBlob(m_loader.arrayBufferResul
t()); | 106 m_PresentationConnection->didFinishLoadingBlob(m_loader.arrayBufferResul
t()); |
| 107 } | 107 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 138 { | 138 { |
| 139 ASSERT(!m_blobLoader); | 139 ASSERT(!m_blobLoader); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // static | 142 // static |
| 143 PresentationConnection* PresentationConnection::take(ScriptPromiseResolver* reso
lver, PassOwnPtr<WebPresentationConnectionClient> client, PresentationRequest* r
equest) | 143 PresentationConnection* PresentationConnection::take(ScriptPromiseResolver* reso
lver, PassOwnPtr<WebPresentationConnectionClient> client, PresentationRequest* r
equest) |
| 144 { | 144 { |
| 145 ASSERT(resolver); | 145 ASSERT(resolver); |
| 146 ASSERT(client); | 146 ASSERT(client); |
| 147 ASSERT(request); | 147 ASSERT(request); |
| 148 ASSERT(resolver->executionContext()->isDocument()); | 148 ASSERT(resolver->getExecutionContext()->isDocument()); |
| 149 | 149 |
| 150 Document* document = toDocument(resolver->executionContext()); | 150 Document* document = toDocument(resolver->getExecutionContext()); |
| 151 if (!document->frame()) | 151 if (!document->frame()) |
| 152 return nullptr; | 152 return nullptr; |
| 153 | 153 |
| 154 PresentationController* controller = PresentationController::from(*document-
>frame()); | 154 PresentationController* controller = PresentationController::from(*document-
>frame()); |
| 155 if (!controller) | 155 if (!controller) |
| 156 return nullptr; | 156 return nullptr; |
| 157 | 157 |
| 158 return take(controller, client, request); | 158 return take(controller, client, request); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // static | 161 // static |
| 162 PresentationConnection* PresentationConnection::take(PresentationController* con
troller, PassOwnPtr<WebPresentationConnectionClient> client, PresentationRequest
* request) | 162 PresentationConnection* PresentationConnection::take(PresentationController* con
troller, PassOwnPtr<WebPresentationConnectionClient> client, PresentationRequest
* request) |
| 163 { | 163 { |
| 164 ASSERT(controller); | 164 ASSERT(controller); |
| 165 ASSERT(request); | 165 ASSERT(request); |
| 166 | 166 |
| 167 PresentationConnection* connection = new PresentationConnection(controller->
frame(), client->getId(), client->getUrl()); | 167 PresentationConnection* connection = new PresentationConnection(controller->
frame(), client->getId(), client->getUrl()); |
| 168 controller->registerConnection(connection); | 168 controller->registerConnection(connection); |
| 169 request->dispatchEvent(PresentationConnectionAvailableEvent::create(EventTyp
eNames::connectionavailable, connection)); | 169 request->dispatchEvent(PresentationConnectionAvailableEvent::create(EventTyp
eNames::connectionavailable, connection)); |
| 170 | 170 |
| 171 return connection; | 171 return connection; |
| 172 } | 172 } |
| 173 | 173 |
| 174 const AtomicString& PresentationConnection::interfaceName() const | 174 const AtomicString& PresentationConnection::interfaceName() const |
| 175 { | 175 { |
| 176 return EventTargetNames::PresentationConnection; | 176 return EventTargetNames::PresentationConnection; |
| 177 } | 177 } |
| 178 | 178 |
| 179 ExecutionContext* PresentationConnection::executionContext() const | 179 ExecutionContext* PresentationConnection::getExecutionContext() const |
| 180 { | 180 { |
| 181 if (!frame()) | 181 if (!frame()) |
| 182 return nullptr; | 182 return nullptr; |
| 183 return frame()->document(); | 183 return frame()->document(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 bool PresentationConnection::addEventListenerInternal(const AtomicString& eventT
ype, PassRefPtrWillBeRawPtr<EventListener> listener, const EventListenerOptions&
options) | 186 bool PresentationConnection::addEventListenerInternal(const AtomicString& eventT
ype, PassRefPtrWillBeRawPtr<EventListener> listener, const EventListenerOptions&
options) |
| 187 { | 187 { |
| 188 if (eventType == EventTypeNames::statechange) | 188 if (eventType == EventTypeNames::statechange) |
| 189 Deprecation::countDeprecation(executionContext(), UseCounter::Presentati
onConnectionStateChangeEventListener); | 189 Deprecation::countDeprecation(getExecutionContext(), UseCounter::Present
ationConnectionStateChangeEventListener); |
| 190 else if (eventType == EventTypeNames::connect) | 190 else if (eventType == EventTypeNames::connect) |
| 191 UseCounter::count(executionContext(), UseCounter::PresentationConnection
ConnectEventListener); | 191 UseCounter::count(getExecutionContext(), UseCounter::PresentationConnect
ionConnectEventListener); |
| 192 else if (eventType == EventTypeNames::close) | 192 else if (eventType == EventTypeNames::close) |
| 193 UseCounter::count(executionContext(), UseCounter::PresentationConnection
CloseEventListener); | 193 UseCounter::count(getExecutionContext(), UseCounter::PresentationConnect
ionCloseEventListener); |
| 194 else if (eventType == EventTypeNames::terminate) | 194 else if (eventType == EventTypeNames::terminate) |
| 195 UseCounter::count(executionContext(), UseCounter::PresentationConnection
TerminateEventListener); | 195 UseCounter::count(getExecutionContext(), UseCounter::PresentationConnect
ionTerminateEventListener); |
| 196 else if (eventType == EventTypeNames::message) | 196 else if (eventType == EventTypeNames::message) |
| 197 UseCounter::count(executionContext(), UseCounter::PresentationConnection
MessageEventListener); | 197 UseCounter::count(getExecutionContext(), UseCounter::PresentationConnect
ionMessageEventListener); |
| 198 | 198 |
| 199 return EventTarget::addEventListenerInternal(eventType, listener, options); | 199 return EventTarget::addEventListenerInternal(eventType, listener, options); |
| 200 } | 200 } |
| 201 | 201 |
| 202 DEFINE_TRACE(PresentationConnection) | 202 DEFINE_TRACE(PresentationConnection) |
| 203 { | 203 { |
| 204 visitor->trace(m_blobLoader); | 204 visitor->trace(m_blobLoader); |
| 205 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationConnection>:
:trace(visitor); | 205 RefCountedGarbageCollectedEventTargetWithInlineData<PresentationConnection>:
:trace(visitor); |
| 206 DOMWindowProperty::trace(visitor); | 206 DOMWindowProperty::trace(visitor); |
| 207 } | 207 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 251 } |
| 252 | 252 |
| 253 bool PresentationConnection::canSendMessage(ExceptionState& exceptionState) | 253 bool PresentationConnection::canSendMessage(ExceptionState& exceptionState) |
| 254 { | 254 { |
| 255 if (m_state != WebPresentationConnectionState::Connected) { | 255 if (m_state != WebPresentationConnectionState::Connected) { |
| 256 throwPresentationDisconnectedError(exceptionState); | 256 throwPresentationDisconnectedError(exceptionState); |
| 257 return false; | 257 return false; |
| 258 } | 258 } |
| 259 | 259 |
| 260 // The connection can send a message if there is a client available. | 260 // The connection can send a message if there is a client available. |
| 261 return !!presentationClient(executionContext()); | 261 return !!presentationClient(getExecutionContext()); |
| 262 } | 262 } |
| 263 | 263 |
| 264 void PresentationConnection::handleMessageQueue() | 264 void PresentationConnection::handleMessageQueue() |
| 265 { | 265 { |
| 266 WebPresentationClient* client = presentationClient(executionContext()); | 266 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 267 if (!client) | 267 if (!client) |
| 268 return; | 268 return; |
| 269 | 269 |
| 270 while (!m_messages.isEmpty() && !m_blobLoader) { | 270 while (!m_messages.isEmpty() && !m_blobLoader) { |
| 271 Message* message = m_messages.first().get(); | 271 Message* message = m_messages.first().get(); |
| 272 switch (message->type) { | 272 switch (message->type) { |
| 273 case MessageTypeText: | 273 case MessageTypeText: |
| 274 client->sendString(m_url, m_id, message->text); | 274 client->sendString(m_url, m_id, message->text); |
| 275 m_messages.removeFirst(); | 275 m_messages.removeFirst(); |
| 276 break; | 276 break; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 dispatchEvent(MessageEvent::create(buffer.release())); | 337 dispatchEvent(MessageEvent::create(buffer.release())); |
| 338 return; | 338 return; |
| 339 } | 339 } |
| 340 ASSERT_NOT_REACHED(); | 340 ASSERT_NOT_REACHED(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void PresentationConnection::close() | 343 void PresentationConnection::close() |
| 344 { | 344 { |
| 345 if (m_state != WebPresentationConnectionState::Connected) | 345 if (m_state != WebPresentationConnectionState::Connected) |
| 346 return; | 346 return; |
| 347 WebPresentationClient* client = presentationClient(executionContext()); | 347 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 348 if (client) | 348 if (client) |
| 349 client->closeSession(m_url, m_id); | 349 client->closeSession(m_url, m_id); |
| 350 | 350 |
| 351 tearDown(); | 351 tearDown(); |
| 352 } | 352 } |
| 353 | 353 |
| 354 void PresentationConnection::terminate() | 354 void PresentationConnection::terminate() |
| 355 { | 355 { |
| 356 if (m_state != WebPresentationConnectionState::Connected) | 356 if (m_state != WebPresentationConnectionState::Connected) |
| 357 return; | 357 return; |
| 358 WebPresentationClient* client = presentationClient(executionContext()); | 358 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 359 if (client) | 359 if (client) |
| 360 client->terminateSession(m_url, m_id); | 360 client->terminateSession(m_url, m_id); |
| 361 | 361 |
| 362 tearDown(); | 362 tearDown(); |
| 363 } | 363 } |
| 364 | 364 |
| 365 bool PresentationConnection::matches(WebPresentationConnectionClient* client) co
nst | 365 bool PresentationConnection::matches(WebPresentationConnectionClient* client) co
nst |
| 366 { | 366 { |
| 367 return client && m_url == static_cast<String>(client->getUrl()) && m_id == s
tatic_cast<String>(client->getId()); | 367 return client && m_url == static_cast<String>(client->getUrl()) && m_id == s
tatic_cast<String>(client->getId()); |
| 368 } | 368 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 395 | 395 |
| 396 m_state = WebPresentationConnectionState::Closed; | 396 m_state = WebPresentationConnectionState::Closed; |
| 397 dispatchEvent(PresentationConnectionCloseEvent::create(EventTypeNames::close
, connectionCloseReasonToString(reason), message)); | 397 dispatchEvent(PresentationConnectionCloseEvent::create(EventTypeNames::close
, connectionCloseReasonToString(reason), message)); |
| 398 } | 398 } |
| 399 | 399 |
| 400 void PresentationConnection::didFinishLoadingBlob(PassRefPtr<DOMArrayBuffer> buf
fer) | 400 void PresentationConnection::didFinishLoadingBlob(PassRefPtr<DOMArrayBuffer> buf
fer) |
| 401 { | 401 { |
| 402 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob)
; | 402 ASSERT(!m_messages.isEmpty() && m_messages.first()->type == MessageTypeBlob)
; |
| 403 ASSERT(buffer && buffer->buffer()); | 403 ASSERT(buffer && buffer->buffer()); |
| 404 // Send the loaded blob immediately here and continue processing the queue. | 404 // Send the loaded blob immediately here and continue processing the queue. |
| 405 WebPresentationClient* client = presentationClient(executionContext()); | 405 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 406 if (client) | 406 if (client) |
| 407 client->sendBlobData(m_url, m_id, static_cast<const uint8_t*>(buffer->da
ta()), buffer->byteLength()); | 407 client->sendBlobData(m_url, m_id, static_cast<const uint8_t*>(buffer->da
ta()), buffer->byteLength()); |
| 408 | 408 |
| 409 m_messages.removeFirst(); | 409 m_messages.removeFirst(); |
| 410 m_blobLoader.clear(); | 410 m_blobLoader.clear(); |
| 411 handleMessageQueue(); | 411 handleMessageQueue(); |
| 412 } | 412 } |
| 413 | 413 |
| 414 void PresentationConnection::didFailLoadingBlob(FileError::ErrorCode errorCode) | 414 void PresentationConnection::didFailLoadingBlob(FileError::ErrorCode errorCode) |
| 415 { | 415 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 428 m_blobLoader->cancel(); | 428 m_blobLoader->cancel(); |
| 429 m_blobLoader.clear(); | 429 m_blobLoader.clear(); |
| 430 } | 430 } |
| 431 | 431 |
| 432 // Clear message queue. | 432 // Clear message queue. |
| 433 Deque<OwnPtr<Message>> empty; | 433 Deque<OwnPtr<Message>> empty; |
| 434 m_messages.swap(empty); | 434 m_messages.swap(empty); |
| 435 } | 435 } |
| 436 | 436 |
| 437 } // namespace blink | 437 } // namespace blink |
| OLD | NEW |