summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-05 18:53:18 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-05 18:53:18 +0000
commitabbd2f4b36da8c89e6f3002eb84f60064a6ff067 (patch)
tree4b48b0baf723ff20e57aa668a7b9307ebcfc9198
parent8ecb8f9598f0b3ee1117e14b5eb6cd020eda6b6a (diff)
downloadchromium_src-abbd2f4b36da8c89e6f3002eb84f60064a6ff067.zip
chromium_src-abbd2f4b36da8c89e6f3002eb84f60064a6ff067.tar.gz
chromium_src-abbd2f4b36da8c89e6f3002eb84f60064a6ff067.tar.bz2
ntp4: show larger favicons in most visited page
extend favicon source to provide larger icons. For now, larger means at most 32x32. Also, the only icon we actually support at this resolution is the default (globe). BUG=none TEST=manual Review URL: http://codereview.chromium.org/7300017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91517 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/favicon/favicon_service.h3
-rw-r--r--chrome/browser/resources/ntp4/most_visited_page.css4
-rw-r--r--chrome/browser/resources/ntp4/most_visited_page.js3
-rw-r--r--chrome/browser/ui/webui/favicon_source.cc42
-rw-r--r--chrome/browser/ui/webui/favicon_source.h7
-rw-r--r--chrome/browser/ui/webui/ntp/favicon_webui_handler.cc19
-rw-r--r--ui/resources/ui_resources.grd1
7 files changed, 60 insertions, 19 deletions
diff --git a/chrome/browser/favicon/favicon_service.h b/chrome/browser/favicon/favicon_service.h
index 1407eb8..5753085 100644
--- a/chrome/browser/favicon/favicon_service.h
+++ b/chrome/browser/favicon/favicon_service.h
@@ -46,7 +46,8 @@ class FaviconService : public CancelableRequestProvider,
typedef CancelableRequest<FaviconDataCallback> GetFaviconRequest;
// Requests the |icon_type| of favicon. |consumer| is notified when the bits
- // have been fetched.
+ // have been fetched. |icon_url| is the URL of the icon itself, e.g.
+ // <http://www.google.com/favicon.ico>.
Handle GetFavicon(const GURL& icon_url,
history::IconType icon_type,
CancelableRequestConsumerBase* consumer,
diff --git a/chrome/browser/resources/ntp4/most_visited_page.css b/chrome/browser/resources/ntp4/most_visited_page.css
index f989f58..49f0af7 100644
--- a/chrome/browser/resources/ntp4/most_visited_page.css
+++ b/chrome/browser/resources/ntp4/most_visited_page.css
@@ -136,11 +136,11 @@
.most-visited .favicon {
background: no-repeat 5px 50%;
- background-size: 16px;
+ background-size: 32px;
bottom: 7px;
box-sizing: border-box;
display: block;
- height: 16px;
+ height: 32px;
position: absolute;
width: 100%;
}
diff --git a/chrome/browser/resources/ntp4/most_visited_page.js b/chrome/browser/resources/ntp4/most_visited_page.js
index b30bb63..89495ef 100644
--- a/chrome/browser/resources/ntp4/most_visited_page.js
+++ b/chrome/browser/resources/ntp4/most_visited_page.js
@@ -89,7 +89,8 @@ cr.define('ntp4', function() {
this.classList.remove('filler');
var faviconDiv = this.querySelector('.favicon');
- var faviconUrl = data.faviconUrl || 'chrome://favicon/' + data.url;
+ var faviconUrl = data.faviconUrl ||
+ 'chrome://favicon/size/32/' + data.url;
faviconDiv.style.backgroundImage = url(faviconUrl);
faviconDiv.dir = data.direction;
if (data.faviconDominantColor)
diff --git a/chrome/browser/ui/webui/favicon_source.cc b/chrome/browser/ui/webui/favicon_source.cc
index e2aa160..7b66fb7 100644
--- a/chrome/browser/ui/webui/favicon_source.cc
+++ b/chrome/browser/ui/webui/favicon_source.cc
@@ -29,12 +29,12 @@ void FaviconSource::StartDataRequest(const std::string& path,
FaviconService* favicon_service =
profile_->GetFaviconService(Profile::EXPLICIT_ACCESS);
if (favicon_service) {
- FaviconService::Handle handle;
if (path.empty()) {
SendDefaultResponse(request_id);
return;
}
+ FaviconService::Handle handle;
if (path.size() > 8 && path.substr(0, 8) == "iconurl/") {
// TODO : Change GetFavicon to support combination of IconType.
handle = favicon_service->GetFavicon(
@@ -43,8 +43,24 @@ void FaviconSource::StartDataRequest(const std::string& path,
&cancelable_consumer_,
NewCallback(this, &FaviconSource::OnFaviconDataAvailable));
} else {
+ GURL url;
+
+ if (path.size() > 5 && path.substr(0, 5) == "size/") {
+ size_t slash = path.find("/", 5);
+ std::string size = path.substr(5, slash - 5);
+ int pixel_size = atoi(size.c_str());
+ CHECK(pixel_size == 32 || pixel_size == 16) <<
+ "only 32x32 and 16x16 icons are supported";
+ request_size_map_[request_id] = pixel_size;
+ url = GURL(path.substr(slash + 1));
+ } else {
+ request_size_map_[request_id] = 16;
+ url = GURL(path);
+ }
+
+ // TODO(estade): fetch the requested size.
handle = favicon_service->GetFaviconForURL(
- GURL(path),
+ url,
icon_types_,
&cancelable_consumer_,
NewCallback(this, &FaviconSource::OnFaviconDataAvailable));
@@ -85,11 +101,23 @@ void FaviconSource::OnFaviconDataAvailable(
}
void FaviconSource::SendDefaultResponse(int request_id) {
- if (!default_favicon_.get()) {
- default_favicon_ =
- ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
- IDR_DEFAULT_FAVICON);
+ RefCountedMemory* bytes = NULL;
+ if (request_size_map_[request_id] == 32) {
+ if (!default_favicon_large_.get()) {
+ default_favicon_large_ =
+ ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
+ IDR_DEFAULT_LARGE_FAVICON);
+ }
+ bytes = default_favicon_large_;
+ } else {
+ if (!default_favicon_.get()) {
+ default_favicon_ =
+ ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
+ IDR_DEFAULT_FAVICON);
+ }
+ bytes = default_favicon_;
}
+ request_size_map_.erase(request_id);
- SendResponse(request_id, default_favicon_);
+ SendResponse(request_id, bytes);
}
diff --git a/chrome/browser/ui/webui/favicon_source.h b/chrome/browser/ui/webui/favicon_source.h
index 413e3d9..1692d96 100644
--- a/chrome/browser/ui/webui/favicon_source.h
+++ b/chrome/browser/ui/webui/favicon_source.h
@@ -54,9 +54,16 @@ class FaviconSource : public ChromeURLDataManager::DataSource {
Profile* profile_;
CancelableRequestConsumerT<int, 0> cancelable_consumer_;
+ // Map from request ID to size requested (in pixels). TODO(estade): Get rid of
+ // this map when we properly support multiple favicon sizes.
+ std::map<int, int> request_size_map_;
+
// Raw PNG representation of the favicon to show when the favicon
// database doesn't have a favicon for a webpage.
+ // 16x16
scoped_refptr<RefCountedMemory> default_favicon_;
+ // 32x32
+ scoped_refptr<RefCountedMemory> default_favicon_large_;
// The history::IconTypes of icon that this FaviconSource handles.
const int icon_types_;
diff --git a/chrome/browser/ui/webui/ntp/favicon_webui_handler.cc b/chrome/browser/ui/webui/ntp/favicon_webui_handler.cc
index fc4f8e2..72466c4 100644
--- a/chrome/browser/ui/webui/ntp/favicon_webui_handler.cc
+++ b/chrome/browser/ui/webui/ntp/favicon_webui_handler.cc
@@ -28,9 +28,9 @@ void FaviconWebUIHandler::RegisterMessages() {
void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) {
std::string path;
CHECK(args->GetString(0, &path));
- DCHECK(StartsWithASCII(path, "chrome://favicon/", false)) << "path is "
- << path;
- path = path.substr(arraysize("chrome://favicon/") - 1);
+ DCHECK(StartsWithASCII(path, "chrome://favicon/size/32/", false)) <<
+ "path is " << path;
+ path = path.substr(arraysize("chrome://favicon/size/32/") - 1);
double id;
CHECK(args->GetDouble(1, &id));
@@ -54,11 +54,11 @@ void FaviconWebUIHandler::OnFaviconDataAvailable(
FaviconService* favicon_service =
web_ui_->GetProfile()->GetFaviconService(Profile::EXPLICIT_ACCESS);
int id = consumer_.GetClientData(favicon_service, request_handle);
+ FundamentalValue id_value(id);
+ scoped_ptr<StringValue> color_value;
if (favicon.is_valid()) {
// TODO(estade): cache the response
- FundamentalValue id_value(id);
-
color_utils::GridSampler sampler;
SkColor color =
color_utils::CalculateKMeanColorOfPNG(favicon.image_data, 100, 665,
@@ -67,8 +67,11 @@ void FaviconWebUIHandler::OnFaviconDataAvailable(
SkColorGetR(color),
SkColorGetG(color),
SkColorGetB(color));
- StringValue color_value(css_color);
- web_ui_->CallJavascriptFunction("ntp4.setFaviconDominantColor",
- id_value, color_value);
+ color_value.reset(new StringValue(css_color));
+ } else {
+ color_value.reset(new StringValue("#919191"));
}
+
+ web_ui_->CallJavascriptFunction("ntp4.setFaviconDominantColor",
+ id_value, *color_value);
}
diff --git a/ui/resources/ui_resources.grd b/ui/resources/ui_resources.grd
index 1c3e60a..15dfaac 100644
--- a/ui/resources/ui_resources.grd
+++ b/ui/resources/ui_resources.grd
@@ -30,6 +30,7 @@
<include name="IDR_CONTENT_RIGHT_SIDE" file="content_right_side.png" type="BINDATA" />
<if expr="not pp_ifdef('touchui')">
<include name="IDR_DEFAULT_FAVICON" file="default_favicon.png" type="BINDATA" />
+ <include name="IDR_DEFAULT_LARGE_FAVICON" file="default_large_favicon.png" type="BINDATA" />
</if>
<if expr="pp_ifdef('touchui')">
<include name="IDR_DEFAULT_FAVICON" file="default_large_favicon.png" type="BINDATA" />