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

Unified Diff: Source/modules/presentation/PresentationSession.cpp

Issue 1002293005: [PresentationAPI] Plumbing send() from PresentationSession IDL to platform/. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Forward declare the Blob class. Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: Source/modules/presentation/PresentationSession.cpp
diff --git a/Source/modules/presentation/PresentationSession.cpp b/Source/modules/presentation/PresentationSession.cpp
index 47ba6253b3d33c471419808f6e6918b48f272bdd..866fb2039c8fdb5f6c1d078916fba5c6cd7f69a1 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,54 @@ const AtomicString& PresentationSession::state() const
return SessionStateToString(m_state);
}
-void PresentationSession::postMessage(const String& message)
+void PresentationSession::send(const String& message, ExceptionState& exceptionState)
+{
+ if (m_state != WebPresentationSessionState::Connected) {
+ throwPresentationDisconnectedError(exceptionState);
+ return;
+ }
+ if (message.isNull() || message.isEmpty())
whywhat 2015/04/13 12:58:45 I wonder if sending empty messages should be okay
USE s.singapati at gmail.com 2015/04/13 16:45:36 Acknowledged.
+ return;
+
+ PresentationController* controller = presentationController();
+ if (controller)
+ controller->send(m_url, m_id, message);
+}
+
+void PresentationSession::send(Blob* data, ExceptionState& exceptionState)
+{
+ exceptionState.throwDOMException(NotSupportedError, "Blob support not implemented yet.");
+ // TODO(s.singapati): To be implemented.
+}
+
+void PresentationSession::send(PassRefPtr<DOMArrayBuffer> data, ExceptionState& exceptionState)
{
+ if (m_state != WebPresentationSessionState::Connected) {
+ throwPresentationDisconnectedError(exceptionState);
+ return;
+ }
+ ASSERT(data && data->buffer());
+ if (!data->byteLength())
+ return;
+
+ PresentationController* controller = presentationController();
+ if (controller)
+ controller->send(m_url, m_id, static_cast<const char*>(data->data()), data->byteLength());
+}
+
+void PresentationSession::send(PassRefPtr<DOMArrayBufferView> data, ExceptionState& exceptionState)
whywhat 2015/04/13 12:58:45 looks like both send() methods for ArrayBufferView
USE s.singapati at gmail.com 2015/04/13 16:45:36 Done. Re factored this. sending a string the same
+{
+ if (m_state != WebPresentationSessionState::Connected) {
+ throwPresentationDisconnectedError(exceptionState);
+ return;
+ }
+ ASSERT(data);
whywhat 2015/04/13 12:58:45 Do you need to ASSERT for data->baseAddress()?
USE s.singapati at gmail.com 2015/04/13 16:45:36 Done. Now it is done in sendInternal().
+ if (!data->byteLength())
+ return;
+
+ PresentationController* controller = presentationController();
+ if (controller)
+ controller->send(m_url, m_id, static_cast<const char*>(data->baseAddress()), data->byteLength());
}
void PresentationSession::close()

Powered by Google App Engine
This is Rietveld 408576698