Commit 72e59805 authored by kevers@chromium.org's avatar kevers@chromium.org

Add support for high DPI favicons on the "other devices" menu.

BUG=152731


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175154 0039d316-1c4b-4281-b951-d872f2087c98
parent 5d5ebea3
......@@ -212,7 +212,8 @@ cr.define('ntp', function() {
a.className = 'footer-menu-item';
a.textContent = tab.title;
a.href = tab.url;
a.style.backgroundImage = url('chrome://session-favicon/' + tab.url);
a.style.backgroundImage = url(
getFaviconUrl(tab.url, 16, /* session-favicon */ true));
var clickHandler = this.makeClickHandler_(
session.tag, String(window.sessionId), String(tab.sessionId));
......
......@@ -231,11 +231,14 @@ function appendParam(url, key, value) {
* Creates a new URL for a favicon request.
* @param {string} url The url for the favicon.
* @param {number=} opt_size Optional preferred size of the favicon.
* @param {boolean=} opt_sessionFavicon Optional flag to indicate if
* requesting a session favicon.
* @return {string} Updated URL for the favicon.
*/
function getFaviconUrl(url, opt_size) {
function getFaviconUrl(url, opt_size, opt_sessionFavicon) {
var size = opt_size || 16;
return 'chrome://favicon/size/' + size + '@' +
var type = opt_sessionFavicon ? 'session-favicon' : 'favicon';
return 'chrome://' + type + '/size/' + size + '@' +
window.devicePixelRatio + 'x/' + url;
}
......
......@@ -47,7 +47,10 @@ void FaviconSource::StartDataRequest(const std::string& path,
FaviconService* favicon_service =
FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
if (!favicon_service || path.empty()) {
SendDefaultResponse(IconRequest(request_id, 16, ui::SCALE_FACTOR_100P));
SendDefaultResponse(IconRequest(request_id,
"",
16,
ui::SCALE_FACTOR_100P));
return;
}
......@@ -73,7 +76,10 @@ void FaviconSource::StartDataRequest(const std::string& path,
scale_factor,
base::Bind(&FaviconSource::OnFaviconDataAvailable,
base::Unretained(this),
IconRequest(request_id, size_in_dip, scale_factor)),
IconRequest(request_id,
path.substr(prefix_length),
size_in_dip,
scale_factor)),
&cancelable_task_tracker_);
} else {
GURL url;
......@@ -131,7 +137,10 @@ void FaviconSource::StartDataRequest(const std::string& path,
scale_factor,
base::Bind(&FaviconSource::OnFaviconDataAvailable,
base::Unretained(this),
IconRequest(request_id, size_in_dip, scale_factor)),
IconRequest(request_id,
url.spec(),
size_in_dip,
scale_factor)),
&cancelable_task_tracker_);
}
}
......@@ -148,13 +157,19 @@ bool FaviconSource::ShouldReplaceExistingSource() const {
return false;
}
bool FaviconSource::HandleMissingResource(const IconRequest& request) {
// No additional checks to locate the favicon resource in the base
// implementation.
return false;
}
void FaviconSource::OnFaviconDataAvailable(
const IconRequest& request,
const history::FaviconBitmapResult& bitmap_result) {
if (bitmap_result.is_valid()) {
// Forward the data along to the networking system.
SendResponse(request.request_id, bitmap_result.bitmap_data);
} else {
} else if (!HandleMissingResource(request)) {
SendDefaultResponse(request);
}
}
......
......@@ -48,35 +48,47 @@ class FaviconSource : public ChromeURLDataManager::DataSource {
virtual bool ShouldReplaceExistingSource() const OVERRIDE;
protected:
virtual ~FaviconSource();
Profile* profile_;
private:
// Defines the allowed pixel sizes for requested favicons.
enum IconSize {
SIZE_16,
SIZE_32,
SIZE_64,
NUM_SIZES
};
struct IconRequest {
IconRequest()
: request_id(0),
request_path(""),
size_in_dip(gfx::kFaviconSize),
scale_factor(ui::SCALE_FACTOR_NONE) {
}
IconRequest(int id, int size, ui::ScaleFactor scale)
IconRequest(int id,
const std::string& path,
int size,
ui::ScaleFactor scale)
: request_id(id),
request_path(path),
size_in_dip(size),
scale_factor(scale) {
}
int request_id;
std::string request_path;
int size_in_dip;
ui::ScaleFactor scale_factor;
};
virtual ~FaviconSource();
// Called when the favicon data is missing to perform additional checks to
// locate the resource.
// |request| contains information for the failed request.
// Returns true if the missing resource is found.
virtual bool HandleMissingResource(const IconRequest& request);
Profile* profile_;
private:
// Defines the allowed pixel sizes for requested favicons.
enum IconSize {
SIZE_16,
SIZE_32,
SIZE_64,
NUM_SIZES
};
void Init(Profile* profile, IconType type);
// Called when favicon data is available from the history backend.
......
......@@ -20,26 +20,6 @@ SessionFaviconSource::SessionFaviconSource(Profile* profile)
SessionFaviconSource::~SessionFaviconSource() {
}
void SessionFaviconSource::StartDataRequest(const std::string& path,
bool is_incognito,
int request_id) {
ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
SessionModelAssociator* associator = sync_service ?
sync_service->GetSessionModelAssociator() : NULL;
std::string favicon_data;
if (associator &&
associator->GetSyncedFaviconForPageURL(path, &favicon_data)) {
scoped_refptr<base::RefCountedString> response =
new base::RefCountedString();
response->data() = favicon_data;
SendResponse(request_id, response);
} else {
FaviconSource::StartDataRequest(path, is_incognito, request_id);
}
}
std::string SessionFaviconSource::GetMimeType(const std::string&) const {
return "image/png";
}
......@@ -55,3 +35,22 @@ bool SessionFaviconSource::AllowCaching() const {
// update in a timely manner.
return false;
}
bool SessionFaviconSource::HandleMissingResource(const IconRequest& request) {
ProfileSyncService* sync_service =
ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
SessionModelAssociator* associator = sync_service ?
sync_service->GetSessionModelAssociator() : NULL;
std::string favicon_data;
if (associator &&
associator->GetSyncedFaviconForPageURL(request.request_path,
&favicon_data)) {
scoped_refptr<base::RefCountedString> response =
new base::RefCountedString();
response->data() = favicon_data;
SendResponse(request.request_id, response);
return true;
}
return false;
}
......@@ -19,15 +19,13 @@ class SessionFaviconSource : public FaviconSource {
explicit SessionFaviconSource(Profile* profile);
// FaviconSource implementation.
virtual void StartDataRequest(const std::string& path,
bool is_incognito,
int request_id) OVERRIDE;
virtual std::string GetMimeType(const std::string&) const OVERRIDE;
virtual bool ShouldReplaceExistingSource() const OVERRIDE;
virtual bool AllowCaching() const OVERRIDE;
protected:
virtual ~SessionFaviconSource();
virtual bool HandleMissingResource(const IconRequest& request) OVERRIDE;
};
#endif // CHROME_BROWSER_UI_WEBUI_SESSION_FAVICON_SOURCE_H_
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