| 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 11 matching lines...) Expand all Loading... |
| 22 #include "net/base/host_port_pair.h" | 22 #include "net/base/host_port_pair.h" |
| 23 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
| 24 #include "net/base/ip_endpoint.h" | 24 #include "net/base/ip_endpoint.h" |
| 25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 26 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| 27 #include "net/log/net_log.h" | 27 #include "net/log/net_log.h" |
| 28 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
| 29 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
| 30 | 30 |
| 31 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
| 32 #include "base/command_line.h" | |
| 33 #include "chromeos/chromeos_switches.h" | |
| 34 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 35 #endif // OS_CHROMEOS | 33 #endif // OS_CHROMEOS |
| 36 | 34 |
| 37 namespace extensions { | 35 namespace extensions { |
| 38 | 36 |
| 39 using content::BrowserThread; | 37 using content::BrowserThread; |
| 40 using content::SocketPermissionRequest; | 38 using content::SocketPermissionRequest; |
| 41 | 39 |
| 42 const char kAddressKey[] = "address"; | 40 const char kAddressKey[] = "address"; |
| 43 const char kPortKey[] = "port"; | 41 const char kPortKey[] = "port"; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 95 } |
| 98 | 96 |
| 99 void SocketAsyncApiFunction::RemoveSocket(int api_resource_id) { | 97 void SocketAsyncApiFunction::RemoveSocket(int api_resource_id) { |
| 100 manager_->Remove(extension_->id(), api_resource_id); | 98 manager_->Remove(extension_->id(), api_resource_id); |
| 101 } | 99 } |
| 102 | 100 |
| 103 void SocketAsyncApiFunction::OpenFirewallHole(const std::string& address, | 101 void SocketAsyncApiFunction::OpenFirewallHole(const std::string& address, |
| 104 int socket_id, | 102 int socket_id, |
| 105 Socket* socket) { | 103 Socket* socket) { |
| 106 #if defined(OS_CHROMEOS) | 104 #if defined(OS_CHROMEOS) |
| 107 if (!net::IsLocalhost(address) && | 105 if (!net::IsLocalhost(address)) { |
| 108 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 109 chromeos::switches::kEnableFirewallHolePunching)) { | |
| 110 net::IPEndPoint local_address; | 106 net::IPEndPoint local_address; |
| 111 if (!socket->GetLocalAddress(&local_address)) { | 107 if (!socket->GetLocalAddress(&local_address)) { |
| 112 NOTREACHED() << "Cannot get address of recently bound socket."; | 108 NOTREACHED() << "Cannot get address of recently bound socket."; |
| 113 error_ = kFirewallFailure; | 109 error_ = kFirewallFailure; |
| 114 SetResult(new base::FundamentalValue(-1)); | 110 SetResult(new base::FundamentalValue(-1)); |
| 115 AsyncWorkCompleted(); | 111 AsyncWorkCompleted(); |
| 116 return; | 112 return; |
| 117 } | 113 } |
| 118 | 114 |
| 119 AppFirewallHole::PortType type = socket->GetSocketType() == Socket::TYPE_TCP | 115 AppFirewallHole::PortType type = socket->GetSocketType() == Socket::TYPE_TCP |
| (...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 } else { | 1076 } else { |
| 1081 RemoveSocket(params_->socket_id); | 1077 RemoveSocket(params_->socket_id); |
| 1082 error_ = net::ErrorToString(result); | 1078 error_ = net::ErrorToString(result); |
| 1083 } | 1079 } |
| 1084 | 1080 |
| 1085 results_ = core_api::socket::Secure::Results::Create(result); | 1081 results_ = core_api::socket::Secure::Results::Create(result); |
| 1086 AsyncWorkCompleted(); | 1082 AsyncWorkCompleted(); |
| 1087 } | 1083 } |
| 1088 | 1084 |
| 1089 } // namespace extensions | 1085 } // namespace extensions |
| OLD | NEW |