| 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_SESSION_BLIMP_ENGINE_SESSION_H_ | |
| 6 #define BLIMP_ENGINE_SESSION_BLIMP_ENGINE_SESSION_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <memory> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "blimp/common/proto/blimp_message.pb.h" | |
| 15 #include "blimp/engine/feature/engine_render_widget_feature.h" | |
| 16 #include "blimp/engine/feature/engine_settings_feature.h" | |
| 17 #include "blimp/engine/feature/geolocation/engine_geolocation_feature.h" | |
| 18 #include "blimp/engine/mojo/blob_channel_service.h" | |
| 19 #include "blimp/net/blimp_message_processor.h" | |
| 20 #include "blimp/net/blob_channel/blob_channel_sender_impl.h" | |
| 21 #include "blimp/net/connection_error_observer.h" | |
| 22 #include "content/public/browser/invalidate_type.h" | |
| 23 #include "content/public/browser/web_contents_delegate.h" | |
| 24 #include "net/base/completion_callback.h" | |
| 25 #include "ui/base/ime/input_method_observer.h" | |
| 26 #include "ui/gfx/geometry/size.h" | |
| 27 | |
| 28 namespace aura { | |
| 29 class WindowTreeHost; | |
| 30 | |
| 31 namespace client { | |
| 32 class DefaultCaptureClient; | |
| 33 class WindowParentingClient; | |
| 34 } // namespace client | |
| 35 } // namespace aura | |
| 36 | |
| 37 namespace content { | |
| 38 class BrowserContext; | |
| 39 class WebContents; | |
| 40 } | |
| 41 | |
| 42 namespace gfx { | |
| 43 class Size; | |
| 44 } | |
| 45 | |
| 46 namespace net { | |
| 47 class NetLog; | |
| 48 } | |
| 49 | |
| 50 namespace wm { | |
| 51 class FocusController; | |
| 52 } | |
| 53 | |
| 54 namespace blimp { | |
| 55 | |
| 56 class BlimpMessage; | |
| 57 class HeliumBlobSenderDelegate; | |
| 58 class ThreadPipeManager; | |
| 59 class SettingsManager; | |
| 60 | |
| 61 namespace engine { | |
| 62 | |
| 63 class BlimpBrowserContext; | |
| 64 class BlimpEngineConfig; | |
| 65 class BlimpScreen; | |
| 66 class BlimpWindowTreeHost; | |
| 67 class EngineNetworkComponents; | |
| 68 class Tab; | |
| 69 | |
| 70 class BlimpEngineSession : public BlimpMessageProcessor, | |
| 71 public content::WebContentsDelegate, | |
| 72 public ui::InputMethodObserver { | |
| 73 public: | |
| 74 using GetPortCallback = base::Callback<void(uint16_t)>; | |
| 75 | |
| 76 BlimpEngineSession(std::unique_ptr<BlimpBrowserContext> browser_context, | |
| 77 net::NetLog* net_log, | |
| 78 BlimpEngineConfig* config, | |
| 79 SettingsManager* settings_manager); | |
| 80 ~BlimpEngineSession() override; | |
| 81 | |
| 82 // Starts the network stack on the IO thread, and sets default placeholder | |
| 83 // values for e.g. screen size pending real values being supplied by the | |
| 84 // client. | |
| 85 void Initialize(); | |
| 86 | |
| 87 BlimpBrowserContext* browser_context() { return browser_context_.get(); } | |
| 88 | |
| 89 BlobChannelSender* blob_channel_sender() { | |
| 90 return blob_channel_sender_.get(); | |
| 91 } | |
| 92 | |
| 93 BlobChannelService* GetBlobChannelService(); | |
| 94 | |
| 95 // Gets Engine's listening port. Invokes callback with the allocated port. | |
| 96 void GetEnginePortForTesting(const GetPortCallback& callback); | |
| 97 | |
| 98 // BlimpMessageProcessor implementation. | |
| 99 // This object handles incoming TAB_CONTROL and NAVIGATION messages directly. | |
| 100 void ProcessMessage(std::unique_ptr<BlimpMessage> message, | |
| 101 const net::CompletionCallback& callback) override; | |
| 102 | |
| 103 private: | |
| 104 // Creates ThreadPipeManager, registers features, and then starts to accept | |
| 105 // incoming connection. | |
| 106 void RegisterFeatures(); | |
| 107 | |
| 108 // TabControlMessage handler methods. | |
| 109 // Creates a new tab, which will be indexed by |target_tab_id|. | |
| 110 // Returns true if a new tab is created, false otherwise. | |
| 111 bool CreateTab(const int target_tab_id); | |
| 112 | |
| 113 // Closes an existing tab, indexed by |target_tab_id|. | |
| 114 void CloseTab(const int target_tab_id); | |
| 115 | |
| 116 // Resizes screen to |size| in pixels, and updates its device pixel ratio to | |
| 117 // |device_pixel_ratio|. | |
| 118 void HandleResize(float device_pixel_ratio, const gfx::Size& size); | |
| 119 | |
| 120 // content::WebContentsDelegate implementation. | |
| 121 content::WebContents* OpenURLFromTab( | |
| 122 content::WebContents* source, | |
| 123 const content::OpenURLParams& params) override; | |
| 124 void AddNewContents(content::WebContents* source, | |
| 125 content::WebContents* new_contents, | |
| 126 WindowOpenDisposition disposition, | |
| 127 const gfx::Rect& initial_rect, | |
| 128 bool user_gesture, | |
| 129 bool* was_blocked) override; | |
| 130 void RequestToLockMouse(content::WebContents* web_contents, | |
| 131 bool user_gesture, | |
| 132 bool last_unlocked_by_target) override; | |
| 133 void CloseContents(content::WebContents* source) override; | |
| 134 void ActivateContents(content::WebContents* contents) override; | |
| 135 void ForwardCompositorProto( | |
| 136 content::RenderWidgetHost* render_widget_host, | |
| 137 const std::vector<uint8_t>& proto) override; | |
| 138 void NavigationStateChanged(content::WebContents* source, | |
| 139 content::InvalidateTypes changed_flags) override; | |
| 140 | |
| 141 // ui::InputMethodObserver overrides. | |
| 142 void OnTextInputTypeChanged(const ui::TextInputClient* client) override; | |
| 143 void OnFocus() override; | |
| 144 void OnBlur() override; | |
| 145 void OnCaretBoundsChanged(const ui::TextInputClient* client) override; | |
| 146 void OnTextInputStateChanged(const ui::TextInputClient* client) override; | |
| 147 void OnInputMethodDestroyed(const ui::InputMethod* input_method) override; | |
| 148 void OnShowImeIfNeeded() override; | |
| 149 | |
| 150 // Sets up |new_contents| to be associated with the root window. | |
| 151 void PlatformSetContents(std::unique_ptr<content::WebContents> new_contents, | |
| 152 const int target_tab_id); | |
| 153 | |
| 154 // Presents the client's single screen. | |
| 155 // Screen should be deleted after browser context (crbug.com/613372). | |
| 156 std::unique_ptr<BlimpScreen> screen_; | |
| 157 | |
| 158 // Content BrowserContext for this session. | |
| 159 std::unique_ptr<BlimpBrowserContext> browser_context_; | |
| 160 | |
| 161 // Engine configuration including assigned client token. | |
| 162 BlimpEngineConfig* engine_config_; | |
| 163 | |
| 164 // Represents the (currently single) browser window into which tab(s) will | |
| 165 // be rendered. | |
| 166 std::unique_ptr<BlimpWindowTreeHost> window_tree_host_; | |
| 167 | |
| 168 // Used to apply standard focus conventions to the windows in the | |
| 169 // WindowTreeHost hierarchy. | |
| 170 std::unique_ptr<wm::FocusController> focus_client_; | |
| 171 | |
| 172 // Used to manage input capture. | |
| 173 std::unique_ptr<aura::client::DefaultCaptureClient> capture_client_; | |
| 174 | |
| 175 // Used to attach null-parented windows (e.g. popups) to the root window. | |
| 176 std::unique_ptr<aura::client::WindowParentingClient> window_parenting_client_; | |
| 177 | |
| 178 // Manages all global settings for the engine session. | |
| 179 SettingsManager* settings_manager_; | |
| 180 | |
| 181 // Handles all incoming messages for type SETTINGS. | |
| 182 EngineSettingsFeature settings_feature_; | |
| 183 | |
| 184 // Handles all incoming and outgoing messages related to RenderWidget, | |
| 185 // including INPUT, COMPOSITOR and RENDER_WIDGET messages. | |
| 186 EngineRenderWidgetFeature render_widget_feature_; | |
| 187 | |
| 188 // Sends outgoing blob data as BlimpMessages. | |
| 189 HeliumBlobSenderDelegate* blob_delegate_; | |
| 190 | |
| 191 // Receives image data and sends it to the client via | |
| 192 // |blob_delegate_|. | |
| 193 std::unique_ptr<BlobChannelSenderImpl> blob_channel_sender_; | |
| 194 | |
| 195 std::unique_ptr<base::WeakPtrFactory<BlobChannelSenderImpl>> | |
| 196 blob_channel_sender_weak_factory_; | |
| 197 | |
| 198 // Receives image data from the renderer and sends it to | |
| 199 // |blob_channel_sender_|. | |
| 200 std::unique_ptr<BlobChannelService> blob_channel_service_; | |
| 201 | |
| 202 // Handles all incoming and outgoing messages related to Geolocation. | |
| 203 EngineGeolocationFeature geolocation_feature_; | |
| 204 | |
| 205 // Container for connection manager, authentication handler, and | |
| 206 // browser connection handler. The components run on the I/O thread, and | |
| 207 // this object is destroyed there. | |
| 208 std::unique_ptr<EngineNetworkComponents> net_components_; | |
| 209 | |
| 210 std::unique_ptr<ThreadPipeManager> thread_pipe_manager_; | |
| 211 | |
| 212 // Used to send TAB_CONTROL or NAVIGATION messages to client. | |
| 213 std::unique_ptr<BlimpMessageProcessor> tab_control_message_sender_; | |
| 214 std::unique_ptr<BlimpMessageProcessor> navigation_message_sender_; | |
| 215 | |
| 216 // TODO(haibinlu): Support more than one tab (crbug/547231) | |
| 217 std::unique_ptr<Tab> tab_; | |
| 218 | |
| 219 DISALLOW_COPY_AND_ASSIGN(BlimpEngineSession); | |
| 220 }; | |
| 221 | |
| 222 } // namespace engine | |
| 223 } // namespace blimp | |
| 224 | |
| 225 #endif // BLIMP_ENGINE_SESSION_BLIMP_ENGINE_SESSION_H_ | |
| OLD | NEW |