Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(690)

Side by Side Diff: blimp/engine/session/blimp_engine_session.cc

Issue 2035543002: [Blimp] Creates engine tab class to handle tab related operations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_blimp.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
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
Kevin M 2016/06/06 21:44:38 Not needed; placing the tab at the end of the fiel
haibinlu 2016/06/06 22:32:28 Done.
237
238 // Ensure that all WebContents are torn down first, since teardown will
239 // trigger RenderViewDeleted callbacks to their observers. 238 // trigger RenderViewDeleted callbacks to their observers.
240 web_contents_.reset(); 239 tab_.reset();
241 240
242 // Safely delete network components on the IO thread. 241 // Safely delete network components on the IO thread.
243 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE, 242 content::BrowserThread::DeleteSoon(content::BrowserThread::IO, FROM_HERE,
244 net_components_.release()); 243 net_components_.release());
245 } 244 }
246 245
247 void BlimpEngineSession::Initialize() { 246 void BlimpEngineSession::Initialize() {
248 DCHECK(!display::Screen::GetScreen()); 247 DCHECK(!display::Screen::GetScreen());
249 display::Screen::SetScreenInstance(screen_.get()); 248 display::Screen::SetScreenInstance(screen_.get());
250 249
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 render_widget_feature_.set_ime_message_sender( 311 render_widget_feature_.set_ime_message_sender(
313 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme, 312 thread_pipe_manager_->RegisterFeature(BlimpMessage::kIme,
314 &render_widget_feature_)); 313 &render_widget_feature_));
315 314
316 // The Settings feature does not need an outgoing message processor, since we 315 // The Settings feature does not need an outgoing message processor, since we
317 // don't send any messages to the client right now. 316 // don't send any messages to the client right now.
318 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings, 317 thread_pipe_manager_->RegisterFeature(BlimpMessage::kSettings,
319 &settings_feature_); 318 &settings_feature_);
320 } 319 }
321 320
322 bool BlimpEngineSession::CreateWebContents(const int target_tab_id) { 321 bool BlimpEngineSession::CreateTab(const int target_tab_id) {
323 DVLOG(1) << "Create tab " << target_tab_id; 322 DVLOG(1) << "Create tab " << target_tab_id;
324 // TODO(haibinlu): Support more than one active WebContents (crbug/547231). 323 // TODO(haibinlu): Support more than one tab (crbug/547231).
Kevin M 2016/06/06 21:44:38 We specify this issue multiple times, can we just
haibinlu 2016/06/06 22:32:27 Done.
325 if (web_contents_) { 324 if (tab_) {
326 DLOG(WARNING) << "Tab " << target_tab_id << " already existed"; 325 DLOG(WARNING) << "Tab " << target_tab_id << " already existed";
Kevin M 2016/06/06 21:44:38 This warning doesn't apply - the issue is the pre-
haibinlu 2016/06/06 22:32:27 Done.
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 }
358
359 if (web_contents_ && web_contents_->GetRenderViewHost() &&
360 web_contents_->GetRenderViewHost()->GetWidget()) {
361 web_contents_->GetRenderViewHost()->GetWidget()->WasResized();
362 } 351 }
363 } 352 }
364 353
365 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) { 354 void BlimpEngineSession::LoadUrl(const int target_tab_id, const GURL& url) {
366 TRACE_EVENT1("blimp", "BlimpEngineSession::LoadUrl", "URL", url.spec()); 355 if (tab_)
367 DVLOG(1) << "Load URL " << url << " in tab " << target_tab_id; 356 tab_->LoadUrl(url);
Kevin M 2016/06/06 21:44:38 Why are we silently failing here? This is invalid
haibinlu 2016/06/06 22:32:27 log a info instead. I argue we should not drop th
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 } 357 }
383 358
384 void BlimpEngineSession::GoBack(const int target_tab_id) { 359 void BlimpEngineSession::GoBack(const int target_tab_id) {
385 DVLOG(1) << "Back in tab " << target_tab_id; 360 if (tab_)
386 web_contents_->GetController().GoBack(); 361 tab_->GoBack();
387 } 362 }
388 363
389 void BlimpEngineSession::GoForward(const int target_tab_id) { 364 void BlimpEngineSession::GoForward(const int target_tab_id) {
390 DVLOG(1) << "Forward in tab " << target_tab_id; 365 if (tab_)
391 web_contents_->GetController().GoForward(); 366 tab_->GoForward();
392 } 367 }
393 368
394 void BlimpEngineSession::Reload(const int target_tab_id) { 369 void BlimpEngineSession::Reload(const int target_tab_id) {
395 DVLOG(1) << "Reload in tab " << target_tab_id; 370 if (tab_)
396 web_contents_->GetController().Reload(true); 371 tab_->Reload();
397 } 372 }
398 373
399 void BlimpEngineSession::OnWebGestureEvent( 374 void BlimpEngineSession::OnWebGestureEvent(
400 content::RenderWidgetHost* render_widget_host, 375 content::RenderWidgetHost* render_widget_host,
401 std::unique_ptr<blink::WebGestureEvent> event) { 376 std::unique_ptr<blink::WebGestureEvent> event) {
402 TRACE_EVENT1("blimp", "BlimpEngineSession::OnWebGestureEvent", "type", 377 TRACE_EVENT1("blimp", "BlimpEngineSession::OnWebGestureEvent", "type",
403 event->type); 378 event->type);
404 render_widget_host->ForwardGestureEvent(*event); 379 render_widget_host->ForwardGestureEvent(*event);
405 } 380 }
406 381
(...skipping 13 matching lines...) Expand all
420 void BlimpEngineSession::OnBlur() {} 395 void BlimpEngineSession::OnBlur() {}
421 396
422 void BlimpEngineSession::OnCaretBoundsChanged( 397 void BlimpEngineSession::OnCaretBoundsChanged(
423 const ui::TextInputClient* client) {} 398 const ui::TextInputClient* client) {}
424 399
425 // Called when either: 400 // Called when either:
426 // - the TextInputClient is changed (e.g. by a change of focus) 401 // - the TextInputClient is changed (e.g. by a change of focus)
427 // - the TextInputType of the TextInputClient changes 402 // - the TextInputType of the TextInputClient changes
428 void BlimpEngineSession::OnTextInputStateChanged( 403 void BlimpEngineSession::OnTextInputStateChanged(
429 const ui::TextInputClient* client) { 404 const ui::TextInputClient* client) {
430 if (!web_contents_->GetRenderWidgetHostView()) 405 if (!tab_->web_contents()->GetRenderWidgetHostView())
431 return; 406 return;
432 407
433 ui::TextInputType type = 408 ui::TextInputType type =
434 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE; 409 client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
435 410
436 // TODO(shaktisahu): Propagate the new type to the client. 411 // 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 412 // 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, 413 // changes to ui::TEXT_INPUT_TYPE_NONE. For other text input types,
439 // OnShowImeIfNeeded is used instead to send show IME request to client. 414 // OnShowImeIfNeeded is used instead to send show IME request to client.
440 if (type == ui::TEXT_INPUT_TYPE_NONE) 415 if (type == ui::TEXT_INPUT_TYPE_NONE)
441 render_widget_feature_.SendHideImeRequest( 416 render_widget_feature_.SendHideImeRequest(
442 kDummyTabId, 417 kDummyTabId,
443 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost()); 418 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost());
444 } 419 }
445 420
446 void BlimpEngineSession::OnInputMethodDestroyed( 421 void BlimpEngineSession::OnInputMethodDestroyed(
447 const ui::InputMethod* input_method) {} 422 const ui::InputMethod* input_method) {}
448 423
449 // Called when a user input should trigger showing the IME. 424 // Called when a user input should trigger showing the IME.
450 void BlimpEngineSession::OnShowImeIfNeeded() { 425 void BlimpEngineSession::OnShowImeIfNeeded() {
451 TRACE_EVENT0("blimp", "BlimpEngineSession::OnShowImeIfNeeded"); 426 TRACE_EVENT0("blimp", "BlimpEngineSession::OnShowImeIfNeeded");
452 if (!web_contents_->GetRenderWidgetHostView() || 427 if (!tab_ || !tab_->web_contents()->GetRenderWidgetHostView() ||
453 !window_tree_host_->GetInputMethod()->GetTextInputClient()) 428 !window_tree_host_->GetInputMethod()->GetTextInputClient())
454 return; 429 return;
455 430
456 render_widget_feature_.SendShowImeRequest( 431 render_widget_feature_.SendShowImeRequest(
457 kDummyTabId, 432 kDummyTabId,
458 web_contents_->GetRenderWidgetHostView()->GetRenderWidgetHost(), 433 tab_->web_contents()->GetRenderWidgetHostView()->GetRenderWidgetHost(),
459 window_tree_host_->GetInputMethod()->GetTextInputClient()); 434 window_tree_host_->GetInputMethod()->GetTextInputClient());
460 } 435 }
461 436
462 void BlimpEngineSession::ProcessMessage( 437 void BlimpEngineSession::ProcessMessage(
463 std::unique_ptr<BlimpMessage> message, 438 std::unique_ptr<BlimpMessage> message,
464 const net::CompletionCallback& callback) { 439 const net::CompletionCallback& callback) {
465 TRACE_EVENT1("blimp", "BlimpEngineSession::ProcessMessage", "TabId", 440 TRACE_EVENT1("blimp", "BlimpEngineSession::ProcessMessage", "TabId",
466 message->target_tab_id()); 441 message->target_tab_id());
467 DCHECK(!callback.is_null()); 442 DCHECK(!callback.is_null());
468 DCHECK(BlimpMessage::kTabControl == message->feature_case() || 443 DCHECK(BlimpMessage::kTabControl == message->feature_case() ||
469 BlimpMessage::kNavigation == message->feature_case()); 444 BlimpMessage::kNavigation == message->feature_case());
470 445
471 net::Error result = net::OK; 446 net::Error result = net::OK;
472 if (message->has_tab_control()) { 447 if (message->has_tab_control()) {
473 switch (message->tab_control().tab_control_case()) { 448 switch (message->tab_control().tab_control_case()) {
474 case TabControlMessage::kCreateTab: 449 case TabControlMessage::kCreateTab:
475 if (!CreateWebContents(message->target_tab_id())) 450 if (!CreateTab(message->target_tab_id()))
476 result = net::ERR_FAILED; 451 result = net::ERR_FAILED;
477 break; 452 break;
478 case TabControlMessage::kCloseTab: 453 case TabControlMessage::kCloseTab:
479 CloseWebContents(message->target_tab_id()); 454 CloseTab(message->target_tab_id());
480 case TabControlMessage::kSize: 455 case TabControlMessage::kSize:
481 HandleResize(message->tab_control().size().device_pixel_ratio(), 456 HandleResize(message->tab_control().size().device_pixel_ratio(),
482 gfx::Size(message->tab_control().size().width(), 457 gfx::Size(message->tab_control().size().width(),
483 message->tab_control().size().height())); 458 message->tab_control().size().height()));
484 break; 459 break;
485 default: 460 default:
486 NOTIMPLEMENTED(); 461 NOTIMPLEMENTED();
487 result = net::ERR_NOT_IMPLEMENTED; 462 result = net::ERR_NOT_IMPLEMENTED;
488 } 463 }
489 } else if (message->has_navigation() && web_contents_) { 464 } else if (message->has_navigation()) {
Kevin M 2016/06/06 21:44:38 Check if the tab_ exists here?
haibinlu 2016/06/06 22:32:27 Done.
490 switch (message->navigation().type()) { 465 switch (message->navigation().type()) {
491 case NavigationMessage::LOAD_URL: 466 case NavigationMessage::LOAD_URL:
492 LoadUrl(message->target_tab_id(), 467 LoadUrl(message->target_tab_id(),
493 GURL(message->navigation().load_url().url())); 468 GURL(message->navigation().load_url().url()));
494 break; 469 break;
495 case NavigationMessage::GO_BACK: 470 case NavigationMessage::GO_BACK:
496 GoBack(message->target_tab_id()); 471 GoBack(message->target_tab_id());
497 break; 472 break;
498 case NavigationMessage::GO_FORWARD: 473 case NavigationMessage::GO_FORWARD:
499 GoForward(message->target_tab_id()); 474 GoForward(message->target_tab_id());
500 break; 475 break;
501 case NavigationMessage::RELOAD: 476 case NavigationMessage::RELOAD:
502 Reload(message->target_tab_id()); 477 Reload(message->target_tab_id());
503 break; 478 break;
504 default: 479 default:
505 NOTIMPLEMENTED(); 480 NOTIMPLEMENTED();
506 result = net::ERR_NOT_IMPLEMENTED; 481 result = net::ERR_NOT_IMPLEMENTED;
507 } 482 }
508 } else { 483 } else {
509 DVLOG(1) << "No WebContents for navigation control"; 484 DVLOG(1) << "No tab for navigation control";
Kevin M 2016/06/06 21:44:38 This error seems N/A for the current logic
haibinlu 2016/06/06 22:32:27 Done.
510 result = net::ERR_FAILED; 485 result = net::ERR_FAILED;
511 } 486 }
512 487
513 callback.Run(result); 488 callback.Run(result);
514 } 489 }
515 490
516 void BlimpEngineSession::AddNewContents(content::WebContents* source, 491 void BlimpEngineSession::AddNewContents(content::WebContents* source,
517 content::WebContents* new_contents, 492 content::WebContents* new_contents,
518 WindowOpenDisposition disposition, 493 WindowOpenDisposition disposition,
519 const gfx::Rect& initial_rect, 494 const gfx::Rect& initial_rect,
(...skipping 28 matching lines...) Expand all
548 return source; 523 return source;
549 } 524 }
550 525
551 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents, 526 void BlimpEngineSession::RequestToLockMouse(content::WebContents* web_contents,
552 bool user_gesture, 527 bool user_gesture,
553 bool last_unlocked_by_target) { 528 bool last_unlocked_by_target) {
554 web_contents->GotResponseToLockMouseRequest(true); 529 web_contents->GotResponseToLockMouseRequest(true);
555 } 530 }
556 531
557 void BlimpEngineSession::CloseContents(content::WebContents* source) { 532 void BlimpEngineSession::CloseContents(content::WebContents* source) {
558 if (source == web_contents_.get()) { 533 if (source == tab_->web_contents()) {
559 Observe(nullptr); 534 tab_.reset();
560 web_contents_.reset();
561 } 535 }
562 } 536 }
563 537
564 void BlimpEngineSession::ActivateContents(content::WebContents* contents) { 538 void BlimpEngineSession::ActivateContents(content::WebContents* contents) {
565 contents->GetRenderViewHost()->GetWidget()->Focus(); 539 contents->GetRenderViewHost()->GetWidget()->Focus();
566 } 540 }
567 541
568 void BlimpEngineSession::ForwardCompositorProto( 542 void BlimpEngineSession::ForwardCompositorProto(
569 content::RenderWidgetHost* render_widget_host, 543 content::RenderWidgetHost* render_widget_host,
570 const std::vector<uint8_t>& proto) { 544 const std::vector<uint8_t>& proto) {
571 TRACE_EVENT0("blimp", "BlimpEngineSession::ForwardCompositorProto"); 545 TRACE_EVENT0("blimp", "BlimpEngineSession::ForwardCompositorProto");
572 render_widget_feature_.SendCompositorMessage(kDummyTabId, render_widget_host, 546 render_widget_feature_.SendCompositorMessage(kDummyTabId, render_widget_host,
573 proto); 547 proto);
574 } 548 }
575 549
576 void BlimpEngineSession::NavigationStateChanged( 550 void BlimpEngineSession::NavigationStateChanged(
577 content::WebContents* source, 551 content::WebContents* source,
578 content::InvalidateTypes changed_flags) { 552 content::InvalidateTypes changed_flags) {
579 TRACE_EVENT0("blimp", "BlimpEngineSession::NavigationStateChanged"); 553 TRACE_EVENT0("blimp", "BlimpEngineSession::NavigationStateChanged");
580 if (source != web_contents_.get() || !changed_flags) 554 if (source == tab_->web_contents())
581 return; 555 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 } 556 }
652 557
653 void BlimpEngineSession::PlatformSetContents( 558 void BlimpEngineSession::PlatformSetContents(
Kevin M 2016/06/06 21:44:38 What's the reason for having this be separate from
haibinlu 2016/06/06 22:32:27 When BlimpEngineSession::AddNewContents is impleme
654 std::unique_ptr<content::WebContents> new_contents) { 559 std::unique_ptr<content::WebContents> new_contents,
560 const int target_tab_id) {
655 new_contents->SetDelegate(this); 561 new_contents->SetDelegate(this);
656 Observe(new_contents.get());
657 web_contents_ = std::move(new_contents);
658 562
659 page_load_tracker_.reset(new PageLoadTracker(web_contents_.get(), this));
660 aura::Window* parent = window_tree_host_->window(); 563 aura::Window* parent = window_tree_host_->window();
661 aura::Window* content = web_contents_->GetNativeView(); 564 aura::Window* content = new_contents->GetNativeView();
662 if (!parent->Contains(content)) 565 if (!parent->Contains(content))
663 parent->AddChild(content); 566 parent->AddChild(content);
664 content->Show(); 567 content->Show();
568
569 tab_ = base::WrapUnique(new TabBlimp(std::move(new_contents), target_tab_id,
570 &render_widget_feature_,
571 navigation_message_sender_.get()));
665 } 572 }
666 573
667 } // namespace engine 574 } // namespace engine
668 } // namespace blimp 575 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698