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 #ifndef BLIMP_CLIENT_FEATURE_RENDER_WIDGET_FEATURE_H_ | |
6 #define BLIMP_CLIENT_FEATURE_RENDER_WIDGET_FEATURE_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <map> | |
11 #include <memory> | |
12 | |
13 #include "base/containers/small_map.h" | |
14 #include "base/macros.h" | |
15 #include "blimp/net/blimp_message_processor.h" | |
16 #include "blimp/net/input_message_generator.h" | |
17 | |
18 namespace blink { | |
19 class WebGestureEvent; | |
20 } | |
21 | |
22 namespace cc { | |
23 namespace proto { | |
24 class CompositorMessage; | |
25 } | |
26 } | |
27 | |
28 namespace blimp { | |
29 class RenderWidgetMessage; | |
30 class CompositorMessage; | |
31 | |
32 namespace client { | |
33 | |
34 // Handles all incoming and outgoing protobuf message types tied to a specific | |
35 // RenderWidget. This includes BlimpMessage::INPUT, BlimpMessage::COMPOSITOR, | |
36 // and BlimpMessage::RENDER_WIDGET messages. Delegates can be added to be | |
37 // notified of incoming messages. This class automatically attaches a specific | |
38 // id so that the engine can drop stale RenderWidget related messages after it | |
39 // sends a RenderWidgetMessage::INITIALIZE message. | |
40 class RenderWidgetFeature : public BlimpMessageProcessor { | |
41 public: | |
42 // A delegate to be notified of specific RenderWidget related incoming events. | |
43 class RenderWidgetFeatureDelegate { | |
44 public: | |
45 virtual ~RenderWidgetFeatureDelegate() {} | |
46 virtual void OnRenderWidgetCreated(int render_widget_id) = 0; | |
47 | |
48 // Called when the engine's RenderWidget has changed for a particular | |
49 // WebContents. When this is received all state related to the existing | |
50 // client RenderWidget should be reset. | |
51 virtual void OnRenderWidgetInitialized(int render_widget_id) = 0; | |
52 | |
53 virtual void OnRenderWidgetDeleted(int render_widget_id) = 0; | |
54 | |
55 // Called when the engine sent a CompositorMessage. These messages should | |
56 // be sent to the client's RemoteChannel of the compositor. | |
57 virtual void OnCompositorMessageReceived( | |
58 int render_widget_id, | |
59 std::unique_ptr<cc::proto::CompositorMessage> message) = 0; | |
60 }; | |
61 | |
62 RenderWidgetFeature(); | |
63 ~RenderWidgetFeature() override; | |
64 | |
65 // Set the BlimpMessageProcessor that will be used to send BlimpMessage::INPUT | |
66 // messages to the engine. | |
67 void set_outgoing_input_message_processor( | |
68 std::unique_ptr<BlimpMessageProcessor> processor); | |
69 | |
70 // Set the BlimpMessageProcessor that will be used to send | |
71 // BlimpMessage::COMPOSITOR messages to the engine. | |
72 void set_outgoing_compositor_message_processor( | |
73 std::unique_ptr<BlimpMessageProcessor> processor); | |
74 | |
75 // Sends a WebGestureEvent for |tab_id| to the engine. | |
76 void SendWebGestureEvent(const int tab_id, | |
77 const int render_widget_id, | |
78 const blink::WebGestureEvent& event); | |
79 | |
80 // Sends a CompositorMessage for |tab_id| to the engine. | |
81 void SendCompositorMessage(const int tab_id, | |
82 const int render_widget_id, | |
83 const cc::proto::CompositorMessage& message); | |
84 | |
85 // Sets a RenderWidgetMessageDelegate to be notified of all incoming | |
86 // RenderWidget related messages for |tab_id| from the engine. There can only | |
87 // be one RenderWidgetMessageDelegate per tab. | |
88 // virtual for testing. | |
89 virtual void SetDelegate(int tab_id, RenderWidgetFeatureDelegate* delegate); | |
90 virtual void RemoveDelegate(const int tab_id); | |
91 | |
92 // BlimpMessageProcessor implementation. | |
93 void ProcessMessage(std::unique_ptr<BlimpMessage> message, | |
94 const net::CompletionCallback& callback) override; | |
95 | |
96 private: | |
97 void ProcessRenderWidgetMessage( | |
98 RenderWidgetFeatureDelegate* delegate, | |
99 const RenderWidgetMessage& message); | |
100 | |
101 void ProcessCompositorMessage(RenderWidgetFeatureDelegate* delegate, | |
102 const CompositorMessage& message); | |
103 | |
104 // Returns nullptr if no delegate is found. | |
105 RenderWidgetFeatureDelegate* FindDelegate(const int tab_id); | |
106 | |
107 typedef base::SmallMap<std::map<int, RenderWidgetFeatureDelegate*>> | |
108 DelegateMap; | |
109 | |
110 DelegateMap delegates_; | |
111 | |
112 InputMessageGenerator input_message_generator_; | |
113 | |
114 // Used to send BlimpMessage::INPUT type messages to the engine. | |
115 std::unique_ptr<BlimpMessageProcessor> outgoing_input_message_processor_; | |
116 | |
117 // Used to send BlimpMessage::COMPOSITOR messages to the engine. | |
118 std::unique_ptr<BlimpMessageProcessor> outgoing_compositor_message_processor_; | |
119 | |
120 DISALLOW_COPY_AND_ASSIGN(RenderWidgetFeature); | |
121 }; | |
122 | |
123 } // namespace client | |
124 } // namespace blimp | |
125 | |
126 #endif // BLIMP_CLIENT_FEATURE_RENDER_WIDGET_FEATURE_H_ | |
OLD | NEW |