chrome.vpnProvider
Description: |
Use the chrome.vpnProvider API to implement a VPN
client.
|
Availability: |
Since Chrome 43.
|
Permissions: |
"vpnProvider"
|
Important: This API works only on Chrome OS.
Usage
Typical usage of vpnProvider is as follows:
- Create VPN configurations using the createConfig method. A VPN configuration is a persistent entry shown to the user in a native Chrome OS UI. The user can select a VPN configuration from a list and connect to it or disconnect from it.
- Add listeners to the events onPlatformMessage, onPacketReceived and onConfigRemoved.
- When the user connects to the VPN configuration, onPlatformMessage
will be received with the message
"connected"
. We refer to the period between the messages"connected"
and"disconnected"
as a VPN session. In this time period, the extension that receives the message is said to own the VPN session. - Initiate connection to the VPN server and start the VPN client.
- Set the Parameters of the connection using setParameters.
- Notify the connection state as
"connected"
using notifyConnectionStateChanged. - When the steps above are completed without errors, a virtual tunnel is created to the network stack of Chrome OS. IP packets can be sent through the tunnel using sendPacket and any packets originating on the Chrome OS device will be received using the event onPacketReceived.
- When the user disconnects from the VPN configuration,
onPlatformMessage will be fired with the message
"disconnected"
. - If the VPN configuration is no longer necessary, it can be destroyed using destroyConfig.
Summary
Methods | |
---|---|
createConfig −
chrome.vpnProvider.createConfig(string name, function callback)
| |
destroyConfig −
chrome.vpnProvider.destroyConfig(string id, function callback)
| |
setParameters −
chrome.vpnProvider.setParameters(object parameters, function callback)
| |
sendPacket −
chrome.vpnProvider.sendPacket(ArrayBuffer data, function callback)
| |
notifyConnectionStateChanged −
chrome.vpnProvider.notifyConnectionStateChanged(enum of
| |
Events | |
onPlatformMessage | |
onPacketReceived | |
onConfigRemoved | |
onConfigCreated | |
onUIEvent |
Methods
createConfig
chrome.vpnProvider.createConfig(string name, function callback)
Creates a new VPN configuration that persists across multiple login sessions of the user.
Parameters | |||||
---|---|---|---|---|---|
string | name |
The name of the VPN configuration. |
|||
function | callback |
Called when the configuration is created or if there is an error. The callback parameter should be a function that looks like this: function(string id) {...};
|
destroyConfig
chrome.vpnProvider.destroyConfig(string id, function callback)
Destroys a VPN configuration created by the extension.
Parameters | ||
---|---|---|
string | id |
ID of the VPN configuration to destroy. |
function | (optional) callback |
Called when the configuration is destroyed or if there is an error. If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
setParameters
chrome.vpnProvider.setParameters(object parameters, function callback)
Sets the parameters for the VPN session. This should be called immediately after "connected"
is received from the platform. This will succeed only when the VPN session is owned by the extension.
Parameters | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
object | parameters |
The parameters for the VPN session.
|
||||||||||||||||||||||||
function | callback |
Called when the parameters are set or if there is an error. The callback parameter should be a function that looks like this: function() {...};
|
sendPacket
chrome.vpnProvider.sendPacket(ArrayBuffer data, function callback)
Sends an IP packet through the tunnel created for the VPN session. This will succeed only when the VPN session is owned by the extension.
Parameters | ||
---|---|---|
ArrayBuffer | data |
The IP packet to be sent to the platform. |
function | (optional) callback |
Called when the packet is sent or if there is an error. If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
notifyConnectionStateChanged
chrome.vpnProvider.notifyConnectionStateChanged(enum of "connected"
, or "failure"
state, function callback)
Notifies the VPN session state to the platform. This will succeed only when the VPN session is owned by the extension.
Parameters | ||
---|---|---|
enum of "connected" , or "failure" |
state |
The VPN session state of the VPN client.
|
function | (optional) callback |
Called when the notification is complete or if there is an error. If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
Events
onPlatformMessage
Triggered when a message is received from the platform for a VPN configuration owned by the extension.
addListener
chrome.vpnProvider.onPlatformMessage.addListener(function callback)
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(string id, enum of
|
onPacketReceived
Triggered when an IP packet is received via the tunnel for the VPN session owned by the extension.
addListener
chrome.vpnProvider.onPacketReceived.addListener(function callback)
Parameters | |||||
---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(ArrayBuffer data) {...};
|
onConfigRemoved
Triggered when a configuration created by the extension is removed by the platform.
addListener
chrome.vpnProvider.onConfigRemoved.addListener(function callback)
Parameters | |||||
---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(string id) {...};
|
onConfigCreated
Triggered when a configuration is created by the platform for the extension.
addListener
chrome.vpnProvider.onConfigCreated.addListener(function callback)
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(string id, string name, object data) {...};
|
onUIEvent
Triggered when there is a UI event for the extension. UI events are signals from the platform that indicate to the app that a UI dialog needs to be shown to the user.
addListener
chrome.vpnProvider.onUIEvent.addListener(function callback)
Parameters | ||||||||
---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(enum of
|