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/content/content_proxy.h" |
9 #include "athena/input/public/accelerator_manager.h" | 10 #include "athena/input/public/accelerator_manager.h" |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "content/public/browser/native_web_keyboard_event.h" | 14 #include "content/public/browser/native_web_keyboard_event.h" |
14 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
17 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 169 } |
169 | 170 |
170 virtual ~AthenaWebView() {} | 171 virtual ~AthenaWebView() {} |
171 | 172 |
172 void InstallAccelerators() { controller_->InstallAccelerators(); } | 173 void InstallAccelerators() { controller_->InstallAccelerators(); } |
173 | 174 |
174 void EvictContent() { | 175 void EvictContent() { |
175 scoped_ptr<content::WebContents> old_contents(SwapWebContents( | 176 scoped_ptr<content::WebContents> old_contents(SwapWebContents( |
176 scoped_ptr<content::WebContents>(content::WebContents::Create( | 177 scoped_ptr<content::WebContents>(content::WebContents::Create( |
177 content::WebContents::CreateParams(browser_context()))))); | 178 content::WebContents::CreateParams(browser_context()))))); |
| 179 // If there is a progress bar, we need to get rid of it now since its |
| 180 // associated content, parent window and layers will disappear with evicting |
| 181 // the content. |
| 182 progress_bar_.reset(); |
178 evicted_web_contents_.reset( | 183 evicted_web_contents_.reset( |
179 content::WebContents::Create(content::WebContents::CreateParams( | 184 content::WebContents::Create(content::WebContents::CreateParams( |
180 old_contents->GetBrowserContext()))); | 185 old_contents->GetBrowserContext()))); |
181 evicted_web_contents_->GetController().CopyStateFrom( | 186 evicted_web_contents_->GetController().CopyStateFrom( |
182 old_contents->GetController()); | 187 old_contents->GetController()); |
183 // As soon as the new contents becomes visible, it should reload. | 188 // As soon as the new contents becomes visible, it should reload. |
184 // TODO(skuhne): This breaks script connections with other activities. | 189 // TODO(skuhne): This breaks script connections with other activities. |
185 // Even though this is the same technique as used by the TabStripModel, | 190 // Even though this is the same technique as used by the TabStripModel, |
186 // we might want to address this cleaner since we are more likely to | 191 // we might want to address this cleaner since we are more likely to |
187 // run into this state. by unloading. | 192 // run into this state. by unloading. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 ActivityViewModel* WebActivity::GetActivityViewModel() { | 358 ActivityViewModel* WebActivity::GetActivityViewModel() { |
354 return this; | 359 return this; |
355 } | 360 } |
356 | 361 |
357 void WebActivity::SetCurrentState(Activity::ActivityState state) { | 362 void WebActivity::SetCurrentState(Activity::ActivityState state) { |
358 DCHECK_NE(state, current_state_); | 363 DCHECK_NE(state, current_state_); |
359 switch (state) { | 364 switch (state) { |
360 case ACTIVITY_VISIBLE: | 365 case ACTIVITY_VISIBLE: |
361 if (!web_view_) | 366 if (!web_view_) |
362 break; | 367 break; |
363 MakeVisible(); | 368 HideContentProxy(); |
364 ReloadAndObserve(); | 369 ReloadAndObserve(); |
365 break; | 370 break; |
366 case ACTIVITY_INVISIBLE: | 371 case ACTIVITY_INVISIBLE: |
367 if (!web_view_) | 372 if (!web_view_) |
368 break; | 373 break; |
| 374 |
369 if (current_state_ == ACTIVITY_VISIBLE) | 375 if (current_state_ == ACTIVITY_VISIBLE) |
370 MakeInvisible(); | 376 ShowContentProxy(); |
371 ReloadAndObserve(); | 377 else |
| 378 ReloadAndObserve(); |
| 379 |
372 break; | 380 break; |
373 case ACTIVITY_BACKGROUND_LOW_PRIORITY: | 381 case ACTIVITY_BACKGROUND_LOW_PRIORITY: |
374 DCHECK(ACTIVITY_VISIBLE == current_state_ || | 382 DCHECK(ACTIVITY_VISIBLE == current_state_ || |
375 ACTIVITY_INVISIBLE == current_state_); | 383 ACTIVITY_INVISIBLE == current_state_); |
376 // TODO(skuhne): Do this. | 384 // TODO(skuhne): Do this. |
377 break; | 385 break; |
378 case ACTIVITY_PERSISTENT: | 386 case ACTIVITY_PERSISTENT: |
379 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state_); | 387 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state_); |
380 // TODO(skuhne): Do this. As soon as the new resource management is | 388 // TODO(skuhne): Do this. As soon as the new resource management is |
381 // agreed upon - or remove otherwise. | 389 // agreed upon - or remove otherwise. |
382 break; | 390 break; |
383 case ACTIVITY_UNLOADED: | 391 case ACTIVITY_UNLOADED: |
384 DCHECK_NE(ACTIVITY_UNLOADED, current_state_); | 392 DCHECK_NE(ACTIVITY_UNLOADED, current_state_); |
| 393 if (content_proxy_.get()) |
| 394 content_proxy_->ContentWillUnload(); |
385 Observe(NULL); | 395 Observe(NULL); |
386 web_view_->EvictContent(); | 396 web_view_->EvictContent(); |
387 break; | 397 break; |
388 } | 398 } |
389 // Remember the last requested state. | 399 // Remember the last requested state. |
390 current_state_ = state; | 400 current_state_ = state; |
391 } | 401 } |
392 | 402 |
393 Activity::ActivityState WebActivity::GetCurrentState() { | 403 Activity::ActivityState WebActivity::GetCurrentState() { |
394 // If the content is evicted, the state has to be UNLOADED. | 404 // If the content is evicted, the state has to be UNLOADED. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 bool WebActivity::UsesFrame() const { | 447 bool WebActivity::UsesFrame() const { |
438 return true; | 448 return true; |
439 } | 449 } |
440 | 450 |
441 views::View* WebActivity::GetContentsView() { | 451 views::View* WebActivity::GetContentsView() { |
442 if (!web_view_) { | 452 if (!web_view_) { |
443 web_view_ = new AthenaWebView(browser_context_); | 453 web_view_ = new AthenaWebView(browser_context_); |
444 web_view_->LoadInitialURL(url_); | 454 web_view_->LoadInitialURL(url_); |
445 // Make sure the content gets properly shown. | 455 // Make sure the content gets properly shown. |
446 if (current_state_ == ACTIVITY_VISIBLE) { | 456 if (current_state_ == ACTIVITY_VISIBLE) { |
447 MakeVisible(); | 457 HideContentProxy(); |
448 ReloadAndObserve(); | 458 ReloadAndObserve(); |
449 } else if (current_state_ == ACTIVITY_INVISIBLE) { | 459 } else if (current_state_ == ACTIVITY_INVISIBLE) { |
450 MakeInvisible(); | 460 ShowContentProxy(); |
451 ReloadAndObserve(); | 461 ReloadAndObserve(); |
452 } else { | 462 } else { |
453 // If not previously specified, we change the state now to invisible.. | 463 // If not previously specified, we change the state now to invisible.. |
454 SetCurrentState(ACTIVITY_INVISIBLE); | 464 SetCurrentState(ACTIVITY_INVISIBLE); |
455 } | 465 } |
456 } | 466 } |
457 return web_view_; | 467 return web_view_; |
458 } | 468 } |
459 | 469 |
460 void WebActivity::CreateOverviewModeImage() { | |
461 // TODO(skuhne): Create an overview. | |
462 } | |
463 | |
464 gfx::ImageSkia WebActivity::GetOverviewModeImage() { | 470 gfx::ImageSkia WebActivity::GetOverviewModeImage() { |
465 return overview_mode_image_; | 471 if (content_proxy_.get()) |
| 472 content_proxy_->GetContentImage(); |
| 473 return gfx::ImageSkia(); |
466 } | 474 } |
467 | 475 |
468 void WebActivity::PrepareContentsForOverview() { | 476 void WebActivity::PrepareContentsForOverview() { |
469 // Turn on fast resizing to avoid re-laying out the web contents when | 477 // Turn on fast resizing to avoid re-laying out the web contents when |
470 // entering / exiting overview mode. | 478 // entering / exiting overview mode and the content is visible. |
471 web_view_->SetFastResize(true); | 479 if (!content_proxy_.get()) |
| 480 web_view_->SetFastResize(true); |
472 } | 481 } |
473 | 482 |
474 void WebActivity::ResetContentsView() { | 483 void WebActivity::ResetContentsView() { |
475 web_view_->SetFastResize(false); | 484 // Turn on fast resizing to avoid re-laying out the web contents when |
476 web_view_->Layout(); | 485 // entering / exiting overview mode and the content is visible. |
| 486 if (!content_proxy_.get()) { |
| 487 web_view_->SetFastResize(false); |
| 488 web_view_->Layout(); |
| 489 } |
477 } | 490 } |
478 | 491 |
479 void WebActivity::TitleWasSet(content::NavigationEntry* entry, | 492 void WebActivity::TitleWasSet(content::NavigationEntry* entry, |
480 bool explicit_set) { | 493 bool explicit_set) { |
481 ActivityManager::Get()->UpdateActivity(this); | 494 ActivityManager::Get()->UpdateActivity(this); |
482 } | 495 } |
483 | 496 |
484 void WebActivity::DidUpdateFaviconURL( | 497 void WebActivity::DidUpdateFaviconURL( |
485 const std::vector<content::FaviconURL>& candidates) { | 498 const std::vector<content::FaviconURL>& candidates) { |
486 ActivityManager::Get()->UpdateActivity(this); | 499 ActivityManager::Get()->UpdateActivity(this); |
487 } | 500 } |
488 | 501 |
489 void WebActivity::DidChangeThemeColor(SkColor theme_color) { | 502 void WebActivity::DidChangeThemeColor(SkColor theme_color) { |
490 title_color_ = theme_color; | 503 title_color_ = theme_color; |
491 ActivityManager::Get()->UpdateActivity(this); | 504 ActivityManager::Get()->UpdateActivity(this); |
492 } | 505 } |
493 | 506 |
494 void WebActivity::MakeVisible() { | 507 void WebActivity::HideContentProxy() { |
495 // TODO(skuhne): Once we know how to handle the Overview mode, this has to | 508 if (content_proxy_.get()) |
496 // be moved into an ActivityContentController which is used by all activities. | 509 content_proxy_.reset(NULL); |
497 // Make the content visible. | |
498 // TODO(skuhne): If this can be combined with app_activity, move this into a | |
499 // separate class. | |
500 web_view_->SetVisible(true); | |
501 web_view_->GetWebContents()->GetNativeView()->Show(); | |
502 // If we have a proxy image, we can delete it now since the contet goes live. | |
503 // TODO(skuhne): Once we have figured out how to do overview mode that code | |
504 // needs to go here. | |
505 overview_mode_image_ = gfx::ImageSkia(); | |
506 } | 510 } |
507 | 511 |
508 void WebActivity::MakeInvisible() { | 512 void WebActivity::ShowContentProxy() { |
509 // TODO(skuhne): Once we know how to handle the Overview mode, this has to | 513 if (!content_proxy_.get() && web_view_) |
510 // be moved into an ActivityContentController which is used by all activities. | 514 content_proxy_.reset(new ContentProxy(web_view_, this)); |
511 // TODO(skuhne): If this can be combined with app_activity, move this into a | |
512 // separate class. | |
513 DCHECK(web_view_->visible()); | |
514 // Create our proxy image / layer. | |
515 if (current_state_ == ACTIVITY_VISIBLE) { | |
516 // Create a proxy image of the current visible content. | |
517 // TODO(skuhne): Do this once we figure out how to do overview mode. | |
518 overview_mode_image_ = gfx::ImageSkia(); | |
519 } | |
520 // Now we can hide this. | |
521 // Note: This might have to be done asynchronously after the read back took | |
522 // place. | |
523 web_view_->GetWebContents()->GetNativeView()->Hide(); | |
524 web_view_->SetVisible(false); | |
525 } | 515 } |
526 | 516 |
527 void WebActivity::ReloadAndObserve() { | 517 void WebActivity::ReloadAndObserve() { |
528 if (web_view_->IsContentEvicted()) { | 518 if (web_view_->IsContentEvicted()) { |
529 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); | 519 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); |
530 web_view_->ReloadContent(); | 520 web_view_->ReloadContent(); |
531 } | 521 } |
532 Observe(web_view_->GetWebContents()); | 522 Observe(web_view_->GetWebContents()); |
533 } | 523 } |
534 | 524 |
535 } // namespace athena | 525 } // namespace athena |
OLD | NEW |