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/activity/public/activity_view.h" |
9 #include "athena/content/content_proxy.h" | 10 #include "athena/content/content_proxy.h" |
10 #include "athena/content/media_utils.h" | 11 #include "athena/content/media_utils.h" |
11 #include "athena/content/public/dialogs.h" | 12 #include "athena/content/public/dialogs.h" |
12 #include "athena/content/web_activity_helpers.h" | 13 #include "athena/content/web_activity_helpers.h" |
13 #include "athena/input/public/accelerator_manager.h" | 14 #include "athena/input/public/accelerator_manager.h" |
14 #include "athena/strings/grit/athena_strings.h" | 15 #include "athena/strings/grit/athena_strings.h" |
15 #include "base/bind.h" | 16 #include "base/bind.h" |
16 #include "base/command_line.h" | 17 #include "base/command_line.h" |
17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
18 #include "components/favicon_base/select_favicon_frames.h" | 19 #include "components/favicon_base/select_favicon_frames.h" |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 }; | 435 }; |
435 | 436 |
436 WebActivity::WebActivity(content::BrowserContext* browser_context, | 437 WebActivity::WebActivity(content::BrowserContext* browser_context, |
437 const base::string16& title, | 438 const base::string16& title, |
438 const GURL& url) | 439 const GURL& url) |
439 : browser_context_(browser_context), | 440 : browser_context_(browser_context), |
440 web_view_(new AthenaWebView(browser_context, this)), | 441 web_view_(new AthenaWebView(browser_context, this)), |
441 title_(title), | 442 title_(title), |
442 title_color_(kDefaultTitleColor), | 443 title_color_(kDefaultTitleColor), |
443 current_state_(ACTIVITY_UNLOADED), | 444 current_state_(ACTIVITY_UNLOADED), |
| 445 activity_view_(nullptr), |
444 weak_ptr_factory_(this) { | 446 weak_ptr_factory_(this) { |
445 // Order is important. The web activity helpers must be attached prior to the | 447 // Order is important. The web activity helpers must be attached prior to the |
446 // RenderView being created. | 448 // RenderView being created. |
447 SetCurrentState(ACTIVITY_INVISIBLE); | 449 SetCurrentState(ACTIVITY_INVISIBLE); |
448 web_view_->LoadInitialURL(url); | 450 web_view_->LoadInitialURL(url); |
449 } | 451 } |
450 | 452 |
451 WebActivity::WebActivity(content::WebContents* contents) | 453 WebActivity::WebActivity(content::WebContents* contents) |
452 : browser_context_(contents->GetBrowserContext()), | 454 : browser_context_(contents->GetBrowserContext()), |
453 web_view_(new AthenaWebView(contents, this)), | 455 web_view_(new AthenaWebView(contents, this)), |
454 title_color_(kDefaultTitleColor), | 456 title_color_(kDefaultTitleColor), |
455 current_state_(ACTIVITY_UNLOADED), | 457 current_state_(ACTIVITY_UNLOADED), |
| 458 activity_view_(nullptr), |
456 weak_ptr_factory_(this) { | 459 weak_ptr_factory_(this) { |
457 // If the activity was created as a result of | 460 // If the activity was created as a result of |
458 // WebContentsDelegate::AddNewContents(), web activity helpers may not be | 461 // WebContentsDelegate::AddNewContents(), web activity helpers may not be |
459 // created prior to the RenderView being created. Desktop Chrome has a | 462 // created prior to the RenderView being created. Desktop Chrome has a |
460 // similar problem. | 463 // similar problem. |
461 SetCurrentState(ACTIVITY_INVISIBLE); | 464 SetCurrentState(ACTIVITY_INVISIBLE); |
462 } | 465 } |
463 | 466 |
464 WebActivity::~WebActivity() { | 467 WebActivity::~WebActivity() { |
465 // It is not required to change the activity state to UNLOADED - unless we | 468 // It is not required to change the activity state to UNLOADED - unless we |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 const base::string16& title = web_view_->GetWebContents()->GetTitle(); | 553 const base::string16& title = web_view_->GetWebContents()->GetTitle(); |
551 if (!title.empty()) | 554 if (!title.empty()) |
552 return title; | 555 return title; |
553 return base::UTF8ToUTF16(web_view_->GetWebContents()->GetVisibleURL().host()); | 556 return base::UTF8ToUTF16(web_view_->GetWebContents()->GetVisibleURL().host()); |
554 } | 557 } |
555 | 558 |
556 gfx::ImageSkia WebActivity::GetIcon() const { | 559 gfx::ImageSkia WebActivity::GetIcon() const { |
557 return icon_; | 560 return icon_; |
558 } | 561 } |
559 | 562 |
| 563 void WebActivity::SetActivityView(ActivityView* view) { |
| 564 DCHECK(!activity_view_); |
| 565 activity_view_ = view; |
| 566 } |
| 567 |
560 bool WebActivity::UsesFrame() const { | 568 bool WebActivity::UsesFrame() const { |
561 return true; | 569 return true; |
562 } | 570 } |
563 | 571 |
564 views::View* WebActivity::GetContentsView() { | 572 views::View* WebActivity::GetContentsView() { |
565 return web_view_; | 573 return web_view_; |
566 } | 574 } |
567 | 575 |
568 gfx::ImageSkia WebActivity::GetOverviewModeImage() { | 576 gfx::ImageSkia WebActivity::GetOverviewModeImage() { |
569 if (content_proxy_.get()) | 577 if (content_proxy_.get()) |
(...skipping 12 matching lines...) Expand all Loading... |
582 // Turn on fast resizing to avoid re-laying out the web contents when | 590 // Turn on fast resizing to avoid re-laying out the web contents when |
583 // entering / exiting overview mode and the content is visible. | 591 // entering / exiting overview mode and the content is visible. |
584 if (!content_proxy_.get()) { | 592 if (!content_proxy_.get()) { |
585 web_view_->SetFastResize(false); | 593 web_view_->SetFastResize(false); |
586 web_view_->Layout(); | 594 web_view_->Layout(); |
587 } | 595 } |
588 } | 596 } |
589 | 597 |
590 void WebActivity::TitleWasSet(content::NavigationEntry* entry, | 598 void WebActivity::TitleWasSet(content::NavigationEntry* entry, |
591 bool explicit_set) { | 599 bool explicit_set) { |
592 ActivityManager::Get()->UpdateActivity(this); | 600 if (activity_view_) |
| 601 activity_view_->UpdateTitle(); |
593 } | 602 } |
594 | 603 |
595 void WebActivity::DidNavigateMainFrame( | 604 void WebActivity::DidNavigateMainFrame( |
596 const content::LoadCommittedDetails& details, | 605 const content::LoadCommittedDetails& details, |
597 const content::FrameNavigateParams& params) { | 606 const content::FrameNavigateParams& params) { |
598 // Prevent old image requests from calling back to OnDidDownloadFavicon(). | 607 // Prevent old image requests from calling back to OnDidDownloadFavicon(). |
599 weak_ptr_factory_.InvalidateWeakPtrs(); | 608 weak_ptr_factory_.InvalidateWeakPtrs(); |
600 | 609 |
601 icon_ = gfx::ImageSkia(); | 610 icon_ = gfx::ImageSkia(); |
602 ActivityManager::Get()->UpdateActivity(this); | 611 if (activity_view_) |
| 612 activity_view_->UpdateIcon(); |
603 } | 613 } |
604 | 614 |
605 void WebActivity::DidUpdateFaviconURL( | 615 void WebActivity::DidUpdateFaviconURL( |
606 const std::vector<content::FaviconURL>& candidates) { | 616 const std::vector<content::FaviconURL>& candidates) { |
607 // Pick an arbitrary favicon of type FAVICON to use. | 617 // Pick an arbitrary favicon of type FAVICON to use. |
608 // TODO(pkotwicz): Do something better once the favicon code is componentized. | 618 // TODO(pkotwicz): Do something better once the favicon code is componentized. |
609 // (crbug.com/401997) | 619 // (crbug.com/401997) |
610 weak_ptr_factory_.InvalidateWeakPtrs(); | 620 weak_ptr_factory_.InvalidateWeakPtrs(); |
611 for (size_t i = 0; i < candidates.size(); ++i) { | 621 for (size_t i = 0; i < candidates.size(); ++i) { |
612 if (candidates[i].icon_type == content::FaviconURL::FAVICON) { | 622 if (candidates[i].icon_type == content::FaviconURL::FAVICON) { |
613 web_view_->GetWebContents()->DownloadImage( | 623 web_view_->GetWebContents()->DownloadImage( |
614 candidates[i].icon_url, | 624 candidates[i].icon_url, |
615 true, | 625 true, |
616 0, | 626 0, |
617 base::Bind(&WebActivity::OnDidDownloadFavicon, | 627 base::Bind(&WebActivity::OnDidDownloadFavicon, |
618 weak_ptr_factory_.GetWeakPtr())); | 628 weak_ptr_factory_.GetWeakPtr())); |
619 break; | 629 break; |
620 } | 630 } |
621 } | 631 } |
622 } | 632 } |
623 | 633 |
624 void WebActivity::OnDidDownloadFavicon( | 634 void WebActivity::OnDidDownloadFavicon( |
625 int id, | 635 int id, |
626 int http_status_code, | 636 int http_status_code, |
627 const GURL& url, | 637 const GURL& url, |
628 const std::vector<SkBitmap>& bitmaps, | 638 const std::vector<SkBitmap>& bitmaps, |
629 const std::vector<gfx::Size>& original_bitmap_sizes) { | 639 const std::vector<gfx::Size>& original_bitmap_sizes) { |
630 icon_ = CreateFaviconImageSkia( | 640 icon_ = CreateFaviconImageSkia( |
631 bitmaps, original_bitmap_sizes, kIconSize, nullptr); | 641 bitmaps, original_bitmap_sizes, kIconSize, nullptr); |
632 ActivityManager::Get()->UpdateActivity(this); | 642 if (activity_view_) |
| 643 activity_view_->UpdateIcon(); |
633 } | 644 } |
634 | 645 |
635 void WebActivity::DidChangeThemeColor(SkColor theme_color) { | 646 void WebActivity::DidChangeThemeColor(SkColor theme_color) { |
636 title_color_ = theme_color; | 647 title_color_ = theme_color; |
637 ActivityManager::Get()->UpdateActivity(this); | 648 if (activity_view_) |
| 649 activity_view_->UpdateRepresentativeColor(); |
638 } | 650 } |
639 | 651 |
640 void WebActivity::HideContentProxy() { | 652 void WebActivity::HideContentProxy() { |
641 if (content_proxy_.get()) | 653 if (content_proxy_.get()) |
642 content_proxy_.reset(nullptr); | 654 content_proxy_.reset(nullptr); |
643 } | 655 } |
644 | 656 |
645 void WebActivity::ShowContentProxy() { | 657 void WebActivity::ShowContentProxy() { |
646 if (!content_proxy_.get()) | 658 if (!content_proxy_.get()) |
647 content_proxy_.reset(new ContentProxy(web_view_)); | 659 content_proxy_.reset(new ContentProxy(web_view_)); |
648 } | 660 } |
649 | 661 |
650 } // namespace athena | 662 } // namespace athena |
OLD | NEW |