Index: chrome/browser/extensions/api/socket/socket_api.cc |
diff --git a/chrome/browser/extensions/api/socket/socket_api.cc b/chrome/browser/extensions/api/socket/socket_api.cc |
index 93ba29c1e7fa20a0746b0c6d77cb653e6bb08c3d..8a12fd1e84a656c8bfa0b034ab0209231677f68c 100644 |
--- a/chrome/browser/extensions/api/socket/socket_api.cc |
+++ b/chrome/browser/extensions/api/socket/socket_api.cc |
@@ -28,6 +28,12 @@ const char kResultCodeKey[] = "resultCode"; |
const char kSocketIdKey[] = "socketId"; |
const char kTCPOption[] = "tcp"; |
const char kUDPOption[] = "udp"; |
+const char kSocketTypeKey[] = "socketType"; |
+const char kIsConnectedKey[] = "connected"; |
+const char kPeerAddressKey[] = "peerAddress"; |
+const char kPeerPortKey[] = "peerPort"; |
+const char kLocalAddressKey[] = "localAddress"; |
+const char kLocalPortKey[] = "localPort"; |
const char kSocketNotFoundError[] = "Socket not found"; |
const char kSocketTypeInvalidError[] = "Socket type is not supported"; |
@@ -447,4 +453,46 @@ void SocketSetNoDelayFunction::Work() { |
SetResult(Value::CreateBooleanValue(result)); |
} |
+SocketGetInfoFunction::SocketGetInfoFunction() |
+ : params_(NULL) { |
+} |
+ |
+SocketGetInfoFunction::~SocketGetInfoFunction() {} |
+ |
+bool SocketGetInfoFunction::Prepare() { |
+ params_ = api::experimental_socket::GetInfo::Params::Create(*args_); |
+ EXTENSION_FUNCTION_VALIDATE(params_.get()); |
+ return true; |
+} |
+ |
+void SocketGetInfoFunction::Work() { |
+ DictionaryValue* result = new DictionaryValue(); |
+ Socket* socket = manager_->Get(params_->socket_id); |
+ if (socket) { |
+ std::string type = (socket->IsTCPSocket() ? kTCPOption : kUDPOption); |
+ result->Set(kSocketTypeKey, Value::CreateStringValue(type)); |
benwells
2012/07/26 04:18:37
I think there is a nicer way to set this return va
thorogood
2012/07/26 06:19:50
I've had a go at using the generated type. How I r
|
+ result->Set(kIsConnectedKey, |
+ Value::CreateBooleanValue(socket->IsConnected())); |
+ |
+ net::IPEndPoint peerAddress; |
+ if (socket->GetPeerAddress(&peerAddress)) { |
+ result->Set(kPeerAddressKey, |
+ Value::CreateStringValue(peerAddress.ToStringWithoutPort())); |
+ result->Set(kPeerPortKey, |
+ Value::CreateIntegerValue(peerAddress.port())); |
+ } |
+ |
+ net::IPEndPoint localAddress; |
+ if (socket->GetLocalAddress(&localAddress)) { |
+ result->Set(kLocalAddressKey, |
+ Value::CreateStringValue(localAddress.ToStringWithoutPort())); |
+ result->Set(kLocalPortKey, |
+ Value::CreateIntegerValue(localAddress.port())); |
+ } |
+ } else { |
+ error_ = kSocketNotFoundError; |
+ } |
+ SetResult(result); |
+} |
+ |
} // namespace extensions |