Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2943)

Unified Diff: blimp/client/render_widget_message_processor.cc

Issue 1450423002: Add glue between the client and engine for Blimp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blimp_ipc2
Patch Set: Fixed net callback, fixed output surface creation assumption Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+ 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(),
+ 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());
+
+ compositor_message->set_payload(payload.data(),
+ 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;
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698