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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « athena/content/web_activity.h ('k') | athena/resource_manager/resource_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: athena/content/web_activity.cc
diff --git a/athena/content/web_activity.cc b/athena/content/web_activity.cc
index 85ede624a7f6383ceb3c3bc5f9e846e920038617..6a1daef224ab6d6307e49c323022ed147b82971e 100644
--- a/athena/content/web_activity.cc
+++ b/athena/content/web_activity.cc
@@ -10,11 +10,13 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
+#include "components/favicon_base/select_favicon_frames.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/favicon_url.h"
#include "ui/aura/window.h"
#include "ui/compositor/closure_animation_observer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
@@ -145,6 +147,7 @@ class WebActivityController : public AcceleratorHandler {
const SkColor kDefaultTitleColor = SkColorSetRGB(0xf2, 0xf2, 0xf2);
const SkColor kDefaultUnavailableColor = SkColorSetRGB(0xbb, 0x77, 0x77);
+const int kIconSize = 32;
} // namespace
@@ -332,14 +335,16 @@ WebActivity::WebActivity(content::BrowserContext* browser_context,
url_(url),
web_view_(NULL),
title_color_(kDefaultTitleColor),
- current_state_(ACTIVITY_UNLOADED) {
+ current_state_(ACTIVITY_UNLOADED),
+ weak_ptr_factory_(this) {
}
WebActivity::WebActivity(AthenaWebView* web_view)
: browser_context_(web_view->browser_context()),
url_(web_view->GetWebContents()->GetURL()),
web_view_(web_view),
- current_state_(ACTIVITY_UNLOADED) {
+ current_state_(ACTIVITY_UNLOADED),
+ weak_ptr_factory_(this) {
// Transition to state ACTIVITY_INVISIBLE to perform the same setup steps
// as on new activities (namely adding a WebContentsObserver).
SetCurrentState(ACTIVITY_INVISIBLE);
@@ -421,7 +426,6 @@ void WebActivity::Init() {
}
SkColor WebActivity::GetRepresentativeColor() const {
- // TODO(sad): Compute the color from the favicon.
return web_view_ ? title_color_ : kDefaultUnavailableColor;
}
@@ -434,6 +438,10 @@ base::string16 WebActivity::GetTitle() const {
: base::string16();
}
+gfx::ImageSkia WebActivity::GetIcon() const {
+ return icon_;
+}
+
bool WebActivity::UsesFrame() const {
return true;
}
@@ -481,8 +489,39 @@ void WebActivity::TitleWasSet(content::NavigationEntry* entry,
ActivityManager::Get()->UpdateActivity(this);
}
+void WebActivity::DidNavigateMainFrame(
+ const content::LoadCommittedDetails& details,
+ const content::FrameNavigateParams& params) {
+ icon_ = gfx::ImageSkia();
+ ActivityManager::Get()->UpdateActivity(this);
+}
+
void WebActivity::DidUpdateFaviconURL(
const std::vector<content::FaviconURL>& candidates) {
+ // Pick an arbitrary favicon of type FAVICON to use.
+ // TODO(pkotwicz): Do something better once the favicon code is componentized.
+ // (crbug.com/401997)
sadrul 2014/09/09 22:52:40 You may want to weak_ptr_factory_.InvalidateWeakPt
+ for (size_t i = 0; i < candidates.size(); ++i) {
+ if (candidates[i].icon_type == content::FaviconURL::FAVICON) {
+ web_view_->GetWebContents()->DownloadImage(
+ candidates[i].icon_url,
+ true,
+ 0,
+ base::Bind(&WebActivity::OnDidDownloadFavicon,
+ weak_ptr_factory_.GetWeakPtr()));
+ break;
+ }
+ }
+}
+
+void WebActivity::OnDidDownloadFavicon(
+ int id,
+ int http_status_code,
+ const GURL& url,
+ const std::vector<SkBitmap>& bitmaps,
+ const std::vector<gfx::Size>& original_bitmap_sizes) {
+ icon_ = CreateFaviconImageSkia(
+ bitmaps, original_bitmap_sizes, kIconSize, NULL);
ActivityManager::Get()->UpdateActivity(this);
}
« no previous file with comments | « athena/content/web_activity.h ('k') | athena/resource_manager/resource_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698