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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_)); | 179 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_)); |
180 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &hostname_)); | 180 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &hostname_)); |
181 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &port_)); | 181 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &port_)); |
182 return true; | 182 return true; |
183 } | 183 } |
184 | 184 |
185 void SocketConnectFunction::AsyncWorkStart() { | 185 void SocketConnectFunction::AsyncWorkStart() { |
186 socket_ = GetSocket(socket_id_); | 186 socket_ = GetSocket(socket_id_); |
187 if (!socket_) { | 187 if (!socket_) { |
188 error_ = kSocketNotFoundError; | 188 error_ = kSocketNotFoundError; |
189 SetResult(Value::CreateIntegerValue(-1)); | 189 SetResult(new base::FundamentalValue(-1)); |
190 AsyncWorkCompleted(); | 190 AsyncWorkCompleted(); |
191 return; | 191 return; |
192 } | 192 } |
193 | 193 |
194 SocketPermissionRequest::OperationType operation_type; | 194 SocketPermissionRequest::OperationType operation_type; |
195 switch (socket_->GetSocketType()) { | 195 switch (socket_->GetSocketType()) { |
196 case Socket::TYPE_TCP: | 196 case Socket::TYPE_TCP: |
197 operation_type = SocketPermissionRequest::TCP_CONNECT; | 197 operation_type = SocketPermissionRequest::TCP_CONNECT; |
198 break; | 198 break; |
199 case Socket::TYPE_UDP: | 199 case Socket::TYPE_UDP: |
200 operation_type = SocketPermissionRequest::UDP_SEND_TO; | 200 operation_type = SocketPermissionRequest::UDP_SEND_TO; |
201 break; | 201 break; |
202 default: | 202 default: |
203 NOTREACHED() << "Unknown socket type."; | 203 NOTREACHED() << "Unknown socket type."; |
204 operation_type = SocketPermissionRequest::NONE; | 204 operation_type = SocketPermissionRequest::NONE; |
205 break; | 205 break; |
206 } | 206 } |
207 | 207 |
208 SocketPermission::CheckParam param(operation_type, hostname_, port_); | 208 SocketPermission::CheckParam param(operation_type, hostname_, port_); |
209 if (!PermissionsData::CheckAPIPermissionWithParam( | 209 if (!PermissionsData::CheckAPIPermissionWithParam( |
210 GetExtension(), APIPermission::kSocket, ¶m)) { | 210 GetExtension(), APIPermission::kSocket, ¶m)) { |
211 error_ = kPermissionError; | 211 error_ = kPermissionError; |
212 SetResult(Value::CreateIntegerValue(-1)); | 212 SetResult(new base::FundamentalValue(-1)); |
213 AsyncWorkCompleted(); | 213 AsyncWorkCompleted(); |
214 return; | 214 return; |
215 } | 215 } |
216 | 216 |
217 StartDnsLookup(hostname_); | 217 StartDnsLookup(hostname_); |
218 } | 218 } |
219 | 219 |
220 void SocketConnectFunction::AfterDnsLookup(int lookup_result) { | 220 void SocketConnectFunction::AfterDnsLookup(int lookup_result) { |
221 if (lookup_result == net::OK) { | 221 if (lookup_result == net::OK) { |
222 StartConnect(); | 222 StartConnect(); |
223 } else { | 223 } else { |
224 SetResult(Value::CreateIntegerValue(lookup_result)); | 224 SetResult(new base::FundamentalValue(lookup_result)); |
225 AsyncWorkCompleted(); | 225 AsyncWorkCompleted(); |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 void SocketConnectFunction::StartConnect() { | 229 void SocketConnectFunction::StartConnect() { |
230 socket_->Connect(resolved_address_, port_, | 230 socket_->Connect(resolved_address_, port_, |
231 base::Bind(&SocketConnectFunction::OnConnect, this)); | 231 base::Bind(&SocketConnectFunction::OnConnect, this)); |
232 } | 232 } |
233 | 233 |
234 void SocketConnectFunction::OnConnect(int result) { | 234 void SocketConnectFunction::OnConnect(int result) { |
235 SetResult(Value::CreateIntegerValue(result)); | 235 SetResult(new base::FundamentalValue(result)); |
236 AsyncWorkCompleted(); | 236 AsyncWorkCompleted(); |
237 } | 237 } |
238 | 238 |
239 bool SocketDisconnectFunction::Prepare() { | 239 bool SocketDisconnectFunction::Prepare() { |
240 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_)); | 240 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_)); |
241 return true; | 241 return true; |
242 } | 242 } |
243 | 243 |
244 void SocketDisconnectFunction::Work() { | 244 void SocketDisconnectFunction::Work() { |
245 Socket* socket = GetSocket(socket_id_); | 245 Socket* socket = GetSocket(socket_id_); |
(...skipping 10 matching lines...) Expand all Loading... |
256 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &port_)); | 256 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &port_)); |
257 return true; | 257 return true; |
258 } | 258 } |
259 | 259 |
260 void SocketBindFunction::Work() { | 260 void SocketBindFunction::Work() { |
261 int result = -1; | 261 int result = -1; |
262 Socket* socket = GetSocket(socket_id_); | 262 Socket* socket = GetSocket(socket_id_); |
263 | 263 |
264 if (!socket) { | 264 if (!socket) { |
265 error_ = kSocketNotFoundError; | 265 error_ = kSocketNotFoundError; |
266 SetResult(Value::CreateIntegerValue(result)); | 266 SetResult(new base::FundamentalValue(result)); |
267 return; | 267 return; |
268 } | 268 } |
269 | 269 |
270 if (socket->GetSocketType() == Socket::TYPE_UDP) { | 270 if (socket->GetSocketType() == Socket::TYPE_UDP) { |
271 SocketPermission::CheckParam param( | 271 SocketPermission::CheckParam param( |
272 SocketPermissionRequest::UDP_BIND, address_, port_); | 272 SocketPermissionRequest::UDP_BIND, address_, port_); |
273 if (!PermissionsData::CheckAPIPermissionWithParam( | 273 if (!PermissionsData::CheckAPIPermissionWithParam( |
274 GetExtension(), | 274 GetExtension(), |
275 APIPermission::kSocket, | 275 APIPermission::kSocket, |
276 ¶m)) { | 276 ¶m)) { |
277 error_ = kPermissionError; | 277 error_ = kPermissionError; |
278 SetResult(Value::CreateIntegerValue(result)); | 278 SetResult(new base::FundamentalValue(result)); |
279 return; | 279 return; |
280 } | 280 } |
281 } else if (socket->GetSocketType() == Socket::TYPE_TCP) { | 281 } else if (socket->GetSocketType() == Socket::TYPE_TCP) { |
282 error_ = kTCPSocketBindError; | 282 error_ = kTCPSocketBindError; |
283 SetResult(Value::CreateIntegerValue(result)); | 283 SetResult(new base::FundamentalValue(result)); |
284 return; | 284 return; |
285 } | 285 } |
286 | 286 |
287 result = socket->Bind(address_, port_); | 287 result = socket->Bind(address_, port_); |
288 SetResult(Value::CreateIntegerValue(result)); | 288 SetResult(new base::FundamentalValue(result)); |
289 } | 289 } |
290 | 290 |
291 SocketListenFunction::SocketListenFunction() {} | 291 SocketListenFunction::SocketListenFunction() {} |
292 | 292 |
293 SocketListenFunction::~SocketListenFunction() {} | 293 SocketListenFunction::~SocketListenFunction() {} |
294 | 294 |
295 bool SocketListenFunction::Prepare() { | 295 bool SocketListenFunction::Prepare() { |
296 params_ = api::socket::Listen::Params::Create(*args_); | 296 params_ = api::socket::Listen::Params::Create(*args_); |
297 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 297 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
298 return true; | 298 return true; |
299 } | 299 } |
300 | 300 |
301 void SocketListenFunction::Work() { | 301 void SocketListenFunction::Work() { |
302 int result = -1; | 302 int result = -1; |
303 | 303 |
304 Socket* socket = GetSocket(params_->socket_id); | 304 Socket* socket = GetSocket(params_->socket_id); |
305 if (socket) { | 305 if (socket) { |
306 SocketPermission::CheckParam param( | 306 SocketPermission::CheckParam param( |
307 SocketPermissionRequest::TCP_LISTEN, params_->address, params_->port); | 307 SocketPermissionRequest::TCP_LISTEN, params_->address, params_->port); |
308 if (!PermissionsData::CheckAPIPermissionWithParam( | 308 if (!PermissionsData::CheckAPIPermissionWithParam( |
309 GetExtension(), | 309 GetExtension(), |
310 APIPermission::kSocket, | 310 APIPermission::kSocket, |
311 ¶m)) { | 311 ¶m)) { |
312 error_ = kPermissionError; | 312 error_ = kPermissionError; |
313 SetResult(Value::CreateIntegerValue(result)); | 313 SetResult(new base::FundamentalValue(result)); |
314 return; | 314 return; |
315 } | 315 } |
316 | 316 |
317 result = socket->Listen( | 317 result = socket->Listen( |
318 params_->address, | 318 params_->address, |
319 params_->port, | 319 params_->port, |
320 params_->backlog.get() ? *params_->backlog.get() : 5, | 320 params_->backlog.get() ? *params_->backlog.get() : 5, |
321 &error_); | 321 &error_); |
322 } else { | 322 } else { |
323 error_ = kSocketNotFoundError; | 323 error_ = kSocketNotFoundError; |
324 } | 324 } |
325 | 325 |
326 SetResult(Value::CreateIntegerValue(result)); | 326 SetResult(new base::FundamentalValue(result)); |
327 } | 327 } |
328 | 328 |
329 SocketAcceptFunction::SocketAcceptFunction() {} | 329 SocketAcceptFunction::SocketAcceptFunction() {} |
330 | 330 |
331 SocketAcceptFunction::~SocketAcceptFunction() {} | 331 SocketAcceptFunction::~SocketAcceptFunction() {} |
332 | 332 |
333 bool SocketAcceptFunction::Prepare() { | 333 bool SocketAcceptFunction::Prepare() { |
334 params_ = api::socket::Accept::Params::Create(*args_); | 334 params_ = api::socket::Accept::Params::Create(*args_); |
335 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 335 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
336 return true; | 336 return true; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 497 |
498 io_buffer_size_ = data->GetSize(); | 498 io_buffer_size_ = data->GetSize(); |
499 io_buffer_ = new net::WrappedIOBuffer(data->GetBuffer()); | 499 io_buffer_ = new net::WrappedIOBuffer(data->GetBuffer()); |
500 return true; | 500 return true; |
501 } | 501 } |
502 | 502 |
503 void SocketSendToFunction::AsyncWorkStart() { | 503 void SocketSendToFunction::AsyncWorkStart() { |
504 socket_ = GetSocket(socket_id_); | 504 socket_ = GetSocket(socket_id_); |
505 if (!socket_) { | 505 if (!socket_) { |
506 error_ = kSocketNotFoundError; | 506 error_ = kSocketNotFoundError; |
507 SetResult(Value::CreateIntegerValue(-1)); | 507 SetResult(new base::FundamentalValue(-1)); |
508 AsyncWorkCompleted(); | 508 AsyncWorkCompleted(); |
509 return; | 509 return; |
510 } | 510 } |
511 | 511 |
512 if (socket_->GetSocketType() == Socket::TYPE_UDP) { | 512 if (socket_->GetSocketType() == Socket::TYPE_UDP) { |
513 SocketPermission::CheckParam param(SocketPermissionRequest::UDP_SEND_TO, | 513 SocketPermission::CheckParam param(SocketPermissionRequest::UDP_SEND_TO, |
514 hostname_, port_); | 514 hostname_, port_); |
515 if (!PermissionsData::CheckAPIPermissionWithParam( | 515 if (!PermissionsData::CheckAPIPermissionWithParam( |
516 GetExtension(), | 516 GetExtension(), |
517 APIPermission::kSocket, | 517 APIPermission::kSocket, |
518 ¶m)) { | 518 ¶m)) { |
519 error_ = kPermissionError; | 519 error_ = kPermissionError; |
520 SetResult(Value::CreateIntegerValue(-1)); | 520 SetResult(new base::FundamentalValue(-1)); |
521 AsyncWorkCompleted(); | 521 AsyncWorkCompleted(); |
522 return; | 522 return; |
523 } | 523 } |
524 } | 524 } |
525 | 525 |
526 StartDnsLookup(hostname_); | 526 StartDnsLookup(hostname_); |
527 } | 527 } |
528 | 528 |
529 void SocketSendToFunction::AfterDnsLookup(int lookup_result) { | 529 void SocketSendToFunction::AfterDnsLookup(int lookup_result) { |
530 if (lookup_result == net::OK) { | 530 if (lookup_result == net::OK) { |
531 StartSendTo(); | 531 StartSendTo(); |
532 } else { | 532 } else { |
533 SetResult(Value::CreateIntegerValue(lookup_result)); | 533 SetResult(new base::FundamentalValue(lookup_result)); |
534 AsyncWorkCompleted(); | 534 AsyncWorkCompleted(); |
535 } | 535 } |
536 } | 536 } |
537 | 537 |
538 void SocketSendToFunction::StartSendTo() { | 538 void SocketSendToFunction::StartSendTo() { |
539 socket_->SendTo(io_buffer_, io_buffer_size_, resolved_address_, port_, | 539 socket_->SendTo(io_buffer_, io_buffer_size_, resolved_address_, port_, |
540 base::Bind(&SocketSendToFunction::OnCompleted, this)); | 540 base::Bind(&SocketSendToFunction::OnCompleted, this)); |
541 } | 541 } |
542 | 542 |
543 void SocketSendToFunction::OnCompleted(int bytes_written) { | 543 void SocketSendToFunction::OnCompleted(int bytes_written) { |
(...skipping 18 matching lines...) Expand all Loading... |
562 bool result = false; | 562 bool result = false; |
563 Socket* socket = GetSocket(params_->socket_id); | 563 Socket* socket = GetSocket(params_->socket_id); |
564 if (socket) { | 564 if (socket) { |
565 int delay = 0; | 565 int delay = 0; |
566 if (params_->delay.get()) | 566 if (params_->delay.get()) |
567 delay = *params_->delay; | 567 delay = *params_->delay; |
568 result = socket->SetKeepAlive(params_->enable, delay); | 568 result = socket->SetKeepAlive(params_->enable, delay); |
569 } else { | 569 } else { |
570 error_ = kSocketNotFoundError; | 570 error_ = kSocketNotFoundError; |
571 } | 571 } |
572 SetResult(Value::CreateBooleanValue(result)); | 572 SetResult(new base::FundamentalValue(result)); |
573 } | 573 } |
574 | 574 |
575 SocketSetNoDelayFunction::SocketSetNoDelayFunction() {} | 575 SocketSetNoDelayFunction::SocketSetNoDelayFunction() {} |
576 | 576 |
577 SocketSetNoDelayFunction::~SocketSetNoDelayFunction() {} | 577 SocketSetNoDelayFunction::~SocketSetNoDelayFunction() {} |
578 | 578 |
579 bool SocketSetNoDelayFunction::Prepare() { | 579 bool SocketSetNoDelayFunction::Prepare() { |
580 params_ = api::socket::SetNoDelay::Params::Create(*args_); | 580 params_ = api::socket::SetNoDelay::Params::Create(*args_); |
581 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 581 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
582 return true; | 582 return true; |
583 } | 583 } |
584 | 584 |
585 void SocketSetNoDelayFunction::Work() { | 585 void SocketSetNoDelayFunction::Work() { |
586 bool result = false; | 586 bool result = false; |
587 Socket* socket = GetSocket(params_->socket_id); | 587 Socket* socket = GetSocket(params_->socket_id); |
588 if (socket) | 588 if (socket) |
589 result = socket->SetNoDelay(params_->no_delay); | 589 result = socket->SetNoDelay(params_->no_delay); |
590 else | 590 else |
591 error_ = kSocketNotFoundError; | 591 error_ = kSocketNotFoundError; |
592 SetResult(Value::CreateBooleanValue(result)); | 592 SetResult(new base::FundamentalValue(result)); |
593 } | 593 } |
594 | 594 |
595 SocketGetInfoFunction::SocketGetInfoFunction() {} | 595 SocketGetInfoFunction::SocketGetInfoFunction() {} |
596 | 596 |
597 SocketGetInfoFunction::~SocketGetInfoFunction() {} | 597 SocketGetInfoFunction::~SocketGetInfoFunction() {} |
598 | 598 |
599 bool SocketGetInfoFunction::Prepare() { | 599 bool SocketGetInfoFunction::Prepare() { |
600 params_ = api::socket::GetInfo::Params::Create(*args_); | 600 params_ = api::socket::GetInfo::Params::Create(*args_); |
601 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 601 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
602 return true; | 602 return true; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 params_ = api::socket::JoinGroup::Params::Create(*args_); | 694 params_ = api::socket::JoinGroup::Params::Create(*args_); |
695 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 695 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
696 return true; | 696 return true; |
697 } | 697 } |
698 | 698 |
699 void SocketJoinGroupFunction::Work() { | 699 void SocketJoinGroupFunction::Work() { |
700 int result = -1; | 700 int result = -1; |
701 Socket* socket = GetSocket(params_->socket_id); | 701 Socket* socket = GetSocket(params_->socket_id); |
702 if (!socket) { | 702 if (!socket) { |
703 error_ = kSocketNotFoundError; | 703 error_ = kSocketNotFoundError; |
704 SetResult(Value::CreateIntegerValue(result)); | 704 SetResult(new base::FundamentalValue(result)); |
705 return; | 705 return; |
706 } | 706 } |
707 | 707 |
708 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 708 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
709 error_ = kMulticastSocketTypeError; | 709 error_ = kMulticastSocketTypeError; |
710 SetResult(Value::CreateIntegerValue(result)); | 710 SetResult(new base::FundamentalValue(result)); |
711 return; | 711 return; |
712 } | 712 } |
713 | 713 |
714 SocketPermission::CheckParam param( | 714 SocketPermission::CheckParam param( |
715 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, | 715 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, |
716 kWildcardAddress, | 716 kWildcardAddress, |
717 kWildcardPort); | 717 kWildcardPort); |
718 | 718 |
719 if (!PermissionsData::CheckAPIPermissionWithParam( | 719 if (!PermissionsData::CheckAPIPermissionWithParam( |
720 GetExtension(), APIPermission::kSocket, ¶m)) { | 720 GetExtension(), APIPermission::kSocket, ¶m)) { |
721 error_ = kPermissionError; | 721 error_ = kPermissionError; |
722 SetResult(Value::CreateIntegerValue(result)); | 722 SetResult(new base::FundamentalValue(result)); |
723 return; | 723 return; |
724 } | 724 } |
725 | 725 |
726 result = static_cast<UDPSocket*>(socket)->JoinGroup(params_->address); | 726 result = static_cast<UDPSocket*>(socket)->JoinGroup(params_->address); |
727 if (result != 0) { | 727 if (result != 0) { |
728 error_ = net::ErrorToString(result); | 728 error_ = net::ErrorToString(result); |
729 } | 729 } |
730 SetResult(Value::CreateIntegerValue(result)); | 730 SetResult(new base::FundamentalValue(result)); |
731 } | 731 } |
732 | 732 |
733 SocketLeaveGroupFunction::SocketLeaveGroupFunction() {} | 733 SocketLeaveGroupFunction::SocketLeaveGroupFunction() {} |
734 | 734 |
735 SocketLeaveGroupFunction::~SocketLeaveGroupFunction() {} | 735 SocketLeaveGroupFunction::~SocketLeaveGroupFunction() {} |
736 | 736 |
737 bool SocketLeaveGroupFunction::Prepare() { | 737 bool SocketLeaveGroupFunction::Prepare() { |
738 params_ = api::socket::LeaveGroup::Params::Create(*args_); | 738 params_ = api::socket::LeaveGroup::Params::Create(*args_); |
739 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 739 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
740 return true; | 740 return true; |
741 } | 741 } |
742 | 742 |
743 void SocketLeaveGroupFunction::Work() { | 743 void SocketLeaveGroupFunction::Work() { |
744 int result = -1; | 744 int result = -1; |
745 Socket* socket = GetSocket(params_->socket_id); | 745 Socket* socket = GetSocket(params_->socket_id); |
746 | 746 |
747 if (!socket) { | 747 if (!socket) { |
748 error_ = kSocketNotFoundError; | 748 error_ = kSocketNotFoundError; |
749 SetResult(Value::CreateIntegerValue(result)); | 749 SetResult(new base::FundamentalValue(result)); |
750 return; | 750 return; |
751 } | 751 } |
752 | 752 |
753 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 753 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
754 error_ = kMulticastSocketTypeError; | 754 error_ = kMulticastSocketTypeError; |
755 SetResult(Value::CreateIntegerValue(result)); | 755 SetResult(new base::FundamentalValue(result)); |
756 return; | 756 return; |
757 } | 757 } |
758 | 758 |
759 SocketPermission::CheckParam param( | 759 SocketPermission::CheckParam param( |
760 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, | 760 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, |
761 kWildcardAddress, | 761 kWildcardAddress, |
762 kWildcardPort); | 762 kWildcardPort); |
763 if (!PermissionsData::CheckAPIPermissionWithParam(GetExtension(), | 763 if (!PermissionsData::CheckAPIPermissionWithParam(GetExtension(), |
764 APIPermission::kSocket, | 764 APIPermission::kSocket, |
765 ¶m)) { | 765 ¶m)) { |
766 error_ = kPermissionError; | 766 error_ = kPermissionError; |
767 SetResult(Value::CreateIntegerValue(result)); | 767 SetResult(new base::FundamentalValue(result)); |
768 return; | 768 return; |
769 } | 769 } |
770 | 770 |
771 result = static_cast<UDPSocket*>(socket)->LeaveGroup(params_->address); | 771 result = static_cast<UDPSocket*>(socket)->LeaveGroup(params_->address); |
772 if (result != 0) | 772 if (result != 0) |
773 error_ = net::ErrorToString(result); | 773 error_ = net::ErrorToString(result); |
774 SetResult(Value::CreateIntegerValue(result)); | 774 SetResult(new base::FundamentalValue(result)); |
775 } | 775 } |
776 | 776 |
777 SocketSetMulticastTimeToLiveFunction::SocketSetMulticastTimeToLiveFunction() {} | 777 SocketSetMulticastTimeToLiveFunction::SocketSetMulticastTimeToLiveFunction() {} |
778 | 778 |
779 SocketSetMulticastTimeToLiveFunction::~SocketSetMulticastTimeToLiveFunction() {} | 779 SocketSetMulticastTimeToLiveFunction::~SocketSetMulticastTimeToLiveFunction() {} |
780 | 780 |
781 bool SocketSetMulticastTimeToLiveFunction::Prepare() { | 781 bool SocketSetMulticastTimeToLiveFunction::Prepare() { |
782 params_ = api::socket::SetMulticastTimeToLive::Params::Create(*args_); | 782 params_ = api::socket::SetMulticastTimeToLive::Params::Create(*args_); |
783 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 783 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
784 return true; | 784 return true; |
785 } | 785 } |
786 void SocketSetMulticastTimeToLiveFunction::Work() { | 786 void SocketSetMulticastTimeToLiveFunction::Work() { |
787 int result = -1; | 787 int result = -1; |
788 Socket* socket = GetSocket(params_->socket_id); | 788 Socket* socket = GetSocket(params_->socket_id); |
789 if (!socket) { | 789 if (!socket) { |
790 error_ = kSocketNotFoundError; | 790 error_ = kSocketNotFoundError; |
791 SetResult(Value::CreateIntegerValue(result)); | 791 SetResult(new base::FundamentalValue(result)); |
792 return; | 792 return; |
793 } | 793 } |
794 | 794 |
795 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 795 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
796 error_ = kMulticastSocketTypeError; | 796 error_ = kMulticastSocketTypeError; |
797 SetResult(Value::CreateIntegerValue(result)); | 797 SetResult(new base::FundamentalValue(result)); |
798 return; | 798 return; |
799 } | 799 } |
800 | 800 |
801 result = static_cast<UDPSocket*>(socket)->SetMulticastTimeToLive( | 801 result = static_cast<UDPSocket*>(socket)->SetMulticastTimeToLive( |
802 params_->ttl); | 802 params_->ttl); |
803 if (result != 0) | 803 if (result != 0) |
804 error_ = net::ErrorToString(result); | 804 error_ = net::ErrorToString(result); |
805 SetResult(Value::CreateIntegerValue(result)); | 805 SetResult(new base::FundamentalValue(result)); |
806 } | 806 } |
807 | 807 |
808 SocketSetMulticastLoopbackModeFunction:: | 808 SocketSetMulticastLoopbackModeFunction:: |
809 SocketSetMulticastLoopbackModeFunction() {} | 809 SocketSetMulticastLoopbackModeFunction() {} |
810 | 810 |
811 SocketSetMulticastLoopbackModeFunction:: | 811 SocketSetMulticastLoopbackModeFunction:: |
812 ~SocketSetMulticastLoopbackModeFunction() {} | 812 ~SocketSetMulticastLoopbackModeFunction() {} |
813 | 813 |
814 bool SocketSetMulticastLoopbackModeFunction::Prepare() { | 814 bool SocketSetMulticastLoopbackModeFunction::Prepare() { |
815 params_ = api::socket::SetMulticastLoopbackMode::Params::Create(*args_); | 815 params_ = api::socket::SetMulticastLoopbackMode::Params::Create(*args_); |
816 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 816 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
817 return true; | 817 return true; |
818 } | 818 } |
819 | 819 |
820 void SocketSetMulticastLoopbackModeFunction::Work() { | 820 void SocketSetMulticastLoopbackModeFunction::Work() { |
821 int result = -1; | 821 int result = -1; |
822 Socket* socket = GetSocket(params_->socket_id); | 822 Socket* socket = GetSocket(params_->socket_id); |
823 if (!socket) { | 823 if (!socket) { |
824 error_ = kSocketNotFoundError; | 824 error_ = kSocketNotFoundError; |
825 SetResult(Value::CreateIntegerValue(result)); | 825 SetResult(new base::FundamentalValue(result)); |
826 return; | 826 return; |
827 } | 827 } |
828 | 828 |
829 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 829 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
830 error_ = kMulticastSocketTypeError; | 830 error_ = kMulticastSocketTypeError; |
831 SetResult(Value::CreateIntegerValue(result)); | 831 SetResult(new base::FundamentalValue(result)); |
832 return; | 832 return; |
833 } | 833 } |
834 | 834 |
835 result = static_cast<UDPSocket*>(socket)-> | 835 result = static_cast<UDPSocket*>(socket)-> |
836 SetMulticastLoopbackMode(params_->enabled); | 836 SetMulticastLoopbackMode(params_->enabled); |
837 if (result != 0) | 837 if (result != 0) |
838 error_ = net::ErrorToString(result); | 838 error_ = net::ErrorToString(result); |
839 SetResult(Value::CreateIntegerValue(result)); | 839 SetResult(new base::FundamentalValue(result)); |
840 } | 840 } |
841 | 841 |
842 SocketGetJoinedGroupsFunction::SocketGetJoinedGroupsFunction() {} | 842 SocketGetJoinedGroupsFunction::SocketGetJoinedGroupsFunction() {} |
843 | 843 |
844 SocketGetJoinedGroupsFunction::~SocketGetJoinedGroupsFunction() {} | 844 SocketGetJoinedGroupsFunction::~SocketGetJoinedGroupsFunction() {} |
845 | 845 |
846 bool SocketGetJoinedGroupsFunction::Prepare() { | 846 bool SocketGetJoinedGroupsFunction::Prepare() { |
847 params_ = api::socket::GetJoinedGroups::Params::Create(*args_); | 847 params_ = api::socket::GetJoinedGroups::Params::Create(*args_); |
848 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 848 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
849 return true; | 849 return true; |
850 } | 850 } |
851 | 851 |
852 void SocketGetJoinedGroupsFunction::Work() { | 852 void SocketGetJoinedGroupsFunction::Work() { |
853 int result = -1; | 853 int result = -1; |
854 Socket* socket = GetSocket(params_->socket_id); | 854 Socket* socket = GetSocket(params_->socket_id); |
855 if (!socket) { | 855 if (!socket) { |
856 error_ = kSocketNotFoundError; | 856 error_ = kSocketNotFoundError; |
857 SetResult(Value::CreateIntegerValue(result)); | 857 SetResult(new base::FundamentalValue(result)); |
858 return; | 858 return; |
859 } | 859 } |
860 | 860 |
861 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 861 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
862 error_ = kMulticastSocketTypeError; | 862 error_ = kMulticastSocketTypeError; |
863 SetResult(Value::CreateIntegerValue(result)); | 863 SetResult(new base::FundamentalValue(result)); |
864 return; | 864 return; |
865 } | 865 } |
866 | 866 |
867 SocketPermission::CheckParam param( | 867 SocketPermission::CheckParam param( |
868 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, | 868 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, |
869 kWildcardAddress, | 869 kWildcardAddress, |
870 kWildcardPort); | 870 kWildcardPort); |
871 if (!PermissionsData::CheckAPIPermissionWithParam( | 871 if (!PermissionsData::CheckAPIPermissionWithParam( |
872 GetExtension(), | 872 GetExtension(), |
873 APIPermission::kSocket, | 873 APIPermission::kSocket, |
874 ¶m)) { | 874 ¶m)) { |
875 error_ = kPermissionError; | 875 error_ = kPermissionError; |
876 SetResult(Value::CreateIntegerValue(result)); | 876 SetResult(new base::FundamentalValue(result)); |
877 return; | 877 return; |
878 } | 878 } |
879 | 879 |
880 base::ListValue* values = new base::ListValue(); | 880 base::ListValue* values = new base::ListValue(); |
881 values->AppendStrings((std::vector<std::string>&) | 881 values->AppendStrings((std::vector<std::string>&) |
882 static_cast<UDPSocket*>(socket)->GetJoinedGroups()); | 882 static_cast<UDPSocket*>(socket)->GetJoinedGroups()); |
883 SetResult(values); | 883 SetResult(values); |
884 } | 884 } |
885 | 885 |
886 } // namespace extensions | 886 } // namespace extensions |
OLD | NEW |