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

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: Renamed postMessage() api to send(), other review fixes. 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..074053dd95241060c0a2d2c228795f18bc6340de 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::send(const String& message, ExceptionState& exceptionState)
+{
+ if (m_state != WebPresentationSessionState::Connected) {
+ throwPresentationDisconnectedError(exceptionState);
+ return;
+ }
+ PresentationController* controller = presentationController();
+ if (controller)
+ controller->send(m_url, m_id, message);
+}
+
+void PresentationSession::send(Blob* data, ExceptionState& exceptionState)
+{
+ // TODO(): To be implemented.
mark a. foltz 2015/04/08 23:14:35 Throw a DOMException here for an unimplemented fea
mark a. foltz 2015/04/08 23:14:35 Please put your @chromium.org login here and in ot
USE s.singapati at gmail.com 2015/04/09 04:36:13 I do not have username at @chromium.org yet, but @
USE s.singapati at gmail.com 2015/04/09 14:37:11 Done. yes, i think DOMException is ok for now.
+}
+
+void PresentationSession::send(PassRefPtr<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->send(m_url, m_id, static_cast<const char*>(data->data()), data->byteLength());
+}
+
+void PresentationSession::send(PassRefPtr<DOMArrayBufferView> data, ExceptionState& exceptionState)
{
+ if (m_state != WebPresentationSessionState::Connected) {
+ throwPresentationDisconnectedError(exceptionState);
+ return;
+ }
+ // TODO(): DOM exception Or ASSERT(data)?
mark a. foltz 2015/04/08 23:14:35 I think you should be guaranteed to get a live and
USE s.singapati at gmail.com 2015/04/09 14:37:11 Done. It is tested that data is valid. and atleast
+ if (!data) {
+ exceptionState.throwDOMException(
+ SyntaxError,
+ "invalid ArrayBufferView for PresentationSession message.");
+ return;
+ }
+ 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()
« no previous file with comments | « Source/modules/presentation/PresentationSession.h ('k') | Source/modules/presentation/PresentationSession.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698