Index: content/browser/presentation/presentation_service_impl.cc |
diff --git a/content/browser/presentation/presentation_service_impl.cc b/content/browser/presentation/presentation_service_impl.cc |
index 19372a179473915a2e2c95a9b68e0f1dbe60b03e..8c5845b533a13ae1a88b4ca3dd63858e0ec9b932 100644 |
--- a/content/browser/presentation/presentation_service_impl.cc |
+++ b/content/browser/presentation/presentation_service_impl.cc |
@@ -10,12 +10,37 @@ |
#include "content/browser/presentation/presentation_type_converters.h" |
#include "content/public/browser/content_browser_client.h" |
#include "content/public/browser/navigation_details.h" |
+#include "content/public/browser/presentation_session_message.h" |
#include "content/public/browser/render_frame_host.h" |
#include "content/public/browser/render_process_host.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/common/content_client.h" |
#include "content/public/common/frame_navigate_params.h" |
+namespace { |
+ |
+// The return value takes ownership of the actual message of |input|. |
+presentation::SessionMessagePtr ToMojoSessionMessage( |
+ content::PresentationSessionMessage* input) { |
+ presentation::SessionMessagePtr output(presentation::SessionMessage::New()); |
+ output->presentation_url = input->presentation_url; |
+ output->presentation_id = input->presentation_id; |
+ if (input->is_binary()) { |
+ // binary data |
+ output->type = presentation::PresentationMessageType:: |
+ PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; |
+ output->data.Swap(input->data.get()); |
+ } else { |
+ // string message |
+ output->type = |
+ presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT; |
+ output->message.Swap(input->message.get()); |
+ } |
+ return output.Pass(); |
+} |
+ |
+} // namespace |
+ |
namespace content { |
PresentationServiceImpl::PresentationServiceImpl( |
@@ -335,7 +360,35 @@ bool PresentationServiceImpl::FrameMatches( |
void PresentationServiceImpl::ListenForSessionMessages( |
const SessionMessagesCallback& callback) { |
- NOTIMPLEMENTED(); |
+ DVLOG(2) << "ListenForSessionMessages"; |
+ if (!delegate_) { |
+ callback.Run(mojo::Array<presentation::SessionMessagePtr>()); |
+ return; |
+ } |
+ |
+ DCHECK(!on_session_messages_callback_.get()); |
imcheng (use chromium acct)
2015/05/04 19:53:55
I think we should just CHECK here. If renderer is
haibinlu
2015/05/04 21:33:49
Acknowledged.
|
+ |
+ on_session_messages_callback_.reset(new SessionMessagesCallback(callback)); |
+ delegate_->ListenForSessionMessages( |
+ render_process_id_, render_frame_id_, |
+ base::Bind(&PresentationServiceImpl::OnSessionMessages, |
+ weak_factory_.GetWeakPtr())); |
+} |
+ |
+void PresentationServiceImpl::OnSessionMessages( |
+ scoped_ptr<ScopedVector<PresentationSessionMessage>> messages) { |
+ DCHECK(messages.get() && messages->size() > 0); |
imcheng (use chromium acct)
2015/05/04 19:53:55
nit: check !messages->empty() instead of size() >
haibinlu
2015/05/04 21:33:49
Done.
|
+ if (!on_session_messages_callback_.get()) { |
+ // The Reset method of this class was invoked. |
+ return; |
+ } |
+ |
+ mojo::Array<presentation::SessionMessagePtr> mojoMessages(messages->size()); |
+ for (size_t i = 0; i < messages->size(); ++i) { |
+ mojoMessages[i] = ToMojoSessionMessage((*messages)[i]); |
+ } |
+ |
+ on_session_messages_callback_->Run(mojoMessages.Pass()); |
imcheng (use chromium acct)
2015/05/04 19:53:55
Reset on_session_messages_callback_ after Run().
haibinlu
2015/05/04 21:33:49
Done.
|
} |
void PresentationServiceImpl::DidNavigateAnyFrame( |
@@ -388,6 +441,11 @@ void PresentationServiceImpl::Reset() { |
queued_start_session_requests_.clear(); |
FlushNewSessionCallbacks(); |
default_session_start_context_.reset(); |
+ if (on_session_messages_callback_.get()) { |
+ on_session_messages_callback_->Run( |
+ mojo::Array<presentation::SessionMessagePtr>()); |
imcheng (use chromium acct)
2015/05/04 19:53:55
It looks like you would also need to change Presen
haibinlu
2015/05/04 21:33:50
Done.
|
+ on_session_messages_callback_.reset(); |
+ } |
} |
// static |