| 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_ENGINE_FEATURE_ENGINE_RENDER_WIDGET_FEATURE_H_ |  | 
|    6 #define BLIMP_ENGINE_FEATURE_ENGINE_RENDER_WIDGET_FEATURE_H_ |  | 
|    7  |  | 
|    8 #include <stdint.h> |  | 
|    9  |  | 
|   10 #include <map> |  | 
|   11 #include <memory> |  | 
|   12 #include <vector> |  | 
|   13  |  | 
|   14 #include "base/atomic_sequence_num.h" |  | 
|   15 #include "base/containers/small_map.h" |  | 
|   16 #include "base/macros.h" |  | 
|   17 #include "blimp/engine/app/settings_manager.h" |  | 
|   18 #include "blimp/net/blimp_message_processor.h" |  | 
|   19 #include "blimp/net/input_message_converter.h" |  | 
|   20 #include "ui/base/ime/text_input_client.h" |  | 
|   21  |  | 
|   22 namespace blink { |  | 
|   23 class WebGestureEvent; |  | 
|   24 } |  | 
|   25  |  | 
|   26 namespace content { |  | 
|   27 class RenderWidgetHost; |  | 
|   28 struct FormFieldData; |  | 
|   29 } |  | 
|   30  |  | 
|   31 namespace blimp { |  | 
|   32 namespace engine { |  | 
|   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 handles dropping |  | 
|   38 // stale BlimpMessage::RENDER_WIDGET messages from the client after a |  | 
|   39 // RenderWidgetMessage::INITIALIZE message is sent. |  | 
|   40 class EngineRenderWidgetFeature : public BlimpMessageProcessor, |  | 
|   41                                   public SettingsManager::Observer { |  | 
|   42  public: |  | 
|   43   // A delegate to be notified of specific RenderWidget related incoming events. |  | 
|   44   class RenderWidgetMessageDelegate { |  | 
|   45    public: |  | 
|   46     // Called when the client is sending a WebGestureEvent to the engine. |  | 
|   47     virtual void OnWebGestureEvent( |  | 
|   48         content::RenderWidgetHost* render_widget_host, |  | 
|   49         std::unique_ptr<blink::WebGestureEvent> event) = 0; |  | 
|   50  |  | 
|   51     // Called when the client sent a CompositorMessage.  These messages should |  | 
|   52     // be sent to the engine's render process so they can be processed by the |  | 
|   53     // RemoteChannel of the compositor. |  | 
|   54     virtual void OnCompositorMessageReceived( |  | 
|   55         content::RenderWidgetHost* render_widget_host, |  | 
|   56         const std::vector<uint8_t>& message) = 0; |  | 
|   57   }; |  | 
|   58  |  | 
|   59   explicit EngineRenderWidgetFeature(SettingsManager* settings); |  | 
|   60   ~EngineRenderWidgetFeature() override; |  | 
|   61  |  | 
|   62   void set_render_widget_message_sender( |  | 
|   63       std::unique_ptr<BlimpMessageProcessor> message_processor); |  | 
|   64  |  | 
|   65   void set_input_message_sender( |  | 
|   66       std::unique_ptr<BlimpMessageProcessor> message_processor); |  | 
|   67  |  | 
|   68   void set_compositor_message_sender( |  | 
|   69       std::unique_ptr<BlimpMessageProcessor> message_processor); |  | 
|   70  |  | 
|   71   void set_ime_message_sender( |  | 
|   72       std::unique_ptr<BlimpMessageProcessor> message_processor); |  | 
|   73  |  | 
|   74   // Notifes the client that a new RenderWidget for a particular WebContents has |  | 
|   75   // been created. This will trigger the creation of the BlimpCompositor for |  | 
|   76   // this widget on the client. |  | 
|   77   void OnRenderWidgetCreated(const int tab_id, |  | 
|   78                              content::RenderWidgetHost* render_widget_host); |  | 
|   79  |  | 
|   80   // Notifies the client that the RenderWidget for a particular WebContents has |  | 
|   81   // changed.  When this is sent the native view on the client becomes bound to |  | 
|   82   // the BlimpCompositor for this widget. |  | 
|   83   // Since the compositor on the client performs the operations of the view for |  | 
|   84   // this widget, this will set the visibility and draw state correctly for this |  | 
|   85   // widget. |  | 
|   86   // Note: This assumes that this is the RenderWidgetHost for the main frame. |  | 
|   87   // Only one RenderWidget can be in initialized state for a tab. |  | 
|   88   void OnRenderWidgetInitialized(const int tab_id, |  | 
|   89                                  content::RenderWidgetHost* render_widget_host); |  | 
|   90  |  | 
|   91   void OnRenderWidgetDeleted(const int tab_id, |  | 
|   92                              content::RenderWidgetHost* render_widget_host); |  | 
|   93  |  | 
|   94   // Notifies the client to show/hide IME. |  | 
|   95   void SendShowImeRequest(const int tab_id, |  | 
|   96                           content::RenderWidgetHost* render_widget_host, |  | 
|   97                           const content::FormFieldData& field); |  | 
|   98   void SendHideImeRequest(const int tab_id, |  | 
|   99                           content::RenderWidgetHost* render_widget_host); |  | 
|  100  |  | 
|  101   // Sends a CompositorMessage for |tab_id| to the client. |  | 
|  102   void SendCompositorMessage(const int tab_id, |  | 
|  103                              content::RenderWidgetHost* render_widget_host, |  | 
|  104                              const std::vector<uint8_t>& message); |  | 
|  105  |  | 
|  106   // Sets a RenderWidgetMessageDelegate to be notified of all incoming |  | 
|  107   // RenderWidget related messages for |tab_id| from the client.  There can only |  | 
|  108   // be one RenderWidgetMessageDelegate per tab. |  | 
|  109   void SetDelegate(const int tab_id, RenderWidgetMessageDelegate* delegate); |  | 
|  110   void RemoveDelegate(const int tab_id); |  | 
|  111  |  | 
|  112   // BlimpMessageProcessor implementation. |  | 
|  113   void ProcessMessage(std::unique_ptr<BlimpMessage> message, |  | 
|  114                       const net::CompletionCallback& callback) override; |  | 
|  115  |  | 
|  116   // Settings::Observer implementation. |  | 
|  117   void OnWebPreferencesChanged() override; |  | 
|  118  |  | 
|  119  private: |  | 
|  120   typedef base::SmallMap<std::map<int, RenderWidgetMessageDelegate*> > |  | 
|  121   DelegateMap; |  | 
|  122  |  | 
|  123   typedef base::SmallMap<std::map<content::RenderWidgetHost*, int>> |  | 
|  124       RenderWidgetToIdMap; |  | 
|  125  |  | 
|  126   typedef base::SmallMap<std::map<int, content::RenderWidgetHost*>> |  | 
|  127       IdToRenderWidgetMap; |  | 
|  128  |  | 
|  129   typedef std::pair<RenderWidgetToIdMap, IdToRenderWidgetMap> RenderWidgetMaps; |  | 
|  130  |  | 
|  131   typedef base::SmallMap<std::map<int, RenderWidgetMaps>> TabMap; |  | 
|  132  |  | 
|  133   // Returns nullptr if no delegate is found. |  | 
|  134   RenderWidgetMessageDelegate* FindDelegate(const int tab_id); |  | 
|  135  |  | 
|  136   // Adds the RenderWidgetHost to the map and return the render_widget_id. |  | 
|  137   int AddRenderWidget(const int tab_id, |  | 
|  138                       content::RenderWidgetHost* render_widget_host); |  | 
|  139  |  | 
|  140   // Deletes the RenderWidgetHost from the map and returns the render_widget_id |  | 
|  141   // for the deleted host. |  | 
|  142   int DeleteRenderWidget(const int tab_id, |  | 
|  143                          content::RenderWidgetHost* render_widget_host); |  | 
|  144  |  | 
|  145   // Returns the render_widget_id for the RenderWidgetHost. Will return 0U if |  | 
|  146   // the host is not found. |  | 
|  147   int GetRenderWidgetId(const int tab_id, |  | 
|  148                         content::RenderWidgetHost* render_widget_host); |  | 
|  149  |  | 
|  150   // Returns the RenderWidgetHost for the given render_widget_id. Will return |  | 
|  151   // nullptr if no host is found. |  | 
|  152   content::RenderWidgetHost* GetRenderWidgetHost(const int tab_id, |  | 
|  153                                                  const int render_widget_id); |  | 
|  154  |  | 
|  155   // Sends the text entered by the user to the renderer. |  | 
|  156   // The existing text in the box gets replaced by the new text from IME. |  | 
|  157   void SetTextFromIME(content::RenderWidgetHost* render_widget_host, |  | 
|  158                       std::string text, |  | 
|  159                       bool auto_submit); |  | 
|  160  |  | 
|  161   DelegateMap delegates_; |  | 
|  162   TabMap tabs_; |  | 
|  163  |  | 
|  164   // A RenderWidgetHost can also be uniquely identified by the |  | 
|  165   // <process_id, routing_id> where the process_id is the id for the |  | 
|  166   // RenderProcessHost for this widget and the routing_id is the id for the |  | 
|  167   // widget. |  | 
|  168   // But we generate our own ids to avoid having the render widget protocol tied |  | 
|  169   // to always using a combination of these ids, generated by the content layer. |  | 
|  170   // By using an AtomicSequenceNumber for identifying render widgets across |  | 
|  171   // tabs, we can be sure that there will always be a 1:1 mapping between the |  | 
|  172   // render widget and the consumer of the features tied to this widget on the |  | 
|  173   // client, which is the BlimpCompositor. |  | 
|  174   base::AtomicSequenceNumber next_widget_id_; |  | 
|  175  |  | 
|  176   InputMessageConverter input_message_converter_; |  | 
|  177  |  | 
|  178   SettingsManager* settings_manager_; |  | 
|  179  |  | 
|  180   // Outgoing message processors for RENDER_WIDGET, COMPOSITOR and INPUT types. |  | 
|  181   std::unique_ptr<BlimpMessageProcessor> render_widget_message_sender_; |  | 
|  182   std::unique_ptr<BlimpMessageProcessor> compositor_message_sender_; |  | 
|  183   std::unique_ptr<BlimpMessageProcessor> input_message_sender_; |  | 
|  184   std::unique_ptr<BlimpMessageProcessor> ime_message_sender_; |  | 
|  185  |  | 
|  186   base::WeakPtrFactory<EngineRenderWidgetFeature> weak_factory_; |  | 
|  187  |  | 
|  188   DISALLOW_COPY_AND_ASSIGN(EngineRenderWidgetFeature); |  | 
|  189 }; |  | 
|  190  |  | 
|  191 }  // namespace engine |  | 
|  192 }  // namespace blimp |  | 
|  193  |  | 
|  194 #endif  // BLIMP_ENGINE_FEATURE_ENGINE_RENDER_WIDGET_FEATURE_H_ |  | 
| OLD | NEW |