Chromium Code Reviews| Index: blimp/client/render_widget_message_processor.cc |
| diff --git a/blimp/client/render_widget_message_processor.cc b/blimp/client/render_widget_message_processor.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..09f5784e9d1267ca495ba29db3f7b3404857a357 |
| --- /dev/null |
| +++ b/blimp/client/render_widget_message_processor.cc |
| @@ -0,0 +1,129 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "blimp/client/render_widget_message_processor.h" |
| + |
| +#include "base/numerics/safe_conversions.h" |
| +#include "blimp/common/proto/blimp_message.pb.h" |
| +#include "blimp/common/proto/compositor.pb.h" |
| +#include "blimp/common/proto/input.pb.h" |
| +#include "blimp/common/proto/render_widget.pb.h" |
| +#include "cc/proto/compositor_message.pb.h" |
| +#include "net/base/net_errors.h" |
| + |
| +namespace blimp { |
| + |
| +RenderWidgetMessageProcessor::RenderWidgetMessageProcessor( |
| + BlimpMessageProcessor* outgoing_message_processor) |
| + : outgoing_message_processor_(outgoing_message_processor) { |
| + // TODO(dtrainor): Register as a BlimpMessageProcessor for |
| + // BlimpMessage::RENDER_WIDGET and BlimpMessage::COMPOSITOR messages. |
| +} |
| + |
| +RenderWidgetMessageProcessor::~RenderWidgetMessageProcessor() { |
| + // TODO(dtrainor): Unregister as a BlimpMessageProcessor for |
| + // BlimpMessage::RENDER_WIDGET and BlimpMessage::COMPOSITOR messages. |
| +} |
| + |
| +void RenderWidgetMessageProcessor::SendInputEvent( |
| + const int tab_id, const blink::WebInputEvent& event) { |
| + scoped_ptr<BlimpMessage> blimp_message(new BlimpMessage); |
| + blimp_message->set_type(BlimpMessage::INPUT); |
|
Kevin M
2015/11/24 18:39:59
Can be omitted, the MultiplexedSender sets the typ
David Trainor- moved to gerrit
2015/11/25 17:56:41
Done.
|
| + blimp_message->set_target_tab_id(tab_id); |
| + |
| + InputMessage* input_message = blimp_message->mutable_input(); |
| + input_message->set_render_widget_id(GetRenderWidgetId(tab_id)); |
| + input_message_generator_.GenerateMessage(&event, input_message); |
| + |
| + outgoing_message_processor_->ProcessMessage(blimp_message.Pass(), |
|
Kevin M
2015/11/24 18:39:59
The output message processors only handle one mess
David Trainor- moved to gerrit
2015/11/25 17:56:42
Done.
|
| + net::CompletionCallback()); |
| +} |
| + |
| +void RenderWidgetMessageProcessor::SendCompositorMessage( |
| + const int tab_id, |
| + const cc::proto::CompositorMessage& message) { |
| + scoped_ptr<BlimpMessage> blimp_message(new BlimpMessage); |
| + blimp_message->set_type(BlimpMessage::COMPOSITOR); |
| + blimp_message->set_target_tab_id(tab_id); |
| + |
| + CompositorMessage* compositor_message = blimp_message->mutable_compositor(); |
| + compositor_message->set_render_widget_id(GetRenderWidgetId(tab_id)); |
| + |
| + std::vector<uint8_t> payload(base::checked_cast<int>(message.ByteSize())); |
| + message.SerializeToArray(payload.data(), message.ByteSize()); |
|
Kevin M
2015/11/24 18:39:59
message.SerializeWithCachedSizes?
David Trainor- moved to gerrit
2015/11/25 17:56:42
Ended up doing SerializeToString().
|
| + |
| + compositor_message->set_payload(payload.data(), |
|
Kevin M
2015/11/24 18:39:59
What about serializing to *compositor_message->mut
David Trainor- moved to gerrit
2015/11/25 17:56:41
Good call. I ended up doing message->SerializeToS
|
| + base::checked_cast<int>(payload.size())); |
| + |
| + outgoing_message_processor_->ProcessMessage(blimp_message.Pass(), |
| + net::CompletionCallback()); |
| +} |
| + |
| +void RenderWidgetMessageProcessor::SetDelegate( |
| + const int tab_id, RenderWidgetMessageDelegate* delegate) { |
| + DCHECK(!FindDelegate(tab_id)); |
| + delegates_[tab_id] = delegate; |
| +} |
| + |
| +void RenderWidgetMessageProcessor::RemoveDelegate(const int tab_id) { |
| + DelegateMap::iterator it = delegates_.find(tab_id); |
| + if (it != delegates_.end()) |
| + delegates_.erase(it); |
| +} |
| + |
| +void RenderWidgetMessageProcessor::ProcessMessage( |
| + scoped_ptr<BlimpMessage> message, |
| + const net::CompletionCallback& callback) { |
| + DCHECK(message->type() == BlimpMessage::RENDER_WIDGET || |
| + message->type() == BlimpMessage::COMPOSITOR); |
| + |
| + int target_tab_id = message->target_tab_id(); |
| + RenderWidgetMessageDelegate* delegate = FindDelegate(target_tab_id); |
| + DCHECK(delegate); |
| + |
| + switch (message->type()) { |
| + case BlimpMessage::RENDER_WIDGET: |
| + if (message->render_widget().type() == RenderWidgetMessage::INITIALIZE) { |
| + render_widget_ids_[target_tab_id] = |
| + message->render_widget().render_widget_id(); |
| + delegate->OnRenderWidgetInitialized(); |
| + } |
| + break; |
| + case BlimpMessage::COMPOSITOR: |
| + { |
| + DCHECK_EQ(message->compositor().render_widget_id(), |
| + GetRenderWidgetId(target_tab_id)); |
| + scoped_ptr<cc::proto::CompositorMessage> payload( |
| + new cc::proto::CompositorMessage); |
| + if (payload->ParseFromString(message->compositor().payload())) { |
| + delegate->OnCompositorMessageReceived(payload.Pass()); |
| + } |
| + } |
| + break; |
| + default: |
| + NOTIMPLEMENTED(); |
| + } |
| + |
| + if (!callback.is_null()) { |
| + callback.Run(net::OK); |
| + } |
| +} |
| + |
| +RenderWidgetMessageProcessor::RenderWidgetMessageDelegate* |
| +RenderWidgetMessageProcessor::FindDelegate( |
| + const int tab_id) { |
| + DelegateMap::const_iterator it = delegates_.find(tab_id); |
| + if (it != delegates_.end()) |
| + return it->second; |
| + return nullptr; |
| +} |
| + |
| +uint32_t RenderWidgetMessageProcessor::GetRenderWidgetId(const int tab_id) { |
| + RenderWidgetIdMap::const_iterator it = render_widget_ids_.find(tab_id); |
| + if (it != render_widget_ids_.end()) |
| + return it->second; |
| + return 0U; |
|
Kevin M
2015/11/24 18:39:59
Does this indicate an error? Should callers be tes
David Trainor- moved to gerrit
2015/11/25 17:56:41
Yeah good point. I put a comment in the header an
|
| +} |
| + |
| +} // namespace blimp |