Chromium Code Reviews| 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 <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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 case Socket::TYPE_UDP: | 203 case Socket::TYPE_UDP: |
| 204 operation_type = SocketPermissionRequest::UDP_SEND_TO; | 204 operation_type = SocketPermissionRequest::UDP_SEND_TO; |
| 205 break; | 205 break; |
| 206 default: | 206 default: |
| 207 NOTREACHED() << "Unknown socket type."; | 207 NOTREACHED() << "Unknown socket type."; |
| 208 operation_type = SocketPermissionRequest::NONE; | 208 operation_type = SocketPermissionRequest::NONE; |
| 209 break; | 209 break; |
| 210 } | 210 } |
| 211 | 211 |
| 212 SocketPermission::CheckParam param(operation_type, hostname_, port_); | 212 SocketPermission::CheckParam param(operation_type, hostname_, port_); |
| 213 if (!PermissionsData::CheckAPIPermissionWithParam( | 213 if (!PermissionsData::ForExtension(GetExtension()) |
| 214 GetExtension(), APIPermission::kSocket, ¶m)) { | 214 ->CheckAPIPermissionWithParam(APIPermission::kSocket, ¶m)) { |
| 215 error_ = kPermissionError; | 215 error_ = kPermissionError; |
| 216 SetResult(new base::FundamentalValue(-1)); | 216 SetResult(new base::FundamentalValue(-1)); |
| 217 AsyncWorkCompleted(); | 217 AsyncWorkCompleted(); |
| 218 return; | 218 return; |
| 219 } | 219 } |
| 220 | 220 |
| 221 StartDnsLookup(hostname_); | 221 StartDnsLookup(hostname_); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void SocketConnectFunction::AfterDnsLookup(int lookup_result) { | 224 void SocketConnectFunction::AfterDnsLookup(int lookup_result) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 | 268 |
| 269 if (!socket) { | 269 if (!socket) { |
| 270 error_ = kSocketNotFoundError; | 270 error_ = kSocketNotFoundError; |
| 271 SetResult(new base::FundamentalValue(result)); | 271 SetResult(new base::FundamentalValue(result)); |
| 272 return; | 272 return; |
| 273 } | 273 } |
| 274 | 274 |
| 275 if (socket->GetSocketType() == Socket::TYPE_UDP) { | 275 if (socket->GetSocketType() == Socket::TYPE_UDP) { |
| 276 SocketPermission::CheckParam param( | 276 SocketPermission::CheckParam param( |
| 277 SocketPermissionRequest::UDP_BIND, address_, port_); | 277 SocketPermissionRequest::UDP_BIND, address_, port_); |
| 278 if (!PermissionsData::CheckAPIPermissionWithParam( | 278 if (!PermissionsData::ForExtension(GetExtension()) |
| 279 GetExtension(), APIPermission::kSocket, ¶m)) { | 279 ->CheckAPIPermissionWithParam(APIPermission::kSocket, ¶m)) { |
| 280 error_ = kPermissionError; | 280 error_ = kPermissionError; |
| 281 SetResult(new base::FundamentalValue(result)); | 281 SetResult(new base::FundamentalValue(result)); |
| 282 return; | 282 return; |
| 283 } | 283 } |
| 284 } else if (socket->GetSocketType() == Socket::TYPE_TCP) { | 284 } else if (socket->GetSocketType() == Socket::TYPE_TCP) { |
| 285 error_ = kTCPSocketBindError; | 285 error_ = kTCPSocketBindError; |
| 286 SetResult(new base::FundamentalValue(result)); | 286 SetResult(new base::FundamentalValue(result)); |
| 287 return; | 287 return; |
| 288 } | 288 } |
| 289 | 289 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 301 return true; | 301 return true; |
| 302 } | 302 } |
| 303 | 303 |
| 304 void SocketListenFunction::Work() { | 304 void SocketListenFunction::Work() { |
| 305 int result = -1; | 305 int result = -1; |
| 306 | 306 |
| 307 Socket* socket = GetSocket(params_->socket_id); | 307 Socket* socket = GetSocket(params_->socket_id); |
| 308 if (socket) { | 308 if (socket) { |
| 309 SocketPermission::CheckParam param( | 309 SocketPermission::CheckParam param( |
| 310 SocketPermissionRequest::TCP_LISTEN, params_->address, params_->port); | 310 SocketPermissionRequest::TCP_LISTEN, params_->address, params_->port); |
| 311 if (!PermissionsData::CheckAPIPermissionWithParam( | 311 if (!PermissionsData::ForExtension(GetExtension()) |
| 312 GetExtension(), APIPermission::kSocket, ¶m)) { | 312 ->CheckAPIPermissionWithParam(APIPermission::kSocket, ¶m)) { |
| 313 error_ = kPermissionError; | 313 error_ = kPermissionError; |
| 314 SetResult(new base::FundamentalValue(result)); | 314 SetResult(new base::FundamentalValue(result)); |
| 315 return; | 315 return; |
| 316 } | 316 } |
| 317 | 317 |
| 318 result = | 318 result = |
| 319 socket->Listen(params_->address, | 319 socket->Listen(params_->address, |
| 320 params_->port, | 320 params_->port, |
| 321 params_->backlog.get() ? *params_->backlog.get() : 5, | 321 params_->backlog.get() ? *params_->backlog.get() : 5, |
| 322 &error_); | 322 &error_); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 503 if (!socket_) { | 503 if (!socket_) { |
| 504 error_ = kSocketNotFoundError; | 504 error_ = kSocketNotFoundError; |
| 505 SetResult(new base::FundamentalValue(-1)); | 505 SetResult(new base::FundamentalValue(-1)); |
| 506 AsyncWorkCompleted(); | 506 AsyncWorkCompleted(); |
| 507 return; | 507 return; |
| 508 } | 508 } |
| 509 | 509 |
| 510 if (socket_->GetSocketType() == Socket::TYPE_UDP) { | 510 if (socket_->GetSocketType() == Socket::TYPE_UDP) { |
| 511 SocketPermission::CheckParam param( | 511 SocketPermission::CheckParam param( |
| 512 SocketPermissionRequest::UDP_SEND_TO, hostname_, port_); | 512 SocketPermissionRequest::UDP_SEND_TO, hostname_, port_); |
| 513 if (!PermissionsData::CheckAPIPermissionWithParam( | 513 if (!PermissionsData::ForExtension(GetExtension()) |
| 514 GetExtension(), APIPermission::kSocket, ¶m)) { | 514 ->CheckAPIPermissionWithParam(APIPermission::kSocket, ¶m)) { |
| 515 error_ = kPermissionError; | 515 error_ = kPermissionError; |
| 516 SetResult(new base::FundamentalValue(-1)); | 516 SetResult(new base::FundamentalValue(-1)); |
| 517 AsyncWorkCompleted(); | 517 AsyncWorkCompleted(); |
| 518 return; | 518 return; |
| 519 } | 519 } |
| 520 } | 520 } |
| 521 | 521 |
| 522 StartDnsLookup(hostname_); | 522 StartDnsLookup(hostname_); |
| 523 } | 523 } |
| 524 | 524 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 error_ = kMulticastSocketTypeError; | 717 error_ = kMulticastSocketTypeError; |
| 718 SetResult(new base::FundamentalValue(result)); | 718 SetResult(new base::FundamentalValue(result)); |
| 719 return; | 719 return; |
| 720 } | 720 } |
| 721 | 721 |
| 722 SocketPermission::CheckParam param( | 722 SocketPermission::CheckParam param( |
| 723 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, | 723 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, |
| 724 kWildcardAddress, | 724 kWildcardAddress, |
| 725 kWildcardPort); | 725 kWildcardPort); |
| 726 | 726 |
| 727 if (!PermissionsData::CheckAPIPermissionWithParam( | 727 if (!PermissionsData::ForExtension(GetExtension()) |
| 728 GetExtension(), APIPermission::kSocket, ¶m)) { | 728 ->CheckAPIPermissionWithParam(APIPermission::kSocket, ¶m)) { |
| 729 error_ = kPermissionError; | 729 error_ = kPermissionError; |
| 730 SetResult(new base::FundamentalValue(result)); | 730 SetResult(new base::FundamentalValue(result)); |
| 731 return; | 731 return; |
| 732 } | 732 } |
| 733 | 733 |
| 734 result = static_cast<UDPSocket*>(socket)->JoinGroup(params_->address); | 734 result = static_cast<UDPSocket*>(socket)->JoinGroup(params_->address); |
| 735 if (result != 0) { | 735 if (result != 0) { |
| 736 error_ = net::ErrorToString(result); | 736 error_ = net::ErrorToString(result); |
| 737 } | 737 } |
| 738 SetResult(new base::FundamentalValue(result)); | 738 SetResult(new base::FundamentalValue(result)); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 761 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 761 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
| 762 error_ = kMulticastSocketTypeError; | 762 error_ = kMulticastSocketTypeError; |
| 763 SetResult(new base::FundamentalValue(result)); | 763 SetResult(new base::FundamentalValue(result)); |
| 764 return; | 764 return; |
| 765 } | 765 } |
| 766 | 766 |
| 767 SocketPermission::CheckParam param( | 767 SocketPermission::CheckParam param( |
| 768 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, | 768 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, |
| 769 kWildcardAddress, | 769 kWildcardAddress, |
| 770 kWildcardPort); | 770 kWildcardPort); |
| 771 if (!PermissionsData::CheckAPIPermissionWithParam( | 771 if (!PermissionsData::ForExtension(GetExtension()) |
| 772 GetExtension(), APIPermission::kSocket, ¶m)) { | 772 ->CheckAPIPermissionWithParam(APIPermission::kSocket, ¶m)) { |
| 773 error_ = kPermissionError; | 773 error_ = kPermissionError; |
| 774 SetResult(new base::FundamentalValue(result)); | 774 SetResult(new base::FundamentalValue(result)); |
| 775 return; | 775 return; |
| 776 } | 776 } |
| 777 | 777 |
| 778 result = static_cast<UDPSocket*>(socket)->LeaveGroup(params_->address); | 778 result = static_cast<UDPSocket*>(socket)->LeaveGroup(params_->address); |
| 779 if (result != 0) | 779 if (result != 0) |
| 780 error_ = net::ErrorToString(result); | 780 error_ = net::ErrorToString(result); |
| 781 SetResult(new base::FundamentalValue(result)); | 781 SetResult(new base::FundamentalValue(result)); |
| 782 } | 782 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 if (socket->GetSocketType() != Socket::TYPE_UDP) { | 868 if (socket->GetSocketType() != Socket::TYPE_UDP) { |
| 869 error_ = kMulticastSocketTypeError; | 869 error_ = kMulticastSocketTypeError; |
| 870 SetResult(new base::FundamentalValue(result)); | 870 SetResult(new base::FundamentalValue(result)); |
| 871 return; | 871 return; |
| 872 } | 872 } |
| 873 | 873 |
| 874 SocketPermission::CheckParam param( | 874 SocketPermission::CheckParam param( |
| 875 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, | 875 SocketPermissionRequest::UDP_MULTICAST_MEMBERSHIP, |
| 876 kWildcardAddress, | 876 kWildcardAddress, |
| 877 kWildcardPort); | 877 kWildcardPort); |
| 878 if (!PermissionsData::CheckAPIPermissionWithParam( | 878 if (!PermissionsData::ForExtension(GetExtension()) |
|
not at google - send to devlin
2014/06/02 23:20:06
so much of this. almost seems like there should be
Devlin
2014/06/03 15:28:21
Yeah.... let's hold off on that for now.
| |
| 879 GetExtension(), APIPermission::kSocket, ¶m)) { | 879 ->CheckAPIPermissionWithParam(APIPermission::kSocket, ¶m)) { |
| 880 error_ = kPermissionError; | 880 error_ = kPermissionError; |
| 881 SetResult(new base::FundamentalValue(result)); | 881 SetResult(new base::FundamentalValue(result)); |
| 882 return; | 882 return; |
| 883 } | 883 } |
| 884 | 884 |
| 885 base::ListValue* values = new base::ListValue(); | 885 base::ListValue* values = new base::ListValue(); |
| 886 values->AppendStrings((std::vector<std::string>&)static_cast<UDPSocket*>( | 886 values->AppendStrings((std::vector<std::string>&)static_cast<UDPSocket*>( |
| 887 socket)->GetJoinedGroups()); | 887 socket)->GetJoinedGroups()); |
| 888 SetResult(values); | 888 SetResult(values); |
| 889 } | 889 } |
| 890 | 890 |
| 891 } // namespace extensions | 891 } // namespace extensions |
| OLD | NEW |