| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/engine/browser/blimp_engine_session.h" | 5 #include "blimp/engine/browser/blimp_engine_session.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" |
| 7 #include "blimp/common/proto/blimp_message.pb.h" | 8 #include "blimp/common/proto/blimp_message.pb.h" |
| 8 #include "blimp/common/proto/control.pb.h" | 9 #include "blimp/common/proto/control.pb.h" |
| 9 #include "blimp/engine/browser/blimp_browser_context.h" | 10 #include "blimp/engine/browser/blimp_browser_context.h" |
| 10 #include "blimp/engine/ui/blimp_layout_manager.h" | 11 #include "blimp/engine/ui/blimp_layout_manager.h" |
| 11 #include "blimp/engine/ui/blimp_screen.h" | 12 #include "blimp/engine/ui/blimp_screen.h" |
| 12 #include "blimp/engine/ui/blimp_ui_context_factory.h" | 13 #include "blimp/engine/ui/blimp_ui_context_factory.h" |
| 13 #include "blimp/net/blimp_connection.h" | 14 #include "blimp/net/blimp_connection.h" |
| 15 #include "blimp/net/blimp_message_multiplexer.h" |
| 16 #include "blimp/net/null_blimp_message_processor.h" |
| 14 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 15 #include "content/public/browser/navigation_controller.h" | 18 #include "content/public/browser/navigation_controller.h" |
| 16 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
| 17 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 18 #include "content/public/browser/render_widget_host.h" | 21 #include "content/public/browser/render_widget_host.h" |
| 19 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 20 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 21 #include "ui/aura/client/default_capture_client.h" | 24 #include "ui/aura/client/default_capture_client.h" |
| 22 #include "ui/aura/env.h" | 25 #include "ui/aura/env.h" |
| 23 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 24 #include "ui/aura/window_tree_host.h" | 27 #include "ui/aura/window_tree_host.h" |
| 28 #include "ui/gfx/geometry/size.h" |
| 25 #include "ui/wm/core/base_focus_rules.h" | 29 #include "ui/wm/core/base_focus_rules.h" |
| 26 #include "ui/wm/core/default_activation_client.h" | 30 #include "ui/wm/core/default_activation_client.h" |
| 27 #include "ui/wm/core/focus_controller.h" | 31 #include "ui/wm/core/focus_controller.h" |
| 28 | 32 |
| 29 #if !defined(USE_X11) | 33 #if !defined(USE_X11) |
| 30 #include "blimp/engine/ui/blimp_window_tree_host.h" | 34 #include "blimp/engine/ui/blimp_window_tree_host.h" |
| 31 #endif | 35 #endif |
| 32 | 36 |
| 33 namespace blimp { | 37 namespace blimp { |
| 34 namespace engine { | 38 namespace engine { |
| 35 namespace { | 39 namespace { |
| 36 | 40 |
| 41 const int kDummyTabId = 0; |
| 42 |
| 43 base::LazyInstance<blimp::NullBlimpMessageProcessor> g_blimp_message_processor = |
| 44 LAZY_INSTANCE_INITIALIZER; |
| 45 |
| 37 // Focus rules that support activating an child window. | 46 // Focus rules that support activating an child window. |
| 38 class FocusRulesImpl : public wm::BaseFocusRules { | 47 class FocusRulesImpl : public wm::BaseFocusRules { |
| 39 public: | 48 public: |
| 40 FocusRulesImpl() {} | 49 FocusRulesImpl() {} |
| 41 ~FocusRulesImpl() override {} | 50 ~FocusRulesImpl() override {} |
| 42 | 51 |
| 43 bool SupportsChildActivation(aura::Window* window) const override { | 52 bool SupportsChildActivation(aura::Window* window) const override { |
| 44 return true; | 53 return true; |
| 45 } | 54 } |
| 46 | 55 |
| 47 private: | 56 private: |
| 48 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); | 57 DISALLOW_COPY_AND_ASSIGN(FocusRulesImpl); |
| 49 }; | 58 }; |
| 50 | 59 |
| 51 } // namespace | 60 } // namespace |
| 52 | 61 |
| 53 BlimpEngineSession::BlimpEngineSession( | 62 BlimpEngineSession::BlimpEngineSession( |
| 54 scoped_ptr<BlimpBrowserContext> browser_context) | 63 scoped_ptr<BlimpBrowserContext> browser_context) |
| 55 : browser_context_(browser_context.Pass()), screen_(new BlimpScreen) {} | 64 : browser_context_(browser_context.Pass()), |
| 65 screen_(new BlimpScreen), |
| 66 // TODO(dtrainor, haibinlu): Properly pull these from the BlimpMessageMux. |
| 67 render_widget_processor_(g_blimp_message_processor.Pointer(), |
| 68 g_blimp_message_processor.Pointer()) { |
| 69 render_widget_processor_.SetDelegate(kDummyTabId, this); |
| 70 } |
| 56 | 71 |
| 57 BlimpEngineSession::~BlimpEngineSession() {} | 72 BlimpEngineSession::~BlimpEngineSession() { |
| 73 render_widget_processor_.RemoveDelegate(kDummyTabId); |
| 74 } |
| 58 | 75 |
| 59 void BlimpEngineSession::Initialize() { | 76 void BlimpEngineSession::Initialize() { |
| 60 DCHECK(!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)); | 77 DCHECK(!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)); |
| 61 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); | 78 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); |
| 62 | 79 |
| 63 #if defined(USE_X11) | 80 #if defined(USE_X11) |
| 64 window_tree_host_.reset(aura::WindowTreeHost::Create( | 81 window_tree_host_.reset(aura::WindowTreeHost::Create( |
| 65 gfx::Rect(screen_->GetPrimaryDisplay().size()))); | 82 gfx::Rect(screen_->GetPrimaryDisplay().size()))); |
| 66 #else | 83 #else |
| 67 context_factory_.reset(new BlimpUiContextFactory()); | 84 context_factory_.reset(new BlimpUiContextFactory()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 95 scoped_ptr<content::WebContents> new_contents = | 112 scoped_ptr<content::WebContents> new_contents = |
| 96 make_scoped_ptr(content::WebContents::Create(create_params)); | 113 make_scoped_ptr(content::WebContents::Create(create_params)); |
| 97 PlatformSetContents(new_contents.Pass()); | 114 PlatformSetContents(new_contents.Pass()); |
| 98 } | 115 } |
| 99 | 116 |
| 100 void BlimpEngineSession::CloseWebContents(const int target_tab_id) { | 117 void BlimpEngineSession::CloseWebContents(const int target_tab_id) { |
| 101 DCHECK(web_contents_); | 118 DCHECK(web_contents_); |
| 102 web_contents_->Close(); | 119 web_contents_->Close(); |
| 103 } | 120 } |
| 104 | 121 |
| 122 void BlimpEngineSession::HandleResize(const gfx::Size& size) { |
| 123 // TODO(dtrainor, haibinlu): Set the proper size on the WebContents/save for |
| 124 // future WebContents objects. |
| 125 } |
| 126 |
| 105 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { | 127 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { |
| 106 if (url.is_empty() || !web_contents_) | 128 if (url.is_empty() || !web_contents_) |
| 107 return; | 129 return; |
| 108 | 130 |
| 109 content::NavigationController::LoadURLParams params(url); | 131 content::NavigationController::LoadURLParams params(url); |
| 110 params.transition_type = ui::PageTransitionFromInt( | 132 params.transition_type = ui::PageTransitionFromInt( |
| 111 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | 133 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
| 112 web_contents_->GetController().LoadURLWithParams(params); | 134 web_contents_->GetController().LoadURLWithParams(params); |
| 113 web_contents_->Focus(); | 135 web_contents_->Focus(); |
| 114 } | 136 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 127 web_contents_->GetController().GoForward(); | 149 web_contents_->GetController().GoForward(); |
| 128 } | 150 } |
| 129 | 151 |
| 130 void BlimpEngineSession::Reload(const int target_tab_id) { | 152 void BlimpEngineSession::Reload(const int target_tab_id) { |
| 131 if (!web_contents_) | 153 if (!web_contents_) |
| 132 return; | 154 return; |
| 133 | 155 |
| 134 web_contents_->GetController().Reload(true); | 156 web_contents_->GetController().Reload(true); |
| 135 } | 157 } |
| 136 | 158 |
| 159 void BlimpEngineSession::OnWebInputEvent( |
| 160 scoped_ptr<blink::WebInputEvent> event) { |
| 161 if (!web_contents_ || !web_contents_->GetRenderViewHost()) |
| 162 return; |
| 163 |
| 164 // TODO(dtrainor): Send the input event directly to the render process? |
| 165 } |
| 166 |
| 167 void BlimpEngineSession::OnCompositorMessageReceived( |
| 168 const std::vector<uint8_t>& message) { |
| 169 // Make sure that We actually have a valid WebContents and RenderViewHost. |
| 170 if (!web_contents_ || !web_contents_->GetRenderViewHost()) |
| 171 return; |
| 172 |
| 173 content::RenderWidgetHost* host = |
| 174 web_contents_->GetRenderViewHost()->GetWidget(); |
| 175 |
| 176 // Make sure we actually have a valid RenderWidgetHost. |
| 177 if (!host) |
| 178 return; |
| 179 |
| 180 host->HandleCompositorProto(message); |
| 181 } |
| 182 |
| 137 void BlimpEngineSession::ProcessMessage( | 183 void BlimpEngineSession::ProcessMessage( |
| 138 scoped_ptr<BlimpMessage> message, | 184 scoped_ptr<BlimpMessage> message, |
| 139 const net::CompletionCallback& callback) { | 185 const net::CompletionCallback& callback) { |
| 140 DCHECK(message->type() == BlimpMessage::CONTROL || | 186 DCHECK(message->type() == BlimpMessage::CONTROL || |
| 141 message->type() == BlimpMessage::NAVIGATION || | 187 message->type() == BlimpMessage::NAVIGATION); |
| 142 message->type() == BlimpMessage::COMPOSITOR); | |
| 143 | 188 |
| 144 if (message->type() == BlimpMessage::CONTROL) { | 189 if (message->type() == BlimpMessage::CONTROL) { |
| 145 switch (message->control().type()) { | 190 switch (message->control().type()) { |
| 146 case ControlMessage::CREATE_TAB: | 191 case ControlMessage::CREATE_TAB: |
| 147 CreateWebContents(message->target_tab_id()); | 192 CreateWebContents(message->target_tab_id()); |
| 148 break; | 193 break; |
| 149 case ControlMessage::CLOSE_TAB: | 194 case ControlMessage::CLOSE_TAB: |
| 150 CloseWebContents(message->target_tab_id()); | 195 CloseWebContents(message->target_tab_id()); |
| 196 case ControlMessage::SIZE: |
| 197 HandleResize(gfx::Size(message->control().resize().width(), |
| 198 message->control().resize().height())); |
| 199 break; |
| 151 default: | 200 default: |
| 152 NOTIMPLEMENTED(); | 201 NOTIMPLEMENTED(); |
| 153 } | 202 } |
| 154 } else if (message->type() == BlimpMessage::NAVIGATION && web_contents_) { | 203 } else if (message->type() == BlimpMessage::NAVIGATION && web_contents_) { |
| 155 switch (message->navigation().type()) { | 204 switch (message->navigation().type()) { |
| 156 case NavigationMessage::LOAD_URL: | 205 case NavigationMessage::LOAD_URL: |
| 157 LoadUrl(message->target_tab_id(), | 206 LoadUrl(message->target_tab_id(), |
| 158 GURL(message->navigation().load_url().url())); | 207 GURL(message->navigation().load_url().url())); |
| 159 break; | 208 break; |
| 160 case NavigationMessage::GO_BACK: | 209 case NavigationMessage::GO_BACK: |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 return source; | 268 return source; |
| 220 } | 269 } |
| 221 | 270 |
| 222 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, | 271 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, |
| 223 bool user_gesture, | 272 bool user_gesture, |
| 224 bool last_unlocked_by_target) { | 273 bool last_unlocked_by_target) { |
| 225 web_contents->GotResponseToLockMouseRequest(true); | 274 web_contents->GotResponseToLockMouseRequest(true); |
| 226 } | 275 } |
| 227 | 276 |
| 228 void BlimpEngineSession::CloseContents(content::WebContents* source) { | 277 void BlimpEngineSession::CloseContents(content::WebContents* source) { |
| 229 if (source == web_contents_.get()) | 278 if (source == web_contents_.get()) { |
| 279 Observe(nullptr); |
| 230 web_contents_.reset(); | 280 web_contents_.reset(); |
| 281 } |
| 231 } | 282 } |
| 232 | 283 |
| 233 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { | 284 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { |
| 234 contents->GetRenderViewHost()->GetWidget()->Focus(); | 285 contents->GetRenderViewHost()->GetWidget()->Focus(); |
| 235 } | 286 } |
| 236 | 287 |
| 237 void BlimpEngineSession::ForwardCompositorProto( | 288 void BlimpEngineSession::ForwardCompositorProto( |
| 238 const std::vector<uint8_t>& proto) { | 289 const std::vector<uint8_t>& proto) { |
| 239 // Send the compositor proto over the network layer to the client, which will | 290 render_widget_processor_.SendCompositorMessage(kDummyTabId, proto); |
| 240 // apply the proto to their local compositor instance. | 291 } |
| 241 // TODO(dtrainor): Send the compositor proto. | 292 |
| 293 void BlimpEngineSession::RenderViewHostChanged( |
| 294 content::RenderViewHost* old_host, |
| 295 content::RenderViewHost* new_host) { |
| 296 render_widget_processor_.OnRenderWidgetInitialized(kDummyTabId); |
| 242 } | 297 } |
| 243 | 298 |
| 244 void BlimpEngineSession::PlatformSetContents( | 299 void BlimpEngineSession::PlatformSetContents( |
| 245 scoped_ptr<content::WebContents> new_contents) { | 300 scoped_ptr<content::WebContents> new_contents) { |
| 246 new_contents->SetDelegate(this); | 301 new_contents->SetDelegate(this); |
| 302 Observe(new_contents.get()); |
| 247 web_contents_ = new_contents.Pass(); | 303 web_contents_ = new_contents.Pass(); |
| 248 | 304 |
| 249 aura::Window* parent = window_tree_host_->window(); | 305 aura::Window* parent = window_tree_host_->window(); |
| 250 aura::Window* content = web_contents_->GetNativeView(); | 306 aura::Window* content = web_contents_->GetNativeView(); |
| 251 if (!parent->Contains(content)) | 307 if (!parent->Contains(content)) |
| 252 parent->AddChild(content); | 308 parent->AddChild(content); |
| 253 content->Show(); | 309 content->Show(); |
| 254 } | 310 } |
| 255 | 311 |
| 256 } // namespace engine | 312 } // namespace engine |
| 257 } // namespace blimp | 313 } // namespace blimp |
| OLD | NEW |