Chromium Code Reviews| 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 ce400e52555c92c8b066844f108681bec9f28690..89a71dd5bf540aa2944dc8f8a8aa7394bbe8e272 100644 |
| --- a/chrome/browser/extensions/api/socket/socket_api.cc |
| +++ b/chrome/browser/extensions/api/socket/socket_api.cc |
| @@ -275,6 +275,81 @@ void SocketBindFunction::Work() { |
| SetResult(Value::CreateIntegerValue(result)); |
| } |
| +SocketListenFunction::SocketListenFunction() |
| + : params_(NULL) { |
| +} |
| + |
| +SocketListenFunction::~SocketListenFunction() {} |
| + |
| +bool SocketListenFunction::Prepare() { |
| + params_ = api::experimental_socket::Listen::Params::Create(*args_); |
| + EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| + return true; |
| +} |
| + |
| +void SocketListenFunction::Work() { |
| + int result = -1; |
| + net::IPEndPoint bindAddress; |
| + |
| + Socket* socket = GetSocket(params_->socket_id); |
| + if (socket && socket->GetBindAddress(&bindAddress)) { |
|
Peng
2012/09/14 16:27:16
The permissions for bind and listen are udp-bind:i
|
| + std::string address; |
| + int port; |
| + Socket::IPEndPointToStringAndPort(bindAddress, &address, &port); |
| + SocketPermission::CheckParam param( |
| + SocketPermissionData::TCP_LISTEN, address, port); |
| + if (!GetExtension()->CheckAPIPermissionWithParam(APIPermission::kSocket, |
| + ¶m)) { |
| + error_ = kPermissionError; |
| + SetResult(Value::CreateIntegerValue(result)); |
| + return; |
| + } |
| + |
| + result = socket->Listen(params_->backlog, &error_); |
| + } else { |
| + error_ = kSocketNotFoundError; |
| + } |
| + |
| + SetResult(Value::CreateIntegerValue(result)); |
| +} |
| + |
| +SocketAcceptFunction::SocketAcceptFunction() |
| + : params_(NULL) { |
| +} |
| + |
| +SocketAcceptFunction::~SocketAcceptFunction() {} |
| + |
| +bool SocketAcceptFunction::Prepare() { |
| + params_ = api::experimental_socket::Accept::Params::Create(*args_); |
| + EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| + return true; |
| +} |
| + |
| +void SocketAcceptFunction::AsyncWorkStart() { |
| + Socket* socket = GetSocket(params_->socket_id); |
| + if (socket) { |
| + socket->Accept(base::Bind(&SocketAcceptFunction::OnAccept, this)); |
| + } else { |
| + error_ = kSocketNotFoundError; |
| + OnAccept(-1, NULL); |
| + } |
| +} |
| + |
| +void SocketAcceptFunction::OnAccept(int result_code, |
| + net::TCPClientSocket *socket) { |
| + DCHECK(socket); |
| + // TODO(justinlin): This socket won't have an event notifier, but it's not |
| + // used for anything right now. |
| + Socket *client_socket = new TCPSocket(socket, extension_id(), NULL, true); |
| + |
| + DictionaryValue* result = new DictionaryValue(); |
| + result->SetInteger(kResultCodeKey, result_code); |
| + result->SetInteger(kSocketIdKey, manager_->Add(client_socket)); |
| + SetResult(result); |
| + |
| + AsyncWorkCompleted(); |
| +} |
| + |
| SocketReadFunction::SocketReadFunction() |
| : params_(NULL) { |
| } |