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

Unified Diff: chrome/browser/ui/webui/favicon_source.cc

Issue 10909236: Add support for favicon scale factor in WebUI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix HandleGetFaviconDominantColor. Created 8 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 | « chrome/browser/ui/webui/favicon_source.h ('k') | chrome/browser/ui/webui/ntp/favicon_webui_handler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/favicon_source.cc
diff --git a/chrome/browser/ui/webui/favicon_source.cc b/chrome/browser/ui/webui/favicon_source.cc
index 5016affcf605ce35d98d072ede4d3de4926878b7..750e3874a9c7f25dec16578df42455cc7fd6fe5a 100644
--- a/chrome/browser/ui/webui/favicon_source.cc
+++ b/chrome/browser/ui/webui/favicon_source.cc
@@ -9,6 +9,7 @@
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/webui/web_ui_util.h"
#include "chrome/common/url_constants.h"
#include "grit/locale_settings.h"
#include "grit/ui_resources.h"
@@ -47,31 +48,48 @@ void FaviconSource::StartDataRequest(const std::string& path,
FaviconService* favicon_service =
FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
if (!favicon_service || path.empty()) {
- SendDefaultResponse(request_id);
+ SendDefaultResponse(IconRequest(request_id, 16, ui::SCALE_FACTOR_NONE));
return;
}
+ int pixel_size = gfx::kFaviconSize;
+ ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE;
+
FaviconService::Handle handle;
- if (path.size() > 8 && path.substr(0, 8) == "iconurl/") {
+ if (path.size() > 8 &&
+ (path.substr(0, 8) == "iconurl/" || path.substr(0, 8) == "iconurl@")) {
+ size_t prefix_length = 8;
+ // Optional scale factor appended to iconurl, which may be @1x or @2x.
+ if (path.at(7) == '@') {
+ size_t slash = path.find("/");
+ std::string scale_str = path.substr(8, slash - 8);
+ web_ui_util::ParseScaleFactor(scale_str, &scale_factor);
+ prefix_length = slash + 1;
+ }
// TODO : Change GetFavicon to support combination of IconType.
handle = favicon_service->GetRawFavicon(
- GURL(path.substr(8)),
+ GURL(path.substr(prefix_length)),
history::FAVICON,
- gfx::kFaviconSize,
- ui::SCALE_FACTOR_100P,
+ pixel_size,
+ scale_factor,
&cancelable_consumer_,
base::Bind(&FaviconSource::OnFaviconDataAvailable,
base::Unretained(this)));
} else {
GURL url;
-
if (path.size() > 5 && path.substr(0, 5) == "size/") {
size_t slash = path.find("/", 5);
+ size_t scale_delimiter = path.find("@", 5);
std::string size = path.substr(5, slash - 5);
- int pixel_size = atoi(size.c_str());
+ 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;
+ // Optional scale factor.
+ if (scale_delimiter != std::string::npos && scale_delimiter < slash) {
+ std::string scale_str = path.substr(scale_delimiter + 1,
+ slash - scale_delimiter - 1);
+ web_ui_util::ParseScaleFactor(scale_str, &scale_factor);
+ }
url = GURL(path.substr(slash + 1));
} else {
// URL requests prefixed with "origin/" are converted to a form with an
@@ -90,38 +108,38 @@ void FaviconSource::StartDataRequest(const std::string& path,
} else {
url = GURL(path);
}
-
- request_size_map_[request_id] = 16;
}
// Intercept requests for prepopulated pages.
for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) {
if (url.spec() ==
l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) {
- request_size_map_.erase(request_id);
SendResponse(request_id,
ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
history::kPrepopulatedPages[i].favicon_id,
- ui::SCALE_FACTOR_100P));
+ scale_factor));
return;
}
}
- // TODO(estade): fetch the requested size.
handle = favicon_service->GetRawFaviconForURL(
FaviconService::FaviconForURLParams(
profile_,
url,
icon_types_,
- gfx::kFaviconSize,
+ pixel_size,
&cancelable_consumer_),
- ui::SCALE_FACTOR_100P,
+ scale_factor,
base::Bind(&FaviconSource::OnFaviconDataAvailable,
base::Unretained(this)));
}
// Attach the ChromeURLDataManager request ID to the history request.
- cancelable_consumer_.SetClientData(favicon_service, handle, request_id);
+ cancelable_consumer_.SetClientData(favicon_service,
+ handle,
+ IconRequest(request_id,
+ pixel_size,
+ scale_factor));
}
std::string FaviconSource::GetMimeType(const std::string&) const {
@@ -141,35 +159,36 @@ void FaviconSource::OnFaviconDataAvailable(
const history::FaviconBitmapResult& bitmap_result) {
FaviconService* favicon_service =
FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
- int request_id = cancelable_consumer_.GetClientData(favicon_service,
- request_handle);
+ const IconRequest& request =
+ cancelable_consumer_.GetClientData(favicon_service,
+ request_handle);
if (bitmap_result.is_valid()) {
// Forward the data along to the networking system.
- SendResponse(request_id, bitmap_result.bitmap_data);
+ SendResponse(request.request_id, bitmap_result.bitmap_data);
} else {
- SendDefaultResponse(request_id);
+ SendDefaultResponse(request);
}
}
-void FaviconSource::SendDefaultResponse(int request_id) {
+void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) {
base::RefCountedMemory* bytes = NULL;
- if (request_size_map_[request_id] == 32) {
+ ui::ScaleFactor scale_factor = icon_request.scale_factor;
+
+ if (icon_request.pixel_size == 32) {
if (!default_favicon_large_.get()) {
default_favicon_large_ =
ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
- IDR_DEFAULT_LARGE_FAVICON, ui::SCALE_FACTOR_100P);
+ IDR_DEFAULT_LARGE_FAVICON, scale_factor);
}
bytes = default_favicon_large_;
} else {
if (!default_favicon_.get()) {
default_favicon_ =
ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
- IDR_DEFAULT_FAVICON, ui::SCALE_FACTOR_100P);
+ IDR_DEFAULT_FAVICON, scale_factor);
}
bytes = default_favicon_;
}
- request_size_map_.erase(request_id);
-
- SendResponse(request_id, bytes);
+ SendResponse(icon_request.request_id, bytes);
}
« no previous file with comments | « chrome/browser/ui/webui/favicon_source.h ('k') | chrome/browser/ui/webui/ntp/favicon_webui_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698