| 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 #define MAP_ERROR(enumeration, name, message) \ | 15 #define MAP_ERROR(enumeration, name, message) \ |
| 16 case WebBluetoothError::enumeration: \ | 16 case WebBluetoothError::enumeration: \ |
| 17 return DOMException::create(name, message) | 17 return DOMException::create(name, message) |
| 18 | 18 |
| 19 // InvalidModificationErrors: | 19 // InvalidModificationErrors: |
| 20 MAP_ERROR(GATTInvalidAttributeLength, InvalidModificationError, "GATT Er
ror: invalid attribute length."); | 20 MAP_ERROR(GATTInvalidAttributeLength, InvalidModificationError, "GATT Er
ror: invalid attribute length."); |
| 21 | 21 |
| 22 // InvalidStateErrors: | 22 // InvalidStateErrors: |
| 23 MAP_ERROR(ServiceNoLongerExists, InvalidStateError, "GATT Service no lon
ger exists."); | 23 MAP_ERROR(ServiceNoLongerExists, InvalidStateError, "GATT Service no lon
ger exists."); |
| 24 MAP_ERROR(CharacteristicNoLongerExists, InvalidStateError, "GATT Charact
eristic no longer exists."); | 24 MAP_ERROR(CharacteristicNoLongerExists, InvalidStateError, "GATT Charact
eristic no longer exists."); |
| 25 | 25 |
| 26 // NetworkErrors: | 26 // NetworkErrors: |
| 27 MAP_ERROR(GATTOperationInProgress, NetworkError, "GATT operation already
in progress."); | |
| 28 MAP_ERROR(GATTNotPaired, NetworkError, "GATT Error: Not paired."); | |
| 29 MAP_ERROR(DeviceNoLongerInRange, NetworkError, "Bluetooth Device is no l
onger in range."); | |
| 30 MAP_ERROR(ConnectUnknownError, NetworkError, "Unknown error when connect
ing to the device."); | |
| 31 MAP_ERROR(ConnectAlreadyInProgress, NetworkError, "Connection already in
progress."); | 27 MAP_ERROR(ConnectAlreadyInProgress, NetworkError, "Connection already in
progress."); |
| 32 MAP_ERROR(ConnectUnknownFailure, NetworkError, "Connection failed for un
known reason."); | 28 MAP_ERROR(ConnectAttributeLengthInvalid, NetworkError, "Write operation
exceeds the maximum length of the attribute."); |
| 29 MAP_ERROR(ConnectAuthCanceled, NetworkError, "Authentication canceled.")
; |
| 33 MAP_ERROR(ConnectAuthFailed, NetworkError, "Authentication failed."); | 30 MAP_ERROR(ConnectAuthFailed, NetworkError, "Authentication failed."); |
| 34 MAP_ERROR(ConnectAuthCanceled, NetworkError, "Authentication canceled.")
; | |
| 35 MAP_ERROR(ConnectAuthRejected, NetworkError, "Authentication rejected.")
; | 31 MAP_ERROR(ConnectAuthRejected, NetworkError, "Authentication rejected.")
; |
| 36 MAP_ERROR(ConnectAuthTimeout, NetworkError, "Authentication timeout."); | 32 MAP_ERROR(ConnectAuthTimeout, NetworkError, "Authentication timeout."); |
| 33 MAP_ERROR(ConnectConnectionCongested, NetworkError, "Remote device conne
ction is congested."); |
| 34 MAP_ERROR(ConnectInsufficientEncryption, NetworkError, "Insufficient enc
ryption for a given operation"); |
| 35 MAP_ERROR(ConnectOffsetInvalid, NetworkError, "Read or write operation w
as requested with an invalid offset."); |
| 36 MAP_ERROR(ConnectReadNotPermitted, NetworkError, "GATT read operation is
not permitted."); |
| 37 MAP_ERROR(ConnectRequestNotSupported, NetworkError, "The given request i
s not supported."); |
| 38 MAP_ERROR(ConnectUnknownError, NetworkError, "Unknown error when connect
ing to the device."); |
| 39 MAP_ERROR(ConnectUnknownFailure, NetworkError, "Connection failed for un
known reason."); |
| 37 MAP_ERROR(ConnectUnsupportedDevice, NetworkError, "Unsupported device.")
; | 40 MAP_ERROR(ConnectUnsupportedDevice, NetworkError, "Unsupported device.")
; |
| 41 MAP_ERROR(ConnectWriteNotPermitted, NetworkError, "GATT write operation
is not permitted."); |
| 42 MAP_ERROR(DeviceNoLongerInRange, NetworkError, "Bluetooth Device is no l
onger in range."); |
| 43 MAP_ERROR(GATTNotPaired, NetworkError, "GATT Error: Not paired."); |
| 44 MAP_ERROR(GATTOperationInProgress, NetworkError, "GATT operation already
in progress."); |
| 38 MAP_ERROR(UntranslatedConnectErrorCode, NetworkError, "Unknown ConnectEr
rorCode."); | 45 MAP_ERROR(UntranslatedConnectErrorCode, NetworkError, "Unknown ConnectEr
rorCode."); |
| 39 | 46 |
| 40 // NotFoundErrors: | 47 // NotFoundErrors: |
| 41 MAP_ERROR(NoBluetoothAdapter, NotFoundError, "Bluetooth adapter not avai
lable."); | 48 MAP_ERROR(NoBluetoothAdapter, NotFoundError, "Bluetooth adapter not avai
lable."); |
| 42 MAP_ERROR(ChosenDeviceVanished, NotFoundError, "User selected a device t
hat doesn't exist anymore."); | 49 MAP_ERROR(ChosenDeviceVanished, NotFoundError, "User selected a device t
hat doesn't exist anymore."); |
| 43 MAP_ERROR(ChooserCancelled, NotFoundError, "User cancelled the requestDe
vice() chooser."); | 50 MAP_ERROR(ChooserCancelled, NotFoundError, "User cancelled the requestDe
vice() chooser."); |
| 44 MAP_ERROR(ChooserDeniedPermission, NotFoundError, "User denied the brows
er permission to scan for Bluetooth devices."); | 51 MAP_ERROR(ChooserDeniedPermission, NotFoundError, "User denied the brows
er permission to scan for Bluetooth devices."); |
| 45 MAP_ERROR(ServiceNotFound, NotFoundError, "Service not found in device."
); | 52 MAP_ERROR(ServiceNotFound, NotFoundError, "Service not found in device."
); |
| 46 MAP_ERROR(CharacteristicNotFound, NotFoundError, "Characteristic not fou
nd in device."); | 53 MAP_ERROR(CharacteristicNotFound, NotFoundError, "Characteristic not fou
nd in device."); |
| 47 | 54 |
| 48 // NotSupportedErrors: | 55 // NotSupportedErrors: |
| 49 MAP_ERROR(GATTUnknownError, NotSupportedError, "GATT Error Unknown."); | 56 MAP_ERROR(GATTUnknownError, NotSupportedError, "GATT Error Unknown."); |
| 50 MAP_ERROR(GATTUnknownFailure, NotSupportedError, "GATT operation failed
for unknown reason."); | 57 MAP_ERROR(GATTUnknownFailure, NotSupportedError, "GATT operation failed
for unknown reason."); |
| 51 MAP_ERROR(GATTNotPermitted, NotSupportedError, "GATT operation not permi
tted."); | 58 MAP_ERROR(GATTNotPermitted, NotSupportedError, "GATT operation not permi
tted."); |
| 52 MAP_ERROR(GATTNotSupported, NotSupportedError, "GATT Error: Not supporte
d."); | 59 MAP_ERROR(GATTNotSupported, NotSupportedError, "GATT Error: Not supporte
d."); |
| 53 MAP_ERROR(GATTUntranslatedErrorCode, NotSupportedError, "GATT Error: Unk
nown GattErrorCode."); | 60 MAP_ERROR(GATTUntranslatedErrorCode, NotSupportedError, "GATT Error: Unk
nown GattErrorCode."); |
| 54 | 61 |
| 55 // SecurityErrors: | 62 // SecurityErrors: |
| 56 MAP_ERROR(GATTNotAuthorized, SecurityError, "GATT operation not authoriz
ed."); | 63 MAP_ERROR(GATTNotAuthorized, SecurityError, "GATT operation not authoriz
ed."); |
| 57 MAP_ERROR(RequestDeviceWithoutFrame, SecurityError, "No window to show t
he requestDevice() dialog."); | 64 MAP_ERROR(RequestDeviceWithoutFrame, SecurityError, "No window to show t
he requestDevice() dialog."); |
| 58 | 65 |
| 59 #undef MAP_ERROR | 66 #undef MAP_ERROR |
| 60 } | 67 } |
| 61 | 68 |
| 62 ASSERT_NOT_REACHED(); | 69 ASSERT_NOT_REACHED(); |
| 63 return DOMException::create(UnknownError); | 70 return DOMException::create(UnknownError); |
| 64 } | 71 } |
| 65 | 72 |
| 66 } // namespace blink | 73 } // namespace blink |
| OLD | NEW |