diff options
author | kaliamoorthi <kaliamoorthi@chromium.org> | 2014-11-04 13:19:36 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-04 21:19:54 +0000 |
commit | f12e0ba44b4ec3279b3d88ca2bc3c345927ad96e (patch) | |
tree | b5f7307e32a7cc79e0db3fc4ecb5c819295276f9 | |
parent | 5a25b999f075b8560f804b95b27ffdb32a001b77 (diff) | |
download | chromium_src-f12e0ba44b4ec3279b3d88ca2bc3c345927ad96e.zip chromium_src-f12e0ba44b4ec3279b3d88ca2bc3c345927ad96e.tar.gz chromium_src-f12e0ba44b4ec3279b3d88ca2bc3c345927ad96e.tar.bz2 |
Add new extension API for VPN
This CL adds a new extension API that can be used to implement VPN clients by third party.
BUG=407541
Review URL: https://codereview.chromium.org/671163002
Cr-Commit-Position: refs/heads/master@{#302670}
-rw-r--r-- | extensions/browser/BUILD.gn | 2 | ||||
-rw-r--r-- | extensions/browser/api/vpn_provider/OWNERS | 3 | ||||
-rw-r--r-- | extensions/browser/api/vpn_provider/vpn_provider_api.cc | 46 | ||||
-rw-r--r-- | extensions/browser/api/vpn_provider/vpn_provider_api.h | 69 | ||||
-rw-r--r-- | extensions/browser/extension_function_histogram_value.h | 5 | ||||
-rw-r--r-- | extensions/common/api/_api_features.json | 4 | ||||
-rw-r--r-- | extensions/common/api/_permission_features.json | 5 | ||||
-rw-r--r-- | extensions/common/api/schemas.gypi | 1 | ||||
-rw-r--r-- | extensions/common/api/vpn_provider.idl | 96 | ||||
-rw-r--r-- | extensions/common/permissions/api_permission.h | 1 | ||||
-rw-r--r-- | extensions/common/permissions/extensions_api_permissions.cc | 3 | ||||
-rw-r--r-- | extensions/common/permissions/permission_message.h | 1 | ||||
-rw-r--r-- | extensions/extensions.gyp | 2 | ||||
-rw-r--r-- | extensions/extensions_strings.grd | 3 | ||||
-rw-r--r-- | tools/metrics/histograms/histograms.xml | 5 |
15 files changed, 246 insertions, 0 deletions
diff --git a/extensions/browser/BUILD.gn b/extensions/browser/BUILD.gn index 3aaa181..0fb6496 100644 --- a/extensions/browser/BUILD.gn +++ b/extensions/browser/BUILD.gn @@ -238,6 +238,8 @@ source_set("browser") { "api/virtual_keyboard_private/virtual_keyboard_private_api.cc", "api/virtual_keyboard_private/virtual_keyboard_private_api.h", "api/virtual_keyboard_private/virtual_keyboard_delegate.h", + "api/vpn_provider/vpn_provider_api.cc", + "api/vpn_provider/vpn_provider_api.h", "api/web_request/form_data_parser.cc", "api/web_request/form_data_parser.h", "api/web_request/upload_data_presenter.cc", diff --git a/extensions/browser/api/vpn_provider/OWNERS b/extensions/browser/api/vpn_provider/OWNERS new file mode 100644 index 0000000..9e75e8c --- /dev/null +++ b/extensions/browser/api/vpn_provider/OWNERS @@ -0,0 +1,3 @@ +kaliamoorthi@chromium.org +bartfab@chromium.org +pneubeck@chromium.org diff --git a/extensions/browser/api/vpn_provider/vpn_provider_api.cc b/extensions/browser/api/vpn_provider/vpn_provider_api.cc new file mode 100644 index 0000000..52d059b --- /dev/null +++ b/extensions/browser/api/vpn_provider/vpn_provider_api.cc @@ -0,0 +1,46 @@ +// 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 "extensions/browser/api/vpn_provider/vpn_provider_api.h" + +namespace extensions { + +VpnProviderCreateConfigFunction::~VpnProviderCreateConfigFunction() { +} + +ExtensionFunction::ResponseAction VpnProviderCreateConfigFunction::Run() { + return RespondNow(OneArgument(new base::FundamentalValue(-1))); +} + +VpnProviderDestroyConfigFunction::~VpnProviderDestroyConfigFunction() { +} + +ExtensionFunction::ResponseAction VpnProviderDestroyConfigFunction::Run() { + return RespondNow(NoArguments()); +} + +VpnProviderSetParametersFunction::~VpnProviderSetParametersFunction() { +} + +ExtensionFunction::ResponseAction VpnProviderSetParametersFunction::Run() { + return RespondNow(NoArguments()); +} + +VpnProviderSendPacketFunction::~VpnProviderSendPacketFunction() { +} + +ExtensionFunction::ResponseAction VpnProviderSendPacketFunction::Run() { + return RespondNow(NoArguments()); +} + +VpnProviderNotifyConnectionStateChangedFunction:: + ~VpnProviderNotifyConnectionStateChangedFunction() { +} + +ExtensionFunction::ResponseAction +VpnProviderNotifyConnectionStateChangedFunction::Run() { + return RespondNow(NoArguments()); +} + +} // namespace extensions diff --git a/extensions/browser/api/vpn_provider/vpn_provider_api.h b/extensions/browser/api/vpn_provider/vpn_provider_api.h new file mode 100644 index 0000000..fa44ef6 --- /dev/null +++ b/extensions/browser/api/vpn_provider/vpn_provider_api.h @@ -0,0 +1,69 @@ +// 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. + +#ifndef CHROME_BROWSER_EXTENSIONS_API_VPN_PROVIDER_VPN_PROVIDER_API_H_ +#define CHROME_BROWSER_EXTENSIONS_API_VPN_PROVIDER_VPN_PROVIDER_API_H_ + +#include "extensions/browser/extension_function.h" + +namespace extensions { + +class VpnProviderCreateConfigFunction : public UIThreadExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("vpnProvider.createConfig", + VPNPROVIDER_CREATECONFIG); + + protected: + virtual ~VpnProviderCreateConfigFunction(); + + virtual ExtensionFunction::ResponseAction Run() override; +}; + +class VpnProviderDestroyConfigFunction : public UIThreadExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("vpnProvider.destroyConfig", + VPNPROVIDER_DESTROYCONFIG); + + protected: + virtual ~VpnProviderDestroyConfigFunction(); + + virtual ExtensionFunction::ResponseAction Run() override; +}; + +class VpnProviderSetParametersFunction : public UIThreadExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("vpnProvider.setParameters", + VPNPROVIDER_SETPARAMETERS); + + protected: + virtual ~VpnProviderSetParametersFunction(); + + virtual ExtensionFunction::ResponseAction Run() override; +}; + +class VpnProviderSendPacketFunction : public UIThreadExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("vpnProvider.sendPacket", VPNPROVIDER_SENDPACKET); + + protected: + virtual ~VpnProviderSendPacketFunction(); + + virtual ExtensionFunction::ResponseAction Run() override; +}; + +class VpnProviderNotifyConnectionStateChangedFunction + : public UIThreadExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION("vpnProvider.notifyConnectionStateChanged", + VPNPROVIDER_NOTIFYCONNECTIONSTATECHANGED); + + protected: + virtual ~VpnProviderNotifyConnectionStateChangedFunction(); + + virtual ExtensionFunction::ResponseAction Run() override; +}; + +} // namespace extensions + +#endif // CHROME_BROWSER_EXTENSIONS_API_VPN_PROVIDER_VPN_PROVIDER_API_H_ diff --git a/extensions/browser/extension_function_histogram_value.h b/extensions/browser/extension_function_histogram_value.h index 476f977..3497934 100644 --- a/extensions/browser/extension_function_histogram_value.h +++ b/extensions/browser/extension_function_histogram_value.h @@ -974,6 +974,11 @@ enum HistogramValue { HOTWORDPRIVATE_FINALIZESPEAKERMODEL, HOTWORDPRIVATE_STOPTRAINING, GCDPRIVATE_STARTPAIRING, + VPNPROVIDER_CREATECONFIG, + VPNPROVIDER_DESTROYCONFIG, + VPNPROVIDER_SETPARAMETERS, + VPNPROVIDER_SENDPACKET, + VPNPROVIDER_NOTIFYCONNECTIONSTATECHANGED, // Last entry: Add new entries above and ensure to update // tools/metrics/histograms/histograms.xml. ENUM_BOUNDARY diff --git a/extensions/common/api/_api_features.json b/extensions/common/api/_api_features.json index 25c29ea..cf92ef8 100644 --- a/extensions/common/api/_api_features.json +++ b/extensions/common/api/_api_features.json @@ -288,6 +288,10 @@ "dependencies": ["permission:usb"], "contexts": ["blessed_extension"] }, + "vpnProvider": { + "dependencies": ["permission:vpnProvider"], + "contexts": ["blessed_extension"] + }, "webRequest": { "dependencies": ["permission:webRequest"], "contexts": ["blessed_extension"] diff --git a/extensions/common/api/_permission_features.json b/extensions/common/api/_permission_features.json index b535a37..e3d3dbc 100644 --- a/extensions/common/api/_permission_features.json +++ b/extensions/common/api/_permission_features.json @@ -306,6 +306,11 @@ ] } ], + "vpnProvider": { + "channel": "trunk", + "extension_types": ["extension", "platform_app"], + "platforms": ["chromeos"] + }, "webview": [ { "channel": "stable", diff --git a/extensions/common/api/schemas.gypi b/extensions/common/api/schemas.gypi index c3cac8c..b877c3a 100644 --- a/extensions/common/api/schemas.gypi +++ b/extensions/common/api/schemas.gypi @@ -43,6 +43,7 @@ 'test.json', 'usb.idl', 'virtual_keyboard_private.json', + 'vpn_provider.idl', 'web_request.json', 'web_view_internal.json', ], diff --git a/extensions/common/api/vpn_provider.idl b/extensions/common/api/vpn_provider.idl new file mode 100644 index 0000000..74d8a7c --- /dev/null +++ b/extensions/common/api/vpn_provider.idl @@ -0,0 +1,96 @@ +// 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. + +// Use the <code>chrome.vpnProvider</code> API to implement a VPN +// client. +namespace vpnProvider { + // A parameters class for the vpn interface + dictionary Parameters { + // IP address for the VPN interface in CIDR notation. + // IPv4 is currently the only supported mode. + DOMString address; + // Broadcast address for the VPN interface. (default: Deduced + // from IP address and mask). + DOMString? broadcastAddress; + // MTU for the VPN interface. (default: 1500) + DOMString? mtu; + // Bypass network traffic to the below IPs (in CIDR notation) + // from the tunnel. Typically used to bypass traffic to/from + // VPN server. + DOMString[] bypassTunnelForIp; + // A list of search domains (default: system setting). + DOMString[]? domainSearch; + // A list of DNS servers in CIDR notation (default: system + // setting). + DOMString[]? dnsServers; + }; + + // The enum is used by the platform to notify the client of + // connection and network related status. + // TODO(kaliamoorthi) : Document the messages + enum PlatformMessage { + connected, + disconnected, + underlyingNetworkDisconnected, + error + }; + + // The enum is used by the VPN client to inform the platform + // of its current state. This helps provide meaningful messages + // to the user. The states listed below are currently known to + // the platform (Shill daemon). + // TODO(kaliamoorthi) : Document all states + // TODO(kaliamoorthi) : Make failure more informative by expanding the failure + // conditions. + enum VpnConnectionState { + connected, + portal, + online, + failure + }; + + // The callback is used by <code>setParameters, sendPacket</code> + // to signal completion. The callback is called with + // <code>chrome.runtime.lastError</code> set to error code if + // there is an error. + [inline_doc] callback CallCompleteCallback = void (); + + // The callback is used by createConfig to signal completion. + callback ConfigCreatedCallback = void (long handle); + + interface Functions { + // Creates a new VPN configuration. + static void createConfig(DOMString name, + ConfigCreatedCallback callback); + + // Destroys a VPN configuration created by the extension. + static void destroyConfig(long handle, + optional CallCompleteCallback callback); + + // Sets the parameters for a VPN configuration. This should be + // called after connected is received from the platform. + static void setParameters(long handle, Parameters parameters, + CallCompleteCallback callback); + + // Injects an IP packet into the network stack of Chrome OS. + static void sendPacket(long handle, ArrayBuffer data, + optional CallCompleteCallback callback); + + // Notifies the VPN connection state to Chrome OS. + static void notifyConnectionStateChanged( + long handle, VpnConnectionState state, + optional CallCompleteCallback callback); + }; + + interface Events { + // Called when a message is received from the platform for a + // VPN configuration owned by the extension. + static void onPlatformMessage(long handle, + PlatformMessage message); + + // Called when an IP packet is received from the platform for a + // VPN configuration owned by the extension. + static void onPacketReceived(long handle, ArrayBuffer data); + }; +}; diff --git a/extensions/common/permissions/api_permission.h b/extensions/common/permissions/api_permission.h index 51abaad..b691efc 100644 --- a/extensions/common/permissions/api_permission.h +++ b/extensions/common/permissions/api_permission.h @@ -171,6 +171,7 @@ class APIPermission { kUsbDevice, kVideoCapture, kVirtualKeyboardPrivate, + kVpnProvider, kWallpaper, kWallpaperPrivate, kWebcamPrivate, diff --git a/extensions/common/permissions/extensions_api_permissions.cc b/extensions/common/permissions/extensions_api_permissions.cc index 936a8e2..7e8a1ee 100644 --- a/extensions/common/permissions/extensions_api_permissions.cc +++ b/extensions/common/permissions/extensions_api_permissions.cc @@ -80,6 +80,9 @@ std::vector<APIPermissionInfo*> ExtensionsAPIPermissions::GetAllPermissions() {APIPermission::kVideoCapture, "videoCapture", APIPermissionInfo::kFlagNone, IDS_EXTENSION_PROMPT_WARNING_VIDEO_CAPTURE, PermissionMessage::kVideoCapture}, + {APIPermission::kVpnProvider, "vpnProvider", + APIPermissionInfo::kFlagCannotBeOptional, + IDS_EXTENSION_PROMPT_WARNING_VPN, PermissionMessage::kVpnProvider}, // NOTE(kalman): This is provided by a manifest property but needs to // appear in the install permission dialogue, so we need a fake // permission for it. See http://crbug.com/247857. diff --git a/extensions/common/permissions/permission_message.h b/extensions/common/permissions/permission_message.h index 25eda75..0c561f8 100644 --- a/extensions/common/permissions/permission_message.h +++ b/extensions/common/permissions/permission_message.h @@ -90,6 +90,7 @@ class PermissionMessage { kCopresence, kTopSites, kU2fDevices, + kVpnProvider, kEnumBoundary, }; COMPILE_ASSERT(PermissionMessage::kNone > PermissionMessage::kUnknown, diff --git a/extensions/extensions.gyp b/extensions/extensions.gyp index 0ac8d4a..a3e48ea 100644 --- a/extensions/extensions.gyp +++ b/extensions/extensions.gyp @@ -515,6 +515,8 @@ 'browser/api/virtual_keyboard_private/virtual_keyboard_private_api.cc', 'browser/api/virtual_keyboard_private/virtual_keyboard_private_api.h', 'browser/api/virtual_keyboard_private/virtual_keyboard_delegate.h', + 'browser/api/vpn_provider/vpn_provider_api.cc', + 'browser/api/vpn_provider/vpn_provider_api.h', 'browser/api/web_request/form_data_parser.cc', 'browser/api/web_request/form_data_parser.h', 'browser/api/web_request/upload_data_presenter.cc', diff --git a/extensions/extensions_strings.grd b/extensions/extensions_strings.grd index f2f09c7..dbc2156 100644 --- a/extensions/extensions_strings.grd +++ b/extensions/extensions_strings.grd @@ -335,6 +335,9 @@ <message name="IDS_EXTENSION_PROMPT_WARNING_USB" desc="Permission string for access to USB devices."> Access your USB devices </message> + <message name="IDS_EXTENSION_PROMPT_WARNING_VPN" desc="Permission string for access to VPN API."> + Access your network traffic + </message> <message name="IDS_EXTENSION_PROMPT_WARNING_USB_DEVICE" desc="Permission string for access to a specific USB device."> Access the USB device <ph name="PRODUCT_NAME">$1<ex>SoundKnob</ex></ph> from <ph name="VENDOR_NAME">$2<ex>Griffin Technology</ex></ph> </message> diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 1893b37..e3512a2 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -44372,6 +44372,11 @@ Therefore, the affected-histogram name has to have at least one dot in it. <int value="913" label="HOTWORDPRIVATE_FINALIZESPEAKERMODEL"/> <int value="914" label="HOTWORDPRIVATE_STOPTRAINING"/> <int value="915" label="GCDPRIVATE_STARTPAIRING"/> + <int value="916" label="VPNPROVIDER_CREATECONFIG"/> + <int value="917" label="VPNPROVIDER_DESTROYCONFIG"/> + <int value="918" label="VPNPROVIDER_SETPARAMETERS"/> + <int value="919" label="VPNPROVIDER_SENDPACKET"/> + <int value="920" label="VPNPROVIDER_NOTIFYCONNECTIONSTATECHANGED"/> </enum> <enum name="ExtensionInstallCause" type="int"> |