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 const 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 NOTREACHED(); |
| 19 return DOMException::create(UnknownError); | |
| 20 case mojom::blink::WebBluetoothResult::SERVICE_NOT_FOUND: | |
| 21 return DOMException::create(NotFoundError, detailedMessage); | |
| 22 case mojom::blink::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND: | |
| 23 return DOMException::create(NotFoundError, detailedMessage); | |
| 24 case mojom::blink::WebBluetoothResult::DESCRIPTOR_NOT_FOUND: | |
| 25 return DOMException::create(NotFoundError, detailedMessage); | |
| 26 case mojom::blink::WebBluetoothResult::INVALID_SERVICE: | |
| 27 return DOMException::create(InvalidStateError, detailedMessage); | |
| 28 case mojom::blink::WebBluetoothResult::INVALID_CHARACTERISTIC: | |
| 29 return DOMException::create(InvalidStateError, detailedMessage); | |
| 30 case mojom::blink::WebBluetoothResult::INVALID_DESCRIPTOR: | |
| 31 return DOMException::create(InvalidStateError, detailedMessage); | |
| 32 default: | |
| 33 NOTREACHED(); | |
| 34 return DOMException::create(UnknownError); | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 // static | |
| 39 DOMException* BluetoothError::createDOMException( | |
| 40 mojom::blink::WebBluetoothResult error) { | |
| 41 switch (error) { | |
| 42 case mojom::blink::WebBluetoothResult::SUCCESS: | |
| 43 NOTREACHED(); | |
| 17 return DOMException::create(UnknownError); | 44 return DOMException::create(UnknownError); |
| 18 #define MAP_ERROR(enumeration, name, message) \ | 45 #define MAP_ERROR(enumeration, name, message) \ |
| 19 case mojom::blink::WebBluetoothResult::enumeration: \ | 46 case mojom::blink::WebBluetoothResult::enumeration: \ |
| 20 return DOMException::create(name, message) | 47 return DOMException::create(name, message); |
| 21 | 48 |
| 22 // InvalidModificationErrors: | 49 // InvalidModificationErrors: |
| 23 MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, | 50 MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, |
| 24 "GATT Error: invalid attribute length."); | 51 "GATT Error: invalid attribute length."); |
| 25 | 52 |
| 26 // InvalidStateErrors: | 53 // InvalidStateErrors: |
| 27 MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError, | 54 MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError, |
| 28 "GATT Service no longer exists."); | 55 "GATT Service no longer exists."); |
| 29 MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError, | 56 MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError, |
| 30 "GATT Characteristic no longer exists."); | 57 "GATT Characteristic no longer exists."); |
| 31 MAP_ERROR(DESCRIPTOR_NO_LONGER_EXISTS, InvalidStateError, | 58 MAP_ERROR(DESCRIPTOR_NO_LONGER_EXISTS, InvalidStateError, |
| 32 "GATT Descriptor no longer exists."); | 59 "GATT Descriptor no longer exists."); |
| 60 MAP_ERROR(INVALID_CHARACTERISTIC, InvalidStateError, | |
| 61 "Characteristic is no longer valid. Remember to retrieve the " | |
| 62 "characteristic again after reconnecting."); | |
| 63 MAP_ERROR(INVALID_DESCRIPTOR, InvalidStateError, | |
| 64 "Descriptor is no longer valid. Remember to retrieve the " | |
| 65 "Descriptor again after reconnecting."); | |
| 66 MAP_ERROR(INVALID_SERVICE, InvalidStateError, | |
|
scheib
2017/02/10 18:25:34
This new pattern does not LGTM. (Sorry for noticin
| |
| 67 "Service is no longer valid. Remember to retrieve the service " | |
| 68 "again after reconnecting."); | |
| 33 | 69 |
| 34 // NetworkErrors: | 70 // NetworkErrors: |
| 35 MAP_ERROR(CONNECT_ALREADY_IN_PROGRESS, NetworkError, | 71 MAP_ERROR(CONNECT_ALREADY_IN_PROGRESS, NetworkError, |
| 36 "Connection already in progress."); | 72 "Connection already in progress."); |
| 37 MAP_ERROR(CONNECT_ATTRIBUTE_LENGTH_INVALID, NetworkError, | 73 MAP_ERROR(CONNECT_ATTRIBUTE_LENGTH_INVALID, NetworkError, |
| 38 "Write operation exceeds the maximum length of the attribute."); | 74 "Write operation exceeds the maximum length of the attribute."); |
| 39 MAP_ERROR(CONNECT_AUTH_CANCELED, NetworkError, | 75 MAP_ERROR(CONNECT_AUTH_CANCELED, NetworkError, |
| 40 "Authentication canceled."); | 76 "Authentication canceled."); |
| 41 MAP_ERROR(CONNECT_AUTH_FAILED, NetworkError, "Authentication failed."); | 77 MAP_ERROR(CONNECT_AUTH_FAILED, NetworkError, "Authentication failed."); |
| 42 MAP_ERROR(CONNECT_AUTH_REJECTED, NetworkError, | 78 MAP_ERROR(CONNECT_AUTH_REJECTED, NetworkError, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 61 "Unsupported device."); | 97 "Unsupported device."); |
| 62 MAP_ERROR(CONNECT_WRITE_NOT_PERMITTED, NetworkError, | 98 MAP_ERROR(CONNECT_WRITE_NOT_PERMITTED, NetworkError, |
| 63 "GATT write operation is not permitted."); | 99 "GATT write operation is not permitted."); |
| 64 MAP_ERROR(DEVICE_NO_LONGER_IN_RANGE, NetworkError, | 100 MAP_ERROR(DEVICE_NO_LONGER_IN_RANGE, NetworkError, |
| 65 "Bluetooth Device is no longer in range."); | 101 "Bluetooth Device is no longer in range."); |
| 66 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); | 102 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); |
| 67 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, | 103 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, |
| 68 "GATT operation already in progress."); | 104 "GATT operation already in progress."); |
| 69 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, | 105 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, |
| 70 "Unknown ConnectErrorCode."); | 106 "Unknown ConnectErrorCode."); |
| 107 MAP_ERROR(GATT_SERVER_NOT_CONNECTED, NetworkError, | |
| 108 "GATT Server is disconnected. Cannot perform GATT operations."); | |
| 109 MAP_ERROR(GATT_SERVER_DISCONNECTED, NetworkError, | |
| 110 "GATT Server disconnected while performing a GATT operation."); | |
| 111 MAP_ERROR(GATT_SERVER_DISCONNECTED_WHILE_RETRIEVING_CHARACTERISTICS, | |
| 112 NetworkError, | |
| 113 "GATT Server disconnected while retrieving characteristics."); | |
| 114 MAP_ERROR( | |
| 115 GATT_SERVER_NOT_CONNECTED_CANNOT_RETRIEVE_CHARACTERISTICS, | |
| 116 NetworkError, | |
| 117 "GATT Server is disconnected. Cannot retrieve characteristics."); | |
| 71 | 118 |
| 72 // NotFoundErrors: | 119 // NotFoundErrors: |
| 73 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, | 120 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, |
| 74 "Web Bluetooth is not supported on this platform. For a list " | 121 "Web Bluetooth is not supported on this platform. For a list " |
| 75 "of supported platforms see: https://goo.gl/J6ASzs"); | 122 "of supported platforms see: https://goo.gl/J6ASzs"); |
| 76 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, | 123 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, |
| 77 "Bluetooth adapter not available."); | 124 "Bluetooth adapter not available."); |
| 78 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, | 125 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, |
| 79 "User selected a device that doesn't exist anymore."); | 126 "User selected a device that doesn't exist anymore."); |
| 80 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, | 127 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 "requestDevice() called with a filter containing a blocklisted " | 186 "requestDevice() called with a filter containing a blocklisted " |
| 140 "UUID. https://goo.gl/4NeimX"); | 187 "UUID. https://goo.gl/4NeimX"); |
| 141 MAP_ERROR(REQUEST_DEVICE_FROM_CROSS_ORIGIN_IFRAME, SecurityError, | 188 MAP_ERROR(REQUEST_DEVICE_FROM_CROSS_ORIGIN_IFRAME, SecurityError, |
| 142 "requestDevice() called from cross-origin iframe."); | 189 "requestDevice() called from cross-origin iframe."); |
| 143 MAP_ERROR(REQUEST_DEVICE_WITHOUT_FRAME, SecurityError, | 190 MAP_ERROR(REQUEST_DEVICE_WITHOUT_FRAME, SecurityError, |
| 144 "No window to show the requestDevice() dialog."); | 191 "No window to show the requestDevice() dialog."); |
| 145 | 192 |
| 146 #undef MAP_ERROR | 193 #undef MAP_ERROR |
| 147 } | 194 } |
| 148 | 195 |
| 149 ASSERT_NOT_REACHED(); | 196 NOTREACHED(); |
| 150 return DOMException::create(UnknownError); | 197 return DOMException::create(UnknownError); |
| 151 } | 198 } |
| 152 | 199 |
| 153 } // namespace blink | 200 } // namespace blink |
| OLD | NEW |