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 9848020c1725a3d8682f1b6c0f284d0aaecbbe5c..d6654c6b41ff91d10e0ae06bbf9d5ebbc89c03b3 100644 |
--- a/chrome/browser/extensions/api/socket/socket_api.cc |
+++ b/chrome/browser/extensions/api/socket/socket_api.cc |
@@ -28,6 +28,10 @@ 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[] = "peer"; |
+const char kLocalAddressKey[] = "local"; |
const char kSocketNotFoundError[] = "Socket not found"; |
const char kSocketTypeInvalidError[] = "Socket type is not supported"; |
@@ -446,4 +450,41 @@ 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)); |
+ result->Set(kIsConnectedKey, |
+ Value::CreateBooleanValue(socket->IsConnected())); |
+ |
+ net::IPEndPoint peerAddress; |
+ if (socket->GetPeerAddress(&peerAddress)) |
+ result->Set(kPeerAddressKey, |
+ Value::CreateStringValue(peerAddress.ToString())); |
+ |
+ net::IPEndPoint localAddress; |
+ if (socket->GetLocalAddress(&localAddress)) |
+ result->Set(kLocalAddressKey, |
+ Value::CreateStringValue(localAddress.ToString())); |
+ |
+ } else { |
+ error_ = kSocketNotFoundError; |
+ } |
+ SetResult(result); |
+} |
+ |
} // namespace extensions |