chromium/third_party/blink/renderer/modules/nfc/ndef_record.cc

// 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.

#include "third_party/blink/renderer/modules/nfc/ndef_record.h"

#include <string_view>

#include "base/containers/contains.h"
#include "base/notreached.h"
#include "services/device/public/mojom/nfc.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/idl_types.h"
#include "third_party/blink/renderer/bindings/core/v8/native_value_traits_impl.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_typedefs.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_arraybuffer_arraybufferview.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_ndef_message_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_ndef_record_init.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_typedefs.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_piece.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_data_view.h"
#include "third_party/blink/renderer/modules/nfc/ndef_message.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/network/http_parsers.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/text/ascii_ctype.h"
#include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h"
#include "v8/include/v8.h"

namespace blink {

namespace {

WTF::Vector<uint8_t> GetUTF8DataFromString(const String& string) {}

// Retrieves a RecordInit's |data| as a v8::Local<V8::Value> or creates a new
// v8::Undefined if |data| is not set.
// This is necessary because an empty v8::Local<V8::Value> as created in an
// empty ScriptValue will cause calls to v8::Value methods such as IsString()
// to crash.
v8::Local<v8::Value> GetPayloadDataOrUndefined(
    v8::Isolate* isolate,
    const NDEFRecordInit& record_init) {}

// This reproduces the V8 type checks from
// V8UnionArrayBufferOrArrayBufferView::Create() without attempting the V8 ->
// native conversions that can trigger exceptions. We just want to know if the
// V8 type is potentially convertible to a V8BufferSource.
bool MaybeIsBufferSource(const ScriptValue& script_value) {}

bool GetBytesOfBufferSource(const V8BufferSource* buffer_source,
                            WTF::Vector<uint8_t>* target,
                            ExceptionState& exception_state) {}

// https://w3c.github.io/web-nfc/#dfn-validate-external-type
// Validates |input| as an external type.
bool IsValidExternalType(const String& input) {}

// https://w3c.github.io/web-nfc/#dfn-validate-local-type
// Validates |input| as an local type.
bool IsValidLocalType(const String& input) {}

String getDocumentLanguage(const ExecutionContext* execution_context) {}

static NDEFRecord* CreateTextRecord(const ScriptState* script_state,
                                    const String& id,
                                    const NDEFRecordInit& record,
                                    ExceptionState& exception_state) {}

// Create a 'url' record or an 'absolute-url' record.
NDEFRecord* CreateUrlRecord(const ScriptState* script_state,
                            const String& id,
                            const NDEFRecordInit& record,
                            ExceptionState& exception_state) {}

NDEFRecord* CreateMimeRecord(const ScriptState* script_state,
                             const String& id,
                             const NDEFRecordInit& record,
                             ExceptionState& exception_state) {}

NDEFRecord* CreateUnknownRecord(const ScriptState* script_state,
                                const String& id,
                                const NDEFRecordInit& record,
                                ExceptionState& exception_state) {}

NDEFRecord* CreateSmartPosterRecord(const ScriptState* script_state,
                                    const String& id,
                                    const NDEFRecordInit& record,
                                    uint8_t records_depth,
                                    ExceptionState& exception_state) {}

NDEFRecord* CreateExternalRecord(const ScriptState* script_state,
                                 const String& id,
                                 const NDEFRecordInit& record,
                                 uint8_t records_depth,
                                 ExceptionState& exception_state) {}

NDEFRecord* CreateLocalRecord(const ScriptState* script_state,
                              const String& id,
                              const NDEFRecordInit& record,
                              uint8_t records_depth,
                              ExceptionState& exception_state) {}

}  // namespace

// static
NDEFRecord* NDEFRecord::CreateForBindings(const ScriptState* script_state,
                                          const NDEFRecordInit* record,
                                          ExceptionState& exception_state) {}

// static
NDEFRecord* NDEFRecord::Create(const ScriptState* script_state,
                               const NDEFRecordInit* record,
                               ExceptionState& exception_state,
                               uint8_t records_depth,
                               bool is_embedded) {}

NDEFRecord::NDEFRecord(device::mojom::blink::NDEFRecordTypeCategory category,
                       const String& record_type,
                       const String& id,
                       WTF::Vector<uint8_t> data)
    :{}

NDEFRecord::NDEFRecord(device::mojom::blink::NDEFRecordTypeCategory category,
                       const String& record_type,
                       const String& id,
                       NDEFMessage* payload_message)
    :{}

NDEFRecord::NDEFRecord(const String& id,
                       const String& encoding,
                       const String& lang,
                       WTF::Vector<uint8_t> data)
    :{}

NDEFRecord::NDEFRecord(const ScriptState* script_state, const String& text)
    :{}

NDEFRecord::NDEFRecord(const String& id,
                       const String& media_type,
                       WTF::Vector<uint8_t> data)
    :{}

// Even if |record| is for a local type record, here we do not validate if it's
// in the context of a parent record but just expose to JS as is.
NDEFRecord::NDEFRecord(const device::mojom::blink::NDEFRecord& record)
    :{}

const String& NDEFRecord::mediaType() const {}

DOMDataView* NDEFRecord::data() const {}

// https://w3c.github.io/web-nfc/#dfn-convert-ndefrecord-data-bytes
std::optional<HeapVector<Member<NDEFRecord>>> NDEFRecord::toRecords(
    ExceptionState& exception_state) const {}

void NDEFRecord::Trace(Visitor* visitor) const {}

}  // namespace blink