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/permissions/socket_permission.h" | 8 #include "chrome/common/extensions/permissions/socket_permission.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h" | 10 #include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 src_id_(-1), | 113 src_id_(-1), |
114 event_notifier_(NULL) { | 114 event_notifier_(NULL) { |
115 } | 115 } |
116 | 116 |
117 SocketCreateFunction::~SocketCreateFunction() {} | 117 SocketCreateFunction::~SocketCreateFunction() {} |
118 | 118 |
119 bool SocketCreateFunction::Prepare() { | 119 bool SocketCreateFunction::Prepare() { |
120 params_ = api::socket::Create::Params::Create(*args_); | 120 params_ = api::socket::Create::Params::Create(*args_); |
121 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 121 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
122 | 122 |
123 if (params_->type == kTCPOption) { | 123 std::string type = kUnknown; |
124 scoped_ptr<base::Value> type_value(extensions::api::socket::CreateEnumValue( | |
125 params_->type)); | |
126 if (type_value.get()) | |
127 type_value->GetAsString(&type); | |
128 | |
129 if (type == kTCPOption) { | |
not at google - send to devlin
2012/09/14 01:44:51
etc
cduvall
2012/09/17 22:07:46
Done.
| |
124 socket_type_ = kSocketTypeTCP; | 130 socket_type_ = kSocketTypeTCP; |
125 } else if (params_->type == kUDPOption) { | 131 } else if (type == kUDPOption) { |
126 socket_type_ = kSocketTypeUDP; | 132 socket_type_ = kSocketTypeUDP; |
127 } else { | |
128 error_ = kSocketTypeInvalidError; | |
129 return false; | |
130 } | 133 } |
131 if (params_->options.get()) { | 134 if (params_->options.get()) { |
132 scoped_ptr<DictionaryValue> options = params_->options->ToValue(); | 135 scoped_ptr<DictionaryValue> options = params_->options->ToValue(); |
133 src_id_ = ExtractSrcId(options.get()); | 136 src_id_ = ExtractSrcId(options.get()); |
134 event_notifier_ = CreateEventNotifier(src_id_); | 137 event_notifier_ = CreateEventNotifier(src_id_); |
135 } | 138 } |
136 | 139 |
137 return true; | 140 return true; |
138 } | 141 } |
139 | 142 |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 530 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
528 return true; | 531 return true; |
529 } | 532 } |
530 | 533 |
531 void SocketGetInfoFunction::Work() { | 534 void SocketGetInfoFunction::Work() { |
532 api::socket::SocketInfo info; | 535 api::socket::SocketInfo info; |
533 Socket* socket = GetSocket(params_->socket_id); | 536 Socket* socket = GetSocket(params_->socket_id); |
534 if (socket) { | 537 if (socket) { |
535 // This represents what we know about the socket, and does not call through | 538 // This represents what we know about the socket, and does not call through |
536 // to the system. | 539 // to the system. |
537 switch (socket->GetSocketType()) { | 540 if (socket->GetSocketType() == Socket::TYPE_TCP) |
538 case Socket::TYPE_TCP: | 541 info.socket_type = extensions::api::socket::SOCKETTYPE_TCP; |
539 info.socket_type = kTCPOption; | 542 else |
540 break; | 543 info.socket_type = extensions::api::socket::SOCKETTYPE_UDP; |
541 case Socket::TYPE_UDP: | |
542 info.socket_type = kUDPOption; | |
543 break; | |
544 default: | |
545 NOTREACHED() << "Unknown socket type."; | |
546 info.socket_type = kUnknown; | |
547 break; | |
548 } | |
549 info.connected = socket->IsConnected(); | 544 info.connected = socket->IsConnected(); |
550 | 545 |
551 // Grab the peer address as known by the OS. This and the call below will | 546 // Grab the peer address as known by the OS. This and the call below will |
552 // always succeed while the socket is connected, even if the socket has | 547 // always succeed while the socket is connected, even if the socket has |
553 // been remotely closed by the peer; only reading the socket will reveal | 548 // been remotely closed by the peer; only reading the socket will reveal |
554 // that it should be closed locally. | 549 // that it should be closed locally. |
555 net::IPEndPoint peerAddress; | 550 net::IPEndPoint peerAddress; |
556 if (socket->GetPeerAddress(&peerAddress)) { | 551 if (socket->GetPeerAddress(&peerAddress)) { |
557 info.peer_address.reset( | 552 info.peer_address.reset( |
558 new std::string(peerAddress.ToStringWithoutPort())); | 553 new std::string(peerAddress.ToStringWithoutPort())); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 info->name = i->name; | 607 info->name = i->name; |
613 info->address = net::IPAddressToString(i->address); | 608 info->address = net::IPAddressToString(i->address); |
614 create_arg.push_back(info); | 609 create_arg.push_back(info); |
615 } | 610 } |
616 | 611 |
617 results_ = api::socket::GetNetworkList::Results::Create(create_arg); | 612 results_ = api::socket::GetNetworkList::Results::Create(create_arg); |
618 SendResponse(true); | 613 SendResponse(true); |
619 } | 614 } |
620 | 615 |
621 } // namespace extensions | 616 } // namespace extensions |
OLD | NEW |