| 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/sockets_tcp/sockets_tcp_api.h" | 5 #include "extensions/browser/api/sockets_tcp/sockets_tcp_api.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 7 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
| 8 #include "content/public/browser/storage_partition.h" | 9 #include "content/public/browser/storage_partition.h" |
| 9 #include "content/public/common/socket_permission_request.h" | 10 #include "content/public/common/socket_permission_request.h" |
| 10 #include "extensions/browser/api/socket/tcp_socket.h" | 11 #include "extensions/browser/api/socket/tcp_socket.h" |
| 11 #include "extensions/browser/api/socket/tls_socket.h" | 12 #include "extensions/browser/api/socket/tls_socket.h" |
| 12 #include "extensions/browser/api/sockets_tcp/tcp_socket_event_dispatcher.h" | 13 #include "extensions/browser/api/sockets_tcp/tcp_socket_event_dispatcher.h" |
| 13 #include "extensions/common/api/sockets/sockets_manifest_data.h" | 14 #include "extensions/common/api/sockets/sockets_manifest_data.h" |
| 14 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 15 #include "net/url_request/url_request_context.h" | 16 #include "net/url_request/url_request_context.h" |
| 16 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 return true; | 462 return true; |
| 462 } | 463 } |
| 463 | 464 |
| 464 // Override the regular implementation, which would call AsyncWorkCompleted | 465 // Override the regular implementation, which would call AsyncWorkCompleted |
| 465 // immediately after Work(). | 466 // immediately after Work(). |
| 466 void SocketsTcpSecureFunction::AsyncWorkStart() { | 467 void SocketsTcpSecureFunction::AsyncWorkStart() { |
| 467 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 468 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 468 | 469 |
| 469 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 470 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
| 470 if (!socket) { | 471 if (!socket) { |
| 471 SetResult(new base::FundamentalValue(net::ERR_INVALID_ARGUMENT)); | 472 SetResult( |
| 473 base::MakeUnique<base::FundamentalValue>(net::ERR_INVALID_ARGUMENT)); |
| 472 error_ = kSocketNotFoundError; | 474 error_ = kSocketNotFoundError; |
| 473 AsyncWorkCompleted(); | 475 AsyncWorkCompleted(); |
| 474 return; | 476 return; |
| 475 } | 477 } |
| 476 | 478 |
| 477 paused_ = socket->paused(); | 479 paused_ = socket->paused(); |
| 478 persistent_ = socket->persistent(); | 480 persistent_ = socket->persistent(); |
| 479 | 481 |
| 480 // Make sure it's a connected TCP client socket. Error out if it's already | 482 // Make sure it's a connected TCP client socket. Error out if it's already |
| 481 // secure()'d. | 483 // secure()'d. |
| 482 if (socket->GetSocketType() != Socket::TYPE_TCP || | 484 if (socket->GetSocketType() != Socket::TYPE_TCP || |
| 483 socket->ClientStream() == NULL) { | 485 socket->ClientStream() == NULL) { |
| 484 SetResult(new base::FundamentalValue(net::ERR_INVALID_ARGUMENT)); | 486 SetResult( |
| 487 base::MakeUnique<base::FundamentalValue>(net::ERR_INVALID_ARGUMENT)); |
| 485 error_ = kInvalidSocketStateError; | 488 error_ = kInvalidSocketStateError; |
| 486 AsyncWorkCompleted(); | 489 AsyncWorkCompleted(); |
| 487 return; | 490 return; |
| 488 } | 491 } |
| 489 | 492 |
| 490 if (!socket->IsConnected()) { | 493 if (!socket->IsConnected()) { |
| 491 SetResult(new base::FundamentalValue(net::ERR_INVALID_ARGUMENT)); | 494 SetResult( |
| 495 base::MakeUnique<base::FundamentalValue>(net::ERR_INVALID_ARGUMENT)); |
| 492 error_ = kSocketNotConnectedError; | 496 error_ = kSocketNotConnectedError; |
| 493 AsyncWorkCompleted(); | 497 AsyncWorkCompleted(); |
| 494 return; | 498 return; |
| 495 } | 499 } |
| 496 | 500 |
| 497 net::URLRequestContext* url_request_context = | 501 net::URLRequestContext* url_request_context = |
| 498 url_request_getter_->GetURLRequestContext(); | 502 url_request_getter_->GetURLRequestContext(); |
| 499 | 503 |
| 500 // UpgradeSocketToTLS() uses the older API's SecureOptions. Copy over the | 504 // UpgradeSocketToTLS() uses the older API's SecureOptions. Copy over the |
| 501 // only values inside -- TLSVersionConstraints's |min| and |max|, | 505 // only values inside -- TLSVersionConstraints's |min| and |max|, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 RemoveSocket(params_->socket_id); | 539 RemoveSocket(params_->socket_id); |
| 536 error_ = net::ErrorToString(result); | 540 error_ = net::ErrorToString(result); |
| 537 } | 541 } |
| 538 | 542 |
| 539 results_ = api::sockets_tcp::Secure::Results::Create(result); | 543 results_ = api::sockets_tcp::Secure::Results::Create(result); |
| 540 AsyncWorkCompleted(); | 544 AsyncWorkCompleted(); |
| 541 } | 545 } |
| 542 | 546 |
| 543 } // namespace api | 547 } // namespace api |
| 544 } // namespace extensions | 548 } // namespace extensions |
| OLD | NEW |