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

Unified Diff: third_party/WebKit/Source/core/mojo/MojoHandle.cpp

Issue 2720873002: Implements JS bindings for mojo shared buffer. (Closed)
Patch Set: rebaseline2 Created 3 years, 10 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: third_party/WebKit/Source/core/mojo/MojoHandle.cpp
diff --git a/third_party/WebKit/Source/core/mojo/MojoHandle.cpp b/third_party/WebKit/Source/core/mojo/MojoHandle.cpp
index 0ae42778335411c744034c169d24a21ffa984f91..d2441055265f982ca4f212811d946c9ef5815aff 100644
--- a/third_party/WebKit/Source/core/mojo/MojoHandle.cpp
+++ b/third_party/WebKit/Source/core/mojo/MojoHandle.cpp
@@ -8,6 +8,9 @@
#include "bindings/core/v8/ScriptState.h"
#include "core/dom/DOMArrayBuffer.h"
#include "core/dom/DOMArrayBufferView.h"
+#include "core/mojo/MojoCreateSharedBufferResult.h"
+#include "core/mojo/MojoDuplicateBufferHandleOptions.h"
+#include "core/mojo/MojoMapBufferResult.h"
#include "core/mojo/MojoReadMessageFlags.h"
#include "core/mojo/MojoReadMessageResult.h"
#include "core/mojo/MojoWatcher.h"
@@ -92,4 +95,39 @@ void MojoHandle::readMessage(const MojoReadMessageFlags& flagsDict,
resultDict.setHandles(handles);
}
+void MojoHandle::mapBuffer(unsigned offset,
+ unsigned numBytes,
+ MojoMapBufferResult& resultDict) {
+ void* data = nullptr;
+ MojoResult result = MojoMapBuffer(m_handle->value(), offset, numBytes, &data,
+ MOJO_MAP_BUFFER_FLAG_NONE);
+ resultDict.setResult(result);
+ if (result == MOJO_RESULT_OK) {
+ WTF::ArrayBufferContents::DataHandle dataHandle(data, [](void* buffer) {
+ MojoResult result = MojoUnmapBuffer(buffer);
+ DCHECK_EQ(result, MOJO_RESULT_OK);
+ });
+ WTF::ArrayBufferContents contents(std::move(dataHandle), numBytes,
+ WTF::ArrayBufferContents::NotShared);
+ resultDict.setBuffer(DOMArrayBuffer::create(contents));
+ }
+}
+
+void MojoHandle::duplicateBufferHandle(
+ const MojoDuplicateBufferHandleOptions& optionsDict,
+ MojoCreateSharedBufferResult& resultDict) {
+ ::MojoDuplicateBufferHandleOptions options = {
+ sizeof(options), MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
+ if (optionsDict.readOnly())
+ options.flags |= MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_READ_ONLY;
+
+ mojo::Handle handle;
+ MojoResult result = MojoDuplicateBufferHandle(m_handle->value(), &options,
+ handle.mutable_value());
+ resultDict.setResult(result);
+ if (result == MOJO_RESULT_OK) {
+ resultDict.setHandle(MojoHandle::create(mojo::MakeScopedHandle(handle)));
+ }
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/mojo/MojoHandle.h ('k') | third_party/WebKit/Source/core/mojo/MojoHandle.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698