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 | |
238 // Ensure that all WebContents are torn down first, since teardown will | |
239 // trigger RenderViewDeleted callbacks to their observers. | |
240 web_contents_.reset(); | |
241 | |
242 // Safely delete network components on the IO thread. | 237 // Safely delete network components on the IO thread. |
243 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, | 238 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, |
244 net_components_.release()); | 239 net_components_.release()); |
245 } | 240 } |
246 | 241 |
247 void BlimpEngineSession::Initialize() { | 242 void BlimpEngineSession::Initialize() { |
248 DCHECK(!display::Screen::GetScreen()); | 243 DCHECK(!display::Screen::GetScreen()); |
249 display::Screen::SetScreenInstance(screen_.get()); | 244 display::Screen::SetScreenInstance(screen_.get()); |
250 | 245 |
251 window_tree_host_.reset(new BlimpWindowTreeHost()); | 246 window_tree_host_.reset(new BlimpWindowTreeHost()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 render_widget_feature_.set_ime_message_sender( | 307 render_widget_feature_.set_ime_message_sender( |
313 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, | 308 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, |
314 &render_widget_feature_)); | 309 &render_widget_feature_)); |
315 | 310 |
316 // The Settings feature does not need an outgoing message processor, since we | 311 // The Settings feature does not need an outgoing message processor, since we |
317 // don't send any messages to the client right now. | 312 // don't send any messages to the client right now. |
318 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, | 313 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, |
319 &settings_feature_); | 314 &settings_feature_); |
320 } | 315 } |
321 | 316 |
322 bool BlimpEngineSession::CreateWebContents(const int target_tab_id) { | 317 bool BlimpEngineSession::CreateTab(const int target_tab_id) { |
323 DVLOG(1) << "Create tab " << target_tab_id; | 318 DVLOG(1) << "Create tab " << target_tab_id; |
324 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). | 319 if (tab_) { |
325 if (web_contents_) { | |
326 DLOG(WARNING) << "Tab " << target_tab_id << " already existed"; | |
327 return false; | 320 return false; |
328 } | 321 } |
329 | 322 |
330 content::WebContents::CreateParams create_params(browser_context_.get(), | 323 content::WebContents::CreateParams create_params(browser_context_.get(), |
331 nullptr); | 324 nullptr); |
332 std::unique_ptr<content::WebContents> new_contents = | 325 std::unique_ptr<content::WebContents> new_contents = |
333 base::WrapUnique(content::WebContents::Create(create_params)); | 326 base::WrapUnique(content::WebContents::Create(create_params)); |
334 PlatformSetContents(std::move(new_contents)); | 327 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 | 328 |
340 return true; | 329 return true; |
341 } | 330 } |
342 | 331 |
343 void BlimpEngineSession::CloseWebContents(const int target_tab_id) { | 332 void BlimpEngineSession::CloseTab(const int target_tab_id) { |
344 DVLOG(1) << "Close tab " << target_tab_id; | 333 DVLOG(1) << "Close tab " << target_tab_id; |
345 DCHECK(web_contents_); | 334 tab_.reset(); |
346 web_contents_->Close(); | |
347 } | 335 } |
348 | 336 |
349 void BlimpEngineSession::HandleResize(float device_pixel_ratio, | 337 void BlimpEngineSession::HandleResize(float device_pixel_ratio, |
350 const gfx::Size& size) { | 338 const gfx::Size& size) { |
351 DVLOG(1) << "Resize to " << size.ToString() << ", " << device_pixel_ratio; | 339 DVLOG(1) << "Resize to " << size.ToString() << ", " << device_pixel_ratio; |
352 screen_->UpdateDisplayScaleAndSize(device_pixel_ratio, size); | 340 screen_->UpdateDisplayScaleAndSize(device_pixel_ratio, size); |
353 window_tree_host_->SetBounds(gfx::Rect(size)); | 341 window_tree_host_->SetBounds(gfx::Rect(size)); |
354 if (web_contents_) { | 342 if (tab_) { |
355 const gfx::Size size_in_dips = screen_->GetPrimaryDisplay().bounds().size(); | 343 tab_->Resize(device_pixel_ratio, |
356 web_contents_->GetNativeView()->SetBounds(gfx::Rect(size_in_dips)); | 344 screen_->GetPrimaryDisplay().bounds().size()); |
357 } | |
358 | |
359 if (web_contents_ && web_contents_->GetRenderViewHost() && | |
360 web_contents_->GetRenderViewHost()->GetWidget()) { | |
361 web_contents_->GetRenderViewHost()->GetWidget()->WasResized(); | |
362 } | 345 } |
363 } | 346 } |
364 | 347 |
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 } | |
398 | |
399 void BlimpEngineSession::OnWebGestureEvent( | 348 void BlimpEngineSession::OnWebGestureEvent( |
400 content::RenderWidgetHost* render_widget_host, | 349 content::RenderWidgetHost* render_widget_host, |
401 std::unique_ptr<blink::WebGestureEvent> event) { | 350 std::unique_ptr<blink::WebGestureEvent> event) { |
402 TRACE_EVENT1("blimp", "BlimpEngineSession::OnWebGestureEvent", "type", | 351 TRACE_EVENT1("blimp", "BlimpEngineSession::OnWebGestureEvent", "type", |
403 event->type); | 352 event->type); |
404 render_widget_host->ForwardGestureEvent(*event); | 353 render_widget_host->ForwardGestureEvent(*event); |
405 } | 354 } |
406 | 355 |
407 void BlimpEngineSession::OnCompositorMessageReceived( | 356 void BlimpEngineSession::OnCompositorMessageReceived( |
408 content::RenderWidgetHost* render_widget_host, | 357 content::RenderWidgetHost* render_widget_host, |
(...skipping 10 matching lines...) Expand all Loading... | |
419 | 368 |
420 void BlimpEngineSession::OnBlur() {} | 369 void BlimpEngineSession::OnBlur() {} |
421 | 370 |
422 void BlimpEngineSession::OnCaretBoundsChanged( | 371 void BlimpEngineSession::OnCaretBoundsChanged( |
423 const ui::TextInputClient* client) {} | 372 const ui::TextInputClient* client) {} |
424 | 373 |
425 // Called when either: | 374 // Called when either: |
426 // - the TextInputClient is changed (e.g. by a change of focus) | 375 // - the TextInputClient is changed (e.g. by a change of focus) |
427 // - the TextInputType of the TextInputClient changes | 376 // - the TextInputType of the TextInputClient changes |
428 void BlimpEngineSession::OnTextInputStateChanged( | 377 void BlimpEngineSession::OnTextInputStateChanged( |
429 const ui::TextInputClient* client) { | 378 const ui::TextInputClient* client) { |
Kevin M
2016/06/07 22:43:42
Also check that tab_ exists
haibinlu
2016/06/08 17:57:22
Done.
| |
430 if (!web_contents_->GetRenderWidgetHostView()) | 379 if (!tab_->web_contents()->GetRenderWidgetHostView()) |
431 return; | 380 return; |
432 | 381 |
433 ui::TextInputType type = | 382 ui::TextInputType type = |
434 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; | 383 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; |
435 | 384 |
436 // TODO(shaktisahu): Propagate the new type to the client. | 385 // 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 | 386 // 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, | 387 // changes to ui::TEXT_INPUT_TYPE_NONE. For other text input types, |
439 // OnShowImeIfNeeded is used instead to send show IME request to client. | 388 // OnShowImeIfNeeded is used instead to send show IME request to client. |
440 if (type == ui::TEXT_INPUT_TYPE_NONE) | 389 if (type == ui::TEXT_INPUT_TYPE_NONE) |
441 render_widget_feature_.SendHideImeRequest( | 390 render_widget_feature_.SendHideImeRequest( |
442 kDummyTabId, | 391 kDummyTabId, |
443 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()); | 392 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost()); |
444 } | 393 } |
445 | 394 |
446 void BlimpEngineSession::OnInputMethodDestroyed( | 395 void BlimpEngineSession::OnInputMethodDestroyed( |
447 const ui::InputMethod* input_method) {} | 396 const ui::InputMethod* input_method) {} |
448 | 397 |
449 // Called when a user input should trigger showing the IME. | 398 // Called when a user input should trigger showing the IME. |
450 void BlimpEngineSession::OnShowImeIfNeeded() { | 399 void BlimpEngineSession::OnShowImeIfNeeded() { |
451 TRACE_EVENT0("blimp", "BlimpEngineSession::OnShowImeIfNeeded"); | 400 TRACE_EVENT0("blimp", "BlimpEngineSession::OnShowImeIfNeeded"); |
452 if (!web_contents_->GetRenderWidgetHostView() || | 401 if (!tab_ || !tab_->web_contents()->GetRenderWidgetHostView() || |
453 !window_tree_host_->GetInputMethod()->GetTextInputClient()) | 402 !window_tree_host_->GetInputMethod()->GetTextInputClient()) |
454 return; | 403 return; |
455 | 404 |
456 render_widget_feature_.SendShowImeRequest( | 405 render_widget_feature_.SendShowImeRequest( |
457 kDummyTabId, | 406 kDummyTabId, |
458 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(), | 407 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(), |
459 window_tree_host_->GetInputMethod()->GetTextInputClient()); | 408 window_tree_host_->GetInputMethod()->GetTextInputClient()); |
460 } | 409 } |
461 | 410 |
462 void BlimpEngineSession::ProcessMessage( | 411 void BlimpEngineSession::ProcessMessage( |
463 std::unique_ptr<BlimpMessage> message, | 412 std::unique_ptr<BlimpMessage> message, |
464 const net::CompletionCallback& callback) { | 413 const net::CompletionCallback& callback) { |
465 TRACE_EVENT1("blimp", "BlimpEngineSession::ProcessMessage", "TabId", | 414 TRACE_EVENT1("blimp", "BlimpEngineSession::ProcessMessage", "TabId", |
466 message->target_tab_id()); | 415 message->target_tab_id()); |
467 DCHECK(!callback.is_null()); | 416 DCHECK(!callback.is_null()); |
468 DCHECK(BlimpMessage::kTabControl == message->feature_case() || | 417 DCHECK(BlimpMessage::kTabControl == message->feature_case() || |
469 BlimpMessage::kNavigation == message->feature_case()); | 418 BlimpMessage::kNavigation == message->feature_case()); |
470 | 419 |
471 net::Error result = net::OK; | 420 net::Error result = net::OK; |
472 if (message->has_tab_control()) { | 421 if (message->has_tab_control()) { |
473 switch (message->tab_control().tab_control_case()) { | 422 switch (message->tab_control().tab_control_case()) { |
474 case TabControlMessage::kCreateTab: | 423 case TabControlMessage::kCreateTab: |
475 if (!CreateWebContents(message->target_tab_id())) | 424 if (!CreateTab(message->target_tab_id())) |
476 result = net::ERR_FAILED; | 425 result = net::ERR_FAILED; |
477 break; | 426 break; |
478 case TabControlMessage::kCloseTab: | 427 case TabControlMessage::kCloseTab: |
479 CloseWebContents(message->target_tab_id()); | 428 CloseTab(message->target_tab_id()); |
480 case TabControlMessage::kSize: | 429 case TabControlMessage::kSize: |
481 HandleResize(message->tab_control().size().device_pixel_ratio(), | 430 HandleResize(message->tab_control().size().device_pixel_ratio(), |
482 gfx::Size(message->tab_control().size().width(), | 431 gfx::Size(message->tab_control().size().width(), |
483 message->tab_control().size().height())); | 432 message->tab_control().size().height())); |
484 break; | 433 break; |
485 default: | 434 default: |
Kevin M
2016/06/07 22:43:42
Replace default with TAB_CONTROL_NOT_SET
haibinlu
2016/06/08 17:57:22
good idea, but tab control message can be client <
| |
486 NOTIMPLEMENTED(); | 435 NOTIMPLEMENTED(); |
487 result = net::ERR_NOT_IMPLEMENTED; | 436 result = net::ERR_NOT_IMPLEMENTED; |
488 } | 437 } |
489 } else if (message->has_navigation() && web_contents_) { | 438 } else if (message->has_navigation()) { |
490 switch (message->navigation().type()) { | 439 if (tab_) { |
491 case NavigationMessage::LOAD_URL: | 440 switch (message->navigation().type()) { |
492 LoadUrl(message->target_tab_id(), | 441 case NavigationMessage::LOAD_URL: |
493 GURL(message->navigation().load_url().url())); | 442 tab_->LoadUrl(GURL(message->navigation().load_url().url())); |
494 break; | 443 break; |
495 case NavigationMessage::GO_BACK: | 444 case NavigationMessage::GO_BACK: |
496 GoBack(message->target_tab_id()); | 445 tab_->GoBack(); |
497 break; | 446 break; |
498 case NavigationMessage::GO_FORWARD: | 447 case NavigationMessage::GO_FORWARD: |
499 GoForward(message->target_tab_id()); | 448 tab_->GoForward(); |
500 break; | 449 break; |
501 case NavigationMessage::RELOAD: | 450 case NavigationMessage::RELOAD: |
502 Reload(message->target_tab_id()); | 451 tab_->Reload(); |
503 break; | 452 break; |
504 default: | 453 default: |
Kevin M
2016/06/07 22:43:42
Remove "default" for compile time enum coverage ch
haibinlu
2016/06/08 17:57:22
ditto. navigation message type is not client==>eng
| |
505 NOTIMPLEMENTED(); | 454 NOTIMPLEMENTED(); |
506 result = net::ERR_NOT_IMPLEMENTED; | 455 result = net::ERR_NOT_IMPLEMENTED; |
456 } | |
457 } else { | |
458 VLOG(1) << "Tab " << message->target_tab_id() << " does not exist"; | |
507 } | 459 } |
508 } else { | 460 } else { |
509 DVLOG(1) << "No WebContents for navigation control"; | 461 NOTREACHED(); |
510 result = net::ERR_FAILED; | 462 result = net::ERR_FAILED; |
511 } | 463 } |
512 | 464 |
513 callback.Run(result); | 465 callback.Run(result); |
514 } | 466 } |
515 | 467 |
516 void BlimpEngineSession::AddNewContents(content::WebContents* source, | 468 void BlimpEngineSession::AddNewContents(content::WebContents* source, |
517 content::WebContents* new_contents, | 469 content::WebContents* new_contents, |
518 WindowOpenDisposition disposition, | 470 WindowOpenDisposition disposition, |
519 const gfx::Rect& initial_rect, | 471 const gfx::Rect& initial_rect, |
(...skipping 27 matching lines...) Expand all Loading... | |
547 source->GetController().LoadURLWithParams(load_url_params); | 499 source->GetController().LoadURLWithParams(load_url_params); |
548 return source; | 500 return source; |
549 } | 501 } |
550 | 502 |
551 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, | 503 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, |
552 bool user_gesture, | 504 bool user_gesture, |
553 bool last_unlocked_by_target) { | 505 bool last_unlocked_by_target) { |
554 web_contents->GotResponseToLockMouseRequest(true); | 506 web_contents->GotResponseToLockMouseRequest(true); |
555 } | 507 } |
556 | 508 |
557 void BlimpEngineSession::CloseContents(content::WebContents* source) { | 509 void BlimpEngineSession::CloseContents(content::WebContents* source) { |
Kevin M
2016/06/07 22:43:42
Is it possible to have this closed during tab dele
haibinlu
2016/06/08 17:57:22
I donot think the case is possible. CloseContents
| |
558 if (source == web_contents_.get()) { | 510 if (source == tab_->web_contents()) { |
559 Observe(nullptr); | 511 tab_.reset(); |
560 web_contents_.reset(); | |
561 } | 512 } |
562 } | 513 } |
563 | 514 |
564 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { | 515 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { |
565 contents->GetRenderViewHost()->GetWidget()->Focus(); | 516 contents->GetRenderViewHost()->GetWidget()->Focus(); |
566 } | 517 } |
567 | 518 |
568 void BlimpEngineSession::ForwardCompositorProto( | 519 void BlimpEngineSession::ForwardCompositorProto( |
569 content::RenderWidgetHost* render_widget_host, | 520 content::RenderWidgetHost* render_widget_host, |
570 const std::vector<uint8_t>& proto) { | 521 const std::vector<uint8_t>& proto) { |
571 TRACE_EVENT0("blimp", "BlimpEngineSession::ForwardCompositorProto"); | 522 TRACE_EVENT0("blimp", "BlimpEngineSession::ForwardCompositorProto"); |
572 render_widget_feature_.SendCompositorMessage(kDummyTabId, render_widget_host, | 523 render_widget_feature_.SendCompositorMessage(kDummyTabId, render_widget_host, |
573 proto); | 524 proto); |
574 } | 525 } |
575 | 526 |
576 void BlimpEngineSession::NavigationStateChanged( | 527 void BlimpEngineSession::NavigationStateChanged( |
577 content::WebContents* source, | 528 content::WebContents* source, |
578 content::InvalidateTypes changed_flags) { | 529 content::InvalidateTypes changed_flags) { |
579 TRACE_EVENT0("blimp", "BlimpEngineSession::NavigationStateChanged"); | 530 TRACE_EVENT0("blimp", "BlimpEngineSession::NavigationStateChanged"); |
580 if (source != web_contents_.get() || !changed_flags) | 531 if (source == tab_->web_contents()) |
581 return; | 532 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 } | 533 } |
652 | 534 |
653 void BlimpEngineSession::PlatformSetContents( | 535 void BlimpEngineSession::PlatformSetContents( |
654 std::unique_ptr<content::WebContents> new_contents) { | 536 std::unique_ptr<content::WebContents> new_contents, |
537 const int target_tab_id) { | |
655 new_contents->SetDelegate(this); | 538 new_contents->SetDelegate(this); |
656 Observe(new_contents.get()); | |
657 web_contents_ = std::move(new_contents); | |
658 | 539 |
659 page_load_tracker_.reset(new PageLoadTracker(web_contents_.get(), this)); | |
660 aura::Window* parent = window_tree_host_->window(); | 540 aura::Window* parent = window_tree_host_->window(); |
661 aura::Window* content = web_contents_->GetNativeView(); | 541 aura::Window* content = new_contents->GetNativeView(); |
662 if (!parent->Contains(content)) | 542 if (!parent->Contains(content)) |
663 parent->AddChild(content); | 543 parent->AddChild(content); |
664 content->Show(); | 544 content->Show(); |
545 | |
546 tab_ = base::WrapUnique(new Tab(std::move(new_contents), target_tab_id, | |
547 &render_widget_feature_, | |
548 navigation_message_sender_.get())); | |
665 } | 549 } |
666 | 550 |
667 } // namespace engine | 551 } // namespace engine |
668 } // namespace blimp | 552 } // namespace blimp |
OLD | NEW |