OLD | NEW |
---|---|
(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/client/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 "cc/proto/compositor_message.pb.h" | |
13 #include "net/base/net_errors.h" | |
14 | |
15 namespace blimp { | |
16 | |
17 RenderWidgetMessageProcessor::RenderWidgetMessageProcessor( | |
18 BlimpMessageProcessor* outgoing_message_processor) | |
19 : outgoing_message_processor_(outgoing_message_processor) { | |
20 // TODO(dtrainor): Register as a BlimpMessageProcessor for | |
21 // BlimpMessage::RENDER_WIDGET and BlimpMessage::COMPOSITOR messages. | |
22 } | |
23 | |
24 RenderWidgetMessageProcessor::~RenderWidgetMessageProcessor() { | |
25 // TODO(dtrainor): Unregister as a BlimpMessageProcessor for | |
26 // BlimpMessage::RENDER_WIDGET and BlimpMessage::COMPOSITOR messages. | |
27 } | |
28 | |
29 void RenderWidgetMessageProcessor::SendInputEvent( | |
30 const int tab_id, const blink::WebInputEvent& event) { | |
31 scoped_ptr<BlimpMessage> blimp_message(new BlimpMessage); | |
32 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.
| |
33 blimp_message->set_target_tab_id(tab_id); | |
34 | |
35 InputMessage* input_message = blimp_message->mutable_input(); | |
36 input_message->set_render_widget_id(GetRenderWidgetId(tab_id)); | |
37 input_message_generator_.GenerateMessage(&event, input_message); | |
38 | |
39 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.
| |
40 net::CompletionCallback()); | |
41 } | |
42 | |
43 void RenderWidgetMessageProcessor::SendCompositorMessage( | |
44 const int tab_id, | |
45 const cc::proto::CompositorMessage& message) { | |
46 scoped_ptr<BlimpMessage> blimp_message(new BlimpMessage); | |
47 blimp_message->set_type(BlimpMessage::COMPOSITOR); | |
48 blimp_message->set_target_tab_id(tab_id); | |
49 | |
50 CompositorMessage* compositor_message = blimp_message->mutable_compositor(); | |
51 compositor_message->set_render_widget_id(GetRenderWidgetId(tab_id)); | |
52 | |
53 std::vector<uint8_t> payload(base::checked_cast<int>(message.ByteSize())); | |
54 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().
| |
55 | |
56 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
| |
57 base::checked_cast<int>(payload.size())); | |
58 | |
59 outgoing_message_processor_->ProcessMessage(blimp_message.Pass(), | |
60 net::CompletionCallback()); | |
61 } | |
62 | |
63 void RenderWidgetMessageProcessor::SetDelegate( | |
64 const int tab_id, RenderWidgetMessageDelegate* delegate) { | |
65 DCHECK(!FindDelegate(tab_id)); | |
66 delegates_[tab_id] = delegate; | |
67 } | |
68 | |
69 void RenderWidgetMessageProcessor::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 RenderWidgetMessageProcessor::ProcessMessage( | |
76 scoped_ptr<BlimpMessage> message, | |
77 const net::CompletionCallback& callback) { | |
78 DCHECK(message->type() == BlimpMessage::RENDER_WIDGET || | |
79 message->type() == BlimpMessage::COMPOSITOR); | |
80 | |
81 int target_tab_id = message->target_tab_id(); | |
82 RenderWidgetMessageDelegate* delegate = FindDelegate(target_tab_id); | |
83 DCHECK(delegate); | |
84 | |
85 switch (message->type()) { | |
86 case BlimpMessage::RENDER_WIDGET: | |
87 if (message->render_widget().type() == RenderWidgetMessage::INITIALIZE) { | |
88 render_widget_ids_[target_tab_id] = | |
89 message->render_widget().render_widget_id(); | |
90 delegate->OnRenderWidgetInitialized(); | |
91 } | |
92 break; | |
93 case BlimpMessage::COMPOSITOR: | |
94 { | |
95 DCHECK_EQ(message->compositor().render_widget_id(), | |
96 GetRenderWidgetId(target_tab_id)); | |
97 scoped_ptr<cc::proto::CompositorMessage> payload( | |
98 new cc::proto::CompositorMessage); | |
99 if (payload->ParseFromString(message->compositor().payload())) { | |
100 delegate->OnCompositorMessageReceived(payload.Pass()); | |
101 } | |
102 } | |
103 break; | |
104 default: | |
105 NOTIMPLEMENTED(); | |
106 } | |
107 | |
108 if (!callback.is_null()) { | |
109 callback.Run(net::OK); | |
110 } | |
111 } | |
112 | |
113 RenderWidgetMessageProcessor::RenderWidgetMessageDelegate* | |
114 RenderWidgetMessageProcessor::FindDelegate( | |
115 const int tab_id) { | |
116 DelegateMap::const_iterator it = delegates_.find(tab_id); | |
117 if (it != delegates_.end()) | |
118 return it->second; | |
119 return nullptr; | |
120 } | |
121 | |
122 uint32_t RenderWidgetMessageProcessor::GetRenderWidgetId(const int tab_id) { | |
123 RenderWidgetIdMap::const_iterator it = render_widget_ids_.find(tab_id); | |
124 if (it != render_widget_ids_.end()) | |
125 return it->second; | |
126 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
| |
127 } | |
128 | |
129 } // namespace blimp | |
OLD | NEW |