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

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

Issue 550643002: [Athena] Hack to display favicons for web activities in overview mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/input/public/accelerator_manager.h" 9 #include "athena/input/public/accelerator_manager.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "components/favicon_base/select_favicon_frames.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"
19 #include "content/public/common/favicon_url.h"
18 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
19 #include "ui/compositor/closure_animation_observer.h" 21 #include "ui/compositor/closure_animation_observer.h"
20 #include "ui/compositor/scoped_layer_animation_settings.h" 22 #include "ui/compositor/scoped_layer_animation_settings.h"
21 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" 23 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
22 #include "ui/views/controls/webview/webview.h" 24 #include "ui/views/controls/webview/webview.h"
23 #include "ui/views/focus/focus_manager.h" 25 #include "ui/views/focus/focus_manager.h"
24 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
25 27
26 namespace athena { 28 namespace athena {
27 namespace { 29 namespace {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 views::WebView* web_view_; 140 views::WebView* web_view_;
139 bool reserved_accelerator_enabled_; 141 bool reserved_accelerator_enabled_;
140 scoped_ptr<AcceleratorManager> accelerator_manager_; 142 scoped_ptr<AcceleratorManager> accelerator_manager_;
141 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; 143 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
142 144
143 DISALLOW_COPY_AND_ASSIGN(WebActivityController); 145 DISALLOW_COPY_AND_ASSIGN(WebActivityController);
144 }; 146 };
145 147
146 const SkColor kDefaultTitleColor = SkColorSetRGB(0xf2, 0xf2, 0xf2); 148 const SkColor kDefaultTitleColor = SkColorSetRGB(0xf2, 0xf2, 0xf2);
147 const SkColor kDefaultUnavailableColor = SkColorSetRGB(0xbb, 0x77, 0x77); 149 const SkColor kDefaultUnavailableColor = SkColorSetRGB(0xbb, 0x77, 0x77);
150 const int kIconSize = 32;
148 151
149 } // namespace 152 } // namespace
150 153
151 // A web view for athena's web activity. Note that AthenaWebView will create its 154 // A web view for athena's web activity. Note that AthenaWebView will create its
152 // own content so that it can eject and reload it. 155 // own content so that it can eject and reload it.
153 class AthenaWebView : public views::WebView { 156 class AthenaWebView : public views::WebView {
154 public: 157 public:
155 AthenaWebView(content::BrowserContext* context) 158 AthenaWebView(content::BrowserContext* context)
156 : views::WebView(context), controller_(new WebActivityController(this)), 159 : views::WebView(context), controller_(new WebActivityController(this)),
157 fullscreen_(false) { 160 fullscreen_(false) {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 aura::Window* WebActivity::GetWindow() { 417 aura::Window* WebActivity::GetWindow() {
415 return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow(); 418 return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow();
416 } 419 }
417 420
418 void WebActivity::Init() { 421 void WebActivity::Init() {
419 DCHECK(web_view_); 422 DCHECK(web_view_);
420 web_view_->InstallAccelerators(); 423 web_view_->InstallAccelerators();
421 } 424 }
422 425
423 SkColor WebActivity::GetRepresentativeColor() const { 426 SkColor WebActivity::GetRepresentativeColor() const {
424 // TODO(sad): Compute the color from the favicon.
425 return web_view_ ? title_color_ : kDefaultUnavailableColor; 427 return web_view_ ? title_color_ : kDefaultUnavailableColor;
426 } 428 }
427 429
428 base::string16 WebActivity::GetTitle() const { 430 base::string16 WebActivity::GetTitle() const {
429 if (!title_.empty()) 431 if (!title_.empty())
430 return title_; 432 return title_;
431 // TODO(oshima): Use title set by the web contents. 433 // TODO(oshima): Use title set by the web contents.
432 return web_view_ ? base::UTF8ToUTF16( 434 return web_view_ ? base::UTF8ToUTF16(
433 web_view_->GetWebContents()->GetVisibleURL().host()) 435 web_view_->GetWebContents()->GetVisibleURL().host())
434 : base::string16(); 436 : base::string16();
435 } 437 }
436 438
439 gfx::ImageSkia WebActivity::GetIcon() const {
440 return icon_;
441 }
442
437 bool WebActivity::UsesFrame() const { 443 bool WebActivity::UsesFrame() const {
438 return true; 444 return true;
439 } 445 }
440 446
441 views::View* WebActivity::GetContentsView() { 447 views::View* WebActivity::GetContentsView() {
442 if (!web_view_) { 448 if (!web_view_) {
443 web_view_ = new AthenaWebView(browser_context_); 449 web_view_ = new AthenaWebView(browser_context_);
444 web_view_->LoadInitialURL(url_); 450 web_view_->LoadInitialURL(url_);
445 // Make sure the content gets properly shown. 451 // Make sure the content gets properly shown.
446 if (current_state_ == ACTIVITY_VISIBLE) { 452 if (current_state_ == ACTIVITY_VISIBLE) {
(...skipping 27 matching lines...) Expand all
474 void WebActivity::ResetContentsView() { 480 void WebActivity::ResetContentsView() {
475 web_view_->SetFastResize(false); 481 web_view_->SetFastResize(false);
476 web_view_->Layout(); 482 web_view_->Layout();
477 } 483 }
478 484
479 void WebActivity::TitleWasSet(content::NavigationEntry* entry, 485 void WebActivity::TitleWasSet(content::NavigationEntry* entry,
480 bool explicit_set) { 486 bool explicit_set) {
481 ActivityManager::Get()->UpdateActivity(this); 487 ActivityManager::Get()->UpdateActivity(this);
482 } 488 }
483 489
490 void WebActivity::DidNavigateMainFrame(
491 const content::LoadCommittedDetails& details,
492 const content::FrameNavigateParams& params) {
493 icon_ = gfx::ImageSkia();
494 ActivityManager::Get()->UpdateActivity(this);
495 }
496
484 void WebActivity::DidUpdateFaviconURL( 497 void WebActivity::DidUpdateFaviconURL(
485 const std::vector<content::FaviconURL>& candidates) { 498 const std::vector<content::FaviconURL>& candidates) {
499 // Pick an arbitrary favicon of type FAVICON to use.
500 // TODO(pkotwicz): Do something better once the favicon code is componentized.
501 // (crbug.com/401997)
502 for (size_t i = 0; i < candidates.size(); ++i) {
503 if (candidates[i].icon_type == content::FaviconURL::FAVICON) {
504 web_view_->GetWebContents()->DownloadImage(
505 candidates[i].icon_url,
506 true,
507 0,
508 base::Bind(&WebActivity::OnDidDownloadFavicon,
509 base::Unretained(this)));
sadrul 2014/09/07 05:39:18 Use a weak-ptr here instead.
pkotwicz 2014/09/08 21:36:17 Done.
510 break;
511 }
512 }
513 }
514
515 void WebActivity::OnDidDownloadFavicon(
516 int id,
517 int http_status_code,
518 const GURL& url,
519 const std::vector<SkBitmap>& bitmaps,
520 const std::vector<gfx::Size>& original_bitmap_sizes) {
521 icon_ = CreateFaviconImageSkia(
sadrul 2014/09/07 05:39:18 You should probably look at |http_status_code| bef
pkotwicz 2014/09/08 21:36:17 According to MultiResolutionImageResourceFetcher::
522 bitmaps, original_bitmap_sizes, kIconSize, NULL);
486 ActivityManager::Get()->UpdateActivity(this); 523 ActivityManager::Get()->UpdateActivity(this);
487 } 524 }
488 525
489 void WebActivity::DidChangeThemeColor(SkColor theme_color) { 526 void WebActivity::DidChangeThemeColor(SkColor theme_color) {
490 title_color_ = theme_color; 527 title_color_ = theme_color;
491 ActivityManager::Get()->UpdateActivity(this); 528 ActivityManager::Get()->UpdateActivity(this);
492 } 529 }
493 530
494 void WebActivity::MakeVisible() { 531 void WebActivity::MakeVisible() {
495 // TODO(skuhne): Once we know how to handle the Overview mode, this has to 532 // TODO(skuhne): Once we know how to handle the Overview mode, this has to
(...skipping 30 matching lines...) Expand all
526 563
527 void WebActivity::ReloadAndObserve() { 564 void WebActivity::ReloadAndObserve() {
528 if (web_view_->IsContentEvicted()) { 565 if (web_view_->IsContentEvicted()) {
529 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); 566 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_);
530 web_view_->ReloadContent(); 567 web_view_->ReloadContent();
531 } 568 }
532 Observe(web_view_->GetWebContents()); 569 Observe(web_view_->GetWebContents());
533 } 570 }
534 571
535 } // namespace athena 572 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698