| 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/session/blimp_engine_session.h" | 5 #include "blimp/engine/session/blimp_engine_session.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "blimp/net/engine_connection_manager.h" | 24 #include "blimp/net/engine_connection_manager.h" |
| 25 #include "blimp/net/null_blimp_message_processor.h" | 25 #include "blimp/net/null_blimp_message_processor.h" |
| 26 #include "blimp/net/tcp_engine_transport.h" | 26 #include "blimp/net/tcp_engine_transport.h" |
| 27 #include "blimp/net/thread_pipe_manager.h" | 27 #include "blimp/net/thread_pipe_manager.h" |
| 28 #include "content/public/browser/browser_context.h" | 28 #include "content/public/browser/browser_context.h" |
| 29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/navigation_controller.h" | 30 #include "content/public/browser/navigation_controller.h" |
| 31 #include "content/public/browser/navigation_entry.h" | 31 #include "content/public/browser/navigation_entry.h" |
| 32 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/render_widget_host.h" | 33 #include "content/public/browser/render_widget_host.h" |
| 34 #include "content/public/browser/render_widget_host_view.h" |
| 34 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 35 #include "net/base/ip_address.h" | 36 #include "net/base/ip_address.h" |
| 36 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
| 37 #include "ui/aura/client/default_capture_client.h" | 38 #include "ui/aura/client/default_capture_client.h" |
| 38 #include "ui/aura/env.h" | 39 #include "ui/aura/env.h" |
| 39 #include "ui/aura/window.h" | 40 #include "ui/aura/window.h" |
| 40 #include "ui/aura/window_tree_host.h" | 41 #include "ui/aura/window_tree_host.h" |
| 42 #include "ui/base/ime/input_method.h" |
| 43 #include "ui/base/ime/text_input_client.h" |
| 41 #include "ui/gfx/geometry/size.h" | 44 #include "ui/gfx/geometry/size.h" |
| 42 #include "ui/wm/core/base_focus_rules.h" | 45 #include "ui/wm/core/base_focus_rules.h" |
| 43 #include "ui/wm/core/default_activation_client.h" | 46 #include "ui/wm/core/default_activation_client.h" |
| 44 #include "ui/wm/core/focus_controller.h" | 47 #include "ui/wm/core/focus_controller.h" |
| 45 | 48 |
| 46 | 49 |
| 47 namespace blimp { | 50 namespace blimp { |
| 48 namespace engine { | 51 namespace engine { |
| 49 namespace { | 52 namespace { |
| 50 | 53 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 DCHECK(engine_config_); | 189 DCHECK(engine_config_); |
| 187 screen_->UpdateDisplayScaleAndSize(kDefaultScaleFactor, | 190 screen_->UpdateDisplayScaleAndSize(kDefaultScaleFactor, |
| 188 gfx::Size(kDefaultDisplayWidth, | 191 gfx::Size(kDefaultDisplayWidth, |
| 189 kDefaultDisplayHeight)); | 192 kDefaultDisplayHeight)); |
| 190 render_widget_feature_.SetDelegate(kDummyTabId, this); | 193 render_widget_feature_.SetDelegate(kDummyTabId, this); |
| 191 } | 194 } |
| 192 | 195 |
| 193 BlimpEngineSession::~BlimpEngineSession() { | 196 BlimpEngineSession::~BlimpEngineSession() { |
| 194 render_widget_feature_.RemoveDelegate(kDummyTabId); | 197 render_widget_feature_.RemoveDelegate(kDummyTabId); |
| 195 | 198 |
| 199 window_tree_host_->GetInputMethod()->RemoveObserver(this); |
| 200 |
| 196 // Ensure that all WebContents are torn down first, since teardown will | 201 // Ensure that all WebContents are torn down first, since teardown will |
| 197 // trigger RenderViewDeleted callbacks to their observers. | 202 // trigger RenderViewDeleted callbacks to their observers. |
| 198 web_contents_.reset(); | 203 web_contents_.reset(); |
| 199 | 204 |
| 200 // Safely delete network components on the IO thread. | 205 // Safely delete network components on the IO thread. |
| 201 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | 206 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
| 202 net_components_.release()); | 207 net_components_.release()); |
| 203 } | 208 } |
| 204 | 209 |
| 205 void BlimpEngineSession::Initialize() { | 210 void BlimpEngineSession::Initialize() { |
| 206 DCHECK(!gfx::Screen::GetScreen()); | 211 DCHECK(!gfx::Screen::GetScreen()); |
| 207 gfx::Screen::SetScreenInstance(screen_.get()); | 212 gfx::Screen::SetScreenInstance(screen_.get()); |
| 208 | 213 |
| 209 window_tree_host_.reset(new BlimpWindowTreeHost()); | 214 window_tree_host_.reset(new BlimpWindowTreeHost()); |
| 210 | 215 |
| 211 screen_->set_window_tree_host(window_tree_host_.get()); | 216 screen_->set_window_tree_host(window_tree_host_.get()); |
| 212 window_tree_host_->InitHost(); | 217 window_tree_host_->InitHost(); |
| 213 window_tree_host_->window()->SetLayoutManager( | 218 window_tree_host_->window()->SetLayoutManager( |
| 214 new BlimpLayoutManager(window_tree_host_->window())); | 219 new BlimpLayoutManager(window_tree_host_->window())); |
| 215 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); | 220 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); |
| 216 aura::client::SetFocusClient(window_tree_host_->window(), | 221 aura::client::SetFocusClient(window_tree_host_->window(), |
| 217 focus_client_.get()); | 222 focus_client_.get()); |
| 218 aura::client::SetActivationClient(window_tree_host_->window(), | 223 aura::client::SetActivationClient(window_tree_host_->window(), |
| 219 focus_client_.get()); | 224 focus_client_.get()); |
| 220 capture_client_.reset( | 225 capture_client_.reset( |
| 221 new aura::client::DefaultCaptureClient(window_tree_host_->window())); | 226 new aura::client::DefaultCaptureClient(window_tree_host_->window())); |
| 222 | 227 |
| 228 window_tree_host_->GetInputMethod()->AddObserver(this); |
| 229 |
| 223 window_tree_host_->SetBounds(gfx::Rect(screen_->GetPrimaryDisplay().size())); | 230 window_tree_host_->SetBounds(gfx::Rect(screen_->GetPrimaryDisplay().size())); |
| 224 | 231 |
| 225 RegisterFeatures(); | 232 RegisterFeatures(); |
| 226 | 233 |
| 227 // Initialize must only be posted after the RegisterFeature calls have | 234 // Initialize must only be posted after the RegisterFeature calls have |
| 228 // completed. | 235 // completed. |
| 229 content::BrowserThread::PostTask( | 236 content::BrowserThread::PostTask( |
| 230 content::BrowserThread::IO, FROM_HERE, | 237 content::BrowserThread::IO, FROM_HERE, |
| 231 base::Bind(&EngineNetworkComponents::Initialize, | 238 base::Bind(&EngineNetworkComponents::Initialize, |
| 232 base::Unretained(net_components_.get()), | 239 base::Unretained(net_components_.get()), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 248 thread_pipe_manager_->RegisterFeature(BlimpMessage::NAVIGATION, this); | 255 thread_pipe_manager_->RegisterFeature(BlimpMessage::NAVIGATION, this); |
| 249 render_widget_feature_.set_render_widget_message_sender( | 256 render_widget_feature_.set_render_widget_message_sender( |
| 250 thread_pipe_manager_->RegisterFeature(BlimpMessage::RENDER_WIDGET, | 257 thread_pipe_manager_->RegisterFeature(BlimpMessage::RENDER_WIDGET, |
| 251 &render_widget_feature_)); | 258 &render_widget_feature_)); |
| 252 render_widget_feature_.set_input_message_sender( | 259 render_widget_feature_.set_input_message_sender( |
| 253 thread_pipe_manager_->RegisterFeature(BlimpMessage::INPUT, | 260 thread_pipe_manager_->RegisterFeature(BlimpMessage::INPUT, |
| 254 &render_widget_feature_)); | 261 &render_widget_feature_)); |
| 255 render_widget_feature_.set_compositor_message_sender( | 262 render_widget_feature_.set_compositor_message_sender( |
| 256 thread_pipe_manager_->RegisterFeature(BlimpMessage::COMPOSITOR, | 263 thread_pipe_manager_->RegisterFeature(BlimpMessage::COMPOSITOR, |
| 257 &render_widget_feature_)); | 264 &render_widget_feature_)); |
| 265 render_widget_feature_.set_ime_message_sender( |
| 266 thread_pipe_manager_->RegisterFeature(BlimpMessage::IME, |
| 267 &render_widget_feature_)); |
| 258 } | 268 } |
| 259 | 269 |
| 260 bool BlimpEngineSession::CreateWebContents(const int target_tab_id) { | 270 bool BlimpEngineSession::CreateWebContents(const int target_tab_id) { |
| 261 DVLOG(1) << "Create tab " << target_tab_id; | 271 DVLOG(1) << "Create tab " << target_tab_id; |
| 262 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). | 272 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). |
| 263 if (web_contents_) { | 273 if (web_contents_) { |
| 264 DLOG(WARNING) << "Tab " << target_tab_id << " already existed"; | 274 DLOG(WARNING) << "Tab " << target_tab_id << " already existed"; |
| 265 return false; | 275 return false; |
| 266 } | 276 } |
| 267 | 277 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 render_widget_host->ForwardGestureEvent(*event); | 342 render_widget_host->ForwardGestureEvent(*event); |
| 333 } | 343 } |
| 334 | 344 |
| 335 void BlimpEngineSession::OnCompositorMessageReceived( | 345 void BlimpEngineSession::OnCompositorMessageReceived( |
| 336 content::RenderWidgetHost* render_widget_host, | 346 content::RenderWidgetHost* render_widget_host, |
| 337 const std::vector<uint8_t>& message) { | 347 const std::vector<uint8_t>& message) { |
| 338 | 348 |
| 339 render_widget_host->HandleCompositorProto(message); | 349 render_widget_host->HandleCompositorProto(message); |
| 340 } | 350 } |
| 341 | 351 |
| 352 void BlimpEngineSession::OnTextInputTypeChanged( |
| 353 const ui::TextInputClient* client) {} |
| 354 |
| 355 void BlimpEngineSession::OnFocus() {} |
| 356 |
| 357 void BlimpEngineSession::OnBlur() {} |
| 358 |
| 359 void BlimpEngineSession::OnCaretBoundsChanged( |
| 360 const ui::TextInputClient* client) {} |
| 361 |
| 362 // Called when either: |
| 363 // - the TextInputClient is changed (e.g. by a change of focus) |
| 364 // - the TextInputType of the TextInputClient changes |
| 365 void BlimpEngineSession::OnTextInputStateChanged( |
| 366 const ui::TextInputClient* client) { |
| 367 if (!web_contents_->GetRenderWidgetHostView()) |
| 368 return; |
| 369 |
| 370 ui::TextInputType type = |
| 371 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
| 372 |
| 373 // TODO(shaktisahu): Propagate the new type to the client. |
| 374 // Hide IME, when text input is out of focus, i.e. if the text input type |
| 375 // changes to ui::TEXT_INPUT_TYPE_NONE. For other text input types, |
| 376 // OnShowImeIfNeeded is used instead to send show IME request to client. |
| 377 if (type == ui::TEXT_INPUT_TYPE_NONE) |
| 378 render_widget_feature_.SendHideImeRequest( |
| 379 kDummyTabId, |
| 380 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()); |
| 381 } |
| 382 |
| 383 void BlimpEngineSession::OnInputMethodDestroyed( |
| 384 const ui::InputMethod* input_method) {} |
| 385 |
| 386 // Called when a user input should trigger showing the IME. |
| 387 void BlimpEngineSession::OnShowImeIfNeeded() { |
| 388 if (!web_contents_->GetRenderWidgetHostView() || |
| 389 !window_tree_host_->GetInputMethod()->GetTextInputClient()) |
| 390 return; |
| 391 |
| 392 render_widget_feature_.SendShowImeRequest( |
| 393 kDummyTabId, |
| 394 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(), |
| 395 window_tree_host_->GetInputMethod()->GetTextInputClient()); |
| 396 } |
| 397 |
| 342 void BlimpEngineSession::ProcessMessage( | 398 void BlimpEngineSession::ProcessMessage( |
| 343 scoped_ptr<BlimpMessage> message, | 399 scoped_ptr<BlimpMessage> message, |
| 344 const net::CompletionCallback& callback) { | 400 const net::CompletionCallback& callback) { |
| 345 DCHECK(!callback.is_null()); | 401 DCHECK(!callback.is_null()); |
| 346 DCHECK(message->type() == BlimpMessage::TAB_CONTROL || | 402 DCHECK(message->type() == BlimpMessage::TAB_CONTROL || |
| 347 message->type() == BlimpMessage::NAVIGATION); | 403 message->type() == BlimpMessage::NAVIGATION); |
| 348 | 404 |
| 349 net::Error result = net::OK; | 405 net::Error result = net::OK; |
| 350 if (message->type() == BlimpMessage::TAB_CONTROL) { | 406 if (message->type() == BlimpMessage::TAB_CONTROL) { |
| 351 switch (message->tab_control().type()) { | 407 switch (message->tab_control().type()) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 | 533 |
| 478 navigation_message_sender_->ProcessMessage(std::move(message), | 534 navigation_message_sender_->ProcessMessage(std::move(message), |
| 479 net::CompletionCallback()); | 535 net::CompletionCallback()); |
| 480 } | 536 } |
| 481 | 537 |
| 482 void BlimpEngineSession::LoadProgressChanged( | 538 void BlimpEngineSession::LoadProgressChanged( |
| 483 content::WebContents* source, double progress) { | 539 content::WebContents* source, double progress) { |
| 484 if (source != web_contents_.get()) | 540 if (source != web_contents_.get()) |
| 485 return; | 541 return; |
| 486 | 542 |
| 487 bool page_load_completed = progress == 1.0 ? true : false; | 543 bool page_load_completed = (progress == 1.0); |
| 488 | 544 |
| 489 // If the client has been notified of a page load completed change, avoid | 545 // If the client has been notified of a page load completed change, avoid |
| 490 // sending another message. For the first navigation, the initial value used | 546 // sending another message. For the first navigation, the initial value used |
| 491 // by the client is already false. | 547 // by the client is already false. |
| 492 if (last_page_load_completed_value_ == page_load_completed) | 548 if (last_page_load_completed_value_ == page_load_completed) |
| 493 return; | 549 return; |
| 494 | 550 |
| 495 NavigationMessage* navigation_message; | 551 NavigationMessage* navigation_message = nullptr; |
| 496 scoped_ptr<BlimpMessage> message = | 552 scoped_ptr<BlimpMessage> message = |
| 497 CreateBlimpMessage(&navigation_message, kDummyTabId); | 553 CreateBlimpMessage(&navigation_message, kDummyTabId); |
| 498 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); | 554 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); |
| 499 NavigationStateChangeMessage* details = | 555 NavigationStateChangeMessage* details = |
| 500 navigation_message->mutable_navigation_state_changed(); | 556 navigation_message->mutable_navigation_state_changed(); |
| 501 details->set_page_load_completed(page_load_completed); | 557 details->set_page_load_completed(page_load_completed); |
| 502 | 558 |
| 503 navigation_message_sender_->ProcessMessage(std::move(message), | 559 navigation_message_sender_->ProcessMessage(std::move(message), |
| 504 net::CompletionCallback()); | 560 net::CompletionCallback()); |
| 505 | 561 |
| 506 last_page_load_completed_value_ = page_load_completed; | 562 last_page_load_completed_value_ = page_load_completed; |
| 507 } | 563 } |
| 508 | 564 |
| 509 void BlimpEngineSession::RenderViewCreated( | 565 void BlimpEngineSession::RenderViewCreated( |
| 510 content::RenderViewHost* render_view_host) { | 566 content::RenderViewHost* render_view_host) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 535 | 591 |
| 536 aura::Window* parent = window_tree_host_->window(); | 592 aura::Window* parent = window_tree_host_->window(); |
| 537 aura::Window* content = web_contents_->GetNativeView(); | 593 aura::Window* content = web_contents_->GetNativeView(); |
| 538 if (!parent->Contains(content)) | 594 if (!parent->Contains(content)) |
| 539 parent->AddChild(content); | 595 parent->AddChild(content); |
| 540 content->Show(); | 596 content->Show(); |
| 541 } | 597 } |
| 542 | 598 |
| 543 } // namespace engine | 599 } // namespace engine |
| 544 } // namespace blimp | 600 } // namespace blimp |
| OLD | NEW |