| Index: Source/modules/presentation/PresentationSession.cpp
|
| diff --git a/Source/modules/presentation/PresentationSession.cpp b/Source/modules/presentation/PresentationSession.cpp
|
| index 47ba6253b3d33c471419808f6e6918b48f272bdd..51f823140f8af942e57e768a60bbcc563219c71b 100644
|
| --- a/Source/modules/presentation/PresentationSession.cpp
|
| +++ b/Source/modules/presentation/PresentationSession.cpp
|
| @@ -5,7 +5,10 @@
|
| #include "config.h"
|
| #include "modules/presentation/PresentationSession.h"
|
|
|
| +#include "core/dom/DOMArrayBuffer.h"
|
| +#include "core/dom/DOMArrayBufferView.h"
|
| #include "core/dom/Document.h"
|
| +#include "core/dom/ExceptionCode.h"
|
| #include "core/events/Event.h"
|
| #include "core/frame/LocalFrame.h"
|
| #include "modules/EventTargetModules.h"
|
| @@ -36,6 +39,11 @@ const AtomicString& SessionStateToString(WebPresentationSessionState state)
|
| return disconnectedValue;
|
| }
|
|
|
| +void throwPresentationDisconnectedError(ExceptionState& exceptionState)
|
| +{
|
| + exceptionState.throwDOMException(InvalidStateError, "Presentation session is disconnected.");
|
| +}
|
| +
|
| } // namespace
|
|
|
| PresentationSession::PresentationSession(LocalFrame* frame, const String& id, const String& url)
|
| @@ -90,8 +98,62 @@ const AtomicString& PresentationSession::state() const
|
| return SessionStateToString(m_state);
|
| }
|
|
|
| -void PresentationSession::postMessage(const String& message)
|
| +void PresentationSession::postMessage(const String& message, ExceptionState& exceptionState)
|
| +{
|
| + if (m_state != WebPresentationSessionState::Connected) {
|
| + throwPresentationDisconnectedError(exceptionState);
|
| + return;
|
| + }
|
| + PresentationController* controller = presentationController();
|
| + if (controller)
|
| + controller->postMessage(m_url, m_id, message);
|
| +}
|
| +
|
| +void PresentationSession::postMessage(Blob* data, ExceptionState& exceptionState)
|
| +{
|
| + // TODO(s.singapati): To be implemented.
|
| +}
|
| +
|
| +void PresentationSession::postMessage(DOMArrayBuffer* data, ExceptionState& exceptionState)
|
| +{
|
| + if (m_state != WebPresentationSessionState::Connected) {
|
| + throwPresentationDisconnectedError(exceptionState);
|
| + return;
|
| + }
|
| + // TODO(): DOM exception Or ASSERT(data && data->buffer())?
|
| + if (!data) {
|
| + exceptionState.throwDOMException(
|
| + SyntaxError,
|
| + "invalid ArrayBuffer for PresentationSession message.");
|
| + return;
|
| + }
|
| + if (!data->byteLength())
|
| + return;
|
| +
|
| + PresentationController* controller = presentationController();
|
| + if (controller)
|
| + controller->postMessage(m_url, m_id, static_cast<const char*>(data->data()), data->byteLength());
|
| +}
|
| +
|
| +void PresentationSession::postMessage(DOMArrayBufferView* data, ExceptionState& exceptionState)
|
| {
|
| + if (m_state != WebPresentationSessionState::Connected) {
|
| + throwPresentationDisconnectedError(exceptionState);
|
| + return;
|
| + }
|
| + // TODO(): DOM exception Or ASSERT(data)?
|
| + if (!data) {
|
| + exceptionState.throwDOMException(
|
| + SyntaxError,
|
| + "invalid ArrayBufferView for PresentationSession message.");
|
| + return;
|
| + }
|
| + if (!data->byteLength())
|
| + return;
|
| +
|
| + PresentationController* controller = presentationController();
|
| + if (controller)
|
| + controller->postMessage(m_url, m_id, static_cast<const char*>(data->baseAddress()), data->byteLength());
|
| }
|
|
|
| void PresentationSession::close()
|
|
|