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_COMPOSITOR_RENDER_WIDGET_MESSAGE_PROCESSOR_H_ |
| 6 #define BLIMP_CLIENT_COMPOSITOR_RENDER_WIDGET_MESSAGE_PROCESSOR_H_ |
| 7 |
| 8 #include "base/containers/small_map.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "blimp/client/blimp_client_export.h" |
| 12 #include "blimp/net/blimp_message_processor.h" |
| 13 #include "blimp/net/input_message_generator.h" |
| 14 |
| 15 namespace blink { |
| 16 class WebInputEvent; |
| 17 } |
| 18 |
| 19 namespace cc { |
| 20 namespace proto { |
| 21 class CompositorMessage; |
| 22 } |
| 23 } |
| 24 |
| 25 namespace blimp { |
| 26 |
| 27 // Handles all incoming and outgoing protobuf message types tied to a specific |
| 28 // RenderWidget. This includes BlimpMessage::INPUT, BlimpMessage::COMPOSITOR, |
| 29 // and BlimpMessage::RENDER_WIDGET messages. Delegates can be added to be |
| 30 // notified of incoming messages. This class automatically attaches a specific |
| 31 // id so that the engine can drop stale RenderWidget related messages after it |
| 32 // sends a RenderWidgetMessage::INITIALIZE message. |
| 33 class BLIMP_CLIENT_EXPORT RenderWidgetMessageProcessor |
| 34 : public BlimpMessageProcessor { |
| 35 public: |
| 36 // A delegate to be notified of specific RenderWidget related incoming events. |
| 37 class RenderWidgetMessageDelegate { |
| 38 public: |
| 39 // Called when the engine's RenderWidget has changed for a particular |
| 40 // WebContents. When this is received all state related to the existing |
| 41 // client RenderWidget should be reset. |
| 42 virtual void OnRenderWidgetInitialized() = 0; |
| 43 |
| 44 // Called when the engine sent a CompositorMessage. These messages should |
| 45 // be sent to the client's RemoteChannel of the compositor. |
| 46 virtual void OnCompositorMessageReceived( |
| 47 scoped_ptr<cc::proto::CompositorMessage> message) = 0; |
| 48 }; |
| 49 |
| 50 RenderWidgetMessageProcessor( |
| 51 BlimpMessageProcessor* input_message_processor, |
| 52 BlimpMessageProcessor* compositor_message_processor); |
| 53 ~RenderWidgetMessageProcessor() override; |
| 54 |
| 55 // Sends a WebInputEvent for |tab_id| to the engine. |
| 56 void SendInputEvent(const int tab_id, const blink::WebInputEvent& event); |
| 57 |
| 58 // Sends a CompositorMessage for |tab_id| to the engine. |
| 59 void SendCompositorMessage(const int tab_id, |
| 60 const cc::proto::CompositorMessage& message); |
| 61 |
| 62 // Sets a RenderWidgetMessageDelegate to be notified of all incoming |
| 63 // RenderWidget related messages for |tab_id| from the engine. There can only |
| 64 // be one RenderWidgetMessageDelegate per tab. |
| 65 void SetDelegate(const int tab_id, RenderWidgetMessageDelegate* delegate); |
| 66 void RemoveDelegate(const int tab_id); |
| 67 |
| 68 // BlimpMessageProcessor implementation. |
| 69 void ProcessMessage(scoped_ptr<BlimpMessage> message, |
| 70 const net::CompletionCallback& callback) override; |
| 71 |
| 72 private: |
| 73 // Returns nullptr if no delegate is found. |
| 74 RenderWidgetMessageDelegate* FindDelegate(const int tab_id); |
| 75 |
| 76 // Returns 0 if no id is found. |
| 77 uint32_t GetRenderWidgetId(const int tab_id); |
| 78 |
| 79 typedef base::SmallMap<std::map<int, RenderWidgetMessageDelegate*> > |
| 80 DelegateMap; |
| 81 typedef base::SmallMap<std::map<int, uint32_t> > RenderWidgetIdMap; |
| 82 |
| 83 DelegateMap delegates_; |
| 84 RenderWidgetIdMap render_widget_ids_; |
| 85 |
| 86 InputMessageGenerator input_message_generator_; |
| 87 |
| 88 BlimpMessageProcessor* input_message_processor_; |
| 89 BlimpMessageProcessor* compositor_message_processor_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(RenderWidgetMessageProcessor); |
| 92 }; |
| 93 |
| 94 } // namespace blimp |
| 95 |
| 96 #endif // BLIMP_CLIENT_COMPOSITOR_RENDER_WIDGET_MESSAGE_PROCESSOR_H_ |
OLD | NEW |