summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-07 00:13:51 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-07 00:13:51 +0000
commit87b298932261138c0e3363cc3df43f651a8d50f7 (patch)
tree532f4a81a8386c070ddbd3cd01ea999b905c1664
parentddbe551cd57c18397b3260c61a6ff0e4e308f923 (diff)
downloadchromium_src-87b298932261138c0e3363cc3df43f651a8d50f7.zip
chromium_src-87b298932261138c0e3363cc3df43f651a8d50f7.tar.gz
chromium_src-87b298932261138c0e3363cc3df43f651a8d50f7.tar.bz2
Use hi-resolution favicon variants if available.
This changes the favicon IPC to return all favicon variants to the browser, and hands the to the new in-browser variant selection function. Note that favicons that come from the history database will still be lodpi. Reloading a site will force the favicon to be loaded from the network. (chrome:// favicons are always loaded through the favicon cache and hence are always lodpi) BUG=138550 TEST=Go to apple.com, amazon.com, github.com, notice hidpi favicon Review URL: https://chromiumcodereview.appspot.com/10828127 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150184 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/favicon/favicon_tab_helper.cc24
-rw-r--r--chrome/browser/favicon/favicon_tab_helper.h3
-rw-r--r--chrome/browser/ui/views/ash/balloon_view_ash.cc7
-rw-r--r--chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.cc32
-rw-r--r--chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.h3
-rw-r--r--chrome/browser/ui/views/ash/launcher/launcher_favicon_loader_browsertest.cc3
-rw-r--r--chrome/common/icon_messages.h17
-rw-r--r--chrome/renderer/chrome_render_view_observer.cc29
-rw-r--r--chrome/renderer/chrome_render_view_observer.h13
-rw-r--r--webkit/glue/webkit_glue.gypi2
10 files changed, 84 insertions, 49 deletions
diff --git a/chrome/browser/favicon/favicon_tab_helper.cc b/chrome/browser/favicon/favicon_tab_helper.cc
index a0e833a..6495272 100644
--- a/chrome/browser/favicon/favicon_tab_helper.cc
+++ b/chrome/browser/favicon/favicon_tab_helper.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/favicon/favicon_handler.h"
#include "chrome/browser/favicon/favicon_util.h"
+#include "chrome/browser/favicon/select_favicon_frames.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
@@ -24,6 +25,8 @@
#include "content/public/browser/web_ui.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image.h"
+#include "ui/gfx/image/image_skia.h"
+#include "ui/gfx/image/image_skia_rep.h"
using content::FaviconStatus;
using content::NavigationController;
@@ -186,11 +189,22 @@ bool FaviconTabHelper::OnMessageReceived(const IPC::Message& message) {
return message_handled;
}
-void FaviconTabHelper::OnDidDownloadFavicon(int id,
- const GURL& image_url,
- bool errored,
- const SkBitmap& image) {
- gfx::Image favicon(image);
+void FaviconTabHelper::OnDidDownloadFavicon(
+ int id,
+ const GURL& image_url,
+ bool errored,
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps) {
+ // TODO: Possibly do bitmap selection in FaviconHandler, so that it can score
+ // favicons better.
+ std::vector<ui::ScaleFactor> scale_factors;
+#if defined(OS_MACOSX)
+ scale_factors = ui::GetSupportedScaleFactors();
+#else
+ scale_factors.push_back(ui::SCALE_FACTOR_100P); // TODO: Aura?
+#endif
+ gfx::Image favicon(
+ SelectFaviconFrames(bitmaps, scale_factors, requested_size));
favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon);
if (touch_icon_handler_.get())
touch_icon_handler_->OnDidDownloadFavicon(id, image_url, errored, favicon);
diff --git a/chrome/browser/favicon/favicon_tab_helper.h b/chrome/browser/favicon/favicon_tab_helper.h
index 867b476..4c9ee94 100644
--- a/chrome/browser/favicon/favicon_tab_helper.h
+++ b/chrome/browser/favicon/favicon_tab_helper.h
@@ -94,7 +94,8 @@ class FaviconTabHelper : public content::WebContentsObserver,
void OnDidDownloadFavicon(int id,
const GURL& image_url,
bool errored,
- const SkBitmap& image);
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps);
Profile* profile_;
diff --git a/chrome/browser/ui/views/ash/balloon_view_ash.cc b/chrome/browser/ui/views/ash/balloon_view_ash.cc
index 0975e9c..a578e12 100644
--- a/chrome/browser/ui/views/ash/balloon_view_ash.cc
+++ b/chrome/browser/ui/views/ash/balloon_view_ash.cc
@@ -65,11 +65,12 @@ class BalloonViewAsh::IconFetcher : public content::WebContentsObserver {
void OnDidDownloadFavicon(int id,
const GURL& image_url,
bool errored,
- const SkBitmap& bitmap) {
- if (image_url != icon_url_ || id != request_id_)
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps) {
+ if (image_url != icon_url_ || id != request_id_ || bitmaps.empty())
return;
GetWebNotificationTray()->SetNotificationImage(
- notification_id_, gfx::ImageSkia(bitmap));
+ notification_id_, gfx::ImageSkia(bitmaps[0]));
}
private:
diff --git a/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.cc b/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.cc
index 33a08df..6c106ff 100644
--- a/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.cc
+++ b/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.cc
@@ -43,7 +43,8 @@ class FaviconBitmapHandler {
void OnDidDownloadFavicon(int id,
const GURL& image_url,
bool errored,
- const SkBitmap& bitmap);
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps);
private:
void DownloadFavicon(const GURL& image_url);
@@ -112,10 +113,13 @@ void FaviconBitmapHandler::DownloadFavicon(const GURL& image_url) {
FaviconUtil::DownloadFavicon(host, image_url, image_size);
}
-void FaviconBitmapHandler::OnDidDownloadFavicon(int id,
- const GURL& image_url,
- bool errored,
- const SkBitmap& bitmap) {
+
+void FaviconBitmapHandler::OnDidDownloadFavicon(
+ int id,
+ const GURL& image_url,
+ bool errored,
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps) {
UrlSet::iterator iter = pending_requests_.find(image_url);
if (iter == pending_requests_.end()) {
// Updates are received for all downloads; ignore unrequested urls.
@@ -123,8 +127,9 @@ void FaviconBitmapHandler::OnDidDownloadFavicon(int id,
}
pending_requests_.erase(iter);
- if (!errored)
- AddFavicon(image_url, bitmap);
+ // Favicon bitmaps are ordered by decreasing width.
+ if (!errored && !bitmaps.empty())
+ AddFavicon(image_url, bitmaps[0]);
}
void FaviconBitmapHandler::AddFavicon(const GURL& image_url,
@@ -179,9 +184,12 @@ void LauncherFaviconLoader::OnUpdateFaviconURL(
favicon_handler_->OnUpdateFaviconURL(page_id, candidates);
}
-void LauncherFaviconLoader::OnDidDownloadFavicon(int id,
- const GURL& image_url,
- bool errored,
- const SkBitmap& bitmap) {
- favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, bitmap);
+void LauncherFaviconLoader::OnDidDownloadFavicon(
+ int id,
+ const GURL& image_url,
+ bool errored,
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps) {
+ favicon_handler_->OnDidDownloadFavicon(
+ id, image_url, errored, requested_size, bitmaps);
}
diff --git a/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.h b/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.h
index 4dc4df8..87b8ed2 100644
--- a/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.h
+++ b/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.h
@@ -55,7 +55,8 @@ class LauncherFaviconLoader : public content::WebContentsObserver {
void OnDidDownloadFavicon(int id,
const GURL& image_url,
bool errored,
- const SkBitmap& bitmap);
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps);
scoped_ptr<internal::FaviconBitmapHandler> favicon_handler_;
diff --git a/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader_browsertest.cc b/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader_browsertest.cc
index d956b9f..7da6873 100644
--- a/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader_browsertest.cc
+++ b/chrome/browser/ui/views/ash/launcher/launcher_favicon_loader_browsertest.cc
@@ -60,7 +60,8 @@ class ContentsObserver : public content::WebContentsObserver {
void OnDidDownloadFavicon(int id,
const GURL& image_url,
bool errored,
- const SkBitmap& bitmap) {
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps) {
++downloads_received_;
}
diff --git a/chrome/common/icon_messages.h b/chrome/common/icon_messages.h
index 5f04c94..26e8f14 100644
--- a/chrome/common/icon_messages.h
+++ b/chrome/common/icon_messages.h
@@ -1,4 +1,4 @@
-// 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.
@@ -22,14 +22,13 @@ IPC_STRUCT_TRAITS_END()
// Messages sent from the browser to the renderer.
-// Requests the renderer to download the specified favicon image encode it as
-// PNG and send the PNG data back ala IconHostMsg_DidDownloadFavicon.
+// Requests the renderer to download the specified favicon image, decode it,
+// and send the image data back via IconHostMsg_DidDownloadFavicon.
IPC_MESSAGE_ROUTED3(IconMsg_DownloadFavicon,
int /* identifier for the request */,
GURL /* URL of the image */,
- int /* Size of the image. Normally 0, but set if you have
- a preferred image size to request, such as when
- downloading the favicon */)
+ int /* Preferred favicon size. Passed on to
+ IconHostMsg_DidDownloadFavicon, unused otherwise */)
// Messages sent from the renderer to the browser.
@@ -38,8 +37,10 @@ IPC_MESSAGE_ROUTED2(IconHostMsg_UpdateFaviconURL,
int32 /* page_id */,
std::vector<FaviconURL> /* urls of the favicon */)
-IPC_MESSAGE_ROUTED4(IconHostMsg_DidDownloadFavicon,
+IPC_MESSAGE_ROUTED5(IconHostMsg_DidDownloadFavicon,
int /* Identifier of the request */,
GURL /* URL of the image */,
bool /* true if there was a network error */,
- SkBitmap /* image_data */)
+ int /* Preferred icon size passed to
+ IconMsg_DownloadFavicon */,
+ std::vector<SkBitmap> /* image_data */)
diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc
index 9d82096..1aca18d 100644
--- a/chrome/renderer/chrome_render_view_observer.cc
+++ b/chrome/renderer/chrome_render_view_observer.cc
@@ -51,7 +51,7 @@
#include "ui/gfx/size.h"
#include "ui/gfx/skbitmap_operations.h"
#include "webkit/glue/image_decoder.h"
-#include "webkit/glue/image_resource_fetcher.h"
+#include "webkit/glue/multi_resolution_image_resource_fetcher.h"
#include "webkit/glue/webkit_glue.h"
#include "v8/include/v8-testing.h"
@@ -71,7 +71,7 @@ using WebKit::WebURLRequest;
using WebKit::WebView;
using WebKit::WebVector;
using extensions::APIPermission;
-using webkit_glue::ImageResourceFetcher;
+using webkit_glue::MultiResolutionImageResourceFetcher;
// Delay in milliseconds that we'll wait before capturing the page contents
// and thumbnail.
@@ -332,15 +332,17 @@ void ChromeRenderViewObserver::OnDownloadFavicon(int id,
SkBitmap data_image = ImageFromDataUrl(image_url);
data_image_failed = data_image.empty();
if (!data_image_failed) {
+ std::vector<SkBitmap> images(1, data_image);
Send(new IconHostMsg_DidDownloadFavicon(
- routing_id(), id, image_url, false, data_image));
+ routing_id(), id, image_url, false, image_size, images));
}
}
if (data_image_failed ||
!DownloadFavicon(id, image_url, image_size)) {
Send(new IconHostMsg_DidDownloadFavicon(
- routing_id(), id, image_url, true, SkBitmap()));
+ routing_id(), id, image_url, true, image_size,
+ std::vector<SkBitmap>()));
}
}
@@ -1048,26 +1050,29 @@ bool ChromeRenderViewObserver::DownloadFavicon(int id,
if (!render_view()->GetWebView())
return false;
// Create an image resource fetcher and assign it with a call back object.
- image_fetchers_.push_back(linked_ptr<ImageResourceFetcher>(
- new ImageResourceFetcher(
- image_url, render_view()->GetWebView()->mainFrame(), id, image_size,
+ image_fetchers_.push_back(linked_ptr<MultiResolutionImageResourceFetcher>(
+ new MultiResolutionImageResourceFetcher(
+ image_url, render_view()->GetWebView()->mainFrame(), id,
WebURLRequest::TargetIsFavicon,
base::Bind(&ChromeRenderViewObserver::DidDownloadFavicon,
- base::Unretained(this)))));
+ base::Unretained(this), image_size))));
return true;
}
void ChromeRenderViewObserver::DidDownloadFavicon(
- ImageResourceFetcher* fetcher, const SkBitmap& image) {
+ int requested_size,
+ MultiResolutionImageResourceFetcher* fetcher,
+ const std::vector<SkBitmap>& images) {
// Notify requester of image download status.
Send(new IconHostMsg_DidDownloadFavicon(routing_id(),
fetcher->id(),
fetcher->image_url(),
- image.isNull(),
- image));
+ images.empty(),
+ requested_size,
+ images));
// Remove the image fetcher from our pending list. We're in the callback from
- // ImageResourceFetcher, best to delay deletion.
+ // MultiResolutionImageResourceFetcher, best to delay deletion.
ImageResourceFetcherList::iterator iter;
for (iter = image_fetchers_.begin(); iter != image_fetchers_.end(); ++iter) {
if (iter->get() == fetcher) {
diff --git a/chrome/renderer/chrome_render_view_observer.h b/chrome/renderer/chrome_render_view_observer.h
index 8691ad2..7d86ea6 100644
--- a/chrome/renderer/chrome_render_view_observer.h
+++ b/chrome/renderer/chrome_render_view_observer.h
@@ -35,7 +35,7 @@ class PhishingClassifierDelegate;
}
namespace webkit_glue {
-class ImageResourceFetcher;
+class MultiResolutionImageResourceFetcher;
}
// This class holds the Chrome specific parts of RenderView, and has the same
@@ -167,8 +167,10 @@ class ChromeRenderViewObserver : public content::RenderViewObserver,
// This callback is triggered when DownloadFavicon completes, either
// succesfully or with a failure. See DownloadFavicon for more
// details.
- void DidDownloadFavicon(webkit_glue::ImageResourceFetcher* fetcher,
- const SkBitmap& image);
+ void DidDownloadFavicon(
+ int requested_size,
+ webkit_glue::MultiResolutionImageResourceFetcher* fetcher,
+ const std::vector<SkBitmap>& images);
// Requests to download a favicon image. When done, the RenderView
// is notified by way of DidDownloadFavicon. Returns true if the
@@ -218,8 +220,9 @@ class ChromeRenderViewObserver : public content::RenderViewObserver,
// External host exposed through automation controller.
scoped_ptr<ExternalHostBindings> external_host_bindings_;
- typedef std::vector<linked_ptr<webkit_glue::ImageResourceFetcher> >
- ImageResourceFetcherList;
+ typedef std::vector<
+ linked_ptr<webkit_glue::MultiResolutionImageResourceFetcher> >
+ ImageResourceFetcherList;
// ImageResourceFetchers schedule via DownloadImage.
ImageResourceFetcherList image_fetchers_;
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index 06b14d7..dc388d9 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -364,9 +364,9 @@
'image_decoder.cc',
'image_decoder.h',
'image_resource_fetcher.cc',
+ 'image_resource_fetcher.h',
'multi_resolution_image_resource_fetcher.cc',
'multi_resolution_image_resource_fetcher.h',
- 'image_resource_fetcher.h',
'multipart_response_delegate.cc',
'multipart_response_delegate.h',
'network_list_observer.h',