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

Side by Side Diff: blimp/client/core/render_widget/render_widget_feature.cc

Issue 2624903006: Remove all blimp client code. (Closed)
Patch Set: Update buildbot configuration Created 3 years, 11 months 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/client/core/render_widget/render_widget_feature.h"
6
7 #include "base/numerics/safe_conversions.h"
8 #include "blimp/common/create_blimp_message.h"
9 #include "blimp/common/proto/blimp_message.pb.h"
10 #include "blimp/common/proto/compositor.pb.h"
11 #include "blimp/common/proto/input.pb.h"
12 #include "blimp/common/proto/render_widget.pb.h"
13 #include "cc/proto/compositor_message.pb.h"
14 #include "net/base/net_errors.h"
15
16 namespace blimp {
17 namespace client {
18
19 RenderWidgetFeature::RenderWidgetFeature() {}
20
21 RenderWidgetFeature::~RenderWidgetFeature() {}
22
23 void RenderWidgetFeature::set_outgoing_input_message_processor(
24 std::unique_ptr<BlimpMessageProcessor> processor) {
25 outgoing_input_message_processor_ = std::move(processor);
26 }
27
28 void RenderWidgetFeature::set_outgoing_compositor_message_processor(
29 std::unique_ptr<BlimpMessageProcessor> processor) {
30 outgoing_compositor_message_processor_ = std::move(processor);
31 }
32
33 void RenderWidgetFeature::SendWebGestureEvent(
34 const int tab_id,
35 const int render_widget_id,
36 const blink::WebGestureEvent& event) {
37 std::unique_ptr<BlimpMessage> blimp_message =
38 input_message_generator_.GenerateMessage(event);
39
40 // Don't send unsupported WebGestureEvents.
41 if (!blimp_message)
42 return;
43
44 blimp_message->set_target_tab_id(tab_id);
45 blimp_message->mutable_input()->set_render_widget_id(render_widget_id);
46
47 outgoing_input_message_processor_->ProcessMessage(std::move(blimp_message),
48 net::CompletionCallback());
49 }
50
51 void RenderWidgetFeature::SendCompositorMessage(
52 const int tab_id,
53 const int render_widget_id,
54 const cc::proto::CompositorMessage& message) {
55 CompositorMessage* compositor_message;
56 std::unique_ptr<BlimpMessage> blimp_message =
57 CreateBlimpMessage(&compositor_message, tab_id);
58
59 compositor_message->set_render_widget_id(render_widget_id);
60 compositor_message->mutable_payload()->resize(
61 base::checked_cast<size_t>(message.ByteSize()));
62 if (message.SerializeToString(compositor_message->mutable_payload())) {
63 outgoing_compositor_message_processor_->ProcessMessage(
64 std::move(blimp_message), net::CompletionCallback());
65 } else {
66 LOG(ERROR) << "Unable to serialize compositor proto.";
67 }
68 }
69
70 void RenderWidgetFeature::SetDelegate(const int tab_id,
71 RenderWidgetFeatureDelegate* delegate) {
72 DCHECK(!FindDelegate(tab_id));
73 delegates_[tab_id] = delegate;
74 }
75
76 void RenderWidgetFeature::RemoveDelegate(const int tab_id) {
77 DelegateMap::iterator it = delegates_.find(tab_id);
78 if (it != delegates_.end())
79 delegates_.erase(it);
80 }
81
82 void RenderWidgetFeature::ProcessMessage(
83 std::unique_ptr<BlimpMessage> message,
84 const net::CompletionCallback& callback) {
85 DCHECK(!callback.is_null());
86 DCHECK(BlimpMessage::kRenderWidget == message->feature_case() ||
87 BlimpMessage::kCompositor == message->feature_case());
88
89 int target_tab_id = message->target_tab_id();
90 RenderWidgetFeatureDelegate* delegate = FindDelegate(target_tab_id);
91 if (!delegate) {
92 VLOG(1) << "RenderWidgetFeatureDelegate not found for " << target_tab_id
93 << ". Ignoring.";
94 callback.Run(net::OK);
95 return;
96 }
97
98 switch (message->feature_case()) {
99 case BlimpMessage::kRenderWidget:
100 ProcessRenderWidgetMessage(delegate, message->render_widget());
101 break;
102 case BlimpMessage::kCompositor:
103 ProcessCompositorMessage(delegate, message->compositor());
104 break;
105 default:
106 NOTREACHED();
107 break;
108 }
109
110 callback.Run(net::OK);
111 }
112
113 void RenderWidgetFeature::ProcessRenderWidgetMessage(
114 RenderWidgetFeatureDelegate* delegate,
115 const RenderWidgetMessage& message) {
116 int render_widget_id = message.render_widget_id();
117
118 switch (message.type()) {
119 case RenderWidgetMessage::CREATED:
120 delegate->OnRenderWidgetCreated(render_widget_id);
121 break;
122 case RenderWidgetMessage::INITIALIZE:
123 delegate->OnRenderWidgetInitialized(render_widget_id);
124 break;
125 case RenderWidgetMessage::DELETED:
126 delegate->OnRenderWidgetDeleted(render_widget_id);
127 break;
128 case RenderWidgetMessage::UNKNOWN:
129 NOTREACHED();
130 break;
131 }
132 }
133
134 void RenderWidgetFeature::ProcessCompositorMessage(
135 RenderWidgetFeatureDelegate* delegate,
136 const CompositorMessage& message) {
137 int render_widget_id = message.render_widget_id();
138
139 std::unique_ptr<cc::proto::CompositorMessage> payload(
140 new cc::proto::CompositorMessage);
141 if (payload->ParseFromString(message.payload())) {
142 delegate->OnCompositorMessageReceived(render_widget_id, std::move(payload));
143 }
144 }
145
146 RenderWidgetFeature::RenderWidgetFeatureDelegate*
147 RenderWidgetFeature::FindDelegate(const int tab_id) {
148 DelegateMap::const_iterator it = delegates_.find(tab_id);
149 if (it != delegates_.end())
150 return it->second;
151 return nullptr;
152 }
153
154 } // namespace client
155 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698