| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/socket/socket_api.h" | 5 #include "chrome/browser/extensions/api/socket/socket_api.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/extensions/api/api_resource_controller.h" | 8 #include "chrome/browser/extensions/api/api_resource_controller.h" |
| 9 #include "chrome/browser/extensions/api/socket/socket.h" | 9 #include "chrome/browser/extensions/api/socket/socket.h" |
| 10 #include "chrome/browser/extensions/api/socket/tcp_socket.h" | 10 #include "chrome/browser/extensions/api/socket/tcp_socket.h" |
| 11 #include "chrome/browser/extensions/api/socket/udp_socket.h" | 11 #include "chrome/browser/extensions/api/socket/udp_socket.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 14 | 14 |
| 15 namespace extensions { | 15 namespace extensions { |
| 16 | 16 |
| 17 const char kBytesWrittenKey[] = "bytesWritten"; | 17 const char kBytesWrittenKey[] = "bytesWritten"; |
| 18 const char kDataKey[] = "data"; | 18 const char kDataKey[] = "data"; |
| 19 const char kResultCodeKey[] = "resultCode"; | 19 const char kResultCodeKey[] = "resultCode"; |
| 20 const char kSocketIdKey[] = "socketId"; | 20 const char kSocketIdKey[] = "socketId"; |
| 21 const char kTCPOption[] = "tcp"; | 21 const char kTCPOption[] = "tcp"; |
| 22 const char kUDPOption[] = "udp"; | 22 const char kUDPOption[] = "udp"; |
| 23 | 23 |
| 24 const char kSocketNotFoundError[] = "Socket not found"; | 24 const char kSocketNotFoundError[] = "Socket not found"; |
| 25 | 25 |
| 26 SocketCreateFunction::SocketCreateFunction() | 26 SocketCreateFunction::SocketCreateFunction() |
| 27 : src_id_(-1), event_notifier_(NULL) { | 27 : src_id_(-1), |
| 28 event_notifier_(NULL) { |
| 28 } | 29 } |
| 29 | 30 |
| 31 SocketCreateFunction::~SocketCreateFunction() {} |
| 32 |
| 30 bool SocketCreateFunction::Prepare() { | 33 bool SocketCreateFunction::Prepare() { |
| 31 std::string socket_type_string; | 34 std::string socket_type_string; |
| 32 size_t argument_position = 0; | 35 size_t argument_position = 0; |
| 33 EXTENSION_FUNCTION_VALIDATE(args_->GetString(argument_position++, | 36 EXTENSION_FUNCTION_VALIDATE(args_->GetString(argument_position++, |
| 34 &socket_type_string)); | 37 &socket_type_string)); |
| 35 EXTENSION_FUNCTION_VALIDATE(args_->GetString(argument_position++, | 38 EXTENSION_FUNCTION_VALIDATE(args_->GetString(argument_position++, |
| 36 &address_)); | 39 &address_)); |
| 37 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(argument_position++, | 40 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(argument_position++, |
| 38 &port_)); | 41 &port_)); |
| 39 | 42 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 158 |
| 156 bool SocketReadFunction::Respond() { | 159 bool SocketReadFunction::Respond() { |
| 157 return true; | 160 return true; |
| 158 } | 161 } |
| 159 | 162 |
| 160 SocketWriteFunction::SocketWriteFunction() | 163 SocketWriteFunction::SocketWriteFunction() |
| 161 : socket_id_(0), | 164 : socket_id_(0), |
| 162 io_buffer_(NULL) { | 165 io_buffer_(NULL) { |
| 163 } | 166 } |
| 164 | 167 |
| 165 SocketWriteFunction::~SocketWriteFunction() { | 168 SocketWriteFunction::~SocketWriteFunction() {} |
| 166 } | |
| 167 | 169 |
| 168 bool SocketWriteFunction::Prepare() { | 170 bool SocketWriteFunction::Prepare() { |
| 169 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_)); | 171 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_)); |
| 170 base::ListValue* data_list_value = NULL; | 172 base::ListValue* data_list_value = NULL; |
| 171 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &data_list_value)); | 173 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &data_list_value)); |
| 172 | 174 |
| 173 size_t size = data_list_value->GetSize(); | 175 size_t size = data_list_value->GetSize(); |
| 174 if (size != 0) { | 176 if (size != 0) { |
| 175 io_buffer_ = new net::IOBufferWithSize(size); | 177 io_buffer_ = new net::IOBufferWithSize(size); |
| 176 uint8* data_buffer = | 178 uint8* data_buffer = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 198 DictionaryValue* result = new DictionaryValue(); | 200 DictionaryValue* result = new DictionaryValue(); |
| 199 result->SetInteger(kBytesWrittenKey, bytes_written); | 201 result->SetInteger(kBytesWrittenKey, bytes_written); |
| 200 result_.reset(result); | 202 result_.reset(result); |
| 201 } | 203 } |
| 202 | 204 |
| 203 bool SocketWriteFunction::Respond() { | 205 bool SocketWriteFunction::Respond() { |
| 204 return true; | 206 return true; |
| 205 } | 207 } |
| 206 | 208 |
| 207 } // namespace extensions | 209 } // namespace extensions |
| OLD | NEW |