Chromium Code Reviews| Index: remoting/protocol/jingle_session.cc |
| diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc |
| index f421b025e6716af41571af663bc24fefa1568f53..a5cb90b1bc72cf09f3d3cb306a81bbffe8d3ac4a 100644 |
| --- a/remoting/protocol/jingle_session.cc |
| +++ b/remoting/protocol/jingle_session.cc |
| @@ -7,9 +7,11 @@ |
| #include <stdint.h> |
| #include <limits> |
| +#include <memory> |
| #include <utility> |
| #include "base/bind.h" |
| +#include "base/callback.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/stl_util.h" |
| #include "base/strings/string_split.h" |
| @@ -21,6 +23,7 @@ |
| #include "remoting/protocol/jingle_messages.h" |
| #include "remoting/protocol/jingle_session_manager.h" |
| #include "remoting/protocol/session_config.h" |
| +#include "remoting/protocol/session_plugin.h" |
| #include "remoting/protocol/transport.h" |
| #include "remoting/signaling/iq_sender.h" |
| #include "third_party/webrtc/libjingle/xmllite/xmlelement.h" |
| @@ -208,14 +211,11 @@ void JingleSession::StartConnection( |
| session_id_ = base::Uint64ToString( |
| base::RandGenerator(std::numeric_limits<uint64_t>::max())); |
| - // Send session-initiate message. |
| - std::unique_ptr<JingleMessage> message(new JingleMessage( |
| - peer_address_, JingleMessage::SESSION_INITIATE, session_id_)); |
| - message->initiator = session_manager_->signal_strategy_->GetLocalJid(); |
| - message->description.reset(new ContentDescription( |
| - session_manager_->protocol_config_->Clone(), |
| - authenticator_->GetNextMessage())); |
| - SendMessage(std::move(message)); |
| + // Delay sending session-initiate message to ensure SessionPlugin can be |
| + // attached before the message. |
| + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| + base::Bind(&JingleSession::SendSessionInitiateMessage, |
| + weak_factory_.GetWeakPtr())); |
| SetState(CONNECTING); |
| } |
| @@ -249,6 +249,7 @@ void JingleSession::AcceptIncomingConnection( |
| const JingleMessage& initiate_message) { |
| DCHECK(config_); |
| + ExecutePluginsOnIncomingMessage(initiate_message); |
| // Process the first authentication message. |
| const buzz::XmlElement* first_auth_message = |
| initiate_message.description->authenticator_message(); |
| @@ -322,6 +323,7 @@ void JingleSession::SendTransportInfo( |
| std::unique_ptr<JingleMessage> message(new JingleMessage( |
| peer_address_, JingleMessage::TRANSPORT_INFO, session_id_)); |
| message->transport_info = std::move(transport_info); |
| + ExecutePluginsOnOutgoingMessage(message.get()); |
| std::unique_ptr<buzz::XmlElement> stanza = message->ToXml(); |
| stanza->AddAttr(buzz::QN_ID, GetNextOutgoingId()); |
| @@ -386,9 +388,23 @@ void JingleSession::Close(protocol::ErrorCode error) { |
| } |
| } |
| +void JingleSession::AddPlugin(SessionPlugin* plugin) { |
| + DCHECK(plugin); |
| + plugins_.push_back(plugin); |
| +} |
| + |
| void JingleSession::SendMessage(std::unique_ptr<JingleMessage> message) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| + if (message->action != JingleMessage::SESSION_TERMINATE) { |
| + // When the host accepts session-initiate message from a client JID it |
| + // doesn't recognize it sends session-terminate without session-accept. |
| + // Attaching plugin information to this session-terminate message may lead |
| + // to privacy issues (e.g. leaking Windows version to someone who does not |
| + // own the host). So a simply approach is to ignore plugins when sending |
| + // SESSION_TERMINATE message. |
| + ExecutePluginsOnOutgoingMessage(message.get()); |
| + } |
| std::unique_ptr<buzz::XmlElement> stanza = message->ToXml(); |
| stanza->AddAttr(buzz::QN_ID, GetNextOutgoingId()); |
| @@ -482,6 +498,7 @@ void JingleSession::OnTransportInfoResponse(IqRequest* request, |
| void JingleSession::OnIncomingMessage(const std::string& id, |
| std::unique_ptr<JingleMessage> message, |
| const ReplyCallback& reply_callback) { |
| + ExecutePluginsOnIncomingMessage(*message); |
| std::vector<PendingMessage> ordered = message_queue_->OnIncomingMessage( |
| id, PendingMessage{std::move(message), reply_callback}); |
| base::WeakPtr<JingleSession> self = weak_factory_.GetWeakPtr(); |
| @@ -747,6 +764,35 @@ bool JingleSession::is_session_active() { |
| state_ == AUTHENTICATING || state_ == AUTHENTICATED; |
| } |
| +void JingleSession::ExecutePluginsOnIncomingMessage( |
|
Sergey Ulanov
2016/12/29 00:37:58
Maybe call it ProcessIncomingAttachments() or Proc
Hzj_jie
2016/12/29 03:07:56
Done.
|
| + const JingleMessage& message) { |
| + if (message.attachments) { |
|
Sergey Ulanov
2016/12/29 00:37:58
if (!messeage.attachments) {
return;
}
Hzj_jie
2016/12/29 03:07:57
Done.
|
| + for (const auto& plugin : plugins_) { |
| + plugin->OnIncomingMessage(*(message.attachments)); |
| + } |
| + } |
| +} |
| + |
| +void JingleSession::ExecutePluginsOnOutgoingMessage(JingleMessage* message) { |
|
Sergey Ulanov
2016/12/29 00:37:58
Maybe AddPluginAttachments() or something like tha
Hzj_jie
2016/12/29 03:07:57
Done.
|
| + DCHECK(message); |
| + for (const auto& plugin : plugins_) { |
| + std::unique_ptr<XmlElement> attachment = plugin->GetNextMessage(); |
| + if (attachment) { |
| + message->AddAttachment(std::move(attachment)); |
| + } |
| + } |
| +} |
| + |
| +void JingleSession::SendSessionInitiateMessage() { |
| + std::unique_ptr<JingleMessage> message(new JingleMessage( |
|
Sergey Ulanov
2016/12/29 00:37:58
Need to check here that the state_ is still CONNEC
Hzj_jie
2016/12/29 03:07:56
Done.
|
| + peer_address_, JingleMessage::SESSION_INITIATE, session_id_)); |
| + message->initiator = session_manager_->signal_strategy_->GetLocalJid(); |
| + message->description.reset(new ContentDescription( |
| + session_manager_->protocol_config_->Clone(), |
| + authenticator_->GetNextMessage())); |
| + SendMessage(std::move(message)); |
| +} |
| + |
| std::string JingleSession::GetNextOutgoingId() { |
| return outgoing_id_prefix_ + "_" + base::IntToString(++next_outgoing_id_); |
| } |