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

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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 }; 328 };
326 329
327 WebActivity::WebActivity(content::BrowserContext* browser_context, 330 WebActivity::WebActivity(content::BrowserContext* browser_context,
328 const base::string16& title, 331 const base::string16& title,
329 const GURL& url) 332 const GURL& url)
330 : browser_context_(browser_context), 333 : browser_context_(browser_context),
331 title_(title), 334 title_(title),
332 url_(url), 335 url_(url),
333 web_view_(NULL), 336 web_view_(NULL),
334 title_color_(kDefaultTitleColor), 337 title_color_(kDefaultTitleColor),
335 current_state_(ACTIVITY_UNLOADED) { 338 current_state_(ACTIVITY_UNLOADED),
339 weak_ptr_factory_(this) {
336 } 340 }
337 341
338 WebActivity::WebActivity(AthenaWebView* web_view) 342 WebActivity::WebActivity(AthenaWebView* web_view)
339 : browser_context_(web_view->browser_context()), 343 : browser_context_(web_view->browser_context()),
340 url_(web_view->GetWebContents()->GetURL()), 344 url_(web_view->GetWebContents()->GetURL()),
341 web_view_(web_view), 345 web_view_(web_view),
342 current_state_(ACTIVITY_UNLOADED) { 346 current_state_(ACTIVITY_UNLOADED),
347 weak_ptr_factory_(this) {
343 // Transition to state ACTIVITY_INVISIBLE to perform the same setup steps 348 // Transition to state ACTIVITY_INVISIBLE to perform the same setup steps
344 // as on new activities (namely adding a WebContentsObserver). 349 // as on new activities (namely adding a WebContentsObserver).
345 SetCurrentState(ACTIVITY_INVISIBLE); 350 SetCurrentState(ACTIVITY_INVISIBLE);
346 } 351 }
347 352
348 WebActivity::~WebActivity() { 353 WebActivity::~WebActivity() {
349 // It is not required to change the activity state to UNLOADED - unless we 354 // It is not required to change the activity state to UNLOADED - unless we
350 // would add state observers. 355 // would add state observers.
351 } 356 }
352 357
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 aura::Window* WebActivity::GetWindow() { 419 aura::Window* WebActivity::GetWindow() {
415 return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow(); 420 return !web_view_ ? NULL : web_view_->GetWidget()->GetNativeWindow();
416 } 421 }
417 422
418 void WebActivity::Init() { 423 void WebActivity::Init() {
419 DCHECK(web_view_); 424 DCHECK(web_view_);
420 web_view_->InstallAccelerators(); 425 web_view_->InstallAccelerators();
421 } 426 }
422 427
423 SkColor WebActivity::GetRepresentativeColor() const { 428 SkColor WebActivity::GetRepresentativeColor() const {
424 // TODO(sad): Compute the color from the favicon.
425 return web_view_ ? title_color_ : kDefaultUnavailableColor; 429 return web_view_ ? title_color_ : kDefaultUnavailableColor;
426 } 430 }
427 431
428 base::string16 WebActivity::GetTitle() const { 432 base::string16 WebActivity::GetTitle() const {
429 if (!title_.empty()) 433 if (!title_.empty())
430 return title_; 434 return title_;
431 // TODO(oshima): Use title set by the web contents. 435 // TODO(oshima): Use title set by the web contents.
432 return web_view_ ? base::UTF8ToUTF16( 436 return web_view_ ? base::UTF8ToUTF16(
433 web_view_->GetWebContents()->GetVisibleURL().host()) 437 web_view_->GetWebContents()->GetVisibleURL().host())
434 : base::string16(); 438 : base::string16();
435 } 439 }
436 440
441 gfx::ImageSkia WebActivity::GetIcon() const {
442 return icon_;
443 }
444
437 bool WebActivity::UsesFrame() const { 445 bool WebActivity::UsesFrame() const {
438 return true; 446 return true;
439 } 447 }
440 448
441 views::View* WebActivity::GetContentsView() { 449 views::View* WebActivity::GetContentsView() {
442 if (!web_view_) { 450 if (!web_view_) {
443 web_view_ = new AthenaWebView(browser_context_); 451 web_view_ = new AthenaWebView(browser_context_);
444 web_view_->LoadInitialURL(url_); 452 web_view_->LoadInitialURL(url_);
445 // Make sure the content gets properly shown. 453 // Make sure the content gets properly shown.
446 if (current_state_ == ACTIVITY_VISIBLE) { 454 if (current_state_ == ACTIVITY_VISIBLE) {
(...skipping 27 matching lines...) Expand all
474 void WebActivity::ResetContentsView() { 482 void WebActivity::ResetContentsView() {
475 web_view_->SetFastResize(false); 483 web_view_->SetFastResize(false);
476 web_view_->Layout(); 484 web_view_->Layout();
477 } 485 }
478 486
479 void WebActivity::TitleWasSet(content::NavigationEntry* entry, 487 void WebActivity::TitleWasSet(content::NavigationEntry* entry,
480 bool explicit_set) { 488 bool explicit_set) {
481 ActivityManager::Get()->UpdateActivity(this); 489 ActivityManager::Get()->UpdateActivity(this);
482 } 490 }
483 491
492 void WebActivity::DidNavigateMainFrame(
493 const content::LoadCommittedDetails& details,
494 const content::FrameNavigateParams& params) {
495 // Prevent old image requests from calling back to OnDidDownloadFavicon().
496 weak_ptr_factory_.InvalidateWeakPtrs();
497 icon_ = gfx::ImageSkia();
498 ActivityManager::Get()->UpdateActivity(this);
499 }
500
484 void WebActivity::DidUpdateFaviconURL( 501 void WebActivity::DidUpdateFaviconURL(
485 const std::vector<content::FaviconURL>& candidates) { 502 const std::vector<content::FaviconURL>& candidates) {
503 // Pick an arbitrary favicon of type FAVICON to use.
504 // TODO(pkotwicz): Do something better once the favicon code is componentized.
505 // (crbug.com/401997)
506 for (size_t i = 0; i < candidates.size(); ++i) {
507 if (candidates[i].icon_type == content::FaviconURL::FAVICON) {
508 weak_ptr_factory_.InvalidateWeakPtrs();
sadrul 2014/09/11 01:03:17 Should we invalidate regardless of whether we have
509 web_view_->GetWebContents()->DownloadImage(
510 candidates[i].icon_url,
511 true,
512 0,
513 base::Bind(&WebActivity::OnDidDownloadFavicon,
514 weak_ptr_factory_.GetWeakPtr()));
515 break;
516 }
517 }
518 }
519
520 void WebActivity::OnDidDownloadFavicon(
521 int id,
522 int http_status_code,
523 const GURL& url,
524 const std::vector<SkBitmap>& bitmaps,
525 const std::vector<gfx::Size>& original_bitmap_sizes) {
526 if (icon_url_ != url) {
sadrul 2014/09/11 01:03:17 Remove.
527 // This is the icon for an old request.
528 return;
529 }
530
531 icon_ = CreateFaviconImageSkia(
532 bitmaps, original_bitmap_sizes, kIconSize, NULL);
486 ActivityManager::Get()->UpdateActivity(this); 533 ActivityManager::Get()->UpdateActivity(this);
487 } 534 }
488 535
489 void WebActivity::DidChangeThemeColor(SkColor theme_color) { 536 void WebActivity::DidChangeThemeColor(SkColor theme_color) {
490 title_color_ = theme_color; 537 title_color_ = theme_color;
491 ActivityManager::Get()->UpdateActivity(this); 538 ActivityManager::Get()->UpdateActivity(this);
492 } 539 }
493 540
494 void WebActivity::MakeVisible() { 541 void WebActivity::MakeVisible() {
495 // TODO(skuhne): Once we know how to handle the Overview mode, this has to 542 // TODO(skuhne): Once we know how to handle the Overview mode, this has to
(...skipping 30 matching lines...) Expand all
526 573
527 void WebActivity::ReloadAndObserve() { 574 void WebActivity::ReloadAndObserve() {
528 if (web_view_->IsContentEvicted()) { 575 if (web_view_->IsContentEvicted()) {
529 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); 576 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_);
530 web_view_->ReloadContent(); 577 web_view_->ReloadContent();
531 } 578 }
532 Observe(web_view_->GetWebContents()); 579 Observe(web_view_->GetWebContents());
533 } 580 }
534 581
535 } // namespace athena 582 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698