| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bluetooth/BluetoothError.h" | 5 #include "modules/bluetooth/BluetoothError.h" |
| 6 | 6 |
| 7 #include "core/dom/DOMException.h" | 7 #include "core/dom/DOMException.h" |
| 8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 DOMException* BluetoothError::take(ScriptPromiseResolver*, const WebBluetoothErr
or& webError) | 12 DOMException* BluetoothError::take(ScriptPromiseResolver*, const WebBluetoothErr
or& webError) |
| 13 { | 13 { |
| 14 switch (webError) { | 14 switch (webError) { |
| 15 case WebBluetoothError::SUCCESS: |
| 16 ASSERT_NOT_REACHED(); |
| 17 return DOMException::create(UnknownError); |
| 15 #define MAP_ERROR(enumeration, name, message) \ | 18 #define MAP_ERROR(enumeration, name, message) \ |
| 16 case WebBluetoothError::enumeration: \ | 19 case WebBluetoothError::enumeration: \ |
| 17 return DOMException::create(name, message) | 20 return DOMException::create(name, message) |
| 18 | 21 |
| 19 // InvalidModificationErrors: | 22 // InvalidModificationErrors: |
| 20 MAP_ERROR(GATTInvalidAttributeLength, InvalidModificationError, "GATT Er
ror: invalid attribute length."); | 23 MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, "GATT
Error: invalid attribute length."); |
| 21 | 24 |
| 22 // InvalidStateErrors: | 25 // InvalidStateErrors: |
| 23 MAP_ERROR(ServiceNoLongerExists, InvalidStateError, "GATT Service no lon
ger exists."); | 26 MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError, "GATT Service no
longer exists."); |
| 24 MAP_ERROR(CharacteristicNoLongerExists, InvalidStateError, "GATT Charact
eristic no longer exists."); | 27 MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError, "GATT Char
acteristic no longer exists."); |
| 25 | 28 |
| 26 // NetworkErrors: | 29 // NetworkErrors: |
| 27 MAP_ERROR(ConnectAlreadyInProgress, NetworkError, "Connection already in
progress."); | 30 MAP_ERROR(CONNECT_ALREADY_IN_PROGRESS, NetworkError, "Connection already
in progress."); |
| 28 MAP_ERROR(ConnectAttributeLengthInvalid, NetworkError, "Write operation
exceeds the maximum length of the attribute."); | 31 MAP_ERROR(CONNECT_ATTRIBUTE_LENGTH_INVALID, NetworkError, "Write operati
on exceeds the maximum length of the attribute."); |
| 29 MAP_ERROR(ConnectAuthCanceled, NetworkError, "Authentication canceled.")
; | 32 MAP_ERROR(CONNECT_AUTH_CANCELED, NetworkError, "Authentication canceled.
"); |
| 30 MAP_ERROR(ConnectAuthFailed, NetworkError, "Authentication failed."); | 33 MAP_ERROR(CONNECT_AUTH_FAILED, NetworkError, "Authentication failed."); |
| 31 MAP_ERROR(ConnectAuthRejected, NetworkError, "Authentication rejected.")
; | 34 MAP_ERROR(CONNECT_AUTH_REJECTED, NetworkError, "Authentication rejected.
"); |
| 32 MAP_ERROR(ConnectAuthTimeout, NetworkError, "Authentication timeout."); | 35 MAP_ERROR(CONNECT_AUTH_TIMEOUT, NetworkError, "Authentication timeout.")
; |
| 33 MAP_ERROR(ConnectConnectionCongested, NetworkError, "Remote device conne
ction is congested."); | 36 MAP_ERROR(CONNECT_CONNECTION_CONGESTED, NetworkError, "Remote device con
nection is congested."); |
| 34 MAP_ERROR(ConnectInsufficientEncryption, NetworkError, "Insufficient enc
ryption for a given operation"); | 37 MAP_ERROR(CONNECT_INSUFFICIENT_ENCRYPTION, NetworkError, "Insufficient e
ncryption for a given operation"); |
| 35 MAP_ERROR(ConnectOffsetInvalid, NetworkError, "Read or write operation w
as requested with an invalid offset."); | 38 MAP_ERROR(CONNECT_OFFSET_INVALID, NetworkError, "Read or write operation
was requested with an invalid offset."); |
| 36 MAP_ERROR(ConnectReadNotPermitted, NetworkError, "GATT read operation is
not permitted."); | 39 MAP_ERROR(CONNECT_READ_NOT_PERMITTED, NetworkError, "GATT read operation
is not permitted."); |
| 37 MAP_ERROR(ConnectRequestNotSupported, NetworkError, "The given request i
s not supported."); | 40 MAP_ERROR(CONNECT_REQUEST_NOT_SUPPORTED, NetworkError, "The given reques
t is not supported."); |
| 38 MAP_ERROR(ConnectUnknownError, NetworkError, "Unknown error when connect
ing to the device."); | 41 MAP_ERROR(CONNECT_UNKNOWN_ERROR, NetworkError, "Unknown error when conne
cting to the device."); |
| 39 MAP_ERROR(ConnectUnknownFailure, NetworkError, "Connection failed for un
known reason."); | 42 MAP_ERROR(CONNECT_UNKNOWN_FAILURE, NetworkError, "Connection failed for
unknown reason."); |
| 40 MAP_ERROR(ConnectUnsupportedDevice, NetworkError, "Unsupported device.")
; | 43 MAP_ERROR(CONNECT_UNSUPPORTED_DEVICE, NetworkError, "Unsupported device.
"); |
| 41 MAP_ERROR(ConnectWriteNotPermitted, NetworkError, "GATT write operation
is not permitted."); | 44 MAP_ERROR(CONNECT_WRITE_NOT_PERMITTED, NetworkError, "GATT write operati
on is not permitted."); |
| 42 MAP_ERROR(DeviceNoLongerInRange, NetworkError, "Bluetooth Device is no l
onger in range."); | 45 MAP_ERROR(DEVICE_NO_LONGER_IN_RANGE, NetworkError, "Bluetooth Device is
no longer in range."); |
| 43 MAP_ERROR(GATTNotPaired, NetworkError, "GATT Error: Not paired."); | 46 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); |
| 44 MAP_ERROR(GATTOperationInProgress, NetworkError, "GATT operation already
in progress."); | 47 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, "GATT operation alre
ady in progress."); |
| 45 MAP_ERROR(UntranslatedConnectErrorCode, NetworkError, "Unknown ConnectEr
rorCode."); | 48 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, "Unknown Connec
tErrorCode."); |
| 46 | 49 |
| 47 // NotFoundErrors: | 50 // NotFoundErrors: |
| 48 MAP_ERROR(NoBluetoothAdapter, NotFoundError, "Bluetooth adapter not avai
lable."); | 51 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, "Bluetooth adapter not av
ailable."); |
| 49 MAP_ERROR(ChosenDeviceVanished, NotFoundError, "User selected a device t
hat doesn't exist anymore."); | 52 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, "User selected a device
that doesn't exist anymore."); |
| 50 MAP_ERROR(ChooserCancelled, NotFoundError, "User cancelled the requestDe
vice() chooser."); | 53 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, "User cancelled the requestD
evice() chooser."); |
| 51 MAP_ERROR(ChooserDisabled, NotFoundError, "User or their enterprise poli
cy has disabled Web Bluetooth globally."); | 54 MAP_ERROR(CHOOSER_DISABLED, NotFoundError, "User or their enterprise pol
icy has disabled Web Bluetooth globally."); |
| 52 MAP_ERROR(ChooserDeniedPermission, NotFoundError, "User denied the brows
er permission to scan for Bluetooth devices."); | 55 MAP_ERROR(CHOOSER_DENIED_PERMISSION, NotFoundError, "User denied the bro
wser permission to scan for Bluetooth devices."); |
| 53 MAP_ERROR(ServiceNotFound, NotFoundError, "Service not found in device."
); | 56 MAP_ERROR(SERVICE_NOT_FOUND, NotFoundError, "Service not found in device
."); |
| 54 MAP_ERROR(CharacteristicNotFound, NotFoundError, "No Characteristics wit
h specified UUID found in Service."); | 57 MAP_ERROR(CHARACTERISTIC_NOT_FOUND, NotFoundError, "No Characteristics w
ith specified UUID found in Service."); |
| 55 MAP_ERROR(NoCharacteristicsFound, NotFoundError, "No Characteristics fou
nd in service."); | 58 MAP_ERROR(NO_CHARACTERISTICS_FOUND, NotFoundError, "No Characteristics f
ound in service."); |
| 56 | 59 |
| 57 // NotSupportedErrors: | 60 // NotSupportedErrors: |
| 58 MAP_ERROR(GATTUnknownError, NotSupportedError, "GATT Error Unknown."); | 61 MAP_ERROR(GATT_UNKNOWN_ERROR, NotSupportedError, "GATT Error Unknown."); |
| 59 MAP_ERROR(GATTUnknownFailure, NotSupportedError, "GATT operation failed
for unknown reason."); | 62 MAP_ERROR(GATT_UNKNOWN_FAILURE, NotSupportedError, "GATT operation faile
d for unknown reason."); |
| 60 MAP_ERROR(GATTNotPermitted, NotSupportedError, "GATT operation not permi
tted."); | 63 MAP_ERROR(GATT_NOT_PERMITTED, NotSupportedError, "GATT operation not per
mitted."); |
| 61 MAP_ERROR(GATTNotSupported, NotSupportedError, "GATT Error: Not supporte
d."); | 64 MAP_ERROR(GATT_NOT_SUPPORTED, NotSupportedError, "GATT Error: Not suppor
ted."); |
| 62 MAP_ERROR(GATTUntranslatedErrorCode, NotSupportedError, "GATT Error: Unk
nown GattErrorCode."); | 65 MAP_ERROR(GATT_UNTRANSLATED_ERROR_CODE, NotSupportedError, "GATT Error:
Unknown GattErrorCode."); |
| 63 | 66 |
| 64 // SecurityErrors: | 67 // SecurityErrors: |
| 65 MAP_ERROR(GATTNotAuthorized, SecurityError, "GATT operation not authoriz
ed."); | 68 MAP_ERROR(GATT_NOT_AUTHORIZED, SecurityError, "GATT operation not author
ized."); |
| 66 MAP_ERROR(BlacklistedCharacteristicUUID, SecurityError, "getCharacterist
ic(s) called with blacklisted UUID. https://goo.gl/4NeimX"); | 69 MAP_ERROR(BLACKLISTED_CHARACTERISTIC_UUID, SecurityError, "getCharacteri
stic(s) called with blacklisted UUID. https://goo.gl/4NeimX"); |
| 67 MAP_ERROR(BlacklistedRead, SecurityError, "readValue() called on blackli
sted object marked exclude-reads. https://goo.gl/4NeimX"); | 70 MAP_ERROR(BLACKLISTED_READ, SecurityError, "readValue() called on blackl
isted object marked exclude-reads. https://goo.gl/4NeimX"); |
| 68 MAP_ERROR(BlacklistedWrite, SecurityError, "writeValue() called on black
listed object marked exclude-writes. https://goo.gl/4NeimX"); | 71 MAP_ERROR(BLACKLISTED_WRITE, SecurityError, "writeValue() called on blac
klisted object marked exclude-writes. https://goo.gl/4NeimX"); |
| 69 MAP_ERROR(NotAllowedToAccessService, SecurityError, "Origin is not allow
ed to access the service. Remember to add the service to a filter or to optional
Services in requestDevice()."); | 72 MAP_ERROR(NOT_ALLOWED_TO_ACCESS_SERVICE, SecurityError, "Origin is not a
llowed to access the service. Remember to add the service to a filter or to opti
onalServices in requestDevice()."); |
| 70 MAP_ERROR(RequestDeviceWithBlacklistedUUID, SecurityError, "requestDevic
e() called with a filter containing a blacklisted UUID. https://goo.gl/4NeimX"); | 73 MAP_ERROR(REQUEST_DEVICE_WITH_BLACKLISTED_UUID, SecurityError, "requestD
evice() called with a filter containing a blacklisted UUID. https://goo.gl/4Neim
X"); |
| 71 MAP_ERROR(RequestDeviceWithUniqueOrigin, SecurityError, "requestDevice()
called from sandboxed or otherwise unique origin."); | 74 MAP_ERROR(REQUEST_DEVICE_WITH_UNIQUE_ORIGIN, SecurityError, "requestDevi
ce() called from sandboxed or otherwise unique origin."); |
| 72 MAP_ERROR(RequestDeviceWithoutFrame, SecurityError, "No window to show t
he requestDevice() dialog."); | 75 MAP_ERROR(REQUEST_DEVICE_WITHOUT_FRAME, SecurityError, "No window to sho
w the requestDevice() dialog."); |
| 73 | 76 |
| 74 #undef MAP_ERROR | 77 #undef MAP_ERROR |
| 75 } | 78 } |
| 76 | 79 |
| 77 ASSERT_NOT_REACHED(); | 80 ASSERT_NOT_REACHED(); |
| 78 return DOMException::create(UnknownError); | 81 return DOMException::create(UnknownError); |
| 79 } | 82 } |
| 80 | 83 |
| 81 } // namespace blink | 84 } // namespace blink |
| OLD | NEW |