| 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/common/extensions/extension.h" | 8 #include "chrome/common/extensions/extension.h" |
| 9 #include "chrome/common/extensions/permissions/socket_permission.h" | 9 #include "chrome/common/extensions/permissions/socket_permission.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 | 375 |
| 376 void SocketReadFunction::OnCompleted(int bytes_read, | 376 void SocketReadFunction::OnCompleted(int bytes_read, |
| 377 scoped_refptr<net::IOBuffer> io_buffer) { | 377 scoped_refptr<net::IOBuffer> io_buffer) { |
| 378 DictionaryValue* result = new DictionaryValue(); | 378 DictionaryValue* result = new DictionaryValue(); |
| 379 result->SetInteger(kResultCodeKey, bytes_read); | 379 result->SetInteger(kResultCodeKey, bytes_read); |
| 380 if (bytes_read > 0) { | 380 if (bytes_read > 0) { |
| 381 result->Set(kDataKey, | 381 result->Set(kDataKey, |
| 382 base::BinaryValue::CreateWithCopiedBuffer(io_buffer->data(), | 382 base::BinaryValue::CreateWithCopiedBuffer(io_buffer->data(), |
| 383 bytes_read)); | 383 bytes_read)); |
| 384 } else { | 384 } else { |
| 385 // BinaryValue does not support NULL buffer. Workaround it with new char[1]. | 385 result->Set(kDataKey, new base::BinaryValue()); |
| 386 // http://crbug.com/127630 | |
| 387 result->Set(kDataKey, base::BinaryValue::Create(new char[1], 0)); | |
| 388 } | 386 } |
| 389 SetResult(result); | 387 SetResult(result); |
| 390 | 388 |
| 391 AsyncWorkCompleted(); | 389 AsyncWorkCompleted(); |
| 392 } | 390 } |
| 393 | 391 |
| 394 SocketWriteFunction::SocketWriteFunction() | 392 SocketWriteFunction::SocketWriteFunction() |
| 395 : socket_id_(0), | 393 : socket_id_(0), |
| 396 io_buffer_(NULL), | 394 io_buffer_(NULL), |
| 397 io_buffer_size_(0) { | 395 io_buffer_size_(0) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 scoped_refptr<net::IOBuffer> io_buffer, | 456 scoped_refptr<net::IOBuffer> io_buffer, |
| 459 const std::string& address, | 457 const std::string& address, |
| 460 int port) { | 458 int port) { |
| 461 DictionaryValue* result = new DictionaryValue(); | 459 DictionaryValue* result = new DictionaryValue(); |
| 462 result->SetInteger(kResultCodeKey, bytes_read); | 460 result->SetInteger(kResultCodeKey, bytes_read); |
| 463 if (bytes_read > 0) { | 461 if (bytes_read > 0) { |
| 464 result->Set(kDataKey, | 462 result->Set(kDataKey, |
| 465 base::BinaryValue::CreateWithCopiedBuffer(io_buffer->data(), | 463 base::BinaryValue::CreateWithCopiedBuffer(io_buffer->data(), |
| 466 bytes_read)); | 464 bytes_read)); |
| 467 } else { | 465 } else { |
| 468 // BinaryValue does not support NULL buffer. Workaround it with new char[1]. | 466 result->Set(kDataKey, new base::BinaryValue()); |
| 469 // http://crbug.com/127630 | |
| 470 result->Set(kDataKey, base::BinaryValue::Create(new char[1], 0)); | |
| 471 } | 467 } |
| 472 result->SetString(kAddressKey, address); | 468 result->SetString(kAddressKey, address); |
| 473 result->SetInteger(kPortKey, port); | 469 result->SetInteger(kPortKey, port); |
| 474 SetResult(result); | 470 SetResult(result); |
| 475 | 471 |
| 476 AsyncWorkCompleted(); | 472 AsyncWorkCompleted(); |
| 477 } | 473 } |
| 478 | 474 |
| 479 SocketSendToFunction::SocketSendToFunction() | 475 SocketSendToFunction::SocketSendToFunction() |
| 480 : socket_id_(0), | 476 : socket_id_(0), |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 info->name = i->name; | 674 info->name = i->name; |
| 679 info->address = net::IPAddressToString(i->address); | 675 info->address = net::IPAddressToString(i->address); |
| 680 create_arg.push_back(info); | 676 create_arg.push_back(info); |
| 681 } | 677 } |
| 682 | 678 |
| 683 results_ = api::socket::GetNetworkList::Results::Create(create_arg); | 679 results_ = api::socket::GetNetworkList::Results::Create(create_arg); |
| 684 SendResponse(true); | 680 SendResponse(true); |
| 685 } | 681 } |
| 686 | 682 |
| 687 } // namespace extensions | 683 } // namespace extensions |
| OLD | NEW |