| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/socket/socket_api.h" | 5 #include "extensions/browser/api/socket/socket_api.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 void SocketAsyncApiFunction::OpenFirewallHole(const std::string& address, | 117 void SocketAsyncApiFunction::OpenFirewallHole(const std::string& address, |
| 118 int socket_id, | 118 int socket_id, |
| 119 Socket* socket) { | 119 Socket* socket) { |
| 120 #if defined(OS_CHROMEOS) | 120 #if defined(OS_CHROMEOS) |
| 121 if (!net::IsLocalhost(address)) { | 121 if (!net::IsLocalhost(address)) { |
| 122 net::IPEndPoint local_address; | 122 net::IPEndPoint local_address; |
| 123 if (!socket->GetLocalAddress(&local_address)) { | 123 if (!socket->GetLocalAddress(&local_address)) { |
| 124 NOTREACHED() << "Cannot get address of recently bound socket."; | 124 NOTREACHED() << "Cannot get address of recently bound socket."; |
| 125 error_ = kFirewallFailure; | 125 error_ = kFirewallFailure; |
| 126 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 126 SetResult(base::MakeUnique<base::Value>(-1)); |
| 127 AsyncWorkCompleted(); | 127 AsyncWorkCompleted(); |
| 128 return; | 128 return; |
| 129 } | 129 } |
| 130 | 130 |
| 131 AppFirewallHole::PortType type = socket->GetSocketType() == Socket::TYPE_TCP | 131 AppFirewallHole::PortType type = socket->GetSocketType() == Socket::TYPE_TCP |
| 132 ? AppFirewallHole::PortType::TCP | 132 ? AppFirewallHole::PortType::TCP |
| 133 : AppFirewallHole::PortType::UDP; | 133 : AppFirewallHole::PortType::UDP; |
| 134 | 134 |
| 135 BrowserThread::PostTask( | 135 BrowserThread::PostTask( |
| 136 BrowserThread::UI, FROM_HERE, | 136 BrowserThread::UI, FROM_HERE, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 158 base::Bind(&SocketAsyncApiFunction::OnFirewallHoleOpened, this, socket_id, | 158 base::Bind(&SocketAsyncApiFunction::OnFirewallHoleOpened, this, socket_id, |
| 159 base::Passed(&hole))); | 159 base::Passed(&hole))); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void SocketAsyncApiFunction::OnFirewallHoleOpened( | 162 void SocketAsyncApiFunction::OnFirewallHoleOpened( |
| 163 int socket_id, | 163 int socket_id, |
| 164 std::unique_ptr<AppFirewallHole, BrowserThread::DeleteOnUIThread> hole) { | 164 std::unique_ptr<AppFirewallHole, BrowserThread::DeleteOnUIThread> hole) { |
| 165 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 165 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 166 if (!hole) { | 166 if (!hole) { |
| 167 error_ = kFirewallFailure; | 167 error_ = kFirewallFailure; |
| 168 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 168 SetResult(base::MakeUnique<base::Value>(-1)); |
| 169 AsyncWorkCompleted(); | 169 AsyncWorkCompleted(); |
| 170 return; | 170 return; |
| 171 } | 171 } |
| 172 | 172 |
| 173 Socket* socket = GetSocket(socket_id); | 173 Socket* socket = GetSocket(socket_id); |
| 174 if (!socket) { | 174 if (!socket) { |
| 175 error_ = kSocketNotFoundError; | 175 error_ = kSocketNotFoundError; |
| 176 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 176 SetResult(base::MakeUnique<base::Value>(-1)); |
| 177 AsyncWorkCompleted(); | 177 AsyncWorkCompleted(); |
| 178 return; | 178 return; |
| 179 } | 179 } |
| 180 | 180 |
| 181 socket->set_firewall_hole(std::move(hole)); | 181 socket->set_firewall_hole(std::move(hole)); |
| 182 AsyncWorkCompleted(); | 182 AsyncWorkCompleted(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 #endif // OS_CHROMEOS | 185 #endif // OS_CHROMEOS |
| 186 | 186 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 return false; | 284 return false; |
| 285 } | 285 } |
| 286 port_ = static_cast<uint16_t>(port); | 286 port_ = static_cast<uint16_t>(port); |
| 287 return true; | 287 return true; |
| 288 } | 288 } |
| 289 | 289 |
| 290 void SocketConnectFunction::AsyncWorkStart() { | 290 void SocketConnectFunction::AsyncWorkStart() { |
| 291 Socket* socket = GetSocket(socket_id_); | 291 Socket* socket = GetSocket(socket_id_); |
| 292 if (!socket) { | 292 if (!socket) { |
| 293 error_ = kSocketNotFoundError; | 293 error_ = kSocketNotFoundError; |
| 294 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 294 SetResult(base::MakeUnique<base::Value>(-1)); |
| 295 AsyncWorkCompleted(); | 295 AsyncWorkCompleted(); |
| 296 return; | 296 return; |
| 297 } | 297 } |
| 298 | 298 |
| 299 socket->set_hostname(hostname_); | 299 socket->set_hostname(hostname_); |
| 300 | 300 |
| 301 SocketPermissionRequest::OperationType operation_type; | 301 SocketPermissionRequest::OperationType operation_type; |
| 302 switch (socket->GetSocketType()) { | 302 switch (socket->GetSocketType()) { |
| 303 case Socket::TYPE_TCP: | 303 case Socket::TYPE_TCP: |
| 304 operation_type = SocketPermissionRequest::TCP_CONNECT; | 304 operation_type = SocketPermissionRequest::TCP_CONNECT; |
| 305 break; | 305 break; |
| 306 case Socket::TYPE_UDP: | 306 case Socket::TYPE_UDP: |
| 307 operation_type = SocketPermissionRequest::UDP_SEND_TO; | 307 operation_type = SocketPermissionRequest::UDP_SEND_TO; |
| 308 break; | 308 break; |
| 309 default: | 309 default: |
| 310 NOTREACHED() << "Unknown socket type."; | 310 NOTREACHED() << "Unknown socket type."; |
| 311 operation_type = SocketPermissionRequest::NONE; | 311 operation_type = SocketPermissionRequest::NONE; |
| 312 break; | 312 break; |
| 313 } | 313 } |
| 314 | 314 |
| 315 SocketPermission::CheckParam param(operation_type, hostname_, port_); | 315 SocketPermission::CheckParam param(operation_type, hostname_, port_); |
| 316 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( | 316 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( |
| 317 APIPermission::kSocket, ¶m)) { | 317 APIPermission::kSocket, ¶m)) { |
| 318 error_ = kPermissionError; | 318 error_ = kPermissionError; |
| 319 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 319 SetResult(base::MakeUnique<base::Value>(-1)); |
| 320 AsyncWorkCompleted(); | 320 AsyncWorkCompleted(); |
| 321 return; | 321 return; |
| 322 } | 322 } |
| 323 | 323 |
| 324 StartDnsLookup(net::HostPortPair(hostname_, port_)); | 324 StartDnsLookup(net::HostPortPair(hostname_, port_)); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void SocketConnectFunction::AfterDnsLookup(int lookup_result) { | 327 void SocketConnectFunction::AfterDnsLookup(int lookup_result) { |
| 328 if (lookup_result == net::OK) { | 328 if (lookup_result == net::OK) { |
| 329 StartConnect(); | 329 StartConnect(); |
| 330 } else { | 330 } else { |
| 331 SetResult(base::MakeUnique<base::FundamentalValue>(lookup_result)); | 331 SetResult(base::MakeUnique<base::Value>(lookup_result)); |
| 332 AsyncWorkCompleted(); | 332 AsyncWorkCompleted(); |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 | 335 |
| 336 void SocketConnectFunction::StartConnect() { | 336 void SocketConnectFunction::StartConnect() { |
| 337 Socket* socket = GetSocket(socket_id_); | 337 Socket* socket = GetSocket(socket_id_); |
| 338 if (!socket) { | 338 if (!socket) { |
| 339 error_ = kSocketNotFoundError; | 339 error_ = kSocketNotFoundError; |
| 340 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 340 SetResult(base::MakeUnique<base::Value>(-1)); |
| 341 AsyncWorkCompleted(); | 341 AsyncWorkCompleted(); |
| 342 return; | 342 return; |
| 343 } | 343 } |
| 344 | 344 |
| 345 socket->Connect(addresses_, | 345 socket->Connect(addresses_, |
| 346 base::Bind(&SocketConnectFunction::OnConnect, this)); | 346 base::Bind(&SocketConnectFunction::OnConnect, this)); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void SocketConnectFunction::OnConnect(int result) { | 349 void SocketConnectFunction::OnConnect(int result) { |
| 350 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 350 SetResult(base::MakeUnique<base::Value>(result)); |
| 351 AsyncWorkCompleted(); | 351 AsyncWorkCompleted(); |
| 352 } | 352 } |
| 353 | 353 |
| 354 bool SocketDisconnectFunction::Prepare() { | 354 bool SocketDisconnectFunction::Prepare() { |
| 355 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_)); | 355 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &socket_id_)); |
| 356 return true; | 356 return true; |
| 357 } | 357 } |
| 358 | 358 |
| 359 void SocketDisconnectFunction::Work() { | 359 void SocketDisconnectFunction::Work() { |
| 360 Socket* socket = GetSocket(socket_id_); | 360 Socket* socket = GetSocket(socket_id_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 375 return false; | 375 return false; |
| 376 } | 376 } |
| 377 port_ = static_cast<uint16_t>(port); | 377 port_ = static_cast<uint16_t>(port); |
| 378 return true; | 378 return true; |
| 379 } | 379 } |
| 380 | 380 |
| 381 void SocketBindFunction::AsyncWorkStart() { | 381 void SocketBindFunction::AsyncWorkStart() { |
| 382 Socket* socket = GetSocket(socket_id_); | 382 Socket* socket = GetSocket(socket_id_); |
| 383 if (!socket) { | 383 if (!socket) { |
| 384 error_ = kSocketNotFoundError; | 384 error_ = kSocketNotFoundError; |
| 385 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 385 SetResult(base::MakeUnique<base::Value>(-1)); |
| 386 AsyncWorkCompleted(); | 386 AsyncWorkCompleted(); |
| 387 return; | 387 return; |
| 388 } | 388 } |
| 389 | 389 |
| 390 if (socket->GetSocketType() == Socket::TYPE_TCP) { | 390 if (socket->GetSocketType() == Socket::TYPE_TCP) { |
| 391 error_ = kTCPSocketBindError; | 391 error_ = kTCPSocketBindError; |
| 392 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 392 SetResult(base::MakeUnique<base::Value>(-1)); |
| 393 AsyncWorkCompleted(); | 393 AsyncWorkCompleted(); |
| 394 return; | 394 return; |
| 395 } | 395 } |
| 396 | 396 |
| 397 CHECK(socket->GetSocketType() == Socket::TYPE_UDP); | 397 CHECK(socket->GetSocketType() == Socket::TYPE_UDP); |
| 398 SocketPermission::CheckParam param(SocketPermissionRequest::UDP_BIND, | 398 SocketPermission::CheckParam param(SocketPermissionRequest::UDP_BIND, |
| 399 address_, port_); | 399 address_, port_); |
| 400 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( | 400 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( |
| 401 APIPermission::kSocket, ¶m)) { | 401 APIPermission::kSocket, ¶m)) { |
| 402 error_ = kPermissionError; | 402 error_ = kPermissionError; |
| 403 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 403 SetResult(base::MakeUnique<base::Value>(-1)); |
| 404 AsyncWorkCompleted(); | 404 AsyncWorkCompleted(); |
| 405 return; | 405 return; |
| 406 } | 406 } |
| 407 | 407 |
| 408 int result = socket->Bind(address_, port_); | 408 int result = socket->Bind(address_, port_); |
| 409 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 409 SetResult(base::MakeUnique<base::Value>(result)); |
| 410 if (result != net::OK) { | 410 if (result != net::OK) { |
| 411 AsyncWorkCompleted(); | 411 AsyncWorkCompleted(); |
| 412 return; | 412 return; |
| 413 } | 413 } |
| 414 | 414 |
| 415 OpenFirewallHole(address_, socket_id_, socket); | 415 OpenFirewallHole(address_, socket_id_, socket); |
| 416 } | 416 } |
| 417 | 417 |
| 418 SocketListenFunction::SocketListenFunction() {} | 418 SocketListenFunction::SocketListenFunction() {} |
| 419 | 419 |
| 420 SocketListenFunction::~SocketListenFunction() {} | 420 SocketListenFunction::~SocketListenFunction() {} |
| 421 | 421 |
| 422 bool SocketListenFunction::Prepare() { | 422 bool SocketListenFunction::Prepare() { |
| 423 params_ = api::socket::Listen::Params::Create(*args_); | 423 params_ = api::socket::Listen::Params::Create(*args_); |
| 424 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 424 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 425 return true; | 425 return true; |
| 426 } | 426 } |
| 427 | 427 |
| 428 void SocketListenFunction::AsyncWorkStart() { | 428 void SocketListenFunction::AsyncWorkStart() { |
| 429 Socket* socket = GetSocket(params_->socket_id); | 429 Socket* socket = GetSocket(params_->socket_id); |
| 430 if (!socket) { | 430 if (!socket) { |
| 431 error_ = kSocketNotFoundError; | 431 error_ = kSocketNotFoundError; |
| 432 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 432 SetResult(base::MakeUnique<base::Value>(-1)); |
| 433 AsyncWorkCompleted(); | 433 AsyncWorkCompleted(); |
| 434 return; | 434 return; |
| 435 } | 435 } |
| 436 | 436 |
| 437 SocketPermission::CheckParam param(SocketPermissionRequest::TCP_LISTEN, | 437 SocketPermission::CheckParam param(SocketPermissionRequest::TCP_LISTEN, |
| 438 params_->address, params_->port); | 438 params_->address, params_->port); |
| 439 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( | 439 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( |
| 440 APIPermission::kSocket, ¶m)) { | 440 APIPermission::kSocket, ¶m)) { |
| 441 error_ = kPermissionError; | 441 error_ = kPermissionError; |
| 442 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 442 SetResult(base::MakeUnique<base::Value>(-1)); |
| 443 AsyncWorkCompleted(); | 443 AsyncWorkCompleted(); |
| 444 return; | 444 return; |
| 445 } | 445 } |
| 446 | 446 |
| 447 int result = | 447 int result = |
| 448 socket->Listen(params_->address, params_->port, | 448 socket->Listen(params_->address, params_->port, |
| 449 params_->backlog.get() ? *params_->backlog : 5, &error_); | 449 params_->backlog.get() ? *params_->backlog : 5, &error_); |
| 450 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 450 SetResult(base::MakeUnique<base::Value>(result)); |
| 451 if (result != net::OK) { | 451 if (result != net::OK) { |
| 452 AsyncWorkCompleted(); | 452 AsyncWorkCompleted(); |
| 453 return; | 453 return; |
| 454 } | 454 } |
| 455 | 455 |
| 456 OpenFirewallHole(params_->address, params_->socket_id, socket); | 456 OpenFirewallHole(params_->address, params_->socket_id, socket); |
| 457 } | 457 } |
| 458 | 458 |
| 459 SocketAcceptFunction::SocketAcceptFunction() {} | 459 SocketAcceptFunction::SocketAcceptFunction() {} |
| 460 | 460 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 | 631 |
| 632 io_buffer_size_ = data->GetSize(); | 632 io_buffer_size_ = data->GetSize(); |
| 633 io_buffer_ = new net::WrappedIOBuffer(data->GetBuffer()); | 633 io_buffer_ = new net::WrappedIOBuffer(data->GetBuffer()); |
| 634 return true; | 634 return true; |
| 635 } | 635 } |
| 636 | 636 |
| 637 void SocketSendToFunction::AsyncWorkStart() { | 637 void SocketSendToFunction::AsyncWorkStart() { |
| 638 Socket* socket = GetSocket(socket_id_); | 638 Socket* socket = GetSocket(socket_id_); |
| 639 if (!socket) { | 639 if (!socket) { |
| 640 error_ = kSocketNotFoundError; | 640 error_ = kSocketNotFoundError; |
| 641 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 641 SetResult(base::MakeUnique<base::Value>(-1)); |
| 642 AsyncWorkCompleted(); | 642 AsyncWorkCompleted(); |
| 643 return; | 643 return; |
| 644 } | 644 } |
| 645 | 645 |
| 646 if (socket->GetSocketType() == Socket::TYPE_UDP) { | 646 if (socket->GetSocketType() == Socket::TYPE_UDP) { |
| 647 SocketPermission::CheckParam param( | 647 SocketPermission::CheckParam param( |
| 648 SocketPermissionRequest::UDP_SEND_TO, hostname_, port_); | 648 SocketPermissionRequest::UDP_SEND_TO, hostname_, port_); |
| 649 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( | 649 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( |
| 650 APIPermission::kSocket, ¶m)) { | 650 APIPermission::kSocket, ¶m)) { |
| 651 error_ = kPermissionError; | 651 error_ = kPermissionError; |
| 652 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 652 SetResult(base::MakeUnique<base::Value>(-1)); |
| 653 AsyncWorkCompleted(); | 653 AsyncWorkCompleted(); |
| 654 return; | 654 return; |
| 655 } | 655 } |
| 656 } | 656 } |
| 657 | 657 |
| 658 StartDnsLookup(net::HostPortPair(hostname_, port_)); | 658 StartDnsLookup(net::HostPortPair(hostname_, port_)); |
| 659 } | 659 } |
| 660 | 660 |
| 661 void SocketSendToFunction::AfterDnsLookup(int lookup_result) { | 661 void SocketSendToFunction::AfterDnsLookup(int lookup_result) { |
| 662 if (lookup_result == net::OK) { | 662 if (lookup_result == net::OK) { |
| 663 StartSendTo(); | 663 StartSendTo(); |
| 664 } else { | 664 } else { |
| 665 SetResult(base::MakeUnique<base::FundamentalValue>(lookup_result)); | 665 SetResult(base::MakeUnique<base::Value>(lookup_result)); |
| 666 AsyncWorkCompleted(); | 666 AsyncWorkCompleted(); |
| 667 } | 667 } |
| 668 } | 668 } |
| 669 | 669 |
| 670 void SocketSendToFunction::StartSendTo() { | 670 void SocketSendToFunction::StartSendTo() { |
| 671 Socket* socket = GetSocket(socket_id_); | 671 Socket* socket = GetSocket(socket_id_); |
| 672 if (!socket) { | 672 if (!socket) { |
| 673 error_ = kSocketNotFoundError; | 673 error_ = kSocketNotFoundError; |
| 674 SetResult(base::MakeUnique<base::FundamentalValue>(-1)); | 674 SetResult(base::MakeUnique<base::Value>(-1)); |
| 675 AsyncWorkCompleted(); | 675 AsyncWorkCompleted(); |
| 676 return; | 676 return; |
| 677 } | 677 } |
| 678 | 678 |
| 679 socket->SendTo(io_buffer_, io_buffer_size_, addresses_.front(), | 679 socket->SendTo(io_buffer_, io_buffer_size_, addresses_.front(), |
| 680 base::Bind(&SocketSendToFunction::OnCompleted, this)); | 680 base::Bind(&SocketSendToFunction::OnCompleted, this)); |
| 681 } | 681 } |
| 682 | 682 |
| 683 void SocketSendToFunction::OnCompleted(int bytes_written) { | 683 void SocketSendToFunction::OnCompleted(int bytes_written) { |
| 684 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 684 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 702 bool result = false; | 702 bool result = false; |
| 703 Socket* socket = GetSocket(params_->socket_id); | 703 Socket* socket = GetSocket(params_->socket_id); |
| 704 if (socket) { | 704 if (socket) { |
| 705 int delay = 0; | 705 int delay = 0; |
| 706 if (params_->delay.get()) | 706 if (params_->delay.get()) |
| 707 delay = *params_->delay; | 707 delay = *params_->delay; |
| 708 result = socket->SetKeepAlive(params_->enable, delay); | 708 result = socket->SetKeepAlive(params_->enable, delay); |
| 709 } else { | 709 } else { |
| 710 error_ = kSocketNotFoundError; | 710 error_ = kSocketNotFoundError; |
| 711 } | 711 } |
| 712 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 712 SetResult(base::MakeUnique<base::Value>(result)); |
| 713 } | 713 } |
| 714 | 714 |
| 715 SocketSetNoDelayFunction::SocketSetNoDelayFunction() {} | 715 SocketSetNoDelayFunction::SocketSetNoDelayFunction() {} |
| 716 | 716 |
| 717 SocketSetNoDelayFunction::~SocketSetNoDelayFunction() {} | 717 SocketSetNoDelayFunction::~SocketSetNoDelayFunction() {} |
| 718 | 718 |
| 719 bool SocketSetNoDelayFunction::Prepare() { | 719 bool SocketSetNoDelayFunction::Prepare() { |
| 720 params_ = api::socket::SetNoDelay::Params::Create(*args_); | 720 params_ = api::socket::SetNoDelay::Params::Create(*args_); |
| 721 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 721 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 722 return true; | 722 return true; |
| 723 } | 723 } |
| 724 | 724 |
| 725 void SocketSetNoDelayFunction::Work() { | 725 void SocketSetNoDelayFunction::Work() { |
| 726 bool result = false; | 726 bool result = false; |
| 727 Socket* socket = GetSocket(params_->socket_id); | 727 Socket* socket = GetSocket(params_->socket_id); |
| 728 if (socket) | 728 if (socket) |
| 729 result = socket->SetNoDelay(params_->no_delay); | 729 result = socket->SetNoDelay(params_->no_delay); |
| 730 else | 730 else |
| 731 error_ = kSocketNotFoundError; | 731 error_ = kSocketNotFoundError; |
| 732 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 732 SetResult(base::MakeUnique<base::Value>(result)); |
| 733 } | 733 } |
| 734 | 734 |
| 735 SocketGetInfoFunction::SocketGetInfoFunction() {} | 735 SocketGetInfoFunction::SocketGetInfoFunction() {} |
| 736 | 736 |
| 737 SocketGetInfoFunction::~SocketGetInfoFunction() {} | 737 SocketGetInfoFunction::~SocketGetInfoFunction() {} |
| 738 | 738 |
| 739 bool SocketGetInfoFunction::Prepare() { | 739 bool SocketGetInfoFunction::Prepare() { |
| 740 params_ = api::socket::GetInfo::Params::Create(*args_); | 740 params_ = api::socket::GetInfo::Params::Create(*args_); |
| 741 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 741 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 742 return true; | 742 return true; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 params_ = api::socket::JoinGroup::Params::Create(*args_); | 836 params_ = api::socket::JoinGroup::Params::Create(*args_); |
| 837 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 837 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 838 return true; | 838 return true; |
| 839 } | 839 } |
| 840 | 840 |
| 841 void SocketJoinGroupFunction::Work() { | 841 void SocketJoinGroupFunction::Work() { |
| 842 int result = -1; | 842 int result = -1; |
| 843 Socket* socket = GetSocket(params_->socket_id); | 843 Socket* socket = GetSocket(params_->socket_id); |
| 844 if (!socket) { | 844 if (!socket) { |
| 845 error_ = kSocketNotFoundError; | 845 error_ = kSocketNotFoundError; |
| 846 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 846 SetResult(base::MakeUnique<base::Value>(result)); |
| 847 return; | 847 return; |
| 848 } | 848 } |
| 849 | 849 |
| 850 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 850 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
| 851 error_ = kMulticastSocketTypeError; | 851 error_ = kMulticastSocketTypeError; |
| 852 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 852 SetResult(base::MakeUnique<base::Value>(result)); |
| 853 return; | 853 return; |
| 854 } | 854 } |
| 855 | 855 |
| 856 SocketPermission::CheckParam param( | 856 SocketPermission::CheckParam param( |
| 857 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, | 857 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, |
| 858 kWildcardAddress, | 858 kWildcardAddress, |
| 859 kWildcardPort); | 859 kWildcardPort); |
| 860 | 860 |
| 861 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( | 861 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( |
| 862 APIPermission::kSocket, ¶m)) { | 862 APIPermission::kSocket, ¶m)) { |
| 863 error_ = kPermissionError; | 863 error_ = kPermissionError; |
| 864 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 864 SetResult(base::MakeUnique<base::Value>(result)); |
| 865 return; | 865 return; |
| 866 } | 866 } |
| 867 | 867 |
| 868 result = static_cast<UDPSocket*>(socket)->JoinGroup(params_->address); | 868 result = static_cast<UDPSocket*>(socket)->JoinGroup(params_->address); |
| 869 if (result != 0) { | 869 if (result != 0) { |
| 870 error_ = net::ErrorToString(result); | 870 error_ = net::ErrorToString(result); |
| 871 } | 871 } |
| 872 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 872 SetResult(base::MakeUnique<base::Value>(result)); |
| 873 } | 873 } |
| 874 | 874 |
| 875 SocketLeaveGroupFunction::SocketLeaveGroupFunction() {} | 875 SocketLeaveGroupFunction::SocketLeaveGroupFunction() {} |
| 876 | 876 |
| 877 SocketLeaveGroupFunction::~SocketLeaveGroupFunction() {} | 877 SocketLeaveGroupFunction::~SocketLeaveGroupFunction() {} |
| 878 | 878 |
| 879 bool SocketLeaveGroupFunction::Prepare() { | 879 bool SocketLeaveGroupFunction::Prepare() { |
| 880 params_ = api::socket::LeaveGroup::Params::Create(*args_); | 880 params_ = api::socket::LeaveGroup::Params::Create(*args_); |
| 881 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 881 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 882 return true; | 882 return true; |
| 883 } | 883 } |
| 884 | 884 |
| 885 void SocketLeaveGroupFunction::Work() { | 885 void SocketLeaveGroupFunction::Work() { |
| 886 int result = -1; | 886 int result = -1; |
| 887 Socket* socket = GetSocket(params_->socket_id); | 887 Socket* socket = GetSocket(params_->socket_id); |
| 888 | 888 |
| 889 if (!socket) { | 889 if (!socket) { |
| 890 error_ = kSocketNotFoundError; | 890 error_ = kSocketNotFoundError; |
| 891 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 891 SetResult(base::MakeUnique<base::Value>(result)); |
| 892 return; | 892 return; |
| 893 } | 893 } |
| 894 | 894 |
| 895 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 895 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
| 896 error_ = kMulticastSocketTypeError; | 896 error_ = kMulticastSocketTypeError; |
| 897 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 897 SetResult(base::MakeUnique<base::Value>(result)); |
| 898 return; | 898 return; |
| 899 } | 899 } |
| 900 | 900 |
| 901 SocketPermission::CheckParam param( | 901 SocketPermission::CheckParam param( |
| 902 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, | 902 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, |
| 903 kWildcardAddress, | 903 kWildcardAddress, |
| 904 kWildcardPort); | 904 kWildcardPort); |
| 905 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( | 905 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( |
| 906 APIPermission::kSocket, ¶m)) { | 906 APIPermission::kSocket, ¶m)) { |
| 907 error_ = kPermissionError; | 907 error_ = kPermissionError; |
| 908 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 908 SetResult(base::MakeUnique<base::Value>(result)); |
| 909 return; | 909 return; |
| 910 } | 910 } |
| 911 | 911 |
| 912 result = static_cast<UDPSocket*>(socket)->LeaveGroup(params_->address); | 912 result = static_cast<UDPSocket*>(socket)->LeaveGroup(params_->address); |
| 913 if (result != 0) | 913 if (result != 0) |
| 914 error_ = net::ErrorToString(result); | 914 error_ = net::ErrorToString(result); |
| 915 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 915 SetResult(base::MakeUnique<base::Value>(result)); |
| 916 } | 916 } |
| 917 | 917 |
| 918 SocketSetMulticastTimeToLiveFunction::SocketSetMulticastTimeToLiveFunction() {} | 918 SocketSetMulticastTimeToLiveFunction::SocketSetMulticastTimeToLiveFunction() {} |
| 919 | 919 |
| 920 SocketSetMulticastTimeToLiveFunction::~SocketSetMulticastTimeToLiveFunction() {} | 920 SocketSetMulticastTimeToLiveFunction::~SocketSetMulticastTimeToLiveFunction() {} |
| 921 | 921 |
| 922 bool SocketSetMulticastTimeToLiveFunction::Prepare() { | 922 bool SocketSetMulticastTimeToLiveFunction::Prepare() { |
| 923 params_ = api::socket::SetMulticastTimeToLive::Params::Create(*args_); | 923 params_ = api::socket::SetMulticastTimeToLive::Params::Create(*args_); |
| 924 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 924 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 925 return true; | 925 return true; |
| 926 } | 926 } |
| 927 void SocketSetMulticastTimeToLiveFunction::Work() { | 927 void SocketSetMulticastTimeToLiveFunction::Work() { |
| 928 int result = -1; | 928 int result = -1; |
| 929 Socket* socket = GetSocket(params_->socket_id); | 929 Socket* socket = GetSocket(params_->socket_id); |
| 930 if (!socket) { | 930 if (!socket) { |
| 931 error_ = kSocketNotFoundError; | 931 error_ = kSocketNotFoundError; |
| 932 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 932 SetResult(base::MakeUnique<base::Value>(result)); |
| 933 return; | 933 return; |
| 934 } | 934 } |
| 935 | 935 |
| 936 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 936 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
| 937 error_ = kMulticastSocketTypeError; | 937 error_ = kMulticastSocketTypeError; |
| 938 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 938 SetResult(base::MakeUnique<base::Value>(result)); |
| 939 return; | 939 return; |
| 940 } | 940 } |
| 941 | 941 |
| 942 result = | 942 result = |
| 943 static_cast<UDPSocket*>(socket)->SetMulticastTimeToLive(params_->ttl); | 943 static_cast<UDPSocket*>(socket)->SetMulticastTimeToLive(params_->ttl); |
| 944 if (result != 0) | 944 if (result != 0) |
| 945 error_ = net::ErrorToString(result); | 945 error_ = net::ErrorToString(result); |
| 946 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 946 SetResult(base::MakeUnique<base::Value>(result)); |
| 947 } | 947 } |
| 948 | 948 |
| 949 SocketSetMulticastLoopbackModeFunction:: | 949 SocketSetMulticastLoopbackModeFunction:: |
| 950 SocketSetMulticastLoopbackModeFunction() {} | 950 SocketSetMulticastLoopbackModeFunction() {} |
| 951 | 951 |
| 952 SocketSetMulticastLoopbackModeFunction:: | 952 SocketSetMulticastLoopbackModeFunction:: |
| 953 ~SocketSetMulticastLoopbackModeFunction() {} | 953 ~SocketSetMulticastLoopbackModeFunction() {} |
| 954 | 954 |
| 955 bool SocketSetMulticastLoopbackModeFunction::Prepare() { | 955 bool SocketSetMulticastLoopbackModeFunction::Prepare() { |
| 956 params_ = api::socket::SetMulticastLoopbackMode::Params::Create(*args_); | 956 params_ = api::socket::SetMulticastLoopbackMode::Params::Create(*args_); |
| 957 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 957 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 958 return true; | 958 return true; |
| 959 } | 959 } |
| 960 | 960 |
| 961 void SocketSetMulticastLoopbackModeFunction::Work() { | 961 void SocketSetMulticastLoopbackModeFunction::Work() { |
| 962 int result = -1; | 962 int result = -1; |
| 963 Socket* socket = GetSocket(params_->socket_id); | 963 Socket* socket = GetSocket(params_->socket_id); |
| 964 if (!socket) { | 964 if (!socket) { |
| 965 error_ = kSocketNotFoundError; | 965 error_ = kSocketNotFoundError; |
| 966 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 966 SetResult(base::MakeUnique<base::Value>(result)); |
| 967 return; | 967 return; |
| 968 } | 968 } |
| 969 | 969 |
| 970 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 970 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
| 971 error_ = kMulticastSocketTypeError; | 971 error_ = kMulticastSocketTypeError; |
| 972 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 972 SetResult(base::MakeUnique<base::Value>(result)); |
| 973 return; | 973 return; |
| 974 } | 974 } |
| 975 | 975 |
| 976 result = static_cast<UDPSocket*>(socket) | 976 result = static_cast<UDPSocket*>(socket) |
| 977 ->SetMulticastLoopbackMode(params_->enabled); | 977 ->SetMulticastLoopbackMode(params_->enabled); |
| 978 if (result != 0) | 978 if (result != 0) |
| 979 error_ = net::ErrorToString(result); | 979 error_ = net::ErrorToString(result); |
| 980 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 980 SetResult(base::MakeUnique<base::Value>(result)); |
| 981 } | 981 } |
| 982 | 982 |
| 983 SocketGetJoinedGroupsFunction::SocketGetJoinedGroupsFunction() {} | 983 SocketGetJoinedGroupsFunction::SocketGetJoinedGroupsFunction() {} |
| 984 | 984 |
| 985 SocketGetJoinedGroupsFunction::~SocketGetJoinedGroupsFunction() {} | 985 SocketGetJoinedGroupsFunction::~SocketGetJoinedGroupsFunction() {} |
| 986 | 986 |
| 987 bool SocketGetJoinedGroupsFunction::Prepare() { | 987 bool SocketGetJoinedGroupsFunction::Prepare() { |
| 988 params_ = api::socket::GetJoinedGroups::Params::Create(*args_); | 988 params_ = api::socket::GetJoinedGroups::Params::Create(*args_); |
| 989 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 989 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 990 return true; | 990 return true; |
| 991 } | 991 } |
| 992 | 992 |
| 993 void SocketGetJoinedGroupsFunction::Work() { | 993 void SocketGetJoinedGroupsFunction::Work() { |
| 994 int result = -1; | 994 int result = -1; |
| 995 Socket* socket = GetSocket(params_->socket_id); | 995 Socket* socket = GetSocket(params_->socket_id); |
| 996 if (!socket) { | 996 if (!socket) { |
| 997 error_ = kSocketNotFoundError; | 997 error_ = kSocketNotFoundError; |
| 998 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 998 SetResult(base::MakeUnique<base::Value>(result)); |
| 999 return; | 999 return; |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 1002 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
| 1003 error_ = kMulticastSocketTypeError; | 1003 error_ = kMulticastSocketTypeError; |
| 1004 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 1004 SetResult(base::MakeUnique<base::Value>(result)); |
| 1005 return; | 1005 return; |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 SocketPermission::CheckParam param( | 1008 SocketPermission::CheckParam param( |
| 1009 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, | 1009 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, |
| 1010 kWildcardAddress, | 1010 kWildcardAddress, |
| 1011 kWildcardPort); | 1011 kWildcardPort); |
| 1012 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( | 1012 if (!extension()->permissions_data()->CheckAPIPermissionWithParam( |
| 1013 APIPermission::kSocket, ¶m)) { | 1013 APIPermission::kSocket, ¶m)) { |
| 1014 error_ = kPermissionError; | 1014 error_ = kPermissionError; |
| 1015 SetResult(base::MakeUnique<base::FundamentalValue>(result)); | 1015 SetResult(base::MakeUnique<base::Value>(result)); |
| 1016 return; | 1016 return; |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 std::unique_ptr<base::ListValue> values(new base::ListValue()); | 1019 std::unique_ptr<base::ListValue> values(new base::ListValue()); |
| 1020 values->AppendStrings((std::vector<std::string>&)static_cast<UDPSocket*>( | 1020 values->AppendStrings((std::vector<std::string>&)static_cast<UDPSocket*>( |
| 1021 socket)->GetJoinedGroups()); | 1021 socket)->GetJoinedGroups()); |
| 1022 SetResult(std::move(values)); | 1022 SetResult(std::move(values)); |
| 1023 } | 1023 } |
| 1024 | 1024 |
| 1025 SocketSecureFunction::SocketSecureFunction() { | 1025 SocketSecureFunction::SocketSecureFunction() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1037 return true; | 1037 return true; |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 // Override the regular implementation, which would call AsyncWorkCompleted | 1040 // Override the regular implementation, which would call AsyncWorkCompleted |
| 1041 // immediately after Work(). | 1041 // immediately after Work(). |
| 1042 void SocketSecureFunction::AsyncWorkStart() { | 1042 void SocketSecureFunction::AsyncWorkStart() { |
| 1043 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1043 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1044 | 1044 |
| 1045 Socket* socket = GetSocket(params_->socket_id); | 1045 Socket* socket = GetSocket(params_->socket_id); |
| 1046 if (!socket) { | 1046 if (!socket) { |
| 1047 SetResult( | 1047 SetResult(base::MakeUnique<base::Value>(net::ERR_INVALID_ARGUMENT)); |
| 1048 base::MakeUnique<base::FundamentalValue>(net::ERR_INVALID_ARGUMENT)); | |
| 1049 error_ = kSocketNotFoundError; | 1048 error_ = kSocketNotFoundError; |
| 1050 AsyncWorkCompleted(); | 1049 AsyncWorkCompleted(); |
| 1051 return; | 1050 return; |
| 1052 } | 1051 } |
| 1053 | 1052 |
| 1054 // Make sure that the socket is a TCP client socket. | 1053 // Make sure that the socket is a TCP client socket. |
| 1055 if (socket->GetSocketType() != Socket::TYPE_TCP || | 1054 if (socket->GetSocketType() != Socket::TYPE_TCP || |
| 1056 static_cast<TCPSocket*>(socket)->ClientStream() == NULL) { | 1055 static_cast<TCPSocket*>(socket)->ClientStream() == NULL) { |
| 1057 SetResult( | 1056 SetResult(base::MakeUnique<base::Value>(net::ERR_INVALID_ARGUMENT)); |
| 1058 base::MakeUnique<base::FundamentalValue>(net::ERR_INVALID_ARGUMENT)); | |
| 1059 error_ = kSecureSocketTypeError; | 1057 error_ = kSecureSocketTypeError; |
| 1060 AsyncWorkCompleted(); | 1058 AsyncWorkCompleted(); |
| 1061 return; | 1059 return; |
| 1062 } | 1060 } |
| 1063 | 1061 |
| 1064 if (!socket->IsConnected()) { | 1062 if (!socket->IsConnected()) { |
| 1065 SetResult( | 1063 SetResult(base::MakeUnique<base::Value>(net::ERR_INVALID_ARGUMENT)); |
| 1066 base::MakeUnique<base::FundamentalValue>(net::ERR_INVALID_ARGUMENT)); | |
| 1067 error_ = kSocketNotConnectedError; | 1064 error_ = kSocketNotConnectedError; |
| 1068 AsyncWorkCompleted(); | 1065 AsyncWorkCompleted(); |
| 1069 return; | 1066 return; |
| 1070 } | 1067 } |
| 1071 | 1068 |
| 1072 net::URLRequestContext* url_request_context = | 1069 net::URLRequestContext* url_request_context = |
| 1073 url_request_getter_->GetURLRequestContext(); | 1070 url_request_getter_->GetURLRequestContext(); |
| 1074 | 1071 |
| 1075 TLSSocket::UpgradeSocketToTLS( | 1072 TLSSocket::UpgradeSocketToTLS( |
| 1076 socket, url_request_context->ssl_config_service(), | 1073 socket, url_request_context->ssl_config_service(), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1092 } else { | 1089 } else { |
| 1093 RemoveSocket(params_->socket_id); | 1090 RemoveSocket(params_->socket_id); |
| 1094 error_ = net::ErrorToString(result); | 1091 error_ = net::ErrorToString(result); |
| 1095 } | 1092 } |
| 1096 | 1093 |
| 1097 results_ = api::socket::Secure::Results::Create(result); | 1094 results_ = api::socket::Secure::Results::Create(result); |
| 1098 AsyncWorkCompleted(); | 1095 AsyncWorkCompleted(); |
| 1099 } | 1096 } |
| 1100 | 1097 |
| 1101 } // namespace extensions | 1098 } // namespace extensions |
| OLD | NEW |