diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 22:16:02 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-15 22:16:02 +0000 |
commit | 6d3ad505c8e8173e98045d845a910f77fab9ffcf (patch) | |
tree | e996bba53b108dabdcb9b0af89eab2e4664a0bf5 | |
parent | b0f146ff51b2b37a2e3549c875fb42365ded7a21 (diff) | |
download | chromium_src-6d3ad505c8e8173e98045d845a910f77fab9ffcf.zip chromium_src-6d3ad505c8e8173e98045d845a910f77fab9ffcf.tar.gz chromium_src-6d3ad505c8e8173e98045d845a910f77fab9ffcf.tar.bz2 |
Relay server support for P2P Transport API.
BUG=41776
TEST=None
Review URL: http://codereview.chromium.org/7791008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101396 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | content/renderer/p2p/p2p_transport_impl.cc | 6 | ||||
-rw-r--r-- | content/renderer/p2p/p2p_transport_impl.h | 3 | ||||
-rw-r--r-- | content/renderer/p2p/p2p_transport_impl_unittest.cc | 4 | ||||
-rw-r--r-- | content/renderer/p2p/port_allocator.cc | 198 | ||||
-rw-r--r-- | content/renderer/p2p/port_allocator.h | 43 | ||||
-rw-r--r-- | ppapi/c/dev/ppb_transport_dev.h | 29 | ||||
-rw-r--r-- | ppapi/tests/test_transport.cc | 8 | ||||
-rw-r--r-- | remoting/protocol/pepper_stream_channel.cc | 12 | ||||
-rw-r--r-- | webkit/glue/p2p_transport.cc | 1 | ||||
-rw-r--r-- | webkit/glue/p2p_transport.h | 25 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_transport_impl.cc | 43 |
11 files changed, 335 insertions, 37 deletions
diff --git a/content/renderer/p2p/p2p_transport_impl.cc b/content/renderer/p2p/p2p_transport_impl.cc index 29266e2..ada21a5 100644 --- a/content/renderer/p2p/p2p_transport_impl.cc +++ b/content/renderer/p2p/p2p_transport_impl.cc @@ -44,7 +44,8 @@ P2PTransportImpl::P2PTransportImpl(P2PSocketDispatcher* socket_dispatcher) P2PTransportImpl::~P2PTransportImpl() { } -bool P2PTransportImpl::Init(const std::string& name, +bool P2PTransportImpl::Init(WebKit::WebFrame* web_frame, + const std::string& name, Protocol protocol, const Config& config, EventHandler* event_handler) { @@ -58,8 +59,9 @@ bool P2PTransportImpl::Init(const std::string& name, event_handler_ = event_handler; if (socket_dispatcher_) { + DCHECK(web_frame); allocator_.reset(new P2PPortAllocator( - socket_dispatcher_, network_manager_.get(), + web_frame, socket_dispatcher_, network_manager_.get(), socket_factory_.get(), config)); } else { // Use BasicPortAllocator if we don't have P2PSocketDispatcher diff --git a/content/renderer/p2p/p2p_transport_impl.h b/content/renderer/p2p/p2p_transport_impl.h index d5d9e81..82072b1 100644 --- a/content/renderer/p2p/p2p_transport_impl.h +++ b/content/renderer/p2p/p2p_transport_impl.h @@ -53,7 +53,8 @@ class P2PTransportImpl : public webkit_glue::P2PTransport, virtual ~P2PTransportImpl(); // webkit_glue::P2PTransport interface. - virtual bool Init(const std::string& name, + virtual bool Init(WebKit::WebFrame* web_frame, + const std::string& name, Protocol protocol, const Config& config, EventHandler* event_handler) OVERRIDE; diff --git a/content/renderer/p2p/p2p_transport_impl_unittest.cc b/content/renderer/p2p/p2p_transport_impl_unittest.cc index bf6f8d9..83c23e5 100644 --- a/content/renderer/p2p/p2p_transport_impl_unittest.cc +++ b/content/renderer/p2p/p2p_transport_impl_unittest.cc @@ -353,9 +353,9 @@ class P2PTransportImplTest : public testing::Test { void Init(P2PTransport::Protocol protocol) { P2PTransport::Config config; ASSERT_TRUE(transport1_->Init( - kTransportName1, protocol, config, &event_handler1_)); + NULL, kTransportName1, protocol, config, &event_handler1_)); ASSERT_TRUE(transport2_->Init( - kTransportName2, protocol, config, &event_handler2_)); + NULL, kTransportName2, protocol, config, &event_handler2_)); } MessageLoop message_loop_; diff --git a/content/renderer/p2p/port_allocator.cc b/content/renderer/p2p/port_allocator.cc index 55f502a..42df275 100644 --- a/content/renderer/p2p/port_allocator.cc +++ b/content/renderer/p2p/port_allocator.cc @@ -5,18 +5,58 @@ #include "content/renderer/p2p/port_allocator.h" #include "base/bind.h" +#include "base/string_number_conversions.h" +#include "base/string_split.h" +#include "base/string_util.h" #include "content/renderer/p2p/host_address_request.h" #include "jingle/glue/utils.h" #include "net/base/ip_endpoint.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderOptions.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" + +using WebKit::WebString; +using WebKit::WebURL; +using WebKit::WebURLLoader; +using WebKit::WebURLLoaderOptions; +using WebKit::WebURLRequest; +using WebKit::WebURLResponse; namespace content { +namespace { + +// URL used to create a relay session. +const char kCreateRelaySessionURL[] = "/create_session"; + +// Number of times we will try to request relay session. +const int kRelaySessionRetries = 3; + +// Manimum relay server size we would try to parse. +const int kMaximumRelayResponseSize = 102400; + +bool ParsePortNumber( + const std::string& string, int* value) { + if (!base::StringToInt(string, value) || *value <= 0 || *value >= 65536) { + LOG(ERROR) << "Received invalid port number from relay server: " << string; + return false; + } + return true; +} + +} // namespace + P2PPortAllocator::P2PPortAllocator( + WebKit::WebFrame* web_frame, P2PSocketDispatcher* socket_dispatcher, talk_base::NetworkManager* network_manager, talk_base::PacketSocketFactory* socket_factory, const webkit_glue::P2PTransport::Config& config) : cricket::BasicPortAllocator(network_manager, socket_factory), + web_frame_(web_frame), socket_dispatcher_(socket_dispatcher), config_(config) { } @@ -43,15 +83,43 @@ P2PPortAllocatorSession::~P2PPortAllocatorSession() { stun_address_request_->Cancel(); } +void P2PPortAllocatorSession::didReceiveData( + WebURLLoader* loader, const char* data, + int data_length, int encoded_data_length) { + DCHECK_EQ(loader, relay_session_request_.get()); + if (static_cast<int>(relay_session_response_.size()) + data_length > + kMaximumRelayResponseSize) { + LOG(ERROR) << "Response received from the server is too big."; + loader->cancel(); + return; + } + relay_session_response_.append(data, data + data_length); +} + +void P2PPortAllocatorSession::didFinishLoading(WebURLLoader* loader, + double finish_time) { + ParseRelayResponse(); +} + +void P2PPortAllocatorSession::didFail(WebKit::WebURLLoader* loader, + const WebKit::WebURLError& error) { + DCHECK_EQ(loader, relay_session_request_.get()); + DCHECK_NE(error.reason, 0); + + LOG(ERROR) << "Relay session request failed."; + + // Retry the request. + AllocateRelaySession(); +} + void P2PPortAllocatorSession::GetPortConfigurations() { - // Add am empty configuration synchronously, so a local connection + // Add an empty configuration synchronously, so a local connection // can be started immediately. ConfigReady(new cricket::PortConfiguration( talk_base::SocketAddress(), "", "", "")); ResolveStunServerAddress(); - - // TODO(sergeyu): Implement relay server support. + AllocateRelaySession(); } void P2PPortAllocatorSession::ResolveStunServerAddress() { @@ -74,14 +142,132 @@ void P2PPortAllocatorSession::OnStunServerAddress( return; } - talk_base::SocketAddress socket_address; if (!jingle_glue::IPEndPointToSocketAddress( net::IPEndPoint(address, allocator_->config_.stun_server_port), - &socket_address)) { + &stun_server_address_)) { return; } - ConfigReady(new cricket::PortConfiguration(socket_address, "", "", "")); + AddConfig(); +} + +void P2PPortAllocatorSession::AllocateRelaySession() { + if (allocator_->config_.relay_server.empty()) + return; + + if (!allocator_->config_.legacy_relay) { + NOTIMPLEMENTED() << " TURN support is not implemented yet."; + return; + } + + if (relay_session_attemtps_ > kRelaySessionRetries) + return; + relay_session_attemtps_++; + + relay_session_response_.clear(); + + WebURLLoaderOptions options; + options.allowCredentials = false; + options.crossOriginRequestPolicy = + WebURLLoaderOptions::CrossOriginRequestPolicyUseAccessControl; + relay_session_request_.reset( + allocator_->web_frame_->createAssociatedURLLoader(options)); + if (!relay_session_request_.get()) { + LOG(ERROR) << "Failed to create URL loader."; + return; + } + + WebURLRequest request; + request.initialize(); + request.setURL(WebURL(GURL( + "http://" + allocator_->config_.relay_server + kCreateRelaySessionURL))); + request.setAllowStoredCredentials(false); + request.setCachePolicy(WebURLRequest::ReloadIgnoringCacheData); + request.setHTTPMethod("GET"); + request.addHTTPHeaderField( + WebString::fromUTF8("X-Talk-Google-Relay-Auth"), + WebString::fromUTF8(allocator_->config_.relay_password)); + request.addHTTPHeaderField( + WebString::fromUTF8("X-Google-Relay-Auth"), + WebString::fromUTF8(allocator_->config_.relay_password)); + request.addHTTPHeaderField(WebString::fromUTF8("X-Session-Type"), + WebString::fromUTF8(session_type())); + request.addHTTPHeaderField(WebString::fromUTF8("X-Stream-Type"), + WebString::fromUTF8(name())); + + relay_session_request_->loadAsynchronously(request, this); +} + +void P2PPortAllocatorSession::ParseRelayResponse() { + std::vector<std::pair<std::string, std::string> > value_pairs; + if (!base::SplitStringIntoKeyValuePairs(relay_session_response_, '=', '\n', + &value_pairs)) { + LOG(ERROR) << "Received invalid response from relay server"; + return; + } + + relay_username_.clear(); + relay_password_.clear(); + relay_ip_.Clear(); + relay_udp_port_ = 0; + relay_tcp_port_ = 0; + relay_ssltcp_port_ = 0; + + for (std::vector<std::pair<std::string, std::string> >::iterator + it = value_pairs.begin(); + it != value_pairs.end(); ++it) { + std::string key; + std::string value; + TrimWhitespaceASCII(it->first, TRIM_ALL, &key); + TrimWhitespaceASCII(it->second, TRIM_ALL, &value); + + if (key == "username") { + relay_username_ = value; + } else if (key == "password") { + relay_password_ = value; + } else if (key == "relay.ip") { + relay_ip_.SetIP(value); + if (relay_ip_.ip() == 0) { + LOG(ERROR) << "Received unresolved relay server address: " << value; + return; + } + } else if (key == "relay.udp_port") { + if (!ParsePortNumber(value, &relay_udp_port_)) + return; + } else if (key == "relay.tcp_port") { + if (!ParsePortNumber(value, &relay_tcp_port_)) + return; + } else if (key == "relay.ssltcp_port") { + if (!ParsePortNumber(value, &relay_ssltcp_port_)) + return; + } + } + + AddConfig(); +} + +void P2PPortAllocatorSession::AddConfig() { + cricket::PortConfiguration* config = + new cricket::PortConfiguration(stun_server_address_, + relay_username_, relay_password_, ""); + + cricket::PortConfiguration::PortList ports; + if (relay_ip_.ip() != 0) { + if (relay_udp_port_ > 0) { + talk_base::SocketAddress address(relay_ip_.ip(), relay_udp_port_); + ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_UDP)); + } + if (relay_tcp_port_ > 0) { + talk_base::SocketAddress address(relay_ip_.ip(), relay_tcp_port_); + ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_TCP)); + } + if (relay_ssltcp_port_ > 0) { + talk_base::SocketAddress address(relay_ip_.ip(), relay_ssltcp_port_); + ports.push_back(cricket::ProtocolAddress(address, cricket::PROTO_SSLTCP)); + } + } + config->AddRelay(ports, 0.0f); + ConfigReady(config); } } // namespace content diff --git a/content/renderer/p2p/port_allocator.h b/content/renderer/p2p/port_allocator.h index 0761ba2..fe5511a 100644 --- a/content/renderer/p2p/port_allocator.h +++ b/content/renderer/p2p/port_allocator.h @@ -8,17 +8,26 @@ #include "base/memory/ref_counted.h" #include "net/base/net_util.h" #include "third_party/libjingle/source/talk/p2p/client/basicportallocator.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" #include "webkit/glue/p2p_transport.h" +namespace WebKit { +class WebFrame; +class WebURLLoader; +} // namespace WebKit + namespace content { class P2PHostAddressRequest; class P2PPortAllocatorSession; class P2PSocketDispatcher; -class P2PPortAllocator : public cricket::BasicPortAllocator{ +// TODO(sergeyu): There is overlap between this class and +// HttpPortAllocator. Refactor HttpPortAllocator +class P2PPortAllocator : public cricket::BasicPortAllocator { public: - P2PPortAllocator(P2PSocketDispatcher* socket_dispatcher, + P2PPortAllocator(WebKit::WebFrame* web_frame, + P2PSocketDispatcher* socket_dispatcher, talk_base::NetworkManager* network_manager, talk_base::PacketSocketFactory* socket_factory, const webkit_glue::P2PTransport::Config& config); @@ -31,13 +40,15 @@ class P2PPortAllocator : public cricket::BasicPortAllocator{ private: friend class P2PPortAllocatorSession; + WebKit::WebFrame* web_frame_; P2PSocketDispatcher* socket_dispatcher_; webkit_glue::P2PTransport::Config config_; DISALLOW_COPY_AND_ASSIGN(P2PPortAllocator); }; -class P2PPortAllocatorSession : public cricket::BasicPortAllocatorSession { +class P2PPortAllocatorSession : public cricket::BasicPortAllocatorSession, + public WebKit::WebURLLoaderClient { public: P2PPortAllocatorSession( P2PPortAllocator* allocator, @@ -45,6 +56,16 @@ class P2PPortAllocatorSession : public cricket::BasicPortAllocatorSession { const std::string& session_type); virtual ~P2PPortAllocatorSession(); + // WebKit::WebURLLoaderClient overrides. + virtual void didReceiveData(WebKit::WebURLLoader* loader, + const char* data, + int data_length, + int encoded_data_length) OVERRIDE; + virtual void didFinishLoading(WebKit::WebURLLoader* loader, + double finish_time) OVERRIDE; + virtual void didFail(WebKit::WebURLLoader* loader, + const WebKit::WebURLError& error) OVERRIDE; + protected: // Overrides for cricket::BasicPortAllocatorSession. virtual void GetPortConfigurations() OVERRIDE; @@ -53,9 +74,25 @@ class P2PPortAllocatorSession : public cricket::BasicPortAllocatorSession { void ResolveStunServerAddress(); void OnStunServerAddress(const net::IPAddressNumber& address); + void AllocateRelaySession(); + void ParseRelayResponse(); + + void AddConfig(); + P2PPortAllocator* allocator_; scoped_refptr<P2PHostAddressRequest> stun_address_request_; + talk_base::SocketAddress stun_server_address_; + + scoped_ptr<WebKit::WebURLLoader> relay_session_request_; + int relay_session_attemtps_; + std::string relay_session_response_; + std::string relay_username_; + std::string relay_password_; + talk_base::SocketAddress relay_ip_; + int relay_udp_port_; + int relay_tcp_port_; + int relay_ssltcp_port_; DISALLOW_COPY_AND_ASSIGN(P2PPortAllocatorSession); }; diff --git a/ppapi/c/dev/ppb_transport_dev.h b/ppapi/c/dev/ppb_transport_dev.h index f34b3bf..159b784 100644 --- a/ppapi/c/dev/ppb_transport_dev.h +++ b/ppapi/c/dev/ppb_transport_dev.h @@ -25,31 +25,46 @@ typedef enum { // STUN server address and port, e.g "stun.example.com:19302". PP_TRANSPORTPROPERTY_STUN_SERVER = 0, - // Relay server name, e.g. "relay.example.com". + // Relay server address and port, e.g. "relay.example.com:12344". PP_TRANSPORTPROPERTY_RELAY_SERVER = 1, - // Single string that specifies token for use with relay server. - PP_TRANSPORTPROPERTY_RELAY_TOKEN = 2, + // Username for the relay server. + PP_TRANSPORTPROPERTY_RELAY_USERNAME = 2, + + // Password for the relay server. + PP_TRANSPORTPROPERTY_RELAY_PASSWORD = 3, + + // Type of Relay server. Must be one of the PP_TransportRelayMode + // values. By default is set to PP_TRANSPORTRELAYMODE_TURN. + PP_TRANSPORTPROPERTY_RELAY_MODE = 4, // TCP receive window in bytes. Takes effect only for PseudoTCP // connections. - PP_TRANSPORTPROPERTY_TCP_RECEIVE_WINDOW = 3, + PP_TRANSPORTPROPERTY_TCP_RECEIVE_WINDOW = 5, // TCP send window in bytes. Takes effect only for PseudoTCP // connections. - PP_TRANSPORTPROPERTY_TCP_SEND_WINDOW = 4, + PP_TRANSPORTPROPERTY_TCP_SEND_WINDOW = 6, // Boolean value that disables Neagle's algorithm when set to // true. When Neagle's algorithm is disabled, all outgoing packets // are sent as soon as possible. When set to false (by default) data // may be buffered until there is a sufficient amount to send. - PP_TRANSPORTPROPERTY_TCP_NO_DELAY = 5, + PP_TRANSPORTPROPERTY_TCP_NO_DELAY = 7, // Delay for ACK packets in milliseconds. By default set to 100ms. - PP_TRANSPORTPROPERTY_TCP_ACK_DELAY = 6 + PP_TRANSPORTPROPERTY_TCP_ACK_DELAY = 8 } PP_TransportProperty; PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_TransportProperty, 4); +typedef enum { + // RFC5766 compliant relay server. + PP_TRANSPORTRELAYMODE_TURN = 0, + + // Legacy Google relay server. + PP_TRANSPORTRELAYMODE_GOOGLE = 1 +} PP_TransportRelayMode; + struct PPB_Transport_Dev { // Creates a new transport object with the specified name using the // specified protocol. diff --git a/ppapi/tests/test_transport.cc b/ppapi/tests/test_transport.cc index 6e520c5..d2d2850 100644 --- a/ppapi/tests/test_transport.cc +++ b/ppapi/tests/test_transport.cc @@ -144,6 +144,7 @@ std::string TestTransport::Connect() { ASSERT_EQ(transport1_->ReceiveRemoteAddress(address2), PP_OK); ASSERT_EQ(transport2_->ReceiveRemoteAddress(address1), PP_OK); + ASSERT_EQ(connect_cb1.WaitForResult(), PP_OK); ASSERT_EQ(connect_cb2.WaitForResult(), PP_OK); @@ -181,8 +182,11 @@ std::string TestTransport::TestSetProperty() { pp::Var("ralay.example.com:80")), PP_OK); ASSERT_EQ(transport1_->SetProperty( - PP_TRANSPORTPROPERTY_RELAY_TOKEN, - pp::Var("INVALID_TOKEN")), PP_OK); + PP_TRANSPORTPROPERTY_RELAY_USERNAME, + pp::Var("USERNAME")), PP_OK); + ASSERT_EQ(transport1_->SetProperty( + PP_TRANSPORTPROPERTY_RELAY_PASSWORD, + pp::Var("PASSWORD")), PP_OK); // Try changing TCP window size. ASSERT_EQ(transport1_->SetProperty(PP_TRANSPORTPROPERTY_TCP_RECEIVE_WINDOW, diff --git a/remoting/protocol/pepper_stream_channel.cc b/remoting/protocol/pepper_stream_channel.cc index 330893e..e6b07d8 100644 --- a/remoting/protocol/pepper_stream_channel.cc +++ b/remoting/protocol/pepper_stream_channel.cc @@ -127,13 +127,19 @@ void PepperStreamChannel::Connect(pp::Instance* pp_instance, if (transport->SetProperty( PP_TRANSPORTPROPERTY_RELAY_SERVER, pp::Var(transport_config.relay_server)) != PP_OK) { - LOG(ERROR) << "Failed to set Relay server."; + LOG(ERROR) << "Failed to set relay server."; } if (transport->SetProperty( - PP_TRANSPORTPROPERTY_RELAY_TOKEN, + PP_TRANSPORTPROPERTY_RELAY_PASSWORD, pp::Var(transport_config.relay_token)) != PP_OK) { - LOG(ERROR) << "Failed to set Relay token."; + LOG(ERROR) << "Failed to set relay token."; + } + + if (transport->SetProperty( + PP_TRANSPORTPROPERTY_RELAY_MODE, + pp::Var(PP_TRANSPORTRELAYMODE_GOOGLE)) != PP_OK) { + LOG(ERROR) << "Failed to set relay mode."; } } diff --git a/webkit/glue/p2p_transport.cc b/webkit/glue/p2p_transport.cc index a4c518b..f79c21f 100644 --- a/webkit/glue/p2p_transport.cc +++ b/webkit/glue/p2p_transport.cc @@ -9,6 +9,7 @@ namespace webkit_glue { P2PTransport::Config::Config() : stun_server_port(0), relay_server_port(0), + legacy_relay(false), tcp_receive_window(0), tcp_send_window(0), tcp_no_delay(false), diff --git a/webkit/glue/p2p_transport.h b/webkit/glue/p2p_transport.h index 7795344..8e77d28 100644 --- a/webkit/glue/p2p_transport.h +++ b/webkit/glue/p2p_transport.h @@ -12,6 +12,10 @@ namespace net { class Socket; } // namespace net +namespace WebKit { +class WebFrame; +} // namespace WebKit + namespace webkit_glue { // Interface for P2P transport. @@ -48,16 +52,23 @@ class P2PTransport { Config(); ~Config(); - // STUN server address and port, e.g. "stun.example.com:23542". + // STUN server address and port. std::string stun_server; int stun_server_port; - // Relay server address and port, e.g. "relay.example.com:4234". + // Relay server address and port. std::string relay_server; int relay_server_port; - // Relay token to use for relay servers. - std::string relay_token; + // Relay server username. + std::string relay_username; + + // Relay server password. + std::string relay_password; + + // When set to true relay is a legacy Google relay (not TURN + // compliant). + bool legacy_relay; // TCP window sizes. Default size is used when set to 0. int tcp_receive_window; @@ -72,9 +83,11 @@ class P2PTransport { virtual ~P2PTransport() {} - // Initialize transport using specified configuration. Returns true + // Initialize transport using specified configuration. |web_frame| + // is used to make HTTP requests to relay servers. Returns true // if initialization succeeded. - virtual bool Init(const std::string& name, + virtual bool Init(WebKit::WebFrame* web_frame, + const std::string& name, Protocol protocol, const Config& config, EventHandler* event_handler) = 0; diff --git a/webkit/plugins/ppapi/ppb_transport_impl.cc b/webkit/plugins/ppapi/ppb_transport_impl.cc index d097354..1e121e2 100644 --- a/webkit/plugins/ppapi/ppb_transport_impl.cc +++ b/webkit/plugins/ppapi/ppb_transport_impl.cc @@ -14,6 +14,9 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/shared_impl/var.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" #include "webkit/plugins/ppapi/common.h" #include "webkit/plugins/ppapi/plugin_module.h" #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" @@ -52,6 +55,14 @@ int MapNetError(int result) { } } +WebKit::WebFrame* GetFrameForResource(const ::ppapi::Resource* resource) { + PluginInstance* plugin_instance = + ResourceHelper::GetPluginInstance(resource); + if (!plugin_instance) + return NULL; + return plugin_instance->container()->element().document().frame(); +} + } // namespace PPB_Transport_Impl::PPB_Transport_Impl(PP_Instance instance) @@ -115,7 +126,6 @@ int32_t PPB_Transport_Impl::SetProperty(PP_TransportProperty property, StringVar* value_str = StringVar::FromPPVar(value); if (!value_str) return PP_ERROR_BADARGUMENT; - if (!net::ParseHostAndPort(value_str->value(), &config_.stun_server, &config_.stun_server_port)) { return PP_ERROR_BADARGUMENT; @@ -127,7 +137,6 @@ int32_t PPB_Transport_Impl::SetProperty(PP_TransportProperty property, StringVar* value_str = StringVar::FromPPVar(value); if (!value_str) return PP_ERROR_BADARGUMENT; - if (!net::ParseHostAndPort(value_str->value(), &config_.relay_server, &config_.relay_server_port)) { return PP_ERROR_BADARGUMENT; @@ -135,11 +144,33 @@ int32_t PPB_Transport_Impl::SetProperty(PP_TransportProperty property, break; } - case PP_TRANSPORTPROPERTY_RELAY_TOKEN: { + case PP_TRANSPORTPROPERTY_RELAY_USERNAME: { StringVar* value_str = StringVar::FromPPVar(value); if (!value_str) return PP_ERROR_BADARGUMENT; - config_.relay_token = value_str->value(); + config_.relay_username = value_str->value(); + break; + } + + case PP_TRANSPORTPROPERTY_RELAY_PASSWORD: { + StringVar* value_str = StringVar::FromPPVar(value); + if (!value_str) + return PP_ERROR_BADARGUMENT; + config_.relay_password = value_str->value(); + break; + } + + case PP_TRANSPORTPROPERTY_RELAY_MODE: { + switch (value.value.as_int) { + case PP_TRANSPORTRELAYMODE_TURN: + config_.legacy_relay = false; + break; + case PP_TRANSPORTRELAYMODE_GOOGLE: + config_.legacy_relay = true; + break; + default: + return PP_ERROR_BADARGUMENT; + } break; } @@ -210,8 +241,10 @@ int32_t PPB_Transport_Impl::Connect(PP_CompletionCallback callback) { P2PTransport::Protocol protocol = (type_ == PP_TRANSPORTTYPE_STREAM) ? P2PTransport::PROTOCOL_TCP : P2PTransport::PROTOCOL_UDP; - if (!p2p_transport_->Init(name_, protocol, config_, this)) + if (!p2p_transport_->Init( + GetFrameForResource(this), name_, protocol, config_, this)) { return PP_ERROR_FAILED; + } started_ = true; |