Chromium Code Reviews| Index: Source/modules/presentation/PresentationSession.cpp |
| diff --git a/Source/modules/presentation/PresentationSession.cpp b/Source/modules/presentation/PresentationSession.cpp |
| index 6c6e9380d43916753372d614e9046f7806214c83..faf54a8a0a884810a67ed62ada44362e7e6a42cc 100644 |
| --- a/Source/modules/presentation/PresentationSession.cpp |
| +++ b/Source/modules/presentation/PresentationSession.cpp |
| @@ -11,6 +11,8 @@ |
| #include "core/dom/ExceptionCode.h" |
| #include "core/events/Event.h" |
| #include "core/events/MessageEvent.h" |
| +#include "core/fileapi/FileReaderLoader.h" |
| +#include "core/fileapi/FileReaderLoaderClient.h" |
| #include "core/frame/LocalFrame.h" |
| #include "modules/EventTargetModules.h" |
| #include "modules/presentation/Presentation.h" |
| @@ -47,6 +49,43 @@ void throwPresentationDisconnectedError(ExceptionState& exceptionState) |
| } // namespace |
| +class PresentationSession::BlobLoader final : public GarbageCollectedFinalized<PresentationSession::BlobLoader>, public FileReaderLoaderClient { |
| +public: |
| + BlobLoader(PassRefPtr<BlobDataHandle> blobDataHandle, PresentationSession* presentationSession) |
| + : m_presentationSession(presentationSession) |
| + , m_loader(FileReaderLoader::ReadAsArrayBuffer, this) |
| + { |
| + m_loader.start(m_presentationSession->executionContext(), blobDataHandle); |
| + } |
| + virtual ~BlobLoader() { } |
|
mlamouri (slow - plz ping)
2015/05/19 13:08:55
override maybe?
USE s.singapati at gmail.com
2015/05/21 19:49:54
Done.
|
| + |
| + // FileReaderLoaderClient functions. |
| + virtual void didStartLoading() override { } |
| + virtual void didReceiveData() override { } |
| + virtual void didFinishLoading() override |
|
mlamouri (slow - plz ping)
2015/05/19 13:08:54
No need for virtual if you already have override.
USE s.singapati at gmail.com
2015/05/21 19:49:54
Done.
|
| + { |
| + m_presentationSession->didFinishLoadingBlob(m_loader.arrayBufferResult()); |
| + } |
| + virtual void didFail(FileError::ErrorCode errorCode) override |
| + { |
| + m_presentationSession->didFailLoadingBlob(errorCode); |
| + } |
| + |
| + void cancel() |
| + { |
| + m_loader.cancel(); |
| + } |
| + |
| + DEFINE_INLINE_TRACE() |
| + { |
| + visitor->trace(m_presentationSession); |
| + } |
| + |
| +private: |
| + Member<PresentationSession> m_presentationSession; |
| + FileReaderLoader m_loader; |
| +}; |
| + |
| PresentationSession::PresentationSession(LocalFrame* frame, const String& id, const String& url) |
| : DOMWindowProperty(frame) |
| , m_id(id) |
| @@ -57,6 +96,7 @@ PresentationSession::PresentationSession(LocalFrame* frame, const String& id, co |
| PresentationSession::~PresentationSession() |
| { |
| + ASSERT(!m_blobLoader); |
| } |
| // static |
| @@ -90,6 +130,7 @@ ExecutionContext* PresentationSession::executionContext() const |
| DEFINE_TRACE(PresentationSession) |
| { |
| + visitor->trace(m_blobLoader); |
| RefCountedGarbageCollectedEventTargetWithInlineData<PresentationSession>::trace(visitor); |
| DOMWindowProperty::trace(visitor); |
| } |
| @@ -136,6 +177,27 @@ void PresentationSession::sendInternal(const uint8_t* data, size_t size, Excepti |
| controller->send(m_url, m_id, data, size); |
| } |
| +void PresentationSession::send(Blob* data, ExceptionState& exceptionState) |
| +{ |
| + ASSERT(data); |
| + if (m_state == WebPresentationSessionState::Disconnected) { |
| + throwPresentationDisconnectedError(exceptionState); |
| + return; |
| + } |
| + |
| + m_messages.append(adoptPtr(new Message(data->blobDataHandle()))); |
| + handleMessageQueue(); |
| +} |
| + |
| +void PresentationSession::handleMessageQueue() |
| +{ |
| + if (!m_messages.isEmpty() && !m_blobLoader) { |
|
mlamouri (slow - plz ping)
2015/05/19 13:08:54
if (m_messages.isEmpty() || m_blobLoader)
return
USE s.singapati at gmail.com
2015/05/21 19:49:54
Done.
|
| + Message* message = m_messages.first().get(); |
| + ASSERT(!m_blobLoader); |
| + m_blobLoader = new BlobLoader(message->blobDataHandle, this); |
| + } |
| +} |
| + |
| void PresentationSession::didReceiveTextMessage(const String& message) |
| { |
| dispatchEvent(MessageEvent::create(message)); |
| @@ -148,6 +210,16 @@ void PresentationSession::close() |
| PresentationController* controller = presentationController(); |
| if (controller) |
| controller->closeSession(m_url, m_id); |
| + |
| + // Cancel current Blob loading if any. |
| + if (m_blobLoader) { |
| + m_blobLoader->cancel(); |
| + m_blobLoader.clear(); |
| + } |
| + |
| + // Clear Blob message queue. |
| + Deque<OwnPtr<Message>> empty; |
| + m_messages.swap(empty); |
| } |
| bool PresentationSession::matches(WebPresentationSessionClient* client) const |
| @@ -171,4 +243,28 @@ PresentationController* PresentationSession::presentationController() |
| return PresentationController::from(*frame()); |
| } |
| +void PresentationSession::didFinishLoadingBlob(PassRefPtr<DOMArrayBuffer> buffer) |
| +{ |
| + m_blobLoader.clear(); |
| + ASSERT(buffer && buffer->buffer()); |
| + |
| + PresentationController* controller = presentationController(); |
| + if (controller) |
| + controller->sendBlobData(m_url, m_id, static_cast<const uint8_t*>(buffer->data()), buffer->byteLength()); |
| + |
| + ASSERT(m_messages.size() > 0); |
|
mlamouri (slow - plz ping)
2015/05/19 13:08:55
You probably just want to check that it is not emp
USE s.singapati at gmail.com
2015/05/21 19:49:54
Done.
|
| + m_messages.removeFirst(); |
| + handleMessageQueue(); |
| +} |
| + |
| +void PresentationSession::didFailLoadingBlob(FileError::ErrorCode errorCode) |
| +{ |
| + m_blobLoader.clear(); |
| + // FIXME: generate error message? |
|
mlamouri (slow - plz ping)
2015/05/19 13:08:54
Yes, probably. Could .send() return a Promise that
USE s.singapati at gmail.com
2015/05/21 19:49:54
Seems to be API change.
Mark: Do you have any comm
|
| + // Ignore the current failed blob item and continue with next items. |
| + ASSERT(m_messages.size() > 0); |
| + m_messages.removeFirst(); |
| + handleMessageQueue(); |
| +} |
| + |
| } // namespace blink |