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 BluetoothErrorCode error, | |
| 15 const String& detailedMessage) { | |
| 16 switch (error) { | |
| 17 case BluetoothErrorCode::InvalidService: | |
| 18 case BluetoothErrorCode::InvalidCharacteristic: | |
| 19 case BluetoothErrorCode::InvalidDescriptor: | |
| 20 return DOMException::create(InvalidStateError, detailedMessage); | |
| 21 case BluetoothErrorCode::ServiceNotFound: | |
| 22 case BluetoothErrorCode::CharacteristicNotFound: | |
| 23 case BluetoothErrorCode::DescriptorNotFound: | |
| 24 return DOMException::create(NotFoundError, detailedMessage); | |
| 25 } | |
| 26 NOTREACHED(); | |
| 27 return DOMException::create(UnknownError); | |
| 28 } | |
| 29 | |
| 30 // static | |
| 31 DOMException* BluetoothError::createDOMException( | |
| 32 mojom::blink::WebBluetoothResult error) { | |
| 14 switch (error) { | 33 switch (error) { |
| 15 case mojom::blink::WebBluetoothResult::SUCCESS: | 34 case mojom::blink::WebBluetoothResult::SUCCESS: |
| 16 ASSERT_NOT_REACHED(); | 35 case mojom::blink::WebBluetoothResult::SERVICE_NOT_FOUND: |
| 36 case mojom::blink::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND: | |
| 37 case mojom::blink::WebBluetoothResult::DESCRIPTOR_NOT_FOUND: | |
| 38 NOTREACHED(); | |
|
scheib
2017/02/27 17:57:14
Please add a comment here explaining why these thr
perja
2017/02/28 11:45:18
Done.
| |
| 17 return DOMException::create(UnknownError); | 39 return DOMException::create(UnknownError); |
| 18 #define MAP_ERROR(enumeration, name, message) \ | 40 #define MAP_ERROR(enumeration, name, message) \ |
| 19 case mojom::blink::WebBluetoothResult::enumeration: \ | 41 case mojom::blink::WebBluetoothResult::enumeration: \ |
| 20 return DOMException::create(name, message) | 42 return DOMException::create(name, message); |
| 21 | 43 |
| 22 // InvalidModificationErrors: | 44 // InvalidModificationErrors: |
| 23 MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, | 45 MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, |
| 24 "GATT Error: invalid attribute length."); | 46 "GATT Error: invalid attribute length."); |
| 25 | 47 |
| 26 // InvalidStateErrors: | 48 // InvalidStateErrors: |
| 27 MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError, | 49 MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError, |
| 28 "GATT Service no longer exists."); | 50 "GATT Service no longer exists."); |
| 29 MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError, | 51 MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError, |
| 30 "GATT Characteristic no longer exists."); | 52 "GATT Characteristic no longer exists."); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 61 "Unsupported device."); | 83 "Unsupported device."); |
| 62 MAP_ERROR(CONNECT_WRITE_NOT_PERMITTED, NetworkError, | 84 MAP_ERROR(CONNECT_WRITE_NOT_PERMITTED, NetworkError, |
| 63 "GATT write operation is not permitted."); | 85 "GATT write operation is not permitted."); |
| 64 MAP_ERROR(DEVICE_NO_LONGER_IN_RANGE, NetworkError, | 86 MAP_ERROR(DEVICE_NO_LONGER_IN_RANGE, NetworkError, |
| 65 "Bluetooth Device is no longer in range."); | 87 "Bluetooth Device is no longer in range."); |
| 66 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); | 88 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); |
| 67 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, | 89 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, |
| 68 "GATT operation already in progress."); | 90 "GATT operation already in progress."); |
| 69 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, | 91 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, |
| 70 "Unknown ConnectErrorCode."); | 92 "Unknown ConnectErrorCode."); |
| 93 MAP_ERROR(GATT_SERVER_NOT_CONNECTED, NetworkError, | |
| 94 "GATT Server is disconnected. Cannot perform GATT operations."); | |
| 95 MAP_ERROR(GATT_SERVER_DISCONNECTED, NetworkError, | |
| 96 "GATT Server disconnected while performing a GATT operation."); | |
| 97 MAP_ERROR(GATT_SERVER_DISCONNECTED_WHILE_RETRIEVING_CHARACTERISTICS, | |
| 98 NetworkError, | |
| 99 "GATT Server disconnected while retrieving characteristics."); | |
| 100 MAP_ERROR( | |
| 101 GATT_SERVER_NOT_CONNECTED_CANNOT_RETRIEVE_CHARACTERISTICS, | |
| 102 NetworkError, | |
| 103 "GATT Server is disconnected. Cannot retrieve characteristics."); | |
| 71 | 104 |
| 72 // NotFoundErrors: | 105 // NotFoundErrors: |
| 73 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, | 106 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, |
| 74 "Web Bluetooth is not supported on this platform. For a list " | 107 "Web Bluetooth is not supported on this platform. For a list " |
| 75 "of supported platforms see: https://goo.gl/J6ASzs"); | 108 "of supported platforms see: https://goo.gl/J6ASzs"); |
| 76 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, | 109 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, |
| 77 "Bluetooth adapter not available."); | 110 "Bluetooth adapter not available."); |
| 78 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, | 111 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, |
| 79 "User selected a device that doesn't exist anymore."); | 112 "User selected a device that doesn't exist anymore."); |
| 80 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, | 113 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, |
| 81 "User cancelled the requestDevice() chooser."); | 114 "User cancelled the requestDevice() chooser."); |
| 82 MAP_ERROR(CHOOSER_NOT_SHOWN_API_GLOBALLY_DISABLED, NotFoundError, | 115 MAP_ERROR(CHOOSER_NOT_SHOWN_API_GLOBALLY_DISABLED, NotFoundError, |
| 83 "Web Bluetooth API globally disabled."); | 116 "Web Bluetooth API globally disabled."); |
| 84 MAP_ERROR(CHOOSER_NOT_SHOWN_API_LOCALLY_DISABLED, NotFoundError, | 117 MAP_ERROR(CHOOSER_NOT_SHOWN_API_LOCALLY_DISABLED, NotFoundError, |
| 85 "User or their enterprise policy has disabled Web Bluetooth."); | 118 "User or their enterprise policy has disabled Web Bluetooth."); |
| 86 MAP_ERROR( | 119 MAP_ERROR( |
| 87 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN, NotFoundError, | 120 CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN, NotFoundError, |
| 88 "User denied the browser permission to scan for Bluetooth devices."); | 121 "User denied the browser permission to scan for Bluetooth devices."); |
| 89 MAP_ERROR(SERVICE_NOT_FOUND, NotFoundError, | |
| 90 "No Services with specified UUID found in Device."); | |
| 91 MAP_ERROR(NO_SERVICES_FOUND, NotFoundError, | 122 MAP_ERROR(NO_SERVICES_FOUND, NotFoundError, |
| 92 "No Services found in device."); | 123 "No Services found in device."); |
| 93 MAP_ERROR(CHARACTERISTIC_NOT_FOUND, NotFoundError, | |
| 94 "No Characteristics with specified UUID found in Service."); | |
| 95 MAP_ERROR(NO_CHARACTERISTICS_FOUND, NotFoundError, | 124 MAP_ERROR(NO_CHARACTERISTICS_FOUND, NotFoundError, |
| 96 "No Characteristics found in service."); | 125 "No Characteristics found in service."); |
| 97 MAP_ERROR(DESCRIPTOR_NOT_FOUND, NotFoundError, | |
| 98 "No Descriptors with specified UUID found in Characteristic."); | |
| 99 MAP_ERROR(NO_DESCRIPTORS_FOUND, NotFoundError, | 126 MAP_ERROR(NO_DESCRIPTORS_FOUND, NotFoundError, |
| 100 "No Descriptors found in Characteristic."); | 127 "No Descriptors found in Characteristic."); |
| 101 MAP_ERROR(BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE, NotFoundError, | 128 MAP_ERROR(BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE, NotFoundError, |
| 102 "Bluetooth Low Energy not available."); | 129 "Bluetooth Low Energy not available."); |
| 103 | 130 |
| 104 // NotSupportedErrors: | 131 // NotSupportedErrors: |
| 105 MAP_ERROR(GATT_UNKNOWN_ERROR, NotSupportedError, "GATT Error Unknown."); | 132 MAP_ERROR(GATT_UNKNOWN_ERROR, NotSupportedError, "GATT Error Unknown."); |
| 106 MAP_ERROR(GATT_UNKNOWN_FAILURE, NotSupportedError, | 133 MAP_ERROR(GATT_UNKNOWN_FAILURE, NotSupportedError, |
| 107 "GATT operation failed for unknown reason."); | 134 "GATT operation failed for unknown reason."); |
| 108 MAP_ERROR(GATT_NOT_PERMITTED, NotSupportedError, | 135 MAP_ERROR(GATT_NOT_PERMITTED, NotSupportedError, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 133 "options. https://goo.gl/HxfxSQ"); | 160 "options. https://goo.gl/HxfxSQ"); |
| 134 MAP_ERROR(NOT_ALLOWED_TO_ACCESS_SERVICE, SecurityError, | 161 MAP_ERROR(NOT_ALLOWED_TO_ACCESS_SERVICE, SecurityError, |
| 135 "Origin is not allowed to access the service. Tip: Add the " | 162 "Origin is not allowed to access the service. Tip: Add the " |
| 136 "service UUID to 'optionalServices' in requestDevice() " | 163 "service UUID to 'optionalServices' in requestDevice() " |
| 137 "options. https://goo.gl/HxfxSQ"); | 164 "options. https://goo.gl/HxfxSQ"); |
| 138 MAP_ERROR(REQUEST_DEVICE_WITH_BLOCKLISTED_UUID, SecurityError, | 165 MAP_ERROR(REQUEST_DEVICE_WITH_BLOCKLISTED_UUID, SecurityError, |
| 139 "requestDevice() called with a filter containing a blocklisted " | 166 "requestDevice() called with a filter containing a blocklisted " |
| 140 "UUID. https://goo.gl/4NeimX"); | 167 "UUID. https://goo.gl/4NeimX"); |
| 141 MAP_ERROR(REQUEST_DEVICE_FROM_CROSS_ORIGIN_IFRAME, SecurityError, | 168 MAP_ERROR(REQUEST_DEVICE_FROM_CROSS_ORIGIN_IFRAME, SecurityError, |
| 142 "requestDevice() called from cross-origin iframe."); | 169 "requestDevice() called from cross-origin iframe."); |
| 143 MAP_ERROR(REQUEST_DEVICE_WITHOUT_FRAME, SecurityError, | |
| 144 "No window to show the requestDevice() dialog."); | |
| 145 | 170 |
| 146 #undef MAP_ERROR | 171 #undef MAP_ERROR |
| 147 } | 172 } |
| 148 | 173 |
| 149 ASSERT_NOT_REACHED(); | 174 NOTREACHED(); |
| 150 return DOMException::create(UnknownError); | 175 return DOMException::create(UnknownError); |
| 151 } | 176 } |
| 152 | 177 |
| 153 } // namespace blink | 178 } // namespace blink |
| OLD | NEW |