| 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 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj
om-blink.h" | 9 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj
om-blink.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 DOMException* BluetoothError::take( | 13 DOMException* BluetoothError::take( |
| 14 ScriptPromiseResolver* resolver, |
| 15 int32_t |
| 16 webError /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */)
{ |
| 17 return take(resolver, webError, String()); |
| 18 } |
| 19 |
| 20 DOMException* BluetoothError::take( |
| 14 ScriptPromiseResolver*, | 21 ScriptPromiseResolver*, |
| 15 int32_t | 22 int32_t |
| 16 webError /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */)
{ | 23 webError /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */, |
| 24 String detailedMessage) { |
| 17 switch (static_cast<mojom::blink::WebBluetoothResult>(webError)) { | 25 switch (static_cast<mojom::blink::WebBluetoothResult>(webError)) { |
| 18 case mojom::blink::WebBluetoothResult::SUCCESS: | 26 case mojom::blink::WebBluetoothResult::SUCCESS: |
| 19 ASSERT_NOT_REACHED(); | 27 ASSERT_NOT_REACHED(); |
| 20 return DOMException::create(UnknownError); | 28 return DOMException::create(UnknownError); |
| 21 #define MAP_ERROR(enumeration, name, message) \ | 29 #define MAP_ERROR(enumeration, name, message) \ |
| 22 case mojom::blink::WebBluetoothResult::enumeration: \ | 30 case mojom::blink::WebBluetoothResult::enumeration: \ |
| 23 return DOMException::create(name, message) | 31 if (detailedMessage.isEmpty()) { \ |
| 32 return DOMException::create(name, message); \ |
| 33 } else { \ |
| 34 return DOMException::create(name, detailedMessage); \ |
| 35 } |
| 24 | 36 |
| 25 // InvalidModificationErrors: | 37 // InvalidModificationErrors: |
| 26 MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, | 38 MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError, |
| 27 "GATT Error: invalid attribute length."); | 39 "GATT Error: invalid attribute length."); |
| 28 | 40 |
| 29 // InvalidStateErrors: | 41 // InvalidStateErrors: |
| 30 MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError, | 42 MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError, |
| 31 "GATT Service no longer exists."); | 43 "GATT Service no longer exists."); |
| 32 MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError, | 44 MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError, |
| 33 "GATT Characteristic no longer exists."); | 45 "GATT Characteristic no longer exists."); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 MAP_ERROR(REQUEST_DEVICE_WITHOUT_FRAME, SecurityError, | 149 MAP_ERROR(REQUEST_DEVICE_WITHOUT_FRAME, SecurityError, |
| 138 "No window to show the requestDevice() dialog."); | 150 "No window to show the requestDevice() dialog."); |
| 139 | 151 |
| 140 #undef MAP_ERROR | 152 #undef MAP_ERROR |
| 141 } | 153 } |
| 142 | 154 |
| 143 ASSERT_NOT_REACHED(); | 155 ASSERT_NOT_REACHED(); |
| 144 return DOMException::create(UnknownError); | 156 return DOMException::create(UnknownError); |
| 145 } | 157 } |
| 146 | 158 |
| 159 // static |
| 160 bool BluetoothError::isSameError(int32_t error, |
| 161 mojom::blink::WebBluetoothResult webError) { |
| 162 return static_cast<mojom::blink::WebBluetoothResult>(error) == webError; |
| 163 } |
| 164 |
| 147 } // namespace blink | 165 } // namespace blink |
| OLD | NEW |