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/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 "components/favicon_base/select_favicon_frames.h" | 15 #include "components/favicon_base/select_favicon_frames.h" |
15 #include "content/public/browser/native_web_keyboard_event.h" | 16 #include "content/public/browser/native_web_keyboard_event.h" |
16 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_contents_delegate.h" | 19 #include "content/public/browser/web_contents_delegate.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 } | 173 } |
173 | 174 |
174 virtual ~AthenaWebView() {} | 175 virtual ~AthenaWebView() {} |
175 | 176 |
176 void InstallAccelerators() { controller_->InstallAccelerators(); } | 177 void InstallAccelerators() { controller_->InstallAccelerators(); } |
177 | 178 |
178 void EvictContent() { | 179 void EvictContent() { |
179 scoped_ptr<content::WebContents> old_contents(SwapWebContents( | 180 scoped_ptr<content::WebContents> old_contents(SwapWebContents( |
180 scoped_ptr<content::WebContents>(content::WebContents::Create( | 181 scoped_ptr<content::WebContents>(content::WebContents::Create( |
181 content::WebContents::CreateParams(browser_context()))))); | 182 content::WebContents::CreateParams(browser_context()))))); |
183 // If there is a progress bar, we need to get rid of it now since its | |
184 // associated content, parent window and layers will disappear with evicting | |
185 // the content. | |
186 progress_bar_.reset(); | |
182 evicted_web_contents_.reset( | 187 evicted_web_contents_.reset( |
183 content::WebContents::Create(content::WebContents::CreateParams( | 188 content::WebContents::Create(content::WebContents::CreateParams( |
184 old_contents->GetBrowserContext()))); | 189 old_contents->GetBrowserContext()))); |
185 evicted_web_contents_->GetController().CopyStateFrom( | 190 evicted_web_contents_->GetController().CopyStateFrom( |
186 old_contents->GetController()); | 191 old_contents->GetController()); |
187 // As soon as the new contents becomes visible, it should reload. | 192 // As soon as the new contents becomes visible, it should reload. |
188 // TODO(skuhne): This breaks script connections with other activities. | 193 // TODO(skuhne): This breaks script connections with other activities. |
189 // Even though this is the same technique as used by the TabStripModel, | 194 // Even though this is the same technique as used by the TabStripModel, |
190 // we might want to address this cleaner since we are more likely to | 195 // we might want to address this cleaner since we are more likely to |
191 // run into this state. by unloading. | 196 // run into this state. by unloading. |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 ActivityViewModel* WebActivity::GetActivityViewModel() { | 378 ActivityViewModel* WebActivity::GetActivityViewModel() { |
374 return this; | 379 return this; |
375 } | 380 } |
376 | 381 |
377 void WebActivity::SetCurrentState(Activity::ActivityState state) { | 382 void WebActivity::SetCurrentState(Activity::ActivityState state) { |
378 DCHECK_NE(state, current_state_); | 383 DCHECK_NE(state, current_state_); |
379 switch (state) { | 384 switch (state) { |
380 case ACTIVITY_VISIBLE: | 385 case ACTIVITY_VISIBLE: |
381 if (!web_view_) | 386 if (!web_view_) |
382 break; | 387 break; |
383 MakeVisible(); | 388 HideContentProxy(); |
384 ReloadAndObserve(); | 389 ReloadAndObserve(); |
385 break; | 390 break; |
386 case ACTIVITY_INVISIBLE: | 391 case ACTIVITY_INVISIBLE: |
387 if (!web_view_) | 392 if (!web_view_) |
388 break; | 393 break; |
394 | |
389 if (current_state_ == ACTIVITY_VISIBLE) | 395 if (current_state_ == ACTIVITY_VISIBLE) |
390 MakeInvisible(); | 396 ShowContentProxy(); |
391 ReloadAndObserve(); | 397 else |
398 ReloadAndObserve(); | |
399 | |
392 break; | 400 break; |
393 case ACTIVITY_BACKGROUND_LOW_PRIORITY: | 401 case ACTIVITY_BACKGROUND_LOW_PRIORITY: |
394 DCHECK(ACTIVITY_VISIBLE == current_state_ || | 402 DCHECK(ACTIVITY_VISIBLE == current_state_ || |
395 ACTIVITY_INVISIBLE == current_state_); | 403 ACTIVITY_INVISIBLE == current_state_); |
396 // TODO(skuhne): Do this. | 404 // TODO(skuhne): Do this. |
397 break; | 405 break; |
398 case ACTIVITY_PERSISTENT: | 406 case ACTIVITY_PERSISTENT: |
399 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state_); | 407 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state_); |
400 // TODO(skuhne): Do this. As soon as the new resource management is | 408 // TODO(skuhne): Do this. As soon as the new resource management is |
401 // agreed upon - or remove otherwise. | 409 // agreed upon - or remove otherwise. |
402 break; | 410 break; |
403 case ACTIVITY_UNLOADED: | 411 case ACTIVITY_UNLOADED: |
404 DCHECK_NE(ACTIVITY_UNLOADED, current_state_); | 412 DCHECK_NE(ACTIVITY_UNLOADED, current_state_); |
413 if (content_proxy_.get()) | |
sadrul
2014/09/12 16:30:14
You can just do if (content_proxy_) or if (!conten
Mr4D (OOO till 08-26)
2014/09/12 20:11:26
Done.
| |
414 content_proxy_->ContentWillUnload(); | |
405 Observe(NULL); | 415 Observe(NULL); |
406 web_view_->EvictContent(); | 416 web_view_->EvictContent(); |
407 break; | 417 break; |
408 } | 418 } |
409 // Remember the last requested state. | 419 // Remember the last requested state. |
410 current_state_ = state; | 420 current_state_ = state; |
411 } | 421 } |
412 | 422 |
413 Activity::ActivityState WebActivity::GetCurrentState() { | 423 Activity::ActivityState WebActivity::GetCurrentState() { |
414 // If the content is evicted, the state has to be UNLOADED. | 424 // If the content is evicted, the state has to be UNLOADED. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 bool WebActivity::UsesFrame() const { | 470 bool WebActivity::UsesFrame() const { |
461 return true; | 471 return true; |
462 } | 472 } |
463 | 473 |
464 views::View* WebActivity::GetContentsView() { | 474 views::View* WebActivity::GetContentsView() { |
465 if (!web_view_) { | 475 if (!web_view_) { |
466 web_view_ = new AthenaWebView(browser_context_); | 476 web_view_ = new AthenaWebView(browser_context_); |
467 web_view_->LoadInitialURL(url_); | 477 web_view_->LoadInitialURL(url_); |
468 // Make sure the content gets properly shown. | 478 // Make sure the content gets properly shown. |
469 if (current_state_ == ACTIVITY_VISIBLE) { | 479 if (current_state_ == ACTIVITY_VISIBLE) { |
470 MakeVisible(); | 480 HideContentProxy(); |
471 ReloadAndObserve(); | 481 ReloadAndObserve(); |
472 } else if (current_state_ == ACTIVITY_INVISIBLE) { | 482 } else if (current_state_ == ACTIVITY_INVISIBLE) { |
473 MakeInvisible(); | 483 ShowContentProxy(); |
474 ReloadAndObserve(); | 484 ReloadAndObserve(); |
475 } else { | 485 } else { |
476 // If not previously specified, we change the state now to invisible.. | 486 // If not previously specified, we change the state now to invisible.. |
477 SetCurrentState(ACTIVITY_INVISIBLE); | 487 SetCurrentState(ACTIVITY_INVISIBLE); |
478 } | 488 } |
479 } | 489 } |
480 return web_view_; | 490 return web_view_; |
481 } | 491 } |
482 | 492 |
483 views::Widget* WebActivity::CreateWidget() { | 493 views::Widget* WebActivity::CreateWidget() { |
484 return NULL; // Use default widget. | 494 return NULL; // Use default widget. |
485 } | 495 } |
486 | 496 |
487 void WebActivity::CreateOverviewModeImage() { | |
488 // TODO(skuhne): Create an overview. | |
489 } | |
490 | |
491 gfx::ImageSkia WebActivity::GetOverviewModeImage() { | 497 gfx::ImageSkia WebActivity::GetOverviewModeImage() { |
492 return overview_mode_image_; | 498 if (content_proxy_.get()) |
499 content_proxy_->GetContentImage(); | |
500 return gfx::ImageSkia(); | |
493 } | 501 } |
494 | 502 |
495 void WebActivity::PrepareContentsForOverview() { | 503 void WebActivity::PrepareContentsForOverview() { |
496 // Turn on fast resizing to avoid re-laying out the web contents when | 504 // Turn on fast resizing to avoid re-laying out the web contents when |
497 // entering / exiting overview mode. | 505 // entering / exiting overview mode and the content is visible. |
498 web_view_->SetFastResize(true); | 506 if (!content_proxy_.get()) |
507 web_view_->SetFastResize(true); | |
499 } | 508 } |
500 | 509 |
501 void WebActivity::ResetContentsView() { | 510 void WebActivity::ResetContentsView() { |
502 web_view_->SetFastResize(false); | 511 // Turn on fast resizing to avoid re-laying out the web contents when |
503 web_view_->Layout(); | 512 // entering / exiting overview mode and the content is visible. |
513 if (!content_proxy_.get()) { | |
514 web_view_->SetFastResize(false); | |
515 web_view_->Layout(); | |
516 } | |
504 } | 517 } |
505 | 518 |
506 void WebActivity::TitleWasSet(content::NavigationEntry* entry, | 519 void WebActivity::TitleWasSet(content::NavigationEntry* entry, |
507 bool explicit_set) { | 520 bool explicit_set) { |
508 ActivityManager::Get()->UpdateActivity(this); | 521 ActivityManager::Get()->UpdateActivity(this); |
509 } | 522 } |
510 | 523 |
511 void WebActivity::DidNavigateMainFrame( | 524 void WebActivity::DidNavigateMainFrame( |
512 const content::LoadCommittedDetails& details, | 525 const content::LoadCommittedDetails& details, |
513 const content::FrameNavigateParams& params) { | 526 const content::FrameNavigateParams& params) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 icon_ = CreateFaviconImageSkia( | 559 icon_ = CreateFaviconImageSkia( |
547 bitmaps, original_bitmap_sizes, kIconSize, NULL); | 560 bitmaps, original_bitmap_sizes, kIconSize, NULL); |
548 ActivityManager::Get()->UpdateActivity(this); | 561 ActivityManager::Get()->UpdateActivity(this); |
549 } | 562 } |
550 | 563 |
551 void WebActivity::DidChangeThemeColor(SkColor theme_color) { | 564 void WebActivity::DidChangeThemeColor(SkColor theme_color) { |
552 title_color_ = theme_color; | 565 title_color_ = theme_color; |
553 ActivityManager::Get()->UpdateActivity(this); | 566 ActivityManager::Get()->UpdateActivity(this); |
554 } | 567 } |
555 | 568 |
556 void WebActivity::MakeVisible() { | 569 void WebActivity::HideContentProxy() { |
557 // TODO(skuhne): Once we know how to handle the Overview mode, this has to | 570 if (content_proxy_.get()) |
558 // be moved into an ActivityContentController which is used by all activities. | 571 content_proxy_.reset(NULL); |
559 // Make the content visible. | |
560 // TODO(skuhne): If this can be combined with app_activity, move this into a | |
561 // separate class. | |
562 web_view_->SetVisible(true); | |
563 web_view_->GetWebContents()->GetNativeView()->Show(); | |
564 // If we have a proxy image, we can delete it now since the contet goes live. | |
565 // TODO(skuhne): Once we have figured out how to do overview mode that code | |
566 // needs to go here. | |
567 overview_mode_image_ = gfx::ImageSkia(); | |
568 } | 572 } |
569 | 573 |
570 void WebActivity::MakeInvisible() { | 574 void WebActivity::ShowContentProxy() { |
571 // TODO(skuhne): Once we know how to handle the Overview mode, this has to | 575 if (!content_proxy_.get() && web_view_) |
572 // be moved into an ActivityContentController which is used by all activities. | 576 content_proxy_.reset(new ContentProxy(web_view_, this)); |
573 // TODO(skuhne): If this can be combined with app_activity, move this into a | |
574 // separate class. | |
575 DCHECK(web_view_->visible()); | |
576 // Create our proxy image / layer. | |
577 if (current_state_ == ACTIVITY_VISIBLE) { | |
578 // Create a proxy image of the current visible content. | |
579 // TODO(skuhne): Do this once we figure out how to do overview mode. | |
580 overview_mode_image_ = gfx::ImageSkia(); | |
581 } | |
582 // Now we can hide this. | |
583 // Note: This might have to be done asynchronously after the read back took | |
584 // place. | |
585 web_view_->GetWebContents()->GetNativeView()->Hide(); | |
586 web_view_->SetVisible(false); | |
587 } | 577 } |
588 | 578 |
589 void WebActivity::ReloadAndObserve() { | 579 void WebActivity::ReloadAndObserve() { |
590 if (web_view_->IsContentEvicted()) { | 580 if (web_view_->IsContentEvicted()) { |
591 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); | 581 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); |
592 web_view_->ReloadContent(); | 582 web_view_->ReloadContent(); |
593 } | 583 } |
594 Observe(web_view_->GetWebContents()); | 584 Observe(web_view_->GetWebContents()); |
595 } | 585 } |
596 | 586 |
597 } // namespace athena | 587 } // namespace athena |
OLD | NEW |