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

Side by Side Diff: athena/content/web_activity.cc

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

Powered by Google App Engine
This is Rietveld 408576698