Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1421)

Side by Side Diff: extensions/browser/api/socket/socket_api.cc

Issue 315573003: Remove PermissionsData::ForExtension() completely (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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::ForExtension(GetExtension()) 213 if (!GetExtension()->permissions_data()->CheckAPIPermissionWithParam(
214 ->CheckAPIPermissionWithParam(APIPermission::kSocket, &param)) { 214 APIPermission::kSocket, &param)) {
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
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::ForExtension(GetExtension()) 278 if (!GetExtension()->permissions_data()->CheckAPIPermissionWithParam(
279 ->CheckAPIPermissionWithParam(APIPermission::kSocket, &param)) { 279 APIPermission::kSocket, &param)) {
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
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::ForExtension(GetExtension()) 311 if (!GetExtension()->permissions_data()->CheckAPIPermissionWithParam(
312 ->CheckAPIPermissionWithParam(APIPermission::kSocket, &param)) { 312 APIPermission::kSocket, &param)) {
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
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::ForExtension(GetExtension()) 513 if (!GetExtension()->permissions_data()->CheckAPIPermissionWithParam(
514 ->CheckAPIPermissionWithParam(APIPermission::kSocket, &param)) { 514 APIPermission::kSocket, &param)) {
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
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::ForExtension(GetExtension()) 727 if (!GetExtension()->permissions_data()->CheckAPIPermissionWithParam(
728 ->CheckAPIPermissionWithParam(APIPermission::kSocket, &param)) { 728 APIPermission::kSocket, &param)) {
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
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::ForExtension(GetExtension()) 771 if (!GetExtension()->permissions_data()->CheckAPIPermissionWithParam(
772 ->CheckAPIPermissionWithParam(APIPermission::kSocket, &param)) { 772 APIPermission::kSocket, &param)) {
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
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::ForExtension(GetExtension()) 878 if (!GetExtension()->permissions_data()->CheckAPIPermissionWithParam(
879 ->CheckAPIPermissionWithParam(APIPermission::kSocket, &param)) { 879 APIPermission::kSocket, &param)) {
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
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/renderer_permissions_policy_delegate_unittest.cc ('k') | extensions/browser/api/usb/usb_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698