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

Side by Side Diff: blimp/engine/browser/host_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: Address comments! 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "blimp/engine/browser/host_render_widget_message_processor.h"
6
7 #include "base/numerics/safe_conversions.h"
8 #include "blimp/common/proto/blimp_message.pb.h"
9 #include "blimp/common/proto/compositor.pb.h"
10 #include "blimp/common/proto/input.pb.h"
11 #include "blimp/common/proto/render_widget.pb.h"
12 #include "net/base/net_errors.h"
13 #include "third_party/WebKit/public/web/WebInputEvent.h"
14
15 namespace blimp {
16
17 HostRenderWidgetMessageProcessor::HostRenderWidgetMessageProcessor(
18 BlimpMessageProcessor* outgoing_message_processor)
19 : outgoing_message_processor_(outgoing_message_processor) {
20 // TODO(dtrainor): Register as a BlimpMessageProcessor for
21 // BlimpMessage::INPUT and BlimpMessage::COMPOSITOR messages.
22 }
23
24 HostRenderWidgetMessageProcessor::~HostRenderWidgetMessageProcessor() {
25 // TODO(dtrainor): Unregister as a BlimpMessageProcessor for
26 // BlimpMessage::INPUT and BlimpMessage::COMPOSITOR messages.
27 }
28
29 void HostRenderWidgetMessageProcessor::OnRenderWidgetInitialized(
30 const int tab_id) {
31 render_widget_ids_[tab_id] = GetRenderWidgetId(tab_id) + 1;
32
33 scoped_ptr<BlimpMessage> blimp_message(new BlimpMessage);
34 blimp_message->set_type(BlimpMessage::RENDER_WIDGET);
35 blimp_message->set_target_tab_id(tab_id);
36
37 RenderWidgetMessage* render_widget_message =
38 blimp_message->mutable_render_widget();
39
40 render_widget_message->set_type(RenderWidgetMessage::INITIALIZE);
41 render_widget_message->set_render_widget_id(GetRenderWidgetId(tab_id));
42
43 outgoing_message_processor_->ProcessMessage(blimp_message.Pass(),
44 net::CompletionCallback());
45 }
46
47 void HostRenderWidgetMessageProcessor::SendCompositorMessage(
48 const int tab_id,
49 const std::vector<uint8_t>& message) {
Kevin M 2015/11/24 18:39:59 Take a compositor proto scoped ptr?
David Trainor- moved to gerrit 2015/11/25 17:56:42 Can't. At this point we don't have one. It's bee
50 scoped_ptr<BlimpMessage> blimp_message(new BlimpMessage);
51 blimp_message->set_type(BlimpMessage::COMPOSITOR);
52 blimp_message->set_target_tab_id(tab_id);
53
54 CompositorMessage* compositor_message = blimp_message->mutable_compositor();
55 compositor_message->set_render_widget_id(GetRenderWidgetId(tab_id));
56 compositor_message->set_payload(message.data(),
Kevin M 2015/11/24 18:39:59 set_allocated_payload?
David Trainor- moved to gerrit 2015/11/25 17:56:42 Does that work? It's an std::vector not an std::s
57 base::checked_cast<int>(message.size()));
58
59 outgoing_message_processor_->ProcessMessage(blimp_message.Pass(),
60 net::CompletionCallback());
61 }
62
63 void HostRenderWidgetMessageProcessor::SetDelegate(
64 const int tab_id, RenderWidgetMessageDelegate* delegate) {
65 DCHECK(!FindDelegate(tab_id));
66 delegates_[tab_id] = delegate;
67 }
68
69 void HostRenderWidgetMessageProcessor::RemoveDelegate(const int tab_id) {
70 DelegateMap::iterator it = delegates_.find(tab_id);
71 if (it != delegates_.end())
72 delegates_.erase(it);
73 }
74
75 void HostRenderWidgetMessageProcessor::ProcessMessage(
76 scoped_ptr<BlimpMessage> message,
77 const net::CompletionCallback& callback) {
78 DCHECK(message->type() == BlimpMessage::INPUT ||
79 message->type() == BlimpMessage::COMPOSITOR);
80
81 int target_tab_id = message->target_tab_id();
82 uint32_t render_widget_id = GetRenderWidgetId(target_tab_id);
83 DCHECK_GT(render_widget_id, 0U);
84
85 RenderWidgetMessageDelegate* delegate = FindDelegate(target_tab_id);
86 DCHECK(delegate);
87
88 switch (message->type()) {
89 case BlimpMessage::INPUT:
90 if (message->input().render_widget_id() == render_widget_id) {
91 scoped_ptr<blink::WebInputEvent> event =
92 input_message_processor_.ProcessMessage(message->input());
93 if (event)
94 delegate->OnWebInputEvent(event.Pass());
95 }
96 break;
97 case BlimpMessage::COMPOSITOR:
98 if (message->compositor().render_widget_id() == render_widget_id) {
99 std::vector<uint8_t> payload(message->compositor().payload().size());
100 memcpy(payload.data(),
101 message->compositor().payload().data(),
102 payload.size());
103 delegate->OnCompositorMessageReceived(payload);
104 }
105 break;
106 default:
107 NOTREACHED();
108 }
109
110 if (!callback.is_null()) {
111 callback.Run(net::OK);
112 }
113 }
114
115 HostRenderWidgetMessageProcessor::RenderWidgetMessageDelegate*
116 HostRenderWidgetMessageProcessor::FindDelegate(
117 const int tab_id) {
118 DelegateMap::const_iterator it = delegates_.find(tab_id);
119 if (it != delegates_.end())
120 return it->second;
121 return nullptr;
122 }
123
124 uint32_t HostRenderWidgetMessageProcessor::GetRenderWidgetId(const int tab_id) {
125 RenderWidgetIdMap::const_iterator it = render_widget_ids_.find(tab_id);
126 if (it != render_widget_ids_.end())
127 return it->second;
128 return 0U;
129 }
130
131 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698