Chromium Code Reviews| 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*, | 12 // static |
| 13 mojom::blink::WebBluetoothResult error) { | 13 DOMException* BluetoothError::CreateDOMException( |
| 14 mojom::blink::WebBluetoothResult error, | |
| 15 String detailedMessage) { | |
| 14 switch (error) { | 16 switch (error) { |
| 15 case mojom::blink::WebBluetoothResult::SUCCESS: | 17 case mojom::blink::WebBluetoothResult::SUCCESS: |
| 16 ASSERT_NOT_REACHED(); | 18 ASSERT_NOT_REACHED(); |
| 17 return DOMException::create(UnknownError); | 19 return DOMException::create(UnknownError); |
| 18 #define MAP_ERROR(enumeration, name, message) \ | 20 #define MAP_ERROR(enumeration, name, message) \ |
| 19 case mojom::blink::WebBluetoothResult::enumeration: \ | 21 case mojom::blink::WebBluetoothResult::enumeration: \ |
| 20 return DOMException::create(name, message) | 22 if (detailedMessage.isEmpty()) { \ |
| 23 return DOMException::create(name, message); \ | |
| 24 } else { \ | |
| 25 return DOMException::create(name, detailedMessage); \ | |
|
dcheng
2017/02/09 19:16:41
FWIW, I'm not an owner of this code, but I'd prefe
perja
2017/02/10 13:28:16
Done.
| |
| 26 } | |
| 21 | 27 |
| 22 // InvalidModificationErrors: | 28 // InvalidModificationErrors: |
| 23 MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, | 29 MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, |
| 24 "GATT Error: invalid attribute length."); | 30 "GATT Error: invalid attribute length."); |
| 25 | 31 |
| 26 // InvalidStateErrors: | 32 // InvalidStateErrors: |
| 27 MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError, | 33 MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError, |
| 28 "GATT Service no longer exists."); | 34 "GATT Service no longer exists."); |
| 29 MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError, | 35 MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError, |
| 30 "GATT Characteristic no longer exists."); | 36 "GATT Characteristic no longer exists."); |
| 31 MAP_ERROR(DESCRIPTOR_NO_LONGER_EXISTS, InvalidStateError, | 37 MAP_ERROR(DESCRIPTOR_NO_LONGER_EXISTS, InvalidStateError, |
| 32 "GATT Descriptor no longer exists."); | 38 "GATT Descriptor no longer exists."); |
| 39 MAP_ERROR(INVALID_CHARACTERISTIC, InvalidStateError, | |
| 40 "Characteristic is no longer valid. Remember to retrieve the " | |
| 41 "characteristic again after reconnecting."); | |
| 42 MAP_ERROR(INVALID_DESCRIPTOR, InvalidStateError, | |
| 43 "Descriptor is no longer valid. Remember to retrieve the " | |
| 44 "Descriptor again after reconnecting."); | |
| 33 | 45 |
| 34 // NetworkErrors: | 46 // NetworkErrors: |
| 35 MAP_ERROR(CONNECT_ALREADY_IN_PROGRESS, NetworkError, | 47 MAP_ERROR(CONNECT_ALREADY_IN_PROGRESS, NetworkError, |
| 36 "Connection already in progress."); | 48 "Connection already in progress."); |
| 37 MAP_ERROR(CONNECT_ATTRIBUTE_LENGTH_INVALID, NetworkError, | 49 MAP_ERROR(CONNECT_ATTRIBUTE_LENGTH_INVALID, NetworkError, |
| 38 "Write operation exceeds the maximum length of the attribute."); | 50 "Write operation exceeds the maximum length of the attribute."); |
| 39 MAP_ERROR(CONNECT_AUTH_CANCELED, NetworkError, | 51 MAP_ERROR(CONNECT_AUTH_CANCELED, NetworkError, |
| 40 "Authentication canceled."); | 52 "Authentication canceled."); |
| 41 MAP_ERROR(CONNECT_AUTH_FAILED, NetworkError, "Authentication failed."); | 53 MAP_ERROR(CONNECT_AUTH_FAILED, NetworkError, "Authentication failed."); |
| 42 MAP_ERROR(CONNECT_AUTH_REJECTED, NetworkError, | 54 MAP_ERROR(CONNECT_AUTH_REJECTED, NetworkError, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 61 "Unsupported device."); | 73 "Unsupported device."); |
| 62 MAP_ERROR(CONNECT_WRITE_NOT_PERMITTED, NetworkError, | 74 MAP_ERROR(CONNECT_WRITE_NOT_PERMITTED, NetworkError, |
| 63 "GATT write operation is not permitted."); | 75 "GATT write operation is not permitted."); |
| 64 MAP_ERROR(DEVICE_NO_LONGER_IN_RANGE, NetworkError, | 76 MAP_ERROR(DEVICE_NO_LONGER_IN_RANGE, NetworkError, |
| 65 "Bluetooth Device is no longer in range."); | 77 "Bluetooth Device is no longer in range."); |
| 66 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); | 78 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); |
| 67 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, | 79 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, |
| 68 "GATT operation already in progress."); | 80 "GATT operation already in progress."); |
| 69 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, | 81 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, |
| 70 "Unknown ConnectErrorCode."); | 82 "Unknown ConnectErrorCode."); |
| 83 MAP_ERROR(GATT_SERVER_NOT_CONNECTED, NetworkError, | |
| 84 "GATT Server is disconnected. Cannot perform GATT operations."); | |
| 85 MAP_ERROR(GATT_SERVER_DISCONNECTED, NetworkError, | |
| 86 "GATT Server disconnected while performing a GATT operation."); | |
| 71 | 87 |
| 72 // NotFoundErrors: | 88 // NotFoundErrors: |
| 73 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, | 89 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, |
| 74 "Web Bluetooth is not supported on this platform. For a list " | 90 "Web Bluetooth is not supported on this platform. For a list " |
| 75 "of supported platforms see: https://goo.gl/J6ASzs"); | 91 "of supported platforms see: https://goo.gl/J6ASzs"); |
| 76 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, | 92 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, |
| 77 "Bluetooth adapter not available."); | 93 "Bluetooth adapter not available."); |
| 78 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, | 94 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, |
| 79 "User selected a device that doesn't exist anymore."); | 95 "User selected a device that doesn't exist anymore."); |
| 80 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, | 96 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 "No window to show the requestDevice() dialog."); | 160 "No window to show the requestDevice() dialog."); |
| 145 | 161 |
| 146 #undef MAP_ERROR | 162 #undef MAP_ERROR |
| 147 } | 163 } |
| 148 | 164 |
| 149 ASSERT_NOT_REACHED(); | 165 ASSERT_NOT_REACHED(); |
| 150 return DOMException::create(UnknownError); | 166 return DOMException::create(UnknownError); |
| 151 } | 167 } |
| 152 | 168 |
| 153 } // namespace blink | 169 } // namespace blink |
| OLD | NEW |