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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
14 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
15 #include "blimp/common/create_blimp_message.h" | 15 #include "blimp/common/create_blimp_message.h" |
16 #include "blimp/common/proto/tab_control.pb.h" | 16 #include "blimp/common/proto/tab_control.pb.h" |
17 #include "blimp/engine/app/blimp_engine_config.h" | 17 #include "blimp/engine/app/blimp_engine_config.h" |
18 #include "blimp/engine/app/settings_manager.h" | 18 #include "blimp/engine/app/settings_manager.h" |
19 #include "blimp/engine/app/switches.h" | 19 #include "blimp/engine/app/switches.h" |
20 #include "blimp/engine/app/ui/blimp_layout_manager.h" | 20 #include "blimp/engine/app/ui/blimp_layout_manager.h" |
21 #include "blimp/engine/app/ui/blimp_screen.h" | 21 #include "blimp/engine/app/ui/blimp_screen.h" |
22 #include "blimp/engine/app/ui/blimp_window_tree_client.h" | 22 #include "blimp/engine/app/ui/blimp_window_tree_client.h" |
23 #include "blimp/engine/app/ui/blimp_window_tree_host.h" | 23 #include "blimp/engine/app/ui/blimp_window_tree_host.h" |
24 #include "blimp/engine/common/blimp_browser_context.h" | 24 #include "blimp/engine/common/blimp_browser_context.h" |
25 #include "blimp/engine/common/blimp_user_agent.h" | 25 #include "blimp/engine/common/blimp_user_agent.h" |
| 26 #include "blimp/engine/session/tab.h" |
26 #include "blimp/net/blimp_connection.h" | 27 #include "blimp/net/blimp_connection.h" |
27 #include "blimp/net/blimp_connection_statistics.h" | 28 #include "blimp/net/blimp_connection_statistics.h" |
28 #include "blimp/net/blimp_message_multiplexer.h" | 29 #include "blimp/net/blimp_message_multiplexer.h" |
29 #include "blimp/net/blimp_message_thread_pipe.h" | 30 #include "blimp/net/blimp_message_thread_pipe.h" |
30 #include "blimp/net/browser_connection_handler.h" | 31 #include "blimp/net/browser_connection_handler.h" |
31 #include "blimp/net/common.h" | 32 #include "blimp/net/common.h" |
32 #include "blimp/net/engine_authentication_handler.h" | 33 #include "blimp/net/engine_authentication_handler.h" |
33 #include "blimp/net/engine_connection_manager.h" | 34 #include "blimp/net/engine_connection_manager.h" |
34 #include "blimp/net/null_blimp_message_processor.h" | 35 #include "blimp/net/null_blimp_message_processor.h" |
35 #include "blimp/net/tcp_engine_transport.h" | 36 #include "blimp/net/tcp_engine_transport.h" |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 gfx::Size(kDefaultDisplayWidth, | 227 gfx::Size(kDefaultDisplayWidth, |
227 kDefaultDisplayHeight)); | 228 kDefaultDisplayHeight)); |
228 render_widget_feature_.SetDelegate(kDummyTabId, this); | 229 render_widget_feature_.SetDelegate(kDummyTabId, this); |
229 } | 230 } |
230 | 231 |
231 BlimpEngineSession::~BlimpEngineSession() { | 232 BlimpEngineSession::~BlimpEngineSession() { |
232 render_widget_feature_.RemoveDelegate(kDummyTabId); | 233 render_widget_feature_.RemoveDelegate(kDummyTabId); |
233 | 234 |
234 window_tree_host_->GetInputMethod()->RemoveObserver(this); | 235 window_tree_host_->GetInputMethod()->RemoveObserver(this); |
235 | 236 |
236 page_load_tracker_.reset(); | 237 // Ensure that all tabs are torn down first, since teardown will |
237 | 238 // trigger RenderViewDeleted callbacks to their observers, which will in turn |
238 // Ensure that all WebContents are torn down first, since teardown will | 239 // send messages to net_components_, which is already deleted due to the line |
239 // trigger RenderViewDeleted callbacks to their observers. | 240 // below. |
240 web_contents_.reset(); | 241 tab_.reset(); |
241 | 242 |
242 // Safely delete network components on the IO thread. | 243 // Safely delete network components on the IO thread. |
243 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | 244 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
244 net_components_.release()); | 245 net_components_.release()); |
245 } | 246 } |
246 | 247 |
247 void BlimpEngineSession::Initialize() { | 248 void BlimpEngineSession::Initialize() { |
248 DCHECK(!display::Screen::GetScreen()); | 249 DCHECK(!display::Screen::GetScreen()); |
249 display::Screen::SetScreenInstance(screen_.get()); | 250 display::Screen::SetScreenInstance(screen_.get()); |
250 | 251 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 render_widget_feature_.set_ime_message_sender( | 313 render_widget_feature_.set_ime_message_sender( |
313 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, | 314 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, |
314 &render_widget_feature_)); | 315 &render_widget_feature_)); |
315 | 316 |
316 // The Settings feature does not need an outgoing message processor, since we | 317 // The Settings feature does not need an outgoing message processor, since we |
317 // don't send any messages to the client right now. | 318 // don't send any messages to the client right now. |
318 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, | 319 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, |
319 &settings_feature_); | 320 &settings_feature_); |
320 } | 321 } |
321 | 322 |
322 bool BlimpEngineSession::CreateWebContents(const int target_tab_id) { | 323 bool BlimpEngineSession::CreateTab(const int target_tab_id) { |
323 DVLOG(1) << "Create tab " << target_tab_id; | 324 DVLOG(1) << "Create tab " << target_tab_id; |
324 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). | 325 if (tab_) { |
325 if (web_contents_) { | |
326 DLOG(WARNING) << "Tab " << target_tab_id << " already existed"; | |
327 return false; | 326 return false; |
328 } | 327 } |
329 | 328 |
330 content::WebContents::CreateParams create_params(browser_context_.get(), | 329 content::WebContents::CreateParams create_params(browser_context_.get(), |
331 nullptr); | 330 nullptr); |
332 std::unique_ptr<content::WebContents> new_contents = | 331 std::unique_ptr<content::WebContents> new_contents = |
333 base::WrapUnique(content::WebContents::Create(create_params)); | 332 base::WrapUnique(content::WebContents::Create(create_params)); |
334 PlatformSetContents(std::move(new_contents)); | 333 PlatformSetContents(std::move(new_contents), target_tab_id); |
335 | |
336 // Transfer over the user agent override. The default user agent does not | |
337 // have client IO info. | |
338 web_contents_->SetUserAgentOverride(GetBlimpEngineUserAgent()); | |
339 | 334 |
340 return true; | 335 return true; |
341 } | 336 } |
342 | 337 |
343 void BlimpEngineSession::CloseWebContents(const int target_tab_id) { | 338 void BlimpEngineSession::CloseTab(const int target_tab_id) { |
344 DVLOG(1) << "Close tab " << target_tab_id; | 339 DVLOG(1) << "Close tab " << target_tab_id; |
345 DCHECK(web_contents_); | 340 tab_.reset(); |
346 web_contents_->Close(); | |
347 } | 341 } |
348 | 342 |
349 void BlimpEngineSession::HandleResize(float device_pixel_ratio, | 343 void BlimpEngineSession::HandleResize(float device_pixel_ratio, |
350 const gfx::Size& size) { | 344 const gfx::Size& size) { |
351 DVLOG(1) << "Resize to " << size.ToString() << ", " << device_pixel_ratio; | 345 DVLOG(1) << "Resize to " << size.ToString() << ", " << device_pixel_ratio; |
352 screen_->UpdateDisplayScaleAndSize(device_pixel_ratio, size); | 346 screen_->UpdateDisplayScaleAndSize(device_pixel_ratio, size); |
353 window_tree_host_->SetBounds(gfx::Rect(size)); | 347 window_tree_host_->SetBounds(gfx::Rect(size)); |
354 if (web_contents_) { | 348 if (tab_) { |
355 const gfx::Size size_in_dips = screen_->GetPrimaryDisplay().bounds().size(); | 349 tab_->Resize(device_pixel_ratio, |
356 web_contents_->GetNativeView()->SetBounds(gfx::Rect(size_in_dips)); | 350 screen_->GetPrimaryDisplay().bounds().size()); |
357 } | 351 } |
358 | |
359 if (web_contents_ && web_contents_->GetRenderViewHost() && | |
360 web_contents_->GetRenderViewHost()->GetWidget()) { | |
361 web_contents_->GetRenderViewHost()->GetWidget()->WasResized(); | |
362 } | |
363 } | |
364 | |
365 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { | |
366 TRACE_EVENT1("blimp", "BlimpEngineSession::LoadUrl", "URL", url.spec()); | |
367 DVLOG(1) << "Load URL " << url << " in tab " << target_tab_id; | |
368 if (!url.is_valid()) { | |
369 VLOG(1) << "Dropping invalid URL " << url; | |
370 return; | |
371 } | |
372 | |
373 // TODO(dtrainor, haibinlu): Fix up the URL with url_fixer.h. If that doesn't | |
374 // produce a valid spec() then try to build a search query? | |
375 content::NavigationController::LoadURLParams params(url); | |
376 params.transition_type = ui::PageTransitionFromInt( | |
377 ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); | |
378 params.override_user_agent = | |
379 content::NavigationController::UA_OVERRIDE_TRUE; | |
380 web_contents_->GetController().LoadURLWithParams(params); | |
381 web_contents_->Focus(); | |
382 } | |
383 | |
384 void BlimpEngineSession::GoBack(const int target_tab_id) { | |
385 DVLOG(1) << "Back in tab " << target_tab_id; | |
386 web_contents_->GetController().GoBack(); | |
387 } | |
388 | |
389 void BlimpEngineSession::GoForward(const int target_tab_id) { | |
390 DVLOG(1) << "Forward in tab " << target_tab_id; | |
391 web_contents_->GetController().GoForward(); | |
392 } | |
393 | |
394 void BlimpEngineSession::Reload(const int target_tab_id) { | |
395 DVLOG(1) << "Reload in tab " << target_tab_id; | |
396 web_contents_->GetController().Reload(true); | |
397 } | 352 } |
398 | 353 |
399 void BlimpEngineSession::OnWebGestureEvent( | 354 void BlimpEngineSession::OnWebGestureEvent( |
400 content::RenderWidgetHost* render_widget_host, | 355 content::RenderWidgetHost* render_widget_host, |
401 std::unique_ptr<blink::WebGestureEvent> event) { | 356 std::unique_ptr<blink::WebGestureEvent> event) { |
402 TRACE_EVENT1("blimp", "BlimpEngineSession::OnWebGestureEvent", "type", | 357 TRACE_EVENT1("blimp", "BlimpEngineSession::OnWebGestureEvent", "type", |
403 event->type); | 358 event->type); |
404 render_widget_host->ForwardGestureEvent(*event); | 359 render_widget_host->ForwardGestureEvent(*event); |
405 } | 360 } |
406 | 361 |
(...skipping 13 matching lines...) Expand all Loading... |
420 void BlimpEngineSession::OnBlur() {} | 375 void BlimpEngineSession::OnBlur() {} |
421 | 376 |
422 void BlimpEngineSession::OnCaretBoundsChanged( | 377 void BlimpEngineSession::OnCaretBoundsChanged( |
423 const ui::TextInputClient* client) {} | 378 const ui::TextInputClient* client) {} |
424 | 379 |
425 // Called when either: | 380 // Called when either: |
426 // - the TextInputClient is changed (e.g. by a change of focus) | 381 // - the TextInputClient is changed (e.g. by a change of focus) |
427 // - the TextInputType of the TextInputClient changes | 382 // - the TextInputType of the TextInputClient changes |
428 void BlimpEngineSession::OnTextInputStateChanged( | 383 void BlimpEngineSession::OnTextInputStateChanged( |
429 const ui::TextInputClient* client) { | 384 const ui::TextInputClient* client) { |
430 if (!web_contents_->GetRenderWidgetHostView()) | 385 if (!tab_ || !tab_->web_contents()->GetRenderWidgetHostView()) |
431 return; | 386 return; |
432 | 387 |
433 ui::TextInputType type = | 388 ui::TextInputType type = |
434 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 389 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
435 | 390 |
436 // TODO(shaktisahu): Propagate the new type to the client. | 391 // TODO(shaktisahu): Propagate the new type to the client. |
437 // Hide IME, when text input is out of focus, i.e. if the text input type | 392 // Hide IME, when text input is out of focus, i.e. if the text input type |
438 // changes to ui::TEXT_INPUT_TYPE_NONE. For other text input types, | 393 // changes to ui::TEXT_INPUT_TYPE_NONE. For other text input types, |
439 // OnShowImeIfNeeded is used instead to send show IME request to client. | 394 // OnShowImeIfNeeded is used instead to send show IME request to client. |
440 if (type == ui::TEXT_INPUT_TYPE_NONE) | 395 if (type == ui::TEXT_INPUT_TYPE_NONE) |
441 render_widget_feature_.SendHideImeRequest( | 396 render_widget_feature_.SendHideImeRequest( |
442 kDummyTabId, | 397 kDummyTabId, |
443 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()); | 398 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost()); |
444 } | 399 } |
445 | 400 |
446 void BlimpEngineSession::OnInputMethodDestroyed( | 401 void BlimpEngineSession::OnInputMethodDestroyed( |
447 const ui::InputMethod* input_method) {} | 402 const ui::InputMethod* input_method) {} |
448 | 403 |
449 // Called when a user input should trigger showing the IME. | 404 // Called when a user input should trigger showing the IME. |
450 void BlimpEngineSession::OnShowImeIfNeeded() { | 405 void BlimpEngineSession::OnShowImeIfNeeded() { |
451 TRACE_EVENT0("blimp", "BlimpEngineSession::OnShowImeIfNeeded"); | 406 TRACE_EVENT0("blimp", "BlimpEngineSession::OnShowImeIfNeeded"); |
452 if (!web_contents_->GetRenderWidgetHostView() || | 407 if (!tab_ || !tab_->web_contents()->GetRenderWidgetHostView() || |
453 !window_tree_host_->GetInputMethod()->GetTextInputClient()) | 408 !window_tree_host_->GetInputMethod()->GetTextInputClient()) |
454 return; | 409 return; |
455 | 410 |
456 render_widget_feature_.SendShowImeRequest( | 411 render_widget_feature_.SendShowImeRequest( |
457 kDummyTabId, | 412 kDummyTabId, |
458 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(), | 413 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(), |
459 window_tree_host_->GetInputMethod()->GetTextInputClient()); | 414 window_tree_host_->GetInputMethod()->GetTextInputClient()); |
460 } | 415 } |
461 | 416 |
462 void BlimpEngineSession::ProcessMessage( | 417 void BlimpEngineSession::ProcessMessage( |
463 std::unique_ptr<BlimpMessage> message, | 418 std::unique_ptr<BlimpMessage> message, |
464 const net::CompletionCallback& callback) { | 419 const net::CompletionCallback& callback) { |
465 TRACE_EVENT1("blimp", "BlimpEngineSession::ProcessMessage", "TabId", | 420 TRACE_EVENT1("blimp", "BlimpEngineSession::ProcessMessage", "TabId", |
466 message->target_tab_id()); | 421 message->target_tab_id()); |
467 DCHECK(!callback.is_null()); | 422 DCHECK(!callback.is_null()); |
468 DCHECK(BlimpMessage::kTabControl == message->feature_case() || | 423 DCHECK(BlimpMessage::kTabControl == message->feature_case() || |
469 BlimpMessage::kNavigation == message->feature_case()); | 424 BlimpMessage::kNavigation == message->feature_case()); |
470 | 425 |
471 net::Error result = net::OK; | 426 net::Error result = net::OK; |
472 if (message->has_tab_control()) { | 427 if (message->has_tab_control()) { |
473 switch (message->tab_control().tab_control_case()) { | 428 switch (message->tab_control().tab_control_case()) { |
474 case TabControlMessage::kCreateTab: | 429 case TabControlMessage::kCreateTab: |
475 if (!CreateWebContents(message->target_tab_id())) | 430 if (!CreateTab(message->target_tab_id())) |
476 result = net::ERR_FAILED; | 431 result = net::ERR_FAILED; |
477 break; | 432 break; |
478 case TabControlMessage::kCloseTab: | 433 case TabControlMessage::kCloseTab: |
479 CloseWebContents(message->target_tab_id()); | 434 CloseTab(message->target_tab_id()); |
480 case TabControlMessage::kSize: | 435 case TabControlMessage::kSize: |
481 HandleResize(message->tab_control().size().device_pixel_ratio(), | 436 HandleResize(message->tab_control().size().device_pixel_ratio(), |
482 gfx::Size(message->tab_control().size().width(), | 437 gfx::Size(message->tab_control().size().width(), |
483 message->tab_control().size().height())); | 438 message->tab_control().size().height())); |
484 break; | 439 break; |
485 default: | 440 default: |
486 NOTIMPLEMENTED(); | 441 NOTIMPLEMENTED(); |
487 result = net::ERR_NOT_IMPLEMENTED; | 442 result = net::ERR_NOT_IMPLEMENTED; |
488 } | 443 } |
489 } else if (message->has_navigation() && web_contents_) { | 444 } else if (message->has_navigation()) { |
490 switch (message->navigation().type()) { | 445 if (tab_) { |
491 case NavigationMessage::LOAD_URL: | 446 switch (message->navigation().type()) { |
492 LoadUrl(message->target_tab_id(), | 447 case NavigationMessage::LOAD_URL: |
493 GURL(message->navigation().load_url().url())); | 448 tab_->LoadUrl(GURL(message->navigation().load_url().url())); |
494 break; | 449 break; |
495 case NavigationMessage::GO_BACK: | 450 case NavigationMessage::GO_BACK: |
496 GoBack(message->target_tab_id()); | 451 tab_->GoBack(); |
497 break; | 452 break; |
498 case NavigationMessage::GO_FORWARD: | 453 case NavigationMessage::GO_FORWARD: |
499 GoForward(message->target_tab_id()); | 454 tab_->GoForward(); |
500 break; | 455 break; |
501 case NavigationMessage::RELOAD: | 456 case NavigationMessage::RELOAD: |
502 Reload(message->target_tab_id()); | 457 tab_->Reload(); |
503 break; | 458 break; |
504 default: | 459 default: |
505 NOTIMPLEMENTED(); | 460 NOTIMPLEMENTED(); |
506 result = net::ERR_NOT_IMPLEMENTED; | 461 result = net::ERR_NOT_IMPLEMENTED; |
| 462 } |
| 463 } else { |
| 464 VLOG(1) << "Tab " << message->target_tab_id() << " does not exist"; |
507 } | 465 } |
508 } else { | 466 } else { |
509 DVLOG(1) << "No WebContents for navigation control"; | 467 NOTREACHED(); |
510 result = net::ERR_FAILED; | 468 result = net::ERR_FAILED; |
511 } | 469 } |
512 | 470 |
513 callback.Run(result); | 471 callback.Run(result); |
514 } | 472 } |
515 | 473 |
516 void BlimpEngineSession::AddNewContents(content::WebContents* source, | 474 void BlimpEngineSession::AddNewContents(content::WebContents* source, |
517 content::WebContents* new_contents, | 475 content::WebContents* new_contents, |
518 WindowOpenDisposition disposition, | 476 WindowOpenDisposition disposition, |
519 const gfx::Rect& initial_rect, | 477 const gfx::Rect& initial_rect, |
(...skipping 28 matching lines...) Expand all Loading... |
548 return source; | 506 return source; |
549 } | 507 } |
550 | 508 |
551 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, | 509 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, |
552 bool user_gesture, | 510 bool user_gesture, |
553 bool last_unlocked_by_target) { | 511 bool last_unlocked_by_target) { |
554 web_contents->GotResponseToLockMouseRequest(true); | 512 web_contents->GotResponseToLockMouseRequest(true); |
555 } | 513 } |
556 | 514 |
557 void BlimpEngineSession::CloseContents(content::WebContents* source) { | 515 void BlimpEngineSession::CloseContents(content::WebContents* source) { |
558 if (source == web_contents_.get()) { | 516 if (source == tab_->web_contents()) { |
559 Observe(nullptr); | 517 tab_.reset(); |
560 web_contents_.reset(); | |
561 } | 518 } |
562 } | 519 } |
563 | 520 |
564 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { | 521 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { |
565 contents->GetRenderViewHost()->GetWidget()->Focus(); | 522 contents->GetRenderViewHost()->GetWidget()->Focus(); |
566 } | 523 } |
567 | 524 |
568 void BlimpEngineSession::ForwardCompositorProto( | 525 void BlimpEngineSession::ForwardCompositorProto( |
569 content::RenderWidgetHost* render_widget_host, | 526 content::RenderWidgetHost* render_widget_host, |
570 const std::vector<uint8_t>& proto) { | 527 const std::vector<uint8_t>& proto) { |
571 TRACE_EVENT0("blimp", "BlimpEngineSession::ForwardCompositorProto"); | 528 TRACE_EVENT0("blimp", "BlimpEngineSession::ForwardCompositorProto"); |
572 render_widget_feature_.SendCompositorMessage(kDummyTabId, render_widget_host, | 529 render_widget_feature_.SendCompositorMessage(kDummyTabId, render_widget_host, |
573 proto); | 530 proto); |
574 } | 531 } |
575 | 532 |
576 void BlimpEngineSession::NavigationStateChanged( | 533 void BlimpEngineSession::NavigationStateChanged( |
577 content::WebContents* source, | 534 content::WebContents* source, |
578 content::InvalidateTypes changed_flags) { | 535 content::InvalidateTypes changed_flags) { |
579 TRACE_EVENT0("blimp", "BlimpEngineSession::NavigationStateChanged"); | 536 TRACE_EVENT0("blimp", "BlimpEngineSession::NavigationStateChanged"); |
580 if (source != web_contents_.get() || !changed_flags) | 537 if (source == tab_->web_contents()) |
581 return; | 538 tab_->NavigationStateChanged(changed_flags); |
582 | |
583 NavigationMessage* navigation_message; | |
584 std::unique_ptr<BlimpMessage> message = | |
585 CreateBlimpMessage(&navigation_message, kDummyTabId); | |
586 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); | |
587 NavigationStateChangeMessage* details = | |
588 navigation_message->mutable_navigation_state_changed(); | |
589 | |
590 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_URL) | |
591 details->set_url(source->GetURL().spec()); | |
592 | |
593 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TAB) { | |
594 // TODO(dtrainor): Serialize the favicon? crbug.com/597094. | |
595 DVLOG(3) << "Tab favicon changed"; | |
596 } | |
597 | |
598 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_TITLE) | |
599 details->set_title(base::UTF16ToUTF8(source->GetTitle())); | |
600 | |
601 if (changed_flags & content::InvalidateTypes::INVALIDATE_TYPE_LOAD) | |
602 details->set_loading(source->IsLoading()); | |
603 | |
604 navigation_message_sender_->ProcessMessage(std::move(message), | |
605 net::CompletionCallback()); | |
606 } | |
607 | |
608 void BlimpEngineSession::RenderViewCreated( | |
609 content::RenderViewHost* render_view_host) { | |
610 render_widget_feature_.OnRenderWidgetCreated(kDummyTabId, | |
611 render_view_host->GetWidget()); | |
612 } | |
613 | |
614 void BlimpEngineSession::RenderViewHostChanged( | |
615 content::RenderViewHost* old_host, | |
616 content::RenderViewHost* new_host) { | |
617 // Informs client that WebContents swaps its visible RenderViewHost with | |
618 // another one. | |
619 render_widget_feature_.OnRenderWidgetInitialized(kDummyTabId, | |
620 new_host->GetWidget()); | |
621 } | |
622 | |
623 void BlimpEngineSession::RenderViewDeleted( | |
624 content::RenderViewHost* render_view_host) { | |
625 render_widget_feature_.OnRenderWidgetDeleted(kDummyTabId, | |
626 render_view_host->GetWidget()); | |
627 } | |
628 | |
629 void BlimpEngineSession::SendPageLoadStatusUpdate(PageLoadStatus load_status) { | |
630 bool page_load_completed = false; | |
631 | |
632 switch (load_status) { | |
633 case PageLoadStatus::LOADING: | |
634 page_load_completed = false; | |
635 break; | |
636 case PageLoadStatus::LOADED: | |
637 page_load_completed = true; | |
638 break; | |
639 } | |
640 | |
641 NavigationMessage* navigation_message = nullptr; | |
642 std::unique_ptr<BlimpMessage> message = | |
643 CreateBlimpMessage(&navigation_message, kDummyTabId); | |
644 navigation_message->set_type(NavigationMessage::NAVIGATION_STATE_CHANGED); | |
645 NavigationStateChangeMessage* details = | |
646 navigation_message->mutable_navigation_state_changed(); | |
647 details->set_page_load_completed(page_load_completed); | |
648 | |
649 navigation_message_sender_->ProcessMessage(std::move(message), | |
650 net::CompletionCallback()); | |
651 } | 539 } |
652 | 540 |
653 void BlimpEngineSession::PlatformSetContents( | 541 void BlimpEngineSession::PlatformSetContents( |
654 std::unique_ptr<content::WebContents> new_contents) { | 542 std::unique_ptr<content::WebContents> new_contents, |
| 543 const int target_tab_id) { |
655 new_contents->SetDelegate(this); | 544 new_contents->SetDelegate(this); |
656 Observe(new_contents.get()); | |
657 web_contents_ = std::move(new_contents); | |
658 | 545 |
659 page_load_tracker_.reset(new PageLoadTracker(web_contents_.get(), this)); | |
660 aura::Window* parent = window_tree_host_->window(); | 546 aura::Window* parent = window_tree_host_->window(); |
661 aura::Window* content = web_contents_->GetNativeView(); | 547 aura::Window* content = new_contents->GetNativeView(); |
662 if (!parent->Contains(content)) | 548 if (!parent->Contains(content)) |
663 parent->AddChild(content); | 549 parent->AddChild(content); |
664 content->Show(); | 550 content->Show(); |
| 551 |
| 552 tab_ = base::WrapUnique(new Tab(std::move(new_contents), target_tab_id, |
| 553 &render_widget_feature_, |
| 554 navigation_message_sender_.get())); |
665 } | 555 } |
666 | 556 |
667 } // namespace engine | 557 } // namespace engine |
668 } // namespace blimp | 558 } // namespace blimp |
OLD | NEW |