OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/content/web_activity.h" | 5 #include "athena/content/web_activity.h" |
6 | 6 |
7 #include "athena/activity/public/activity_factory.h" | 7 #include "athena/activity/public/activity_factory.h" |
8 #include "athena/activity/public/activity_manager.h" | 8 #include "athena/activity/public/activity_manager.h" |
9 #include "athena/input/public/accelerator_manager.h" | 9 #include "athena/input/public/accelerator_manager.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 WebActivity::~WebActivity() { | 346 WebActivity::~WebActivity() { |
347 // It is not required to change the activity state to UNLOADED - unless we | 347 // It is not required to change the activity state to UNLOADED - unless we |
348 // would add state observers. | 348 // would add state observers. |
349 } | 349 } |
350 | 350 |
351 ActivityViewModel* WebActivity::GetActivityViewModel() { | 351 ActivityViewModel* WebActivity::GetActivityViewModel() { |
352 return this; | 352 return this; |
353 } | 353 } |
354 | 354 |
355 void WebActivity::SetCurrentState(Activity::ActivityState state) { | 355 void WebActivity::SetCurrentState(Activity::ActivityState state) { |
| 356 DCHECK_NE(state, current_state_); |
356 switch (state) { | 357 switch (state) { |
357 case ACTIVITY_VISIBLE: | 358 case ACTIVITY_VISIBLE: |
358 // Fall through (for the moment). | 359 if (!web_view_) |
| 360 break; |
| 361 MakeVisible(); |
| 362 ReloadAndObserve(); |
| 363 break; |
359 case ACTIVITY_INVISIBLE: | 364 case ACTIVITY_INVISIBLE: |
360 // By clearing the overview mode image we allow the content to be shown. | 365 if (!web_view_) |
361 overview_mode_image_ = gfx::ImageSkia(); | 366 break; |
362 if (web_view_->IsContentEvicted()) { | 367 if (current_state_ == ACTIVITY_VISIBLE) |
363 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); | 368 MakeInvisible(); |
364 web_view_->ReloadContent(); | 369 ReloadAndObserve(); |
365 } | |
366 Observe(web_view_->GetWebContents()); | |
367 break; | 370 break; |
368 case ACTIVITY_BACKGROUND_LOW_PRIORITY: | 371 case ACTIVITY_BACKGROUND_LOW_PRIORITY: |
369 DCHECK(ACTIVITY_VISIBLE == current_state_ || | 372 DCHECK(ACTIVITY_VISIBLE == current_state_ || |
370 ACTIVITY_INVISIBLE == current_state_); | 373 ACTIVITY_INVISIBLE == current_state_); |
371 // TODO(skuhne): Do this. | 374 // TODO(skuhne): Do this. |
372 break; | 375 break; |
373 case ACTIVITY_PERSISTENT: | 376 case ACTIVITY_PERSISTENT: |
374 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state_); | 377 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state_); |
375 // TODO(skuhne): Do this. As soon as the new resource management is | 378 // TODO(skuhne): Do this. As soon as the new resource management is |
376 // agreed upon - or remove otherwise. | 379 // agreed upon - or remove otherwise. |
377 break; | 380 break; |
378 case ACTIVITY_UNLOADED: | 381 case ACTIVITY_UNLOADED: |
379 DCHECK_NE(ACTIVITY_UNLOADED, current_state_); | 382 DCHECK_NE(ACTIVITY_UNLOADED, current_state_); |
380 Observe(NULL); | 383 Observe(NULL); |
381 web_view_->EvictContent(); | 384 web_view_->EvictContent(); |
382 break; | 385 break; |
383 } | 386 } |
384 // Remember the last requested state. | 387 // Remember the last requested state. |
385 current_state_ = state; | 388 current_state_ = state; |
386 } | 389 } |
387 | 390 |
388 Activity::ActivityState WebActivity::GetCurrentState() { | 391 Activity::ActivityState WebActivity::GetCurrentState() { |
389 if (!web_view_ || web_view_->IsContentEvicted()) { | 392 // If the content is evicted, the state has to be UNLOADED. |
390 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); | 393 DCHECK(!web_view_ || |
391 return ACTIVITY_UNLOADED; | 394 !web_view_->IsContentEvicted() || |
392 } | 395 current_state_ == ACTIVITY_UNLOADED); |
393 // TODO(skuhne): This should be controlled by an observer and should not | |
394 // reside here. | |
395 if (IsVisible() && current_state_ != ACTIVITY_VISIBLE) | |
396 SetCurrentState(ACTIVITY_VISIBLE); | |
397 // Note: If the activity is not visible it does not necessarily mean that it | |
398 // does not have GPU compositor resources (yet). | |
399 | |
400 return current_state_; | 396 return current_state_; |
401 } | 397 } |
402 | 398 |
403 bool WebActivity::IsVisible() { | 399 bool WebActivity::IsVisible() { |
404 return web_view_ && | 400 return web_view_ && |
405 web_view_->IsDrawn() && | 401 web_view_->visible() && |
406 current_state_ != ACTIVITY_UNLOADED && | 402 current_state_ != ACTIVITY_UNLOADED; |
407 GetWindow() && | |
408 GetWindow()->IsVisible(); | |
409 } | 403 } |
410 | 404 |
411 Activity::ActivityMediaState WebActivity::GetMediaState() { | 405 Activity::ActivityMediaState WebActivity::GetMediaState() { |
412 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents), | 406 // TODO(skuhne): The function GetTabMediaStateForContents(WebContents), |
413 // and the AudioStreamMonitor needs to be moved from Chrome into contents to | 407 // and the AudioStreamMonitor needs to be moved from Chrome into contents to |
414 // make it more modular and so that we can use it from here. | 408 // make it more modular and so that we can use it from here. |
415 return Activity::ACTIVITY_MEDIA_STATE_NONE; | 409 return Activity::ACTIVITY_MEDIA_STATE_NONE; |
416 } | 410 } |
417 | 411 |
418 aura::Window* WebActivity::GetWindow() { | 412 aura::Window* WebActivity::GetWindow() { |
(...skipping 17 matching lines...) Expand all Loading... |
436 } | 430 } |
437 | 431 |
438 bool WebActivity::UsesFrame() const { | 432 bool WebActivity::UsesFrame() const { |
439 return true; | 433 return true; |
440 } | 434 } |
441 | 435 |
442 views::View* WebActivity::GetContentsView() { | 436 views::View* WebActivity::GetContentsView() { |
443 if (!web_view_) { | 437 if (!web_view_) { |
444 web_view_ = new AthenaWebView(browser_context_); | 438 web_view_ = new AthenaWebView(browser_context_); |
445 web_view_->LoadInitialURL(url_); | 439 web_view_->LoadInitialURL(url_); |
446 SetCurrentState(ACTIVITY_INVISIBLE); | 440 // Make sure the content gets properly shown. |
447 // Reset the overview mode image. | 441 if (current_state_ == ACTIVITY_VISIBLE) { |
448 overview_mode_image_ = gfx::ImageSkia(); | 442 MakeVisible(); |
| 443 ReloadAndObserve(); |
| 444 } else if (current_state_ == ACTIVITY_INVISIBLE) { |
| 445 MakeInvisible(); |
| 446 ReloadAndObserve(); |
| 447 } else { |
| 448 // If not previously specified, we change the state now to invisible.. |
| 449 SetCurrentState(ACTIVITY_INVISIBLE); |
| 450 } |
449 } | 451 } |
450 return web_view_; | 452 return web_view_; |
451 } | 453 } |
452 | 454 |
453 void WebActivity::CreateOverviewModeImage() { | 455 void WebActivity::CreateOverviewModeImage() { |
454 // TODO(skuhne): Create an overview. | 456 // TODO(skuhne): Create an overview. |
455 } | 457 } |
456 | 458 |
457 gfx::ImageSkia WebActivity::GetOverviewModeImage() { | 459 gfx::ImageSkia WebActivity::GetOverviewModeImage() { |
458 return overview_mode_image_; | 460 return overview_mode_image_; |
459 } | 461 } |
460 | 462 |
461 void WebActivity::TitleWasSet(content::NavigationEntry* entry, | 463 void WebActivity::TitleWasSet(content::NavigationEntry* entry, |
462 bool explicit_set) { | 464 bool explicit_set) { |
463 ActivityManager::Get()->UpdateActivity(this); | 465 ActivityManager::Get()->UpdateActivity(this); |
464 } | 466 } |
465 | 467 |
466 void WebActivity::DidUpdateFaviconURL( | 468 void WebActivity::DidUpdateFaviconURL( |
467 const std::vector<content::FaviconURL>& candidates) { | 469 const std::vector<content::FaviconURL>& candidates) { |
468 ActivityManager::Get()->UpdateActivity(this); | 470 ActivityManager::Get()->UpdateActivity(this); |
469 } | 471 } |
470 | 472 |
471 void WebActivity::DidChangeThemeColor(SkColor theme_color) { | 473 void WebActivity::DidChangeThemeColor(SkColor theme_color) { |
472 title_color_ = theme_color; | 474 title_color_ = theme_color; |
473 } | 475 } |
474 | 476 |
| 477 void WebActivity::MakeVisible() { |
| 478 // TODO(skuhne): Once we know how to handle the Overview mode, this has to |
| 479 // be moved into an ActivityContentController which is used by all activities. |
| 480 // Make the content visible. |
| 481 // TODO(skuhne): If this can be combined with app_activity, move this into a |
| 482 // separate class. |
| 483 web_view_->SetVisible(true); |
| 484 web_view_->GetWebContents()->GetNativeView()->Show(); |
| 485 // If we have a proxy image, we can delete it now since the contet goes live. |
| 486 // TODO(skuhne): Once we have figured out how to do overview mode that code |
| 487 // needs to go here. |
| 488 overview_mode_image_ = gfx::ImageSkia(); |
| 489 } |
| 490 |
| 491 void WebActivity::MakeInvisible() { |
| 492 // TODO(skuhne): Once we know how to handle the Overview mode, this has to |
| 493 // be moved into an ActivityContentController which is used by all activities. |
| 494 // TODO(skuhne): If this can be combined with app_activity, move this into a |
| 495 // separate class. |
| 496 DCHECK(web_view_->visible()); |
| 497 // Create our proxy image / layer. |
| 498 if (current_state_ == ACTIVITY_VISIBLE) { |
| 499 // Create a proxy image of the current visible content. |
| 500 // TODO(skuhne): Do this once we figure out how to do overview mode. |
| 501 overview_mode_image_ = gfx::ImageSkia(); |
| 502 } |
| 503 // Now we can hide this. |
| 504 // Note: This might have to be done asynchronously after the read back took |
| 505 // place. |
| 506 web_view_->GetWebContents()->GetNativeView()->Hide(); |
| 507 web_view_->SetVisible(false); |
| 508 } |
| 509 |
| 510 void WebActivity::ReloadAndObserve() { |
| 511 if (web_view_->IsContentEvicted()) { |
| 512 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); |
| 513 web_view_->ReloadContent(); |
| 514 } |
| 515 Observe(web_view_->GetWebContents()); |
| 516 } |
| 517 |
475 } // namespace athena | 518 } // namespace athena |
OLD | NEW |