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