Index: remoting/host/it2me/it2me_native_messaging_host.cc |
diff --git a/remoting/host/it2me/it2me_native_messaging_host.cc b/remoting/host/it2me/it2me_native_messaging_host.cc |
index e3d0251d8a9648b2eca19c7b8e9d5e935905a60f..b030036a3620cd50841a3a658f44a747f1ac3122 100644 |
--- a/remoting/host/it2me/it2me_native_messaging_host.cc |
+++ b/remoting/host/it2me/it2me_native_messaging_host.cc |
@@ -22,6 +22,7 @@ |
#include "build/build_config.h" |
#include "components/policy/policy_constants.h" |
#include "net/base/url_util.h" |
+#include "net/socket/client_socket_factory.h" |
#include "net/url_request/url_request_context_getter.h" |
#include "remoting/base/auto_thread_task_runner.h" |
#include "remoting/host/chromoting_host_context.h" |
@@ -29,6 +30,7 @@ |
#include "remoting/host/policy_watcher.h" |
#include "remoting/host/service_urls.h" |
#include "remoting/protocol/name_value_map.h" |
+#include "remoting/signaling/delegating_signal_strategy.h" |
#if defined(OS_WIN) |
#include "base/command_line.h" |
@@ -84,6 +86,7 @@ It2MeNativeMessagingHost::It2MeNativeMessagingHost( |
std::unique_ptr<ChromotingHostContext> context, |
std::unique_ptr<It2MeHostFactory> factory) |
: needs_elevation_(needs_elevation), |
+ delegating_signal_strategy_(nullptr), |
Sergey Ulanov
2016/10/05 21:49:06
please put this initializer in the class declarati
kelvinp
2016/10/06 00:43:05
Done.
|
host_context_(std::move(context)), |
factory_(std::move(factory)), |
policy_service_(policy_service), |
@@ -155,6 +158,8 @@ void It2MeNativeMessagingHost::OnMessage(const std::string& message) { |
ProcessConnect(std::move(message_dict), std::move(response)); |
} else if (type == "disconnect") { |
ProcessDisconnect(std::move(message_dict), std::move(response)); |
+ } else if (type == "incomingIq") { |
+ ProcessIncomingIq(std::move(message_dict), std::move(response)); |
} else { |
SendErrorAndExit(std::move(response), "Unsupported request type: " + type); |
} |
@@ -232,49 +237,75 @@ void It2MeNativeMessagingHost::ProcessConnect( |
SendErrorAndExit(std::move(response), "'userName' not found in request."); |
return; |
} |
+ bool use_signaling_proxy = false; |
Sergey Ulanov
2016/10/05 21:49:06
nit: add empty line here
kelvinp
2016/10/06 00:43:05
Done.
|
+ message->GetBoolean("useSignalingProxy", &use_signaling_proxy); |
- std::string auth_service_with_token; |
- if (!message->GetString("authServiceWithToken", &auth_service_with_token)) { |
- SendErrorAndExit(std::move(response), |
+ std::unique_ptr<SignalStrategy> signal_strategy; |
+ |
+ if (!use_signaling_proxy) { |
+ std::string auth_service_with_token; |
+ if (!message->GetString("authServiceWithToken", &auth_service_with_token)) { |
+ SendErrorAndExit(std::move(response), |
"'authServiceWithToken' not found in request."); |
- return; |
- } |
+ return; |
+ } |
- // For backward compatibility the webapp still passes OAuth service as part of |
- // the authServiceWithToken field. But auth service part is always expected to |
- // be set to oauth2. |
- const char kOAuth2ServicePrefix[] = "oauth2:"; |
- if (!base::StartsWith(auth_service_with_token, kOAuth2ServicePrefix, |
- base::CompareCase::SENSITIVE)) { |
- SendErrorAndExit(std::move(response), "Invalid 'authServiceWithToken': " + |
- auth_service_with_token); |
- return; |
- } |
+ // For backward compatibility the webapp still passes OAuth service as part |
+ // of the authServiceWithToken field. But auth service part is always |
+ // expected to be set to oauth2. |
+ const char kOAuth2ServicePrefix[] = "oauth2:"; |
+ if (!base::StartsWith(auth_service_with_token, kOAuth2ServicePrefix, |
+ base::CompareCase::SENSITIVE)) { |
+ SendErrorAndExit(std::move(response), "Invalid 'authServiceWithToken': " + |
+ auth_service_with_token); |
+ return; |
+ } |
- xmpp_config.auth_token = |
- auth_service_with_token.substr(strlen(kOAuth2ServicePrefix)); |
+ xmpp_config.auth_token = |
+ auth_service_with_token.substr(strlen(kOAuth2ServicePrefix)); |
#if !defined(NDEBUG) |
- std::string address; |
- if (!message->GetString("xmppServerAddress", &address)) { |
- SendErrorAndExit(std::move(response), |
- "'xmppServerAddress' not found in request."); |
- return; |
- } |
+ std::string address; |
+ if (!message->GetString("xmppServerAddress", &address)) { |
+ SendErrorAndExit(std::move(response), |
+ "'xmppServerAddress' not found in request."); |
+ return; |
+ } |
- if (!net::ParseHostAndPort(address, &xmpp_config.host, |
- &xmpp_config.port)) { |
- SendErrorAndExit(std::move(response), |
- "Invalid 'xmppServerAddress': " + address); |
- return; |
- } |
+ if (!net::ParseHostAndPort(address, &xmpp_config.host, |
+ &xmpp_config.port)) { |
+ SendErrorAndExit(std::move(response), |
+ "Invalid 'xmppServerAddress': " + address); |
+ return; |
+ } |
- if (!message->GetBoolean("xmppServerUseTls", &xmpp_config.use_tls)) { |
- SendErrorAndExit(std::move(response), |
- "'xmppServerUseTls' not found in request."); |
- return; |
+ if (!message->GetBoolean("xmppServerUseTls", &xmpp_config.use_tls)) { |
+ SendErrorAndExit(std::move(response), |
+ "'xmppServerUseTls' not found in request."); |
+ return; |
+ } |
+#endif // !defined(NDEBUG) |
+ signal_strategy.reset(new XmppSignalStrategy( |
Sergey Ulanov
2016/10/05 21:49:06
nit: add empty line here
kelvinp
2016/10/06 00:43:05
Done.
|
+ net::ClientSocketFactory::GetDefaultFactory(), |
+ host_context_->url_request_context_getter(), xmpp_config)); |
+ } else { |
+ std::string host_jid; |
+ |
+ if (!message->GetString("hostJid", &host_jid)) { |
Sergey Ulanov
2016/10/05 21:49:06
maybe call this localJid and local_jid?
kelvinp
2016/10/06 00:43:05
Done.
|
+ SendErrorAndExit(std::move(response), "'hostJid' not found in request."); |
+ return; |
+ } |
+ |
+ delegating_signal_strategy_ = new DelegatingSignalStrategy( |
+ host_jid, |
+ task_runner(), |
Sergey Ulanov
2016/10/05 21:49:06
'git cl format' please
kelvinp
2016/10/06 00:43:05
Done.
|
+ host_context_->network_task_runner(), |
+ base::Bind(&It2MeNativeMessagingHost::SendOutgoingIq, |
+ weak_factory_.GetWeakPtr())); |
+ signal_strategy.reset(delegating_signal_strategy_); |
} |
+#if !defined(NDEBUG) |
if (!message->GetString("directoryBotJid", &directory_bot_jid_)) { |
SendErrorAndExit(std::move(response), |
"'directoryBotJid' not found in request."); |
@@ -285,7 +316,9 @@ void It2MeNativeMessagingHost::ProcessConnect( |
// Create the It2Me host and start connecting. |
it2me_host_ = |
factory_->CreateIt2MeHost(host_context_->Copy(), policy_service_, |
- weak_ptr_, xmpp_config, directory_bot_jid_); |
+ weak_ptr_, std::move(signal_strategy), |
+ xmpp_server_config_.username, |
+ directory_bot_jid_); |
it2me_host_->Connect(); |
SendMessageToClient(std::move(response)); |
@@ -317,6 +350,28 @@ void It2MeNativeMessagingHost::ProcessDisconnect( |
SendMessageToClient(std::move(response)); |
} |
+void It2MeNativeMessagingHost::ProcessIncomingIq( |
+ std::unique_ptr<base::DictionaryValue>message, |
+ std::unique_ptr<base::DictionaryValue> response) { |
+ |
+ std::string iq; |
+ if (!message->GetString("iq", &iq)) { |
+ LOG(ERROR) << "Invalid incomingIq() data."; |
+ return; |
+ } |
+ |
+ if (delegating_signal_strategy_) |
+ delegating_signal_strategy_->OnIncomingMessage(iq); |
+ SendMessageToClient(std::move(response)); |
+}; |
+ |
+void It2MeNativeMessagingHost::SendOutgoingIq(const std::string& iq) { |
+ std::unique_ptr<base::DictionaryValue> message(new base::DictionaryValue()); |
+ message->SetString("iq", iq); |
+ message->SetString("type", "sendOutgoingIq"); |
+ SendMessageToClient(std::move(message)); |
+} |
+ |
void It2MeNativeMessagingHost::SendErrorAndExit( |
std::unique_ptr<base::DictionaryValue> response, |
const std::string& description) const { |