OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/mojo/MojoHandle.h" | 5 #include "core/mojo/MojoHandle.h" |
6 | 6 |
7 #include "bindings/core/v8/ArrayBufferOrArrayBufferView.h" | 7 #include "bindings/core/v8/ArrayBufferOrArrayBufferView.h" |
8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
9 #include "core/dom/DOMArrayBuffer.h" | 9 #include "core/dom/DOMArrayBuffer.h" |
10 #include "core/dom/DOMArrayBufferView.h" | 10 #include "core/dom/DOMArrayBufferView.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 handles.begin(), handles.end(), rawHandles.begin(), | 54 handles.begin(), handles.end(), rawHandles.begin(), |
55 [](MojoHandle* handle) { return handle->m_handle.release().value(); }); | 55 [](MojoHandle* handle) { return handle->m_handle.release().value(); }); |
56 | 56 |
57 const void* bytes = nullptr; | 57 const void* bytes = nullptr; |
58 uint32_t numBytes = 0; | 58 uint32_t numBytes = 0; |
59 if (buffer.isArrayBuffer()) { | 59 if (buffer.isArrayBuffer()) { |
60 DOMArrayBuffer* array = buffer.getAsArrayBuffer(); | 60 DOMArrayBuffer* array = buffer.getAsArrayBuffer(); |
61 bytes = array->data(); | 61 bytes = array->data(); |
62 numBytes = array->byteLength(); | 62 numBytes = array->byteLength(); |
63 } else { | 63 } else { |
64 DOMArrayBufferView* view = buffer.getAsArrayBufferView(); | 64 DOMArrayBufferView* view = buffer.getAsArrayBufferView().view(); |
65 bytes = view->baseAddress(); | 65 bytes = view->baseAddress(); |
66 numBytes = view->byteLength(); | 66 numBytes = view->byteLength(); |
67 } | 67 } |
68 | 68 |
69 return MojoWriteMessage(m_handle->value(), bytes, numBytes, rawHandles.data(), | 69 return MojoWriteMessage(m_handle->value(), bytes, numBytes, rawHandles.data(), |
70 rawHandles.size(), MOJO_WRITE_MESSAGE_FLAG_NONE); | 70 rawHandles.size(), MOJO_WRITE_MESSAGE_FLAG_NONE); |
71 } | 71 } |
72 | 72 |
73 void MojoHandle::readMessage(const MojoReadMessageFlags& flagsDict, | 73 void MojoHandle::readMessage(const MojoReadMessageFlags& flagsDict, |
74 MojoReadMessageResult& resultDict) { | 74 MojoReadMessageResult& resultDict) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 if (optionsDict.allOrNone()) | 109 if (optionsDict.allOrNone()) |
110 flags |= MOJO_WRITE_DATA_FLAG_ALL_OR_NONE; | 110 flags |= MOJO_WRITE_DATA_FLAG_ALL_OR_NONE; |
111 | 111 |
112 const void* elements = nullptr; | 112 const void* elements = nullptr; |
113 uint32_t numBytes = 0; | 113 uint32_t numBytes = 0; |
114 if (buffer.isArrayBuffer()) { | 114 if (buffer.isArrayBuffer()) { |
115 DOMArrayBuffer* array = buffer.getAsArrayBuffer(); | 115 DOMArrayBuffer* array = buffer.getAsArrayBuffer(); |
116 elements = array->data(); | 116 elements = array->data(); |
117 numBytes = array->byteLength(); | 117 numBytes = array->byteLength(); |
118 } else { | 118 } else { |
119 DOMArrayBufferView* view = buffer.getAsArrayBufferView(); | 119 DOMArrayBufferView* view = buffer.getAsArrayBufferView().view(); |
120 elements = view->baseAddress(); | 120 elements = view->baseAddress(); |
121 numBytes = view->byteLength(); | 121 numBytes = view->byteLength(); |
122 } | 122 } |
123 | 123 |
124 MojoResult result = | 124 MojoResult result = |
125 MojoWriteData(m_handle->value(), elements, &numBytes, flags); | 125 MojoWriteData(m_handle->value(), elements, &numBytes, flags); |
126 resultDict.setResult(result); | 126 resultDict.setResult(result); |
127 resultDict.setNumBytes(result == MOJO_RESULT_OK ? numBytes : 0); | 127 resultDict.setNumBytes(result == MOJO_RESULT_OK ? numBytes : 0); |
128 } | 128 } |
129 | 129 |
(...skipping 27 matching lines...) Expand all Loading... |
157 if (optionsDict.peek()) | 157 if (optionsDict.peek()) |
158 flags |= MOJO_READ_DATA_FLAG_PEEK; | 158 flags |= MOJO_READ_DATA_FLAG_PEEK; |
159 | 159 |
160 void* elements = nullptr; | 160 void* elements = nullptr; |
161 unsigned numBytes = 0; | 161 unsigned numBytes = 0; |
162 if (buffer.isArrayBuffer()) { | 162 if (buffer.isArrayBuffer()) { |
163 DOMArrayBuffer* array = buffer.getAsArrayBuffer(); | 163 DOMArrayBuffer* array = buffer.getAsArrayBuffer(); |
164 elements = array->data(); | 164 elements = array->data(); |
165 numBytes = array->byteLength(); | 165 numBytes = array->byteLength(); |
166 } else { | 166 } else { |
167 DOMArrayBufferView* view = buffer.getAsArrayBufferView(); | 167 DOMArrayBufferView* view = buffer.getAsArrayBufferView().view(); |
168 elements = view->baseAddress(); | 168 elements = view->baseAddress(); |
169 numBytes = view->byteLength(); | 169 numBytes = view->byteLength(); |
170 } | 170 } |
171 | 171 |
172 MojoResult result = | 172 MojoResult result = |
173 MojoReadData(m_handle->value(), elements, &numBytes, flags); | 173 MojoReadData(m_handle->value(), elements, &numBytes, flags); |
174 resultDict.setResult(result); | 174 resultDict.setResult(result); |
175 resultDict.setNumBytes(result == MOJO_RESULT_OK ? numBytes : 0); | 175 resultDict.setNumBytes(result == MOJO_RESULT_OK ? numBytes : 0); |
176 } | 176 } |
177 | 177 |
(...skipping 26 matching lines...) Expand all Loading... |
204 mojo::Handle handle; | 204 mojo::Handle handle; |
205 MojoResult result = MojoDuplicateBufferHandle(m_handle->value(), &options, | 205 MojoResult result = MojoDuplicateBufferHandle(m_handle->value(), &options, |
206 handle.mutable_value()); | 206 handle.mutable_value()); |
207 resultDict.setResult(result); | 207 resultDict.setResult(result); |
208 if (result == MOJO_RESULT_OK) { | 208 if (result == MOJO_RESULT_OK) { |
209 resultDict.setHandle(MojoHandle::create(mojo::MakeScopedHandle(handle))); | 209 resultDict.setHandle(MojoHandle::create(mojo::MakeScopedHandle(handle))); |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 } // namespace blink | 213 } // namespace blink |
OLD | NEW |