Commit 18df76f0 authored by thakis@chromium.org's avatar thakis@chromium.org

Convert FaviconStatus::bitmap from SkBitmap to gfx::Image.

Also rename it to "image". No intended behavior change.
Part of supporting hidpi favicons in the tab strip.

BUG=138550
TBR=joi

Review URL: https://chromiumcodereview.appspot.com/10832128

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149874 0039d316-1c4b-4281-b951-d872f2087c98
parent 10f0b0f0
......@@ -199,7 +199,7 @@ DevToolsWindow::DevToolsWindow(TabContents* tab_contents,
// Wipe out page icon so that the default application icon is used.
NavigationEntry* entry =
tab_contents_->web_contents()->GetController().GetActiveEntry();
entry->GetFavicon().bitmap = SkBitmap();
entry->GetFavicon().image = gfx::Image();
entry->GetFavicon().valid = true;
// Register on-load actions.
......
......@@ -236,7 +236,7 @@ void FaviconHandler::UpdateFavicon(NavigationEntry* entry,
if (!image)
return;
entry->GetFavicon().bitmap = *image->ToSkBitmap();
entry->GetFavicon().image = *image;
delegate_->NotifyFaviconUpdated();
}
......
......@@ -13,6 +13,7 @@
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image.h"
#include "third_party/skia/include/core/SkBitmap.h"
class TestFaviconHandler;
......@@ -419,7 +420,7 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) {
// Verify NavigationEntry.
EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url);
EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid);
EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty());
EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty());
}
TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
......@@ -509,7 +510,7 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
// Verify NavigationEntry.
EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url);
EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid);
EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty());
EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty());
}
TEST_F(FaviconHandlerTest, UpdateFavicon) {
......@@ -584,7 +585,7 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) {
// Verify the favicon status.
EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url);
EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid);
EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty());
EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty());
}
TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) {
......@@ -892,8 +893,9 @@ TEST_F(FaviconHandlerTest, MultipleFavicon) {
// Verify correct icon size chosen.
EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url);
EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid);
EXPECT_FALSE(handler.GetEntry()->GetFavicon().bitmap.empty());
EXPECT_EQ(gfx::kFaviconSize, handler.GetEntry()->GetFavicon().bitmap.width());
EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty());
EXPECT_EQ(gfx::kFaviconSize,
handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width());
}
TEST_F(FaviconHandlerTest, FirstFavicon) {
......@@ -947,8 +949,9 @@ TEST_F(FaviconHandlerTest, FirstFavicon) {
// Verify correct icon size chosen.
EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url);
EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid);
EXPECT_FALSE(handler.GetEntry()->GetFavicon().bitmap.empty());
EXPECT_EQ(gfx::kFaviconSize, handler.GetEntry()->GetFavicon().bitmap.width());
EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty());
EXPECT_EQ(gfx::kFaviconSize,
handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width());
}
} // namespace.
......@@ -55,11 +55,11 @@ SkBitmap FaviconTabHelper::GetFavicon() const {
const NavigationController& controller = web_contents()->GetController();
NavigationEntry* entry = controller.GetTransientEntry();
if (entry)
return entry->GetFavicon().bitmap;
return entry->GetFavicon().AsBitmap();
entry = controller.GetLastCommittedEntry();
if (entry)
return entry->GetFavicon().bitmap;
return entry->GetFavicon().AsBitmap();
return SkBitmap();
}
......@@ -107,11 +107,12 @@ void FaviconTabHelper::SaveFavicon() {
return;
const FaviconStatus& favicon(entry->GetFavicon());
if (!favicon.valid || favicon.url.is_empty() ||
favicon.bitmap.empty()) {
favicon.image.IsEmpty()) {
return;
}
std::vector<unsigned char> image_data;
gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap, false, &image_data);
// TODO: Save all representations.
gfx::PNGCodec::EncodeBGRASkBitmap(favicon.AsBitmap(), false, &image_data);
service->SetFavicon(
entry->GetURL(), favicon.url, image_data, history::FAVICON);
}
......
......@@ -376,10 +376,11 @@ void InstantLoader::WebContentsDelegateImpl::CommitHistory(
tab->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS);
if (favicon_service && active_entry->GetFavicon().valid &&
!active_entry->GetFavicon().bitmap.empty()) {
!active_entry->GetFavicon().image.IsEmpty()) {
std::vector<unsigned char> image_data;
gfx::PNGCodec::EncodeBGRASkBitmap(active_entry->GetFavicon().bitmap, false,
&image_data);
// TODO: Add all variants once the history service supports it.
gfx::PNGCodec::EncodeBGRASkBitmap(active_entry->GetFavicon().AsBitmap(),
false, &image_data);
favicon_service->SetFavicon(active_entry->GetURL(),
active_entry->GetFavicon().url,
image_data,
......
......@@ -142,7 +142,7 @@ bool BackForwardMenuModel::GetIconAt(int index, gfx::ImageSkia* icon) {
IDR_HISTORY_FAVICON);
} else {
NavigationEntry* entry = GetNavigationEntry(index);
*icon = entry->GetFavicon().bitmap;
*icon = *entry->GetFavicon().image.ToImageSkia();
if (!entry->GetFavicon().valid && menu_model_delegate()) {
FetchFavicon(entry);
}
......@@ -285,7 +285,9 @@ void BackForwardMenuModel::OnFavIconDataAvailable(
entry->GetFavicon().url = favicon.icon_url;
if (fav_icon.empty())
return;
entry->GetFavicon().bitmap = fav_icon;
// TODO: Once the history service returns more representations,
// use them all instead of having just the lodpi favicon.
entry->GetFavicon().image = gfx::Image(fav_icon);
if (menu_model_delegate()) {
menu_model_delegate()->OnIconChanged(model_index);
}
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -10,7 +10,11 @@
namespace content {
FaviconStatus::FaviconStatus() : valid(false) {
bitmap = *GetContentClient()->browser()->GetDefaultFavicon()->bitmap();
image = gfx::Image(*GetContentClient()->browser()->GetDefaultFavicon());
}
SkBitmap FaviconStatus::AsBitmap() const {
return image.IsEmpty() ? SkBitmap() : *image.ToSkBitmap();
}
} // namespace content
......@@ -7,6 +7,7 @@
#include "content/common/content_export.h"
#include "googleurl/src/gurl.h"
#include "ui/gfx/image/image.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace content {
......@@ -15,6 +16,9 @@ namespace content {
struct CONTENT_EXPORT FaviconStatus {
FaviconStatus();
// Returns 1x resolution of image. This function should eventually go away.
SkBitmap AsBitmap() const;
// Indicates whether we've gotten an official favicon for the page, or are
// just using the default favicon.
bool valid;
......@@ -26,7 +30,7 @@ struct CONTENT_EXPORT FaviconStatus {
// set or it empty, it will return the default favicon. Note that this is
// loaded asynchronously, so even if the favicon URL is valid we may return
// the default favicon if we haven't gotten the data yet.
SkBitmap bitmap;
gfx::Image image;
// Copy and assignment is explicitly allowed for this struct.
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment