| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 : socket_type_(kSocketTypeInvalid) { | 113 : socket_type_(kSocketTypeInvalid) { |
| 114 } | 114 } |
| 115 | 115 |
| 116 SocketCreateFunction::~SocketCreateFunction() {} | 116 SocketCreateFunction::~SocketCreateFunction() {} |
| 117 | 117 |
| 118 bool SocketCreateFunction::Prepare() { | 118 bool SocketCreateFunction::Prepare() { |
| 119 params_ = api::socket::Create::Params::Create(*args_); | 119 params_ = api::socket::Create::Params::Create(*args_); |
| 120 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 120 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 121 | 121 |
| 122 switch (params_->type) { | 122 switch (params_->type) { |
| 123 case extensions::api::socket::SOCKET_SOCKET_TYPE_TCP: | 123 case extensions::api::socket::SOCKET_TYPE_TCP: |
| 124 socket_type_ = kSocketTypeTCP; | 124 socket_type_ = kSocketTypeTCP; |
| 125 break; | 125 break; |
| 126 case extensions::api::socket::SOCKET_SOCKET_TYPE_UDP: | 126 case extensions::api::socket::SOCKET_TYPE_UDP: |
| 127 socket_type_ = kSocketTypeUDP; | 127 socket_type_ = kSocketTypeUDP; |
| 128 break; | 128 break; |
| 129 case extensions::api::socket::SOCKET_SOCKET_TYPE_NONE: | 129 case extensions::api::socket::SOCKET_TYPE_NONE: |
| 130 NOTREACHED(); | 130 NOTREACHED(); |
| 131 break; | 131 break; |
| 132 } | 132 } |
| 133 | 133 |
| 134 return true; | 134 return true; |
| 135 } | 135 } |
| 136 | 136 |
| 137 void SocketCreateFunction::Work() { | 137 void SocketCreateFunction::Work() { |
| 138 Socket* socket = NULL; | 138 Socket* socket = NULL; |
| 139 if (socket_type_ == kSocketTypeTCP) { | 139 if (socket_type_ == kSocketTypeTCP) { |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 return true; | 598 return true; |
| 599 } | 599 } |
| 600 | 600 |
| 601 void SocketGetInfoFunction::Work() { | 601 void SocketGetInfoFunction::Work() { |
| 602 api::socket::SocketInfo info; | 602 api::socket::SocketInfo info; |
| 603 Socket* socket = GetSocket(params_->socket_id); | 603 Socket* socket = GetSocket(params_->socket_id); |
| 604 if (socket) { | 604 if (socket) { |
| 605 // This represents what we know about the socket, and does not call through | 605 // This represents what we know about the socket, and does not call through |
| 606 // to the system. | 606 // to the system. |
| 607 if (socket->GetSocketType() == Socket::TYPE_TCP) | 607 if (socket->GetSocketType() == Socket::TYPE_TCP) |
| 608 info.socket_type = extensions::api::socket::SOCKET_SOCKET_TYPE_TCP; | 608 info.socket_type = extensions::api::socket::SOCKET_TYPE_TCP; |
| 609 else | 609 else |
| 610 info.socket_type = extensions::api::socket::SOCKET_SOCKET_TYPE_UDP; | 610 info.socket_type = extensions::api::socket::SOCKET_TYPE_UDP; |
| 611 info.connected = socket->IsConnected(); | 611 info.connected = socket->IsConnected(); |
| 612 | 612 |
| 613 // Grab the peer address as known by the OS. This and the call below will | 613 // Grab the peer address as known by the OS. This and the call below will |
| 614 // always succeed while the socket is connected, even if the socket has | 614 // always succeed while the socket is connected, even if the socket has |
| 615 // been remotely closed by the peer; only reading the socket will reveal | 615 // been remotely closed by the peer; only reading the socket will reveal |
| 616 // that it should be closed locally. | 616 // that it should be closed locally. |
| 617 net::IPEndPoint peerAddress; | 617 net::IPEndPoint peerAddress; |
| 618 if (socket->GetPeerAddress(&peerAddress)) { | 618 if (socket->GetPeerAddress(&peerAddress)) { |
| 619 info.peer_address.reset( | 619 info.peer_address.reset( |
| 620 new std::string(peerAddress.ToStringWithoutPort())); | 620 new std::string(peerAddress.ToStringWithoutPort())); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 info->name = i->name; | 674 info->name = i->name; |
| 675 info->address = net::IPAddressToString(i->address); | 675 info->address = net::IPAddressToString(i->address); |
| 676 create_arg.push_back(info); | 676 create_arg.push_back(info); |
| 677 } | 677 } |
| 678 | 678 |
| 679 results_ = api::socket::GetNetworkList::Results::Create(create_arg); | 679 results_ = api::socket::GetNetworkList::Results::Create(create_arg); |
| 680 SendResponse(true); | 680 SendResponse(true); |
| 681 } | 681 } |
| 682 | 682 |
| 683 } // namespace extensions | 683 } // namespace extensions |
| OLD | NEW |