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, ...@@ -199,7 +199,7 @@ DevToolsWindow::DevToolsWindow(TabContents* tab_contents,
// Wipe out page icon so that the default application icon is used. // Wipe out page icon so that the default application icon is used.
NavigationEntry* entry = NavigationEntry* entry =
tab_contents_->web_contents()->GetController().GetActiveEntry(); tab_contents_->web_contents()->GetController().GetActiveEntry();
entry->GetFavicon().bitmap = SkBitmap(); entry->GetFavicon().image = gfx::Image();
entry->GetFavicon().valid = true; entry->GetFavicon().valid = true;
// Register on-load actions. // Register on-load actions.
......
...@@ -236,7 +236,7 @@ void FaviconHandler::UpdateFavicon(NavigationEntry* entry, ...@@ -236,7 +236,7 @@ void FaviconHandler::UpdateFavicon(NavigationEntry* entry,
if (!image) if (!image)
return; return;
entry->GetFavicon().bitmap = *image->ToSkBitmap(); entry->GetFavicon().image = *image;
delegate_->NotifyFaviconUpdated(); delegate_->NotifyFaviconUpdated();
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/favicon_size.h" #include "ui/gfx/favicon_size.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "third_party/skia/include/core/SkBitmap.h"
class TestFaviconHandler; class TestFaviconHandler;
...@@ -419,7 +420,7 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) { ...@@ -419,7 +420,7 @@ TEST_F(FaviconHandlerTest, DownloadFavicon) {
// Verify NavigationEntry. // Verify NavigationEntry.
EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url); EXPECT_EQ(icon_url, helper.GetEntry()->GetFavicon().url);
EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid);
EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty()); EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty());
} }
TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
...@@ -509,7 +510,7 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { ...@@ -509,7 +510,7 @@ TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) {
// Verify NavigationEntry. // Verify NavigationEntry.
EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url);
EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid);
EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty()); EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty());
} }
TEST_F(FaviconHandlerTest, UpdateFavicon) { TEST_F(FaviconHandlerTest, UpdateFavicon) {
...@@ -584,7 +585,7 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) { ...@@ -584,7 +585,7 @@ TEST_F(FaviconHandlerTest, UpdateFavicon) {
// Verify the favicon status. // Verify the favicon status.
EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url); EXPECT_EQ(new_icon_url, helper.GetEntry()->GetFavicon().url);
EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid); EXPECT_TRUE(helper.GetEntry()->GetFavicon().valid);
EXPECT_FALSE(helper.GetEntry()->GetFavicon().bitmap.empty()); EXPECT_FALSE(helper.GetEntry()->GetFavicon().image.IsEmpty());
} }
TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) {
...@@ -892,8 +893,9 @@ TEST_F(FaviconHandlerTest, MultipleFavicon) { ...@@ -892,8 +893,9 @@ TEST_F(FaviconHandlerTest, MultipleFavicon) {
// Verify correct icon size chosen. // Verify correct icon size chosen.
EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url);
EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid);
EXPECT_FALSE(handler.GetEntry()->GetFavicon().bitmap.empty()); EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty());
EXPECT_EQ(gfx::kFaviconSize, handler.GetEntry()->GetFavicon().bitmap.width()); EXPECT_EQ(gfx::kFaviconSize,
handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width());
} }
TEST_F(FaviconHandlerTest, FirstFavicon) { TEST_F(FaviconHandlerTest, FirstFavicon) {
...@@ -947,8 +949,9 @@ TEST_F(FaviconHandlerTest, FirstFavicon) { ...@@ -947,8 +949,9 @@ TEST_F(FaviconHandlerTest, FirstFavicon) {
// Verify correct icon size chosen. // Verify correct icon size chosen.
EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url); EXPECT_EQ(icon_url_preferred1, handler.GetEntry()->GetFavicon().url);
EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid); EXPECT_TRUE(handler.GetEntry()->GetFavicon().valid);
EXPECT_FALSE(handler.GetEntry()->GetFavicon().bitmap.empty()); EXPECT_FALSE(handler.GetEntry()->GetFavicon().image.IsEmpty());
EXPECT_EQ(gfx::kFaviconSize, handler.GetEntry()->GetFavicon().bitmap.width()); EXPECT_EQ(gfx::kFaviconSize,
handler.GetEntry()->GetFavicon().image.ToSkBitmap()->width());
} }
} // namespace. } // namespace.
...@@ -55,11 +55,11 @@ SkBitmap FaviconTabHelper::GetFavicon() const { ...@@ -55,11 +55,11 @@ SkBitmap FaviconTabHelper::GetFavicon() const {
const NavigationController& controller = web_contents()->GetController(); const NavigationController& controller = web_contents()->GetController();
NavigationEntry* entry = controller.GetTransientEntry(); NavigationEntry* entry = controller.GetTransientEntry();
if (entry) if (entry)
return entry->GetFavicon().bitmap; return entry->GetFavicon().AsBitmap();
entry = controller.GetLastCommittedEntry(); entry = controller.GetLastCommittedEntry();
if (entry) if (entry)
return entry->GetFavicon().bitmap; return entry->GetFavicon().AsBitmap();
return SkBitmap(); return SkBitmap();
} }
...@@ -107,11 +107,12 @@ void FaviconTabHelper::SaveFavicon() { ...@@ -107,11 +107,12 @@ void FaviconTabHelper::SaveFavicon() {
return; return;
const FaviconStatus& favicon(entry->GetFavicon()); const FaviconStatus& favicon(entry->GetFavicon());
if (!favicon.valid || favicon.url.is_empty() || if (!favicon.valid || favicon.url.is_empty() ||
favicon.bitmap.empty()) { favicon.image.IsEmpty()) {
return; return;
} }
std::vector<unsigned char> image_data; 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( service->SetFavicon(
entry->GetURL(), favicon.url, image_data, history::FAVICON); entry->GetURL(), favicon.url, image_data, history::FAVICON);
} }
......
...@@ -376,10 +376,11 @@ void InstantLoader::WebContentsDelegateImpl::CommitHistory( ...@@ -376,10 +376,11 @@ void InstantLoader::WebContentsDelegateImpl::CommitHistory(
tab->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS); tab->profile()->GetFaviconService(Profile::EXPLICIT_ACCESS);
if (favicon_service && active_entry->GetFavicon().valid && if (favicon_service && active_entry->GetFavicon().valid &&
!active_entry->GetFavicon().bitmap.empty()) { !active_entry->GetFavicon().image.IsEmpty()) {
std::vector<unsigned char> image_data; std::vector<unsigned char> image_data;
gfx::PNGCodec::EncodeBGRASkBitmap(active_entry->GetFavicon().bitmap, false, // TODO: Add all variants once the history service supports it.
&image_data); gfx::PNGCodec::EncodeBGRASkBitmap(active_entry->GetFavicon().AsBitmap(),
false, &image_data);
favicon_service->SetFavicon(active_entry->GetURL(), favicon_service->SetFavicon(active_entry->GetURL(),
active_entry->GetFavicon().url, active_entry->GetFavicon().url,
image_data, image_data,
......
...@@ -142,7 +142,7 @@ bool BackForwardMenuModel::GetIconAt(int index, gfx::ImageSkia* icon) { ...@@ -142,7 +142,7 @@ bool BackForwardMenuModel::GetIconAt(int index, gfx::ImageSkia* icon) {
IDR_HISTORY_FAVICON); IDR_HISTORY_FAVICON);
} else { } else {
NavigationEntry* entry = GetNavigationEntry(index); NavigationEntry* entry = GetNavigationEntry(index);
*icon = entry->GetFavicon().bitmap; *icon = *entry->GetFavicon().image.ToImageSkia();
if (!entry->GetFavicon().valid && menu_model_delegate()) { if (!entry->GetFavicon().valid && menu_model_delegate()) {
FetchFavicon(entry); FetchFavicon(entry);
} }
...@@ -285,7 +285,9 @@ void BackForwardMenuModel::OnFavIconDataAvailable( ...@@ -285,7 +285,9 @@ void BackForwardMenuModel::OnFavIconDataAvailable(
entry->GetFavicon().url = favicon.icon_url; entry->GetFavicon().url = favicon.icon_url;
if (fav_icon.empty()) if (fav_icon.empty())
return; 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()) { if (menu_model_delegate()) {
menu_model_delegate()->OnIconChanged(model_index); 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 // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -10,7 +10,11 @@ ...@@ -10,7 +10,11 @@
namespace content { namespace content {
FaviconStatus::FaviconStatus() : valid(false) { 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 } // namespace content
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "googleurl/src/gurl.h" #include "googleurl/src/gurl.h"
#include "ui/gfx/image/image.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
namespace content { namespace content {
...@@ -15,6 +16,9 @@ namespace content { ...@@ -15,6 +16,9 @@ namespace content {
struct CONTENT_EXPORT FaviconStatus { struct CONTENT_EXPORT FaviconStatus {
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 // Indicates whether we've gotten an official favicon for the page, or are
// just using the default favicon. // just using the default favicon.
bool valid; bool valid;
...@@ -26,7 +30,7 @@ struct CONTENT_EXPORT FaviconStatus { ...@@ -26,7 +30,7 @@ struct CONTENT_EXPORT FaviconStatus {
// set or it empty, it will return the default favicon. Note that this is // 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 // loaded asynchronously, so even if the favicon URL is valid we may return
// the default favicon if we haven't gotten the data yet. // 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. // 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