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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #include "ui/base/ime/text_input_client.h" | 60 #include "ui/base/ime/text_input_client.h" |
61 #include "ui/gfx/geometry/size.h" | 61 #include "ui/gfx/geometry/size.h" |
62 #include "ui/wm/core/base_focus_rules.h" | 62 #include "ui/wm/core/base_focus_rules.h" |
63 #include "ui/wm/core/default_activation_client.h" | 63 #include "ui/wm/core/default_activation_client.h" |
64 #include "ui/wm/core/focus_controller.h" | 64 #include "ui/wm/core/focus_controller.h" |
65 | 65 |
66 namespace blimp { | 66 namespace blimp { |
67 namespace engine { | 67 namespace engine { |
68 namespace { | 68 namespace { |
69 | 69 |
70 const int kDummyTabId = 0; | |
71 const float kDefaultScaleFactor = 1.f; | 70 const float kDefaultScaleFactor = 1.f; |
72 const int kDefaultDisplayWidth = 800; | 71 const int kDefaultDisplayWidth = 800; |
73 const int kDefaultDisplayHeight = 600; | 72 const int kDefaultDisplayHeight = 600; |
74 const uint16_t kDefaultPort = 25467; | 73 const uint16_t kDefaultPort = 25467; |
75 | 74 |
76 // Focus rules that support activating an child window. | 75 // Focus rules that support activating an child window. |
77 class FocusRulesImpl : public wm::BaseFocusRules { | 76 class FocusRulesImpl : public wm::BaseFocusRules { |
78 public: | 77 public: |
79 FocusRulesImpl() {} | 78 FocusRulesImpl() {} |
80 ~FocusRulesImpl() override {} | 79 ~FocusRulesImpl() override {} |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 settings_manager_(settings_manager), | 228 settings_manager_(settings_manager), |
230 settings_feature_(settings_manager_), | 229 settings_feature_(settings_manager_), |
231 render_widget_feature_(settings_manager_), | 230 render_widget_feature_(settings_manager_), |
232 net_components_(new EngineNetworkComponents(net_log)) { | 231 net_components_(new EngineNetworkComponents(net_log)) { |
233 DCHECK(engine_config_); | 232 DCHECK(engine_config_); |
234 DCHECK(settings_manager_); | 233 DCHECK(settings_manager_); |
235 | 234 |
236 screen_->UpdateDisplayScaleAndSize( | 235 screen_->UpdateDisplayScaleAndSize( |
237 kDefaultScaleFactor, | 236 kDefaultScaleFactor, |
238 gfx::Size(kDefaultDisplayWidth, kDefaultDisplayHeight)); | 237 gfx::Size(kDefaultDisplayWidth, kDefaultDisplayHeight)); |
239 render_widget_feature_.SetDelegate(kDummyTabId, this); | |
240 | 238 |
241 std::unique_ptr<HeliumBlobSenderDelegate> helium_blob_delegate( | 239 std::unique_ptr<HeliumBlobSenderDelegate> helium_blob_delegate( |
242 new HeliumBlobSenderDelegate); | 240 new HeliumBlobSenderDelegate); |
243 blob_delegate_ = helium_blob_delegate.get(); | 241 blob_delegate_ = helium_blob_delegate.get(); |
244 blob_channel_sender_ = base::MakeUnique<BlobChannelSenderImpl>( | 242 blob_channel_sender_ = base::MakeUnique<BlobChannelSenderImpl>( |
245 base::MakeUnique<InMemoryBlobCache>(), std::move(helium_blob_delegate)); | 243 base::MakeUnique<InMemoryBlobCache>(), std::move(helium_blob_delegate)); |
246 blob_channel_sender_weak_factory_ = | 244 blob_channel_sender_weak_factory_ = |
247 base::MakeUnique<base::WeakPtrFactory<BlobChannelSenderImpl>>( | 245 base::MakeUnique<base::WeakPtrFactory<BlobChannelSenderImpl>>( |
248 blob_channel_sender_.get()); | 246 blob_channel_sender_.get()); |
249 | 247 |
250 device::GeolocationProvider::SetGeolocationDelegate( | 248 device::GeolocationProvider::SetGeolocationDelegate( |
251 geolocation_feature_.CreateGeolocationDelegate()); | 249 geolocation_feature_.CreateGeolocationDelegate()); |
252 } | 250 } |
253 | 251 |
254 BlimpEngineSession::~BlimpEngineSession() { | 252 BlimpEngineSession::~BlimpEngineSession() { |
255 render_widget_feature_.RemoveDelegate(kDummyTabId); | |
256 | |
257 window_tree_host_->GetInputMethod()->RemoveObserver(this); | 253 window_tree_host_->GetInputMethod()->RemoveObserver(this); |
258 | 254 |
259 // Ensure that all tabs are torn down first, since teardown will | 255 // Ensure that all tabs are torn down first, since teardown will |
260 // trigger RenderViewDeleted callbacks to their observers, which will in turn | 256 // trigger RenderViewDeleted callbacks to their observers, which will in turn |
261 // send messages to net_components_, which is already deleted due to the line | 257 // send messages to net_components_, which is already deleted due to the line |
262 // below. | 258 // below. |
263 tab_.reset(); | 259 tab_.reset(); |
264 | 260 |
265 // Safely delete network components on the IO thread. | 261 // Safely delete network components on the IO thread. |
266 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | 262 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 const gfx::Size& size) { | 374 const gfx::Size& size) { |
379 DVLOG(1) << "Resize to " << size.ToString() << ", " << device_pixel_ratio; | 375 DVLOG(1) << "Resize to " << size.ToString() << ", " << device_pixel_ratio; |
380 screen_->UpdateDisplayScaleAndSize(device_pixel_ratio, size); | 376 screen_->UpdateDisplayScaleAndSize(device_pixel_ratio, size); |
381 window_tree_host_->SetBounds(gfx::Rect(size)); | 377 window_tree_host_->SetBounds(gfx::Rect(size)); |
382 if (tab_) { | 378 if (tab_) { |
383 tab_->Resize(device_pixel_ratio, | 379 tab_->Resize(device_pixel_ratio, |
384 screen_->GetPrimaryDisplay().bounds().size()); | 380 screen_->GetPrimaryDisplay().bounds().size()); |
385 } | 381 } |
386 } | 382 } |
387 | 383 |
388 void BlimpEngineSession::OnWebGestureEvent( | |
389 content::RenderWidgetHost* render_widget_host, | |
390 std::unique_ptr<blink::WebGestureEvent> event) { | |
391 TRACE_EVENT1("blimp", "BlimpEngineSession::OnWebGestureEvent", "type", | |
392 event->type); | |
393 render_widget_host->ForwardGestureEvent(*event); | |
394 } | |
395 | |
396 void BlimpEngineSession::OnCompositorMessageReceived( | |
397 content::RenderWidgetHost* render_widget_host, | |
398 const std::vector<uint8_t>& message) { | |
399 TRACE_EVENT0("blimp", "BlimpEngineSession::OnCompositorMessageReceived"); | |
400 | |
401 render_widget_host->HandleCompositorProto(message); | |
402 } | |
403 | |
404 void BlimpEngineSession::OnTextInputTypeChanged( | 384 void BlimpEngineSession::OnTextInputTypeChanged( |
405 const ui::TextInputClient* client) {} | 385 const ui::TextInputClient* client) {} |
406 | 386 |
407 void BlimpEngineSession::OnFocus() {} | 387 void BlimpEngineSession::OnFocus() {} |
408 | 388 |
409 void BlimpEngineSession::OnBlur() {} | 389 void BlimpEngineSession::OnBlur() {} |
410 | 390 |
411 void BlimpEngineSession::OnCaretBoundsChanged( | 391 void BlimpEngineSession::OnCaretBoundsChanged( |
412 const ui::TextInputClient* client) {} | 392 const ui::TextInputClient* client) {} |
413 | 393 |
414 // Called when either: | 394 // Called when either: |
415 // - the TextInputClient is changed (e.g. by a change of focus) | 395 // - the TextInputClient is changed (e.g. by a change of focus) |
416 // - the TextInputType of the TextInputClient changes | 396 // - the TextInputType of the TextInputClient changes |
417 void BlimpEngineSession::OnTextInputStateChanged( | 397 void BlimpEngineSession::OnTextInputStateChanged( |
418 const ui::TextInputClient* client) { | 398 const ui::TextInputClient* client) { |
419 if (!tab_ || !tab_->web_contents()->GetRenderWidgetHostView()) | 399 if (!tab_ || !tab_->web_contents()->GetRenderWidgetHostView()) |
420 return; | 400 return; |
421 | 401 |
422 ui::TextInputType type = | 402 ui::TextInputType type = |
423 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 403 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
424 | 404 |
425 // TODO(shaktisahu): Propagate the new type to the client. | 405 // TODO(shaktisahu): Propagate the new type to the client. |
426 // Hide IME, when text input is out of focus, i.e. if the text input type | 406 // Hide IME, when text input is out of focus, i.e. if the text input type |
427 // changes to ui::TEXT_INPUT_TYPE_NONE. For other text input types, | 407 // changes to ui::TEXT_INPUT_TYPE_NONE. For other text input types, |
428 // OnShowImeIfNeeded is used instead to send show IME request to client. | 408 // OnShowImeIfNeeded is used instead to send show IME request to client. |
429 if (type == ui::TEXT_INPUT_TYPE_NONE) | 409 if (type == ui::TEXT_INPUT_TYPE_NONE) |
430 render_widget_feature_.SendHideImeRequest( | 410 render_widget_feature_.SendHideImeRequest( |
431 kDummyTabId, | 411 tab_->tab_id(), |
432 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost()); | 412 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost()); |
433 } | 413 } |
434 | 414 |
435 void BlimpEngineSession::OnInputMethodDestroyed( | 415 void BlimpEngineSession::OnInputMethodDestroyed( |
436 const ui::InputMethod* input_method) {} | 416 const ui::InputMethod* input_method) {} |
437 | 417 |
438 // Called when a user input should trigger showing the IME. | 418 // Called when a user input should trigger showing the IME. |
439 void BlimpEngineSession::OnShowImeIfNeeded() { | 419 void BlimpEngineSession::OnShowImeIfNeeded() { |
440 TRACE_EVENT0("blimp", "BlimpEngineSession::OnShowImeIfNeeded"); | 420 TRACE_EVENT0("blimp", "BlimpEngineSession::OnShowImeIfNeeded"); |
441 if (!tab_ || !tab_->web_contents()->GetRenderWidgetHostView() || | 421 if (!tab_ || !tab_->web_contents()->GetRenderWidgetHostView() || |
442 !window_tree_host_->GetInputMethod()->GetTextInputClient()) | 422 !window_tree_host_->GetInputMethod()->GetTextInputClient()) |
443 return; | 423 return; |
444 | 424 |
445 render_widget_feature_.SendShowImeRequest( | 425 render_widget_feature_.SendShowImeRequest( |
446 kDummyTabId, | 426 tab_->tab_id(), |
447 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(), | 427 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(), |
448 window_tree_host_->GetInputMethod()->GetTextInputClient()); | 428 window_tree_host_->GetInputMethod()->GetTextInputClient()); |
449 } | 429 } |
450 | 430 |
451 void BlimpEngineSession::ProcessMessage( | 431 void BlimpEngineSession::ProcessMessage( |
452 std::unique_ptr<BlimpMessage> message, | 432 std::unique_ptr<BlimpMessage> message, |
453 const net::CompletionCallback& callback) { | 433 const net::CompletionCallback& callback) { |
454 TRACE_EVENT1("blimp", "BlimpEngineSession::ProcessMessage", "TabId", | 434 TRACE_EVENT1("blimp", "BlimpEngineSession::ProcessMessage", "TabId", |
455 message->target_tab_id()); | 435 message->target_tab_id()); |
456 DCHECK(!callback.is_null()); | 436 DCHECK(!callback.is_null()); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 } | 533 } |
554 | 534 |
555 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { | 535 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { |
556 contents->GetRenderViewHost()->GetWidget()->Focus(); | 536 contents->GetRenderViewHost()->GetWidget()->Focus(); |
557 } | 537 } |
558 | 538 |
559 void BlimpEngineSession::ForwardCompositorProto( | 539 void BlimpEngineSession::ForwardCompositorProto( |
560 content::RenderWidgetHost* render_widget_host, | 540 content::RenderWidgetHost* render_widget_host, |
561 const std::vector<uint8_t>& proto) { | 541 const std::vector<uint8_t>& proto) { |
562 TRACE_EVENT0("blimp", "BlimpEngineSession::ForwardCompositorProto"); | 542 TRACE_EVENT0("blimp", "BlimpEngineSession::ForwardCompositorProto"); |
563 render_widget_feature_.SendCompositorMessage(kDummyTabId, render_widget_host, | 543 if (!tab_) { |
564 proto); | 544 return; |
| 545 } |
| 546 render_widget_feature_.SendCompositorMessage(tab_->tab_id(), |
| 547 render_widget_host, proto); |
565 } | 548 } |
566 | 549 |
567 void BlimpEngineSession::NavigationStateChanged( | 550 void BlimpEngineSession::NavigationStateChanged( |
568 content::WebContents* source, | 551 content::WebContents* source, |
569 content::InvalidateTypes changed_flags) { | 552 content::InvalidateTypes changed_flags) { |
570 TRACE_EVENT0("blimp", "BlimpEngineSession::NavigationStateChanged"); | 553 TRACE_EVENT0("blimp", "BlimpEngineSession::NavigationStateChanged"); |
571 if (source == tab_->web_contents()) | 554 if (source == tab_->web_contents()) |
572 tab_->NavigationStateChanged(changed_flags); | 555 tab_->NavigationStateChanged(changed_flags); |
573 } | 556 } |
574 | 557 |
575 void BlimpEngineSession::PlatformSetContents( | 558 void BlimpEngineSession::PlatformSetContents( |
576 std::unique_ptr<content::WebContents> new_contents, | 559 std::unique_ptr<content::WebContents> new_contents, |
577 const int target_tab_id) { | 560 const int target_tab_id) { |
578 new_contents->SetDelegate(this); | 561 new_contents->SetDelegate(this); |
579 | 562 |
580 aura::Window* parent = window_tree_host_->window(); | 563 aura::Window* parent = window_tree_host_->window(); |
581 aura::Window* content = new_contents->GetNativeView(); | 564 aura::Window* content = new_contents->GetNativeView(); |
582 if (!parent->Contains(content)) | 565 if (!parent->Contains(content)) |
583 parent->AddChild(content); | 566 parent->AddChild(content); |
584 content->Show(); | 567 content->Show(); |
585 | 568 |
586 tab_ = base::MakeUnique<Tab>(std::move(new_contents), target_tab_id, | 569 tab_ = base::MakeUnique<Tab>(std::move(new_contents), target_tab_id, |
587 &render_widget_feature_, | 570 &render_widget_feature_, |
588 navigation_message_sender_.get()); | 571 navigation_message_sender_.get()); |
589 } | 572 } |
590 | 573 |
591 } // namespace engine | 574 } // namespace engine |
592 } // namespace blimp | 575 } // namespace blimp |
OLD | NEW |