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 namespace { |
| 13 |
| 14 const char kGATTServerNotConnectedBase[] = |
| 15 "GATT Server is disconnected. " |
| 16 "Cannot %s. (Re)connect first with `device.gatt.connect`."; |
| 17 |
| 18 } // namespace |
| 19 |
| 20 // static |
| 21 DOMException* BluetoothError::createNotConnectedException( |
| 22 BluetoothOperation operation) { |
| 23 const char* operationString = nullptr; |
| 24 switch (operation) { |
| 25 case BluetoothOperation::ServicesRetrieval: |
| 26 operationString = "retrieve services"; |
| 27 break; |
| 28 case BluetoothOperation::CharacteristicsRetrieval: |
| 29 operationString = "retrieve characteristics"; |
| 30 break; |
| 31 } |
| 32 |
| 33 return DOMException::create( |
| 34 NetworkError, |
| 35 String::format(kGATTServerNotConnectedBase, operationString)); |
| 36 } |
| 37 |
12 // static | 38 // static |
13 DOMException* BluetoothError::createDOMException( | 39 DOMException* BluetoothError::createDOMException( |
14 BluetoothErrorCode error, | 40 BluetoothErrorCode error, |
15 const String& detailedMessage) { | 41 const String& detailedMessage) { |
16 switch (error) { | 42 switch (error) { |
17 case BluetoothErrorCode::InvalidService: | 43 case BluetoothErrorCode::InvalidService: |
18 case BluetoothErrorCode::InvalidCharacteristic: | 44 case BluetoothErrorCode::InvalidCharacteristic: |
19 case BluetoothErrorCode::InvalidDescriptor: | 45 case BluetoothErrorCode::InvalidDescriptor: |
20 return DOMException::create(InvalidStateError, detailedMessage); | 46 return DOMException::create(InvalidStateError, detailedMessage); |
21 case BluetoothErrorCode::ServiceNotFound: | 47 case BluetoothErrorCode::ServiceNotFound: |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 "Bluetooth Device is no longer in range."); | 117 "Bluetooth Device is no longer in range."); |
92 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); | 118 MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired."); |
93 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, | 119 MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError, |
94 "GATT operation already in progress."); | 120 "GATT operation already in progress."); |
95 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, | 121 MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, |
96 "Unknown ConnectErrorCode."); | 122 "Unknown ConnectErrorCode."); |
97 MAP_ERROR(GATT_SERVER_NOT_CONNECTED, NetworkError, | 123 MAP_ERROR(GATT_SERVER_NOT_CONNECTED, NetworkError, |
98 "GATT Server is disconnected. Cannot perform GATT operations."); | 124 "GATT Server is disconnected. Cannot perform GATT operations."); |
99 MAP_ERROR(GATT_SERVER_DISCONNECTED, NetworkError, | 125 MAP_ERROR(GATT_SERVER_DISCONNECTED, NetworkError, |
100 "GATT Server disconnected while performing a GATT operation."); | 126 "GATT Server disconnected while performing a GATT operation."); |
101 MAP_ERROR(GATT_SERVER_DISCONNECTED_WHILE_RETRIEVING_CHARACTERISTICS, | |
102 NetworkError, | |
103 "GATT Server disconnected while retrieving characteristics."); | |
104 MAP_ERROR( | |
105 GATT_SERVER_NOT_CONNECTED_CANNOT_RETRIEVE_CHARACTERISTICS, | |
106 NetworkError, | |
107 "GATT Server is disconnected. Cannot retrieve characteristics."); | |
108 | 127 |
109 // NotFoundErrors: | 128 // NotFoundErrors: |
110 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, | 129 MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, |
111 "Web Bluetooth is not supported on this platform. For a list " | 130 "Web Bluetooth is not supported on this platform. For a list " |
112 "of supported platforms see: https://goo.gl/J6ASzs"); | 131 "of supported platforms see: https://goo.gl/J6ASzs"); |
113 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, | 132 MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError, |
114 "Bluetooth adapter not available."); | 133 "Bluetooth adapter not available."); |
115 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, | 134 MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError, |
116 "User selected a device that doesn't exist anymore."); | 135 "User selected a device that doesn't exist anymore."); |
117 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, | 136 MAP_ERROR(CHOOSER_CANCELLED, NotFoundError, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 "requestDevice() called from cross-origin iframe."); | 192 "requestDevice() called from cross-origin iframe."); |
174 | 193 |
175 #undef MAP_ERROR | 194 #undef MAP_ERROR |
176 } | 195 } |
177 | 196 |
178 NOTREACHED(); | 197 NOTREACHED(); |
179 return DOMException::create(UnknownError); | 198 return DOMException::create(UnknownError); |
180 } | 199 } |
181 | 200 |
182 } // namespace blink | 201 } // namespace blink |
OLD | NEW |