| 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 // Use the <code>chrome.gcdPrivate</code> API to discover GCD APIs and register | 5 // Use the <code>chrome.gcdPrivate</code> API to discover GCD APIs and register |
| 6 // them. | 6 // them. |
| 7 namespace gcdPrivate { | 7 namespace gcdPrivate { |
| 8 | 8 |
| 9 enum SetupType { mdns, wifi, cloud }; | 9 enum SetupType { mdns, wifi, cloud }; |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 // Could not connect to the device. | 43 // Could not connect to the device. |
| 44 connectionError, | 44 connectionError, |
| 45 | 45 |
| 46 // Error in establishing session. | 46 // Error in establishing session. |
| 47 sessionError, | 47 sessionError, |
| 48 | 48 |
| 49 // Unknown session. | 49 // Unknown session. |
| 50 unknownSessionError, | 50 unknownSessionError, |
| 51 | 51 |
| 52 // Bad pairing code. Ask user to retype. | 52 // Bad pairing code. |
| 53 badPairingCodeError, | 53 badPairingCodeError, |
| 54 | 54 |
| 55 // Setup error. | 55 // Device error with details in response object. |
| 56 setupError | 56 deviceError |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 enum PairingType { | 59 enum PairingType { |
| 60 pinCode, | 60 pinCode, |
| 61 embeddedCode | 61 embeddedCode |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 callback CloudDeviceListCallback = void(GCDDevice[] devices); | 64 callback CloudDeviceListCallback = void(GCDDevice[] devices); |
| 65 | 65 |
| 66 // |commandDefinitions| : Is "commandDefs" value of device described at | 66 // |commandDefinitions| : Is "commandDefs" value of device described at |
| 67 // https://developers.google.com/cloud-devices/v1/reference/devices | 67 // https://developers.google.com/cloud-devices/v1/reference/devices |
| 68 // TODO(vitalybuka): consider to describe object in IDL. | 68 // TODO(vitalybuka): consider to describe object in IDL. |
| 69 callback CommandDefinitionsCallback = void(object commandDefinitions); | 69 callback CommandDefinitionsCallback = void(object commandDefinitions); |
| 70 | 70 |
| 71 // |command| : Described at | 71 // |command| : Described at |
| 72 // https://developers.google.com/cloud-devices/v1/reference/commands | 72 // https://developers.google.com/cloud-devices/v1/reference/commands |
| 73 // TODO(vitalybuka): consider to describe object in IDL. | 73 // TODO(vitalybuka): consider to describe object in IDL. |
| 74 callback CommandCallback = void(object command); | 74 callback CommandCallback = void(object command); |
| 75 | 75 |
| 76 // |commands| : Array of commands described at | 76 // |commands| : Array of commands described at |
| 77 // https://developers.google.com/cloud-devices/v1/reference/commands | 77 // https://developers.google.com/cloud-devices/v1/reference/commands |
| 78 // TODO(vitalybuka): consider to describe object in IDL. | 78 // TODO(vitalybuka): consider to describe object in IDL. |
| 79 callback CommandListCallback = void(object[] commands); | 79 callback CommandListCallback = void(object[] commands); |
| 80 | 80 |
| 81 // Generic callback for session calls, with status only. | 81 // Generic callback for session calls, with status only. |
| 82 callback SessionCallback = void(Status status); | 82 callback SessionCallback = void(Status status); |
| 83 | 83 |
| 84 // Called when device starts to establish a secure session. | 84 // Called when device starts to establish a secure session. |
| 85 // If |status| is |success| app should vall |startPairing|. | 85 // If |status| is |success| app should call |startPairing|. |
| 86 // |sessionId| is the session ID (identifies the session for future calls). | 86 // |sessionId| : The session ID (identifies the session for future calls). |
| 87 // |status| is the status (success or type of error). | 87 // |status| : The status of operation (success or type of error). |
| 88 // |pairingTypes| is the list of supported pairing types. | 88 // |pairingTypes| is the list of supported pairing types. |
| 89 callback EstablishSessionCallback = void(long sessionId, | 89 callback EstablishSessionCallback = void(long sessionId, |
| 90 Status status, | 90 Status status, |
| 91 PairingType[] pairingTypes); | 91 PairingType[] pairingTypes); |
| 92 | 92 |
| 93 // Called when the response to the message sent is available or on error. | 93 // Called when the response to the message sent is available or on error. |
| 94 // |status| is the status (success or type of error) | 94 // |status| : The status of operation (success or type of error). |
| 95 // |response| is the response object or null on error | 95 // |response| : The response object with result or error description. May be |
| 96 callback SendMessageCallback = void(Status status, | 96 // empty for some errors. |
| 97 object response); | 97 callback SendMessageCallback = void(Status status, object response); |
| 98 | 98 |
| 99 // Called as a response to |prefetchWifiPassword| | 99 // Called as a response to |prefetchWifiPassword| |
| 100 // |success| Denotes whether the password fetch has succeeded or failed. | 100 // |success| : Denotes whether the password fetch has succeeded or failed. |
| 101 callback SuccessCallback = void(boolean success); | 101 callback SuccessCallback = void(boolean success); |
| 102 | 102 |
| 103 // Called as a response to |getPrefetchedWifiNameList| | 103 // Called as a response to |getPrefetchedWifiNameList| |
| 104 // |list| the list of ssids for which wifi passwords were prefetched. | 104 // |networks| : The list of ssids for which wifi passwords were prefetched. |
| 105 callback SSIDListCallback = void(DOMString[] networks); | 105 callback SSIDListCallback = void(DOMString[] networks); |
| 106 | 106 |
| 107 interface Functions { | 107 interface Functions { |
| 108 // Returns the list of cloud devices visible locally or available in the | 108 // Returns the list of cloud devices visible locally or available in the |
| 109 // cloud for user account. | 109 // cloud for user account. |
| 110 static void getCloudDeviceList(CloudDeviceListCallback callback); | 110 static void getCloudDeviceList(CloudDeviceListCallback callback); |
| 111 | 111 |
| 112 // Queries network for local devices. Triggers an onDeviceStateChanged and | 112 // Queries network for local devices. Triggers an onDeviceStateChanged and |
| 113 // onDeviceRemoved events. Call this function *only* after registering for | 113 // onDeviceRemoved events. Call this function *only* after registering for |
| 114 // onDeviceStateChanged and onDeviceRemoved events, or it will do nothing. | 114 // onDeviceStateChanged and onDeviceRemoved events, or it will do nothing. |
| 115 static void queryForNewLocalDevices(); | 115 static void queryForNewLocalDevices(); |
| 116 | 116 |
| 117 // Cache the WiFi password in the browser process for use during | 117 // Cache the WiFi password in the browser process for use during |
| 118 // provisioning. This is done to allow the gathering of the wifi password to | 118 // provisioning. This is done to allow the gathering of the wifi password to |
| 119 // not be done while connected to the device's network. Callback is called | 119 // not be done while connected to the device's network. Callback is called |
| 120 // with true if wifi password was cached and false if it was unavailable. | 120 // with true if wifi password was cached and false if it was unavailable. |
| 121 // |ssid| : The network to prefetch password for. |
| 121 static void prefetchWifiPassword(DOMString ssid, SuccessCallback callback); | 122 static void prefetchWifiPassword(DOMString ssid, SuccessCallback callback); |
| 122 | 123 |
| 123 // Get the list of ssids with prefetched callbacks. | 124 // Get the list of ssids with prefetched callbacks. |
| 124 static void getPrefetchedWifiNameList(SSIDListCallback callback); | 125 static void getPrefetchedWifiNameList(SSIDListCallback callback); |
| 125 | 126 |
| 126 // Establish the session. | 127 // Establish the session. |
| 128 // |ipAddress| : The IPv4 or IPv6 address of the device. |
| 129 // |port| : The port with Privet HTTP server. |
| 127 static void establishSession(DOMString ipAddress, | 130 static void establishSession(DOMString ipAddress, |
| 128 long port, | 131 long port, |
| 129 EstablishSessionCallback callback); | 132 EstablishSessionCallback callback); |
| 130 | 133 |
| 131 // Start pairing with selected method. | 134 // Start pairing with selected method. Should be called after |
| 132 // |pairingType| is the any value provided | 135 // |establishSession|. |
| 136 // |sessionId| : The ID of the session created with |establishSession|. |
| 137 // |pairingType| : The value selected from the list provided in |
| 138 // callback of |establishSession|. |
| 133 static void startPairing(long sessionId, | 139 static void startPairing(long sessionId, |
| 134 PairingType pairingType, | 140 PairingType pairingType, |
| 135 SessionCallback callback); | 141 SessionCallback callback); |
| 136 | 142 |
| 137 // Confirm pairing code. | 143 // Confirm pairing code. Should be called after |startPairing|. |
| 138 // |code| is the string generated by pairing process and availible to the | 144 // |sessionId| : The ID of the session created with |establishSession|. |
| 145 // |code| : The string generated by pairing process and availible to the |
| 139 // user. | 146 // user. |
| 140 static void confirmCode(long sessionId, | 147 static void confirmCode(long sessionId, |
| 141 DOMString code, | 148 DOMString code, |
| 142 SessionCallback callback); | 149 SessionCallback callback); |
| 143 | 150 |
| 144 // Send an encrypted message to the device. |api| is the API path and | 151 // Send an encrypted message to the device. |
| 145 // |input| is the input object. If the message is a setup message with a | 152 // If the message is a setup message with a wifi ssid specified but no |
| 146 // wifi ssid specified but no password, the password cached from | 153 // password, the password cached by |prefetchWifiPassword| will be used and |
| 147 // |prefetchWifiPassword| will be used and the call will fail if it's not | 154 // the call will fail if it's not available. For open networks use an empty |
| 148 // available. For open networks use an empty string as the password. | 155 // string as the password. |
| 156 // |sessionId| : The ID of the session created with |establishSession|. |
| 157 // |api| : The Privet API name to call. |
| 158 // |input| : Input data for |api|. |
| 149 static void sendMessage(long sessionId, | 159 static void sendMessage(long sessionId, |
| 150 DOMString api, | 160 DOMString api, |
| 151 object input, | 161 object input, |
| 152 SendMessageCallback callback); | 162 SendMessageCallback callback); |
| 153 | 163 |
| 154 // Terminate the session with the device. | 164 // Terminate the session with the device. |
| 165 // |sessionId| : The ID of the session created with |establishSession|. |
| 155 static void terminateSession(long sessionId); | 166 static void terminateSession(long sessionId); |
| 156 | 167 |
| 157 // Returns command definitions. | 168 // Returns command definitions. |
| 158 // |deviceId| : The device to get command definitions for. | 169 // |deviceId| : The device to get command definitions for. |
| 159 // |callback| : The result callback. | 170 // |callback| : The result callback. |
| 160 static void getCommandDefinitions(DOMString deviceId, | 171 static void getCommandDefinitions(DOMString deviceId, |
| 161 CommandDefinitionsCallback callback); | 172 CommandDefinitionsCallback callback); |
| 162 | 173 |
| 163 // Creates and sends a new command. | 174 // Creates and sends a new command. |
| 164 // |deviceId| : The device to send the command to. | 175 // |deviceId| : The device to send the command to. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // Subscribe to this event to start listening new or updated devices. New | 211 // Subscribe to this event to start listening new or updated devices. New |
| 201 // listeners will get called with all known devices on the network, and | 212 // listeners will get called with all known devices on the network, and |
| 202 // status updates for devices available through the cloud. | 213 // status updates for devices available through the cloud. |
| 203 static void onDeviceStateChanged(GCDDevice device); | 214 static void onDeviceStateChanged(GCDDevice device); |
| 204 | 215 |
| 205 // Notifies that device has disappeared. | 216 // Notifies that device has disappeared. |
| 206 // |deviceId| : The device has disappeared. | 217 // |deviceId| : The device has disappeared. |
| 207 static void onDeviceRemoved(DOMString deviceId); | 218 static void onDeviceRemoved(DOMString deviceId); |
| 208 }; | 219 }; |
| 209 }; | 220 }; |
| OLD | NEW |