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 "base/memory/ptr_util.h" |
8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
9 #include "content/public/browser/storage_partition.h" | 9 #include "content/public/browser/storage_partition.h" |
10 #include "content/public/common/socket_permission_request.h" | 10 #include "content/public/common/socket_permission_request.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 new std::string(peerAddress.ToStringWithoutPort())); | 61 new std::string(peerAddress.ToStringWithoutPort())); |
62 socket_info.peer_port.reset(new int(peerAddress.port())); | 62 socket_info.peer_port.reset(new int(peerAddress.port())); |
63 } | 63 } |
64 | 64 |
65 return socket_info; | 65 return socket_info; |
66 } | 66 } |
67 | 67 |
68 void SetSocketProperties(ResumableTCPSocket* socket, | 68 void SetSocketProperties(ResumableTCPSocket* socket, |
69 SocketProperties* properties) { | 69 SocketProperties* properties) { |
70 if (properties->name.get()) { | 70 if (properties->name.get()) { |
71 socket->set_name(*properties->name.get()); | 71 socket->set_name(*properties->name); |
72 } | 72 } |
73 if (properties->persistent.get()) { | 73 if (properties->persistent.get()) { |
74 socket->set_persistent(*properties->persistent.get()); | 74 socket->set_persistent(*properties->persistent); |
75 } | 75 } |
76 if (properties->buffer_size.get()) { | 76 if (properties->buffer_size.get()) { |
77 // buffer size is validated when issuing the actual Recv operation | 77 // buffer size is validated when issuing the actual Recv operation |
78 // on the socket. | 78 // on the socket. |
79 socket->set_buffer_size(*properties->buffer_size.get()); | 79 socket->set_buffer_size(*properties->buffer_size); |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 } // namespace | 83 } // namespace |
84 | 84 |
85 namespace extensions { | 85 namespace extensions { |
86 namespace api { | 86 namespace api { |
87 | 87 |
88 using content::SocketPermissionRequest; | 88 using content::SocketPermissionRequest; |
89 | 89 |
(...skipping 29 matching lines...) Expand all Loading... |
119 | 119 |
120 bool SocketsTcpCreateFunction::Prepare() { | 120 bool SocketsTcpCreateFunction::Prepare() { |
121 params_ = sockets_tcp::Create::Params::Create(*args_); | 121 params_ = sockets_tcp::Create::Params::Create(*args_); |
122 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 122 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
123 return true; | 123 return true; |
124 } | 124 } |
125 | 125 |
126 void SocketsTcpCreateFunction::Work() { | 126 void SocketsTcpCreateFunction::Work() { |
127 ResumableTCPSocket* socket = new ResumableTCPSocket(extension_->id()); | 127 ResumableTCPSocket* socket = new ResumableTCPSocket(extension_->id()); |
128 | 128 |
129 sockets_tcp::SocketProperties* properties = params_.get()->properties.get(); | 129 sockets_tcp::SocketProperties* properties = params_->properties.get(); |
130 if (properties) { | 130 if (properties) { |
131 SetSocketProperties(socket, properties); | 131 SetSocketProperties(socket, properties); |
132 } | 132 } |
133 | 133 |
134 sockets_tcp::CreateInfo create_info; | 134 sockets_tcp::CreateInfo create_info; |
135 create_info.socket_id = AddSocket(socket); | 135 create_info.socket_id = AddSocket(socket); |
136 results_ = sockets_tcp::Create::Results::Create(create_info); | 136 results_ = sockets_tcp::Create::Results::Create(create_info); |
137 } | 137 } |
138 | 138 |
139 SocketsTcpUpdateFunction::SocketsTcpUpdateFunction() {} | 139 SocketsTcpUpdateFunction::SocketsTcpUpdateFunction() {} |
140 | 140 |
141 SocketsTcpUpdateFunction::~SocketsTcpUpdateFunction() {} | 141 SocketsTcpUpdateFunction::~SocketsTcpUpdateFunction() {} |
142 | 142 |
143 bool SocketsTcpUpdateFunction::Prepare() { | 143 bool SocketsTcpUpdateFunction::Prepare() { |
144 params_ = sockets_tcp::Update::Params::Create(*args_); | 144 params_ = sockets_tcp::Update::Params::Create(*args_); |
145 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 145 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
146 return true; | 146 return true; |
147 } | 147 } |
148 | 148 |
149 void SocketsTcpUpdateFunction::Work() { | 149 void SocketsTcpUpdateFunction::Work() { |
150 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 150 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
151 if (!socket) { | 151 if (!socket) { |
152 error_ = kSocketNotFoundError; | 152 error_ = kSocketNotFoundError; |
153 return; | 153 return; |
154 } | 154 } |
155 | 155 |
156 SetSocketProperties(socket, ¶ms_.get()->properties); | 156 SetSocketProperties(socket, ¶ms_->properties); |
157 results_ = sockets_tcp::Update::Results::Create(); | 157 results_ = sockets_tcp::Update::Results::Create(); |
158 } | 158 } |
159 | 159 |
160 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction() | 160 SocketsTcpSetPausedFunction::SocketsTcpSetPausedFunction() |
161 : socket_event_dispatcher_(NULL) {} | 161 : socket_event_dispatcher_(NULL) {} |
162 | 162 |
163 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {} | 163 SocketsTcpSetPausedFunction::~SocketsTcpSetPausedFunction() {} |
164 | 164 |
165 bool SocketsTcpSetPausedFunction::Prepare() { | 165 bool SocketsTcpSetPausedFunction::Prepare() { |
166 params_ = api::sockets_tcp::SetPaused::Params::Create(*args_); | 166 params_ = api::sockets_tcp::SetPaused::Params::Create(*args_); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 return true; | 203 return true; |
204 } | 204 } |
205 | 205 |
206 void SocketsTcpSetKeepAliveFunction::Work() { | 206 void SocketsTcpSetKeepAliveFunction::Work() { |
207 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); | 207 ResumableTCPSocket* socket = GetTcpSocket(params_->socket_id); |
208 if (!socket) { | 208 if (!socket) { |
209 error_ = kSocketNotFoundError; | 209 error_ = kSocketNotFoundError; |
210 return; | 210 return; |
211 } | 211 } |
212 | 212 |
213 int delay = params_->delay ? *params_->delay.get() : 0; | 213 int delay = params_->delay ? *params_->delay : 0; |
214 | 214 |
215 bool success = socket->SetKeepAlive(params_->enable, delay); | 215 bool success = socket->SetKeepAlive(params_->enable, delay); |
216 int net_result = (success ? net::OK : net::ERR_FAILED); | 216 int net_result = (success ? net::OK : net::ERR_FAILED); |
217 if (net_result != net::OK) | 217 if (net_result != net::OK) |
218 error_ = net::ErrorToString(net_result); | 218 error_ = net::ErrorToString(net_result); |
219 results_ = sockets_tcp::SetKeepAlive::Results::Create(net_result); | 219 results_ = sockets_tcp::SetKeepAlive::Results::Create(net_result); |
220 } | 220 } |
221 | 221 |
222 SocketsTcpSetNoDelayFunction::SocketsTcpSetNoDelayFunction() {} | 222 SocketsTcpSetNoDelayFunction::SocketsTcpSetNoDelayFunction() {} |
223 | 223 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 net::URLRequestContext* url_request_context = | 501 net::URLRequestContext* url_request_context = |
502 url_request_getter_->GetURLRequestContext(); | 502 url_request_getter_->GetURLRequestContext(); |
503 | 503 |
504 // UpgradeSocketToTLS() uses the older API's SecureOptions. Copy over the | 504 // UpgradeSocketToTLS() uses the older API's SecureOptions. Copy over the |
505 // only values inside -- TLSVersionConstraints's |min| and |max|, | 505 // only values inside -- TLSVersionConstraints's |min| and |max|, |
506 api::socket::SecureOptions legacy_params; | 506 api::socket::SecureOptions legacy_params; |
507 if (params_->options.get() && params_->options->tls_version.get()) { | 507 if (params_->options.get() && params_->options->tls_version.get()) { |
508 legacy_params.tls_version.reset(new api::socket::TLSVersionConstraints); | 508 legacy_params.tls_version.reset(new api::socket::TLSVersionConstraints); |
509 if (params_->options->tls_version->min.get()) { | 509 if (params_->options->tls_version->min.get()) { |
510 legacy_params.tls_version->min.reset( | 510 legacy_params.tls_version->min.reset( |
511 new std::string(*params_->options->tls_version->min.get())); | 511 new std::string(*params_->options->tls_version->min)); |
512 } | 512 } |
513 if (params_->options->tls_version->max.get()) { | 513 if (params_->options->tls_version->max.get()) { |
514 legacy_params.tls_version->max.reset( | 514 legacy_params.tls_version->max.reset( |
515 new std::string(*params_->options->tls_version->max.get())); | 515 new std::string(*params_->options->tls_version->max)); |
516 } | 516 } |
517 } | 517 } |
518 | 518 |
519 TLSSocket::UpgradeSocketToTLS( | 519 TLSSocket::UpgradeSocketToTLS( |
520 socket, url_request_context->ssl_config_service(), | 520 socket, url_request_context->ssl_config_service(), |
521 url_request_context->cert_verifier(), | 521 url_request_context->cert_verifier(), |
522 url_request_context->transport_security_state(), | 522 url_request_context->transport_security_state(), |
523 url_request_context->cert_transparency_verifier(), | 523 url_request_context->cert_transparency_verifier(), |
524 url_request_context->ct_policy_enforcer(), extension_id(), &legacy_params, | 524 url_request_context->ct_policy_enforcer(), extension_id(), &legacy_params, |
525 base::Bind(&SocketsTcpSecureFunction::TlsConnectDone, this)); | 525 base::Bind(&SocketsTcpSecureFunction::TlsConnectDone, this)); |
(...skipping 12 matching lines...) Expand all Loading... |
538 RemoveSocket(params_->socket_id); | 538 RemoveSocket(params_->socket_id); |
539 error_ = net::ErrorToString(result); | 539 error_ = net::ErrorToString(result); |
540 } | 540 } |
541 | 541 |
542 results_ = api::sockets_tcp::Secure::Results::Create(result); | 542 results_ = api::sockets_tcp::Secure::Results::Create(result); |
543 AsyncWorkCompleted(); | 543 AsyncWorkCompleted(); |
544 } | 544 } |
545 | 545 |
546 } // namespace api | 546 } // namespace api |
547 } // namespace extensions | 547 } // namespace extensions |
OLD | NEW |