OLD | NEW |
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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 v8::Local<v8::Value> toV8( | 489 v8::Local<v8::Value> toV8( |
490 ScriptState* scriptState, | 490 ScriptState* scriptState, |
491 const device::nfc::mojom::blink::NFCRecordPtr& record) { | 491 const device::nfc::mojom::blink::NFCRecordPtr& record) { |
492 switch (record->record_type) { | 492 switch (record->record_type) { |
493 case device::nfc::mojom::blink::NFCRecordType::TEXT: | 493 case device::nfc::mojom::blink::NFCRecordType::TEXT: |
494 case device::nfc::mojom::blink::NFCRecordType::URL: | 494 case device::nfc::mojom::blink::NFCRecordType::URL: |
495 case device::nfc::mojom::blink::NFCRecordType::JSON: { | 495 case device::nfc::mojom::blink::NFCRecordType::JSON: { |
496 String stringData; | 496 String stringData; |
497 if (!record->data.isEmpty()) { | 497 if (!record->data.isEmpty()) { |
498 stringData = String::fromUTF8WithLatin1Fallback( | 498 stringData = String::fromUTF8WithLatin1Fallback( |
499 static_cast<unsigned char*>(&record->data.first()), | 499 static_cast<unsigned char*>(&record->data.front()), |
500 record->data.size()); | 500 record->data.size()); |
501 } | 501 } |
502 | 502 |
503 v8::Isolate* isolate = scriptState->isolate(); | 503 v8::Isolate* isolate = scriptState->isolate(); |
504 v8::Local<v8::String> string = v8String(isolate, stringData); | 504 v8::Local<v8::String> string = v8String(isolate, stringData); |
505 | 505 |
506 // Stringified JSON must be converted back to an Object. | 506 // Stringified JSON must be converted back to an Object. |
507 if (record->record_type == | 507 if (record->record_type == |
508 device::nfc::mojom::blink::NFCRecordType::JSON) { | 508 device::nfc::mojom::blink::NFCRecordType::JSON) { |
509 v8::Local<v8::Value> jsonObject; | 509 v8::Local<v8::Value> jsonObject; |
510 v8::TryCatch tryCatch(isolate); | 510 v8::TryCatch tryCatch(isolate); |
511 if (!v8Call(v8::JSON::Parse(isolate, string), jsonObject, tryCatch)) { | 511 if (!v8Call(v8::JSON::Parse(isolate, string), jsonObject, tryCatch)) { |
512 return v8::Null(isolate); | 512 return v8::Null(isolate); |
513 } | 513 } |
514 | 514 |
515 return jsonObject; | 515 return jsonObject; |
516 } | 516 } |
517 | 517 |
518 return string; | 518 return string; |
519 } | 519 } |
520 | 520 |
521 case device::nfc::mojom::blink::NFCRecordType::OPAQUE_RECORD: { | 521 case device::nfc::mojom::blink::NFCRecordType::OPAQUE_RECORD: { |
522 if (!record->data.isEmpty()) { | 522 if (!record->data.isEmpty()) { |
523 DOMArrayBuffer* buffer = DOMArrayBuffer::create( | 523 DOMArrayBuffer* buffer = DOMArrayBuffer::create( |
524 static_cast<void*>(&record->data.first()), record->data.size()); | 524 static_cast<void*>(&record->data.front()), record->data.size()); |
525 return toV8(buffer, scriptState->context()->Global(), | 525 return toV8(buffer, scriptState->context()->Global(), |
526 scriptState->isolate()); | 526 scriptState->isolate()); |
527 } | 527 } |
528 | 528 |
529 return v8::Null(scriptState->isolate()); | 529 return v8::Null(scriptState->isolate()); |
530 } | 530 } |
531 | 531 |
532 case device::nfc::mojom::blink::NFCRecordType::EMPTY: | 532 case device::nfc::mojom::blink::NFCRecordType::EMPTY: |
533 return v8::Null(scriptState->isolate()); | 533 return v8::Null(scriptState->isolate()); |
534 } | 534 } |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 } | 816 } |
817 | 817 |
818 DEFINE_TRACE(NFC) { | 818 DEFINE_TRACE(NFC) { |
819 PageVisibilityObserver::trace(visitor); | 819 PageVisibilityObserver::trace(visitor); |
820 ContextLifecycleObserver::trace(visitor); | 820 ContextLifecycleObserver::trace(visitor); |
821 visitor->trace(m_requests); | 821 visitor->trace(m_requests); |
822 visitor->trace(m_callbacks); | 822 visitor->trace(m_callbacks); |
823 } | 823 } |
824 | 824 |
825 } // namespace blink | 825 } // namespace blink |
OLD | NEW |