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

Side by Side Diff: third_party/WebKit/Source/modules/nfc/NFC.cpp

Issue 2498543003: Mojo C++ bindings: switch device/nfc mojom target to use STL/WTF types. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/nfc/NFC.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "modules/nfc/NFC.h" 5 #include "modules/nfc/NFC.h"
6 6
7 #include "bindings/core/v8/ScriptPromiseResolver.h" 7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "bindings/core/v8/V8ArrayBuffer.h" 8 #include "bindings/core/v8/V8ArrayBuffer.h"
9 #include "bindings/core/v8/V8StringResource.h" 9 #include "bindings/core/v8/V8StringResource.h"
10 #include "core/dom/DOMArrayBuffer.h" 10 #include "core/dom/DOMArrayBuffer.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 124 }
125 }; 125 };
126 126
127 template <> 127 template <>
128 struct TypeConverter<NFCRecordPtr, WTF::String> { 128 struct TypeConverter<NFCRecordPtr, WTF::String> {
129 static NFCRecordPtr Convert(const WTF::String& string) { 129 static NFCRecordPtr Convert(const WTF::String& string) {
130 NFCRecordPtr record = NFCRecord::New(); 130 NFCRecordPtr record = NFCRecord::New();
131 record->record_type = NFCRecordType::TEXT; 131 record->record_type = NFCRecordType::TEXT;
132 record->media_type = kPlainTextMimeType; 132 record->media_type = kPlainTextMimeType;
133 record->media_type.append(kCharSetUTF8); 133 record->media_type.append(kCharSetUTF8);
134 record->data = mojo::WTFArray<uint8_t>::From(string); 134 record->data = mojo::WTFArray<uint8_t>::From(string).PassStorage();
135 return record; 135 return record;
136 } 136 }
137 }; 137 };
138 138
139 template <> 139 template <>
140 struct TypeConverter<NFCRecordPtr, blink::DOMArrayBuffer*> { 140 struct TypeConverter<NFCRecordPtr, blink::DOMArrayBuffer*> {
141 static NFCRecordPtr Convert(blink::DOMArrayBuffer* buffer) { 141 static NFCRecordPtr Convert(blink::DOMArrayBuffer* buffer) {
142 NFCRecordPtr record = NFCRecord::New(); 142 NFCRecordPtr record = NFCRecord::New();
143 record->record_type = NFCRecordType::OPAQUE_RECORD; 143 record->record_type = NFCRecordType::OPAQUE_RECORD;
144 record->media_type = kOpaqueMimeType; 144 record->media_type = kOpaqueMimeType;
145 record->data = mojo::WTFArray<uint8_t>::From(buffer); 145 record->data = mojo::WTFArray<uint8_t>::From(buffer).PassStorage();
haraken 2016/11/12 01:35:41 Would you help me understand what PassStorage is d
yzshen1 2016/11/14 17:10:42 Because with this CL, record->data's type becomes
haraken 2016/11/14 18:38:30 Thanks, makes sense.
146 return record; 146 return record;
147 } 147 }
148 }; 148 };
149 149
150 template <> 150 template <>
151 struct TypeConverter<NFCMessagePtr, WTF::String> { 151 struct TypeConverter<NFCMessagePtr, WTF::String> {
152 static NFCMessagePtr Convert(const WTF::String& string) { 152 static NFCMessagePtr Convert(const WTF::String& string) {
153 NFCMessagePtr message = NFCMessage::New(); 153 NFCMessagePtr message = NFCMessage::New();
154 message->data = mojo::WTFArray<NFCRecordPtr>::New(1); 154 message->data.append(NFCRecord::From(string));
155 message->data[0] = NFCRecord::From(string);
156 return message; 155 return message;
157 } 156 }
158 }; 157 };
159 158
160 template <> 159 template <>
161 struct TypeConverter<mojo::WTFArray<uint8_t>, blink::ScriptValue> { 160 struct TypeConverter<mojo::WTFArray<uint8_t>, blink::ScriptValue> {
162 static mojo::WTFArray<uint8_t> Convert( 161 static mojo::WTFArray<uint8_t> Convert(
163 const blink::ScriptValue& scriptValue) { 162 const blink::ScriptValue& scriptValue) {
164 v8::Local<v8::Value> value = scriptValue.v8Value(); 163 v8::Local<v8::Value> value = scriptValue.v8Value();
165 164
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 setMediaType(recordPtr, record.mediaType(), kJsonMimeType); 215 setMediaType(recordPtr, record.mediaType(), kJsonMimeType);
217 break; 216 break;
218 case NFCRecordType::OPAQUE_RECORD: 217 case NFCRecordType::OPAQUE_RECORD:
219 setMediaType(recordPtr, record.mediaType(), kOpaqueMimeType); 218 setMediaType(recordPtr, record.mediaType(), kOpaqueMimeType);
220 break; 219 break;
221 default: 220 default:
222 NOTREACHED(); 221 NOTREACHED();
223 break; 222 break;
224 } 223 }
225 224
226 recordPtr->data = mojo::WTFArray<uint8_t>::From(record.data()); 225 auto recordData = mojo::WTFArray<uint8_t>::From(record.data());
227
228 // If JS object cannot be converted to uint8_t array, return null, 226 // If JS object cannot be converted to uint8_t array, return null,
229 // interrupt NFCMessage conversion algorithm and reject promise with 227 // interrupt NFCMessage conversion algorithm and reject promise with
230 // SyntaxError exception. 228 // SyntaxError exception.
231 if (recordPtr->data.is_null()) 229 if (recordData.is_null())
232 return nullptr; 230 return nullptr;
233 231
232 recordPtr->data = recordData.PassStorage();
234 return recordPtr; 233 return recordPtr;
235 } 234 }
236 }; 235 };
237 236
238 template <> 237 template <>
239 struct TypeConverter<NFCMessagePtr, blink::NFCMessage> { 238 struct TypeConverter<NFCMessagePtr, blink::NFCMessage> {
240 static NFCMessagePtr Convert(const blink::NFCMessage& message) { 239 static NFCMessagePtr Convert(const blink::NFCMessage& message) {
241 NFCMessagePtr messagePtr = NFCMessage::New(); 240 NFCMessagePtr messagePtr = NFCMessage::New();
242 messagePtr->url = message.url(); 241 messagePtr->url = message.url();
243 messagePtr->data.resize(message.data().size()); 242 messagePtr->data.resize(message.data().size());
244 for (size_t i = 0; i < message.data().size(); ++i) { 243 for (size_t i = 0; i < message.data().size(); ++i) {
245 NFCRecordPtr record = NFCRecord::From(message.data()[i]); 244 NFCRecordPtr record = NFCRecord::From(message.data()[i]);
246 if (record.is_null()) 245 if (record.is_null())
247 return nullptr; 246 return nullptr;
248 247
249 messagePtr->data[i] = std::move(record); 248 messagePtr->data[i] = std::move(record);
250 } 249 }
251 messagePtr->data = mojo::WTFArray<NFCRecordPtr>::From(message.data());
haraken 2016/11/12 01:35:41 Why can we remove this?
yzshen1 2016/11/14 17:10:42 Because line 243-250 does the same thing as line 2
252 return messagePtr; 250 return messagePtr;
253 } 251 }
254 }; 252 };
255 253
256 template <> 254 template <>
257 struct TypeConverter<NFCMessagePtr, blink::DOMArrayBuffer*> { 255 struct TypeConverter<NFCMessagePtr, blink::DOMArrayBuffer*> {
258 static NFCMessagePtr Convert(blink::DOMArrayBuffer* buffer) { 256 static NFCMessagePtr Convert(blink::DOMArrayBuffer* buffer) {
259 NFCMessagePtr message = NFCMessage::New(); 257 NFCMessagePtr message = NFCMessage::New();
260 message->data = mojo::WTFArray<NFCRecordPtr>::New(1); 258 message->data.append(NFCRecord::From(buffer));
261 message->data[0] = NFCRecord::From(buffer);
262 return message; 259 return message;
263 } 260 }
264 }; 261 };
265 262
266 template <> 263 template <>
267 struct TypeConverter<NFCMessagePtr, blink::NFCPushMessage> { 264 struct TypeConverter<NFCMessagePtr, blink::NFCPushMessage> {
268 static NFCMessagePtr Convert(const blink::NFCPushMessage& message) { 265 static NFCMessagePtr Convert(const blink::NFCPushMessage& message) {
269 if (message.isString()) 266 if (message.isString())
270 return NFCMessage::From(message.getAsString()); 267 return NFCMessage::From(message.getAsString());
271 268
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 571
575 // If NFCService is not available or disappears when NFC hardware is 572 // If NFCService is not available or disappears when NFC hardware is
576 // disabled, reject promise with NotSupportedError exception. 573 // disabled, reject promise with NotSupportedError exception.
577 for (ScriptPromiseResolver* resolver : m_requests) 574 for (ScriptPromiseResolver* resolver : m_requests)
578 resolver->reject( 575 resolver->reject(
579 NFCError::take(resolver, mojom::NFCErrorType::NOT_SUPPORTED)); 576 NFCError::take(resolver, mojom::NFCErrorType::NOT_SUPPORTED));
580 577
581 m_requests.clear(); 578 m_requests.clear();
582 } 579 }
583 580
584 void NFC::OnWatch(mojo::WTFArray<uint32_t> ids, mojom::NFCMessagePtr) { 581 void NFC::OnWatch(const WTF::Vector<uint32_t>& ids, mojom::NFCMessagePtr) {
585 // TODO(shalamov): Not implemented. 582 // TODO(shalamov): Not implemented.
586 } 583 }
587 584
588 DEFINE_TRACE(NFC) { 585 DEFINE_TRACE(NFC) {
589 PageVisibilityObserver::trace(visitor); 586 PageVisibilityObserver::trace(visitor);
590 ContextLifecycleObserver::trace(visitor); 587 ContextLifecycleObserver::trace(visitor);
591 visitor->trace(m_requests); 588 visitor->trace(m_requests);
592 } 589 }
593 590
594 } // namespace blink 591 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/nfc/NFC.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698