Commit aca54053 authored by Francois Beaufort's avatar Francois Beaufort Committed by Chromium LUCI CQ

[WebNFC] Move NDEFErrorTypeToDOMException to ndef_reader.cc

This CL has no functional changes. It moves NDEFErrorTypeToDOMException
function to the only file where it's used: ndef_reader.cc.

Bug: 520391
Change-Id: I910d57147dba47579b78586edce8041d0b2d326c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2587167Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarRijubrata Bhaumik <rijubrata.bhaumik@intel.com>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/master@{#837098}
parent fcf01df7
......@@ -18,8 +18,6 @@ blink_modules_sources("nfc") {
"nfc_proxy.h",
"nfc_type_converters.cc",
"nfc_type_converters.h",
"nfc_utils.cc",
"nfc_utils.h",
]
deps = [ "//third_party/blink/renderer/modules/permissions" ]
}
......@@ -22,7 +22,6 @@
#include "third_party/blink/renderer/modules/nfc/ndef_reading_event.h"
#include "third_party/blink/renderer/modules/nfc/nfc_proxy.h"
#include "third_party/blink/renderer/modules/nfc/nfc_type_converters.h"
#include "third_party/blink/renderer/modules/nfc/nfc_utils.h"
#include "third_party/blink/renderer/modules/permissions/permission_utils.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/scheduler/public/frame_scheduler.h"
......@@ -37,6 +36,34 @@ using mojom::blink::PermissionStatus;
namespace {
DOMException* NDEFErrorTypeToDOMException(
device::mojom::blink::NDEFErrorType error_type,
const String& error_message) {
switch (error_type) {
case device::mojom::blink::NDEFErrorType::NOT_ALLOWED:
return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotAllowedError, error_message);
case device::mojom::blink::NDEFErrorType::NOT_SUPPORTED:
return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotSupportedError, error_message);
case device::mojom::blink::NDEFErrorType::NOT_READABLE:
return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotReadableError, error_message);
case device::mojom::blink::NDEFErrorType::INVALID_MESSAGE:
return MakeGarbageCollected<DOMException>(DOMExceptionCode::kSyntaxError,
error_message);
case device::mojom::blink::NDEFErrorType::OPERATION_CANCELLED:
return MakeGarbageCollected<DOMException>(DOMExceptionCode::kAbortError,
error_message);
case device::mojom::blink::NDEFErrorType::IO_ERROR:
return MakeGarbageCollected<DOMException>(DOMExceptionCode::kNetworkError,
error_message);
}
NOTREACHED();
// Don't need to handle the case after a NOTREACHED().
return nullptr;
}
constexpr char kNotSupportedOrPermissionDenied[] =
"Web NFC is unavailable or permission denied.";
......
......@@ -15,7 +15,6 @@
#include "third_party/blink/renderer/core/frame/local_dom_window.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/modules/nfc/nfc_utils.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/network/http_parsers.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
......
......@@ -11,7 +11,6 @@
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/modules/nfc/ndef_reader.h"
#include "third_party/blink/renderer/modules/nfc/nfc_type_converters.h"
#include "third_party/blink/renderer/modules/nfc/nfc_utils.h"
#include "third_party/blink/renderer/platform/mojo/mojo_helper.h"
namespace blink {
......
......@@ -11,7 +11,6 @@
#include "third_party/blink/renderer/bindings/modules/v8/v8_ndef_write_options.h"
#include "third_party/blink/renderer/modules/nfc/ndef_message.h"
#include "third_party/blink/renderer/modules/nfc/ndef_record.h"
#include "third_party/blink/renderer/modules/nfc/nfc_utils.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
using device::mojom::blink::NDEFMessage;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// 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/nfc_utils.h"
#include <limits>
#include <utility>
#include "services/device/public/mojom/nfc.mojom-blink.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
namespace blink {
DOMException* NDEFErrorTypeToDOMException(
device::mojom::blink::NDEFErrorType error_type,
const String& error_message) {
switch (error_type) {
case device::mojom::blink::NDEFErrorType::NOT_ALLOWED:
return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotAllowedError, error_message);
case device::mojom::blink::NDEFErrorType::NOT_SUPPORTED:
return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotSupportedError, error_message);
case device::mojom::blink::NDEFErrorType::NOT_READABLE:
return MakeGarbageCollected<DOMException>(
DOMExceptionCode::kNotReadableError, error_message);
case device::mojom::blink::NDEFErrorType::INVALID_MESSAGE:
return MakeGarbageCollected<DOMException>(DOMExceptionCode::kSyntaxError,
error_message);
case device::mojom::blink::NDEFErrorType::OPERATION_CANCELLED:
return MakeGarbageCollected<DOMException>(DOMExceptionCode::kAbortError,
error_message);
case device::mojom::blink::NDEFErrorType::IO_ERROR:
return MakeGarbageCollected<DOMException>(DOMExceptionCode::kNetworkError,
error_message);
}
NOTREACHED();
// Don't need to handle the case after a NOTREACHED().
return nullptr;
}
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// 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_NFC_UTILS_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_NFC_NFC_UTILS_H_
#include "services/device/public/mojom/nfc.mojom-blink-forward.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class DOMException;
DOMException* NDEFErrorTypeToDOMException(
device::mojom::blink::NDEFErrorType error_type,
const String& error_message);
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_NFC_NFC_UTILS_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment