Chromium Code Reviews| Index: third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp |
| diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp b/third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp |
| index 383649d5fa405a3c9da61f73c70abbcee2f0525a..1f5f12f86b6fb5176b6c64e7f872df90741c7e95 100644 |
| --- a/third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp |
| +++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothError.cpp |
| @@ -9,15 +9,37 @@ |
| namespace blink { |
| -DOMException* BluetoothError::take(ScriptPromiseResolver*, |
| - mojom::blink::WebBluetoothResult error) { |
| +// static |
| +DOMException* BluetoothError::createDOMException( |
| + BluetoothErrorCode error, |
| + const String& detailedMessage) { |
| + switch (error) { |
| + case BluetoothErrorCode::InvalidService: |
| + case BluetoothErrorCode::InvalidCharacteristic: |
| + case BluetoothErrorCode::InvalidDescriptor: |
| + return DOMException::create(InvalidStateError, detailedMessage); |
| + case BluetoothErrorCode::ServiceNotFound: |
| + case BluetoothErrorCode::CharacteristicNotFound: |
| + case BluetoothErrorCode::DescriptorNotFound: |
| + return DOMException::create(NotFoundError, detailedMessage); |
| + } |
| + NOTREACHED(); |
| + return DOMException::create(UnknownError); |
| +} |
| + |
| +// static |
| +DOMException* BluetoothError::createDOMException( |
| + mojom::blink::WebBluetoothResult error) { |
| switch (error) { |
| case mojom::blink::WebBluetoothResult::SUCCESS: |
| - ASSERT_NOT_REACHED(); |
| + case mojom::blink::WebBluetoothResult::SERVICE_NOT_FOUND: |
| + case mojom::blink::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND: |
| + case mojom::blink::WebBluetoothResult::DESCRIPTOR_NOT_FOUND: |
| + 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.
|
| return DOMException::create(UnknownError); |
| #define MAP_ERROR(enumeration, name, message) \ |
| case mojom::blink::WebBluetoothResult::enumeration: \ |
| - return DOMException::create(name, message) |
| + return DOMException::create(name, message); |
| // InvalidModificationErrors: |
| MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, |
| @@ -68,6 +90,17 @@ DOMException* BluetoothError::take(ScriptPromiseResolver*, |
| "GATT operation already in progress."); |
| MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError, |
| "Unknown ConnectErrorCode."); |
| + MAP_ERROR(GATT_SERVER_NOT_CONNECTED, NetworkError, |
| + "GATT Server is disconnected. Cannot perform GATT operations."); |
| + MAP_ERROR(GATT_SERVER_DISCONNECTED, NetworkError, |
| + "GATT Server disconnected while performing a GATT operation."); |
| + MAP_ERROR(GATT_SERVER_DISCONNECTED_WHILE_RETRIEVING_CHARACTERISTICS, |
| + NetworkError, |
| + "GATT Server disconnected while retrieving characteristics."); |
| + MAP_ERROR( |
| + GATT_SERVER_NOT_CONNECTED_CANNOT_RETRIEVE_CHARACTERISTICS, |
| + NetworkError, |
| + "GATT Server is disconnected. Cannot retrieve characteristics."); |
| // NotFoundErrors: |
| MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError, |
| @@ -86,16 +119,10 @@ DOMException* BluetoothError::take(ScriptPromiseResolver*, |
| MAP_ERROR( |
| CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN, NotFoundError, |
| "User denied the browser permission to scan for Bluetooth devices."); |
| - MAP_ERROR(SERVICE_NOT_FOUND, NotFoundError, |
| - "No Services with specified UUID found in Device."); |
| MAP_ERROR(NO_SERVICES_FOUND, NotFoundError, |
| "No Services found in device."); |
| - MAP_ERROR(CHARACTERISTIC_NOT_FOUND, NotFoundError, |
| - "No Characteristics with specified UUID found in Service."); |
| MAP_ERROR(NO_CHARACTERISTICS_FOUND, NotFoundError, |
| "No Characteristics found in service."); |
| - MAP_ERROR(DESCRIPTOR_NOT_FOUND, NotFoundError, |
| - "No Descriptors with specified UUID found in Characteristic."); |
| MAP_ERROR(NO_DESCRIPTORS_FOUND, NotFoundError, |
| "No Descriptors found in Characteristic."); |
| MAP_ERROR(BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE, NotFoundError, |
| @@ -140,13 +167,11 @@ DOMException* BluetoothError::take(ScriptPromiseResolver*, |
| "UUID. https://goo.gl/4NeimX"); |
| MAP_ERROR(REQUEST_DEVICE_FROM_CROSS_ORIGIN_IFRAME, SecurityError, |
| "requestDevice() called from cross-origin iframe."); |
| - MAP_ERROR(REQUEST_DEVICE_WITHOUT_FRAME, SecurityError, |
| - "No window to show the requestDevice() dialog."); |
| #undef MAP_ERROR |
| } |
| - ASSERT_NOT_REACHED(); |
| + NOTREACHED(); |
| return DOMException::create(UnknownError); |
| } |