File: ndef_record.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (111 lines) | stat: -rw-r--r-- 4,409 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_NFC_NDEF_RECORD_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_NFC_NDEF_RECORD_H_

#include <stdint.h>

#include <optional>

#include "services/device/public/mojom/nfc.mojom-blink-forward.h"
#include "third_party/blink/renderer/core/typed_arrays/array_buffer_view_helpers.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"

namespace blink {

class DOMDataView;
class ExceptionState;
class NDEFMessage;
class NDEFRecordInit;
class ScriptState;

class MODULES_EXPORT NDEFRecord final : public ScriptWrappable {
  DEFINE_WRAPPERTYPEINFO();

 public:
  // This function is only supposed to be used by the automatically generated
  // bindings code. Use Create() instead.
  static NDEFRecord* CreateForBindings(const ScriptState*,
                                       const NDEFRecordInit*,
                                       ExceptionState&);

  // |is_embedded| indicates if this record is within the context of a parent
  // record.
  static NDEFRecord* Create(const ScriptState*,
                            const NDEFRecordInit*,
                            ExceptionState&,
                            uint8_t records_depth,
                            bool is_embedded);

  explicit NDEFRecord(device::mojom::NDEFRecordTypeCategory,
                      const String& record_type,
                      const String& id,
                      WTF::Vector<uint8_t>);

  // For constructing a "smart-poster", an external type or a local type record
  // whose payload is an NDEF message.
  explicit NDEFRecord(device::mojom::NDEFRecordTypeCategory,
                      const String& record_type,
                      const String& id,
                      NDEFMessage*);

  // Only for constructing "text" type record. The type category will be
  // device::mojom::NDEFRecordTypeCategory::kStandardized.
  explicit NDEFRecord(const String& id,
                      const String& encoding,
                      const String& lang,
                      WTF::Vector<uint8_t>);

  // Only for constructing "text" type record from just a text. The type
  // category will be device::mojom::NDEFRecordTypeCategory::kStandardized.
  // Called by NDEFMessage.
  explicit NDEFRecord(const ScriptState*, const String&);

  // Only for constructing "mime" type record. The type category will be
  // device::mojom::NDEFRecordTypeCategory::kStandardized.
  explicit NDEFRecord(const String& id,
                      const String& media_type,
                      WTF::Vector<uint8_t>);

  explicit NDEFRecord(const device::mojom::blink::NDEFRecord&);

  const String& recordType() const { return record_type_; }
  const String& mediaType() const;
  const String& id() const { return id_; }
  const String& encoding() const { return encoding_; }
  const String& lang() const { return lang_; }
  NotShared<DOMDataView> data() const;
  std::optional<HeapVector<Member<NDEFRecord>>> toRecords(
      ExceptionState& exception_state) const;

  device::mojom::NDEFRecordTypeCategory category() const { return category_; }
  const WTF::Vector<uint8_t>& payloadData() const { return payload_data_; }
  const NDEFMessage* payload_message() const { return payload_message_.Get(); }

  void Trace(Visitor*) const override;

 private:
  const device::mojom::NDEFRecordTypeCategory category_;
  const String record_type_;
  const String id_;
  const String media_type_;
  const String encoding_;
  const String lang_;
  // Holds the NDEFRecord.[[PayloadData]] bytes defined at
  // https://w3c.github.io/web-nfc/#the-ndefrecord-interface.
  const WTF::Vector<uint8_t> payload_data_;
  // |payload_data_| parsed as an NDEFMessage. This field will be set for some
  // "smart-poster", external, and local type records.
  const Member<NDEFMessage> payload_message_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_NFC_NDEF_RECORD_H_