File: BluetoothError.cpp

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (151 lines) | stat: -rw-r--r-- 7,660 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "modules/bluetooth/BluetoothError.h"

#include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h"

namespace blink {

DOMException* BluetoothError::take(ScriptPromiseResolver*,
                                   mojom::blink::WebBluetoothResult error) {
  switch (error) {
    case mojom::blink::WebBluetoothResult::SUCCESS:
      ASSERT_NOT_REACHED();
      return DOMException::create(UnknownError);
#define MAP_ERROR(enumeration, name, message)         \
  case mojom::blink::WebBluetoothResult::enumeration: \
    return DOMException::create(name, message)

      // InvalidModificationErrors:
      MAP_ERROR(GATT_INVALID_ATTRIBUTE_LENGTH, InvalidModificationError,
                "GATT Error: invalid attribute length.");

      // InvalidStateErrors:
      MAP_ERROR(SERVICE_NO_LONGER_EXISTS, InvalidStateError,
                "GATT Service no longer exists.");
      MAP_ERROR(CHARACTERISTIC_NO_LONGER_EXISTS, InvalidStateError,
                "GATT Characteristic no longer exists.");

      // NetworkErrors:
      MAP_ERROR(CONNECT_ALREADY_IN_PROGRESS, NetworkError,
                "Connection already in progress.");
      MAP_ERROR(CONNECT_ATTRIBUTE_LENGTH_INVALID, NetworkError,
                "Write operation exceeds the maximum length of the attribute.");
      MAP_ERROR(CONNECT_AUTH_CANCELED, NetworkError,
                "Authentication canceled.");
      MAP_ERROR(CONNECT_AUTH_FAILED, NetworkError, "Authentication failed.");
      MAP_ERROR(CONNECT_AUTH_REJECTED, NetworkError,
                "Authentication rejected.");
      MAP_ERROR(CONNECT_AUTH_TIMEOUT, NetworkError, "Authentication timeout.");
      MAP_ERROR(CONNECT_CONNECTION_CONGESTED, NetworkError,
                "Remote device connection is congested.");
      MAP_ERROR(CONNECT_INSUFFICIENT_ENCRYPTION, NetworkError,
                "Insufficient encryption for a given operation");
      MAP_ERROR(
          CONNECT_OFFSET_INVALID, NetworkError,
          "Read or write operation was requested with an invalid offset.");
      MAP_ERROR(CONNECT_READ_NOT_PERMITTED, NetworkError,
                "GATT read operation is not permitted.");
      MAP_ERROR(CONNECT_REQUEST_NOT_SUPPORTED, NetworkError,
                "The given request is not supported.");
      MAP_ERROR(CONNECT_UNKNOWN_ERROR, NetworkError,
                "Unknown error when connecting to the device.");
      MAP_ERROR(CONNECT_UNKNOWN_FAILURE, NetworkError,
                "Connection failed for unknown reason.");
      MAP_ERROR(CONNECT_UNSUPPORTED_DEVICE, NetworkError,
                "Unsupported device.");
      MAP_ERROR(CONNECT_WRITE_NOT_PERMITTED, NetworkError,
                "GATT write operation is not permitted.");
      MAP_ERROR(DEVICE_NO_LONGER_IN_RANGE, NetworkError,
                "Bluetooth Device is no longer in range.");
      MAP_ERROR(GATT_NOT_PAIRED, NetworkError, "GATT Error: Not paired.");
      MAP_ERROR(GATT_OPERATION_IN_PROGRESS, NetworkError,
                "GATT operation already in progress.");
      MAP_ERROR(UNTRANSLATED_CONNECT_ERROR_CODE, NetworkError,
                "Unknown ConnectErrorCode.");

      // NotFoundErrors:
      MAP_ERROR(WEB_BLUETOOTH_NOT_SUPPORTED, NotFoundError,
                "Web Bluetooth is not supported on this platform. For a list "
                "of supported platforms see: https://goo.gl/J6ASzs");
      MAP_ERROR(NO_BLUETOOTH_ADAPTER, NotFoundError,
                "Bluetooth adapter not available.");
      MAP_ERROR(CHOSEN_DEVICE_VANISHED, NotFoundError,
                "User selected a device that doesn't exist anymore.");
      MAP_ERROR(CHOOSER_CANCELLED, NotFoundError,
                "User cancelled the requestDevice() chooser.");
      MAP_ERROR(CHOOSER_NOT_SHOWN_API_GLOBALLY_DISABLED, NotFoundError,
                "Web Bluetooth API globally disabled.");
      MAP_ERROR(CHOOSER_NOT_SHOWN_API_LOCALLY_DISABLED, NotFoundError,
                "User or their enterprise policy has disabled Web Bluetooth.");
      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,
                "Bluetooth Low Energy not available.");

      // NotSupportedErrors:
      MAP_ERROR(GATT_UNKNOWN_ERROR, NotSupportedError, "GATT Error Unknown.");
      MAP_ERROR(GATT_UNKNOWN_FAILURE, NotSupportedError,
                "GATT operation failed for unknown reason.");
      MAP_ERROR(GATT_NOT_PERMITTED, NotSupportedError,
                "GATT operation not permitted.");
      MAP_ERROR(GATT_NOT_SUPPORTED, NotSupportedError,
                "GATT Error: Not supported.");
      MAP_ERROR(GATT_UNTRANSLATED_ERROR_CODE, NotSupportedError,
                "GATT Error: Unknown GattErrorCode.");

      // SecurityErrors:
      MAP_ERROR(GATT_NOT_AUTHORIZED, SecurityError,
                "GATT operation not authorized.");
      MAP_ERROR(BLOCKLISTED_CHARACTERISTIC_UUID, SecurityError,
                "getCharacteristic(s) called with blocklisted UUID. "
                "https://goo.gl/4NeimX");
      MAP_ERROR(BLOCKLISTED_DESCRIPTOR_UUID, SecurityError,
                "getDescriptor(s) called with blocklisted UUID. "
                "https://goo.gl/4NeimX");
      MAP_ERROR(BLOCKLISTED_READ, SecurityError,
                "readValue() called on blocklisted object marked "
                "exclude-reads. https://goo.gl/4NeimX");
      MAP_ERROR(BLOCKLISTED_WRITE, SecurityError,
                "writeValue() called on blocklisted object marked "
                "exclude-writes. https://goo.gl/4NeimX");
      MAP_ERROR(NOT_ALLOWED_TO_ACCESS_ANY_SERVICE, SecurityError,
                "Origin is not allowed to access any service. Tip: Add the "
                "service UUID to 'optionalServices' in requestDevice() "
                "options. https://goo.gl/HxfxSQ");
      MAP_ERROR(NOT_ALLOWED_TO_ACCESS_SERVICE, SecurityError,
                "Origin is not allowed to access the service. Tip: Add the "
                "service UUID to 'optionalServices' in requestDevice() "
                "options. https://goo.gl/HxfxSQ");
      MAP_ERROR(REQUEST_DEVICE_WITH_BLOCKLISTED_UUID, SecurityError,
                "requestDevice() called with a filter containing a blocklisted "
                "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();
  return DOMException::create(UnknownError);
}

}  // namespace blink