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

Unified Diff: ui/webui/resources/js/icon.js

Issue 2280853002: Slightly nicer icon.js APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
Index: ui/webui/resources/js/icon.js
diff --git a/ui/webui/resources/js/icon.js b/ui/webui/resources/js/icon.js
index 122b707fd645e24959d1389717d980d281c23715..1c0c412924324f314238d7e6602a7a676cbd6872 100644
--- a/ui/webui/resources/js/icon.js
+++ b/ui/webui/resources/js/icon.js
@@ -27,30 +27,16 @@ cr.define('cr.icon', function() {
}
/**
- * Returns the URL of the image, or an image set of URLs for the profile
- * avatar. Default avatars have resources available for multiple scalefactors,
- * whereas the GAIA profile image only comes in one size.
- *
- * @param {string} path The path of the image.
- * @return {string} The url, or an image set of URLs of the avatar image.
- */
- function getProfileAvatarIcon(path) {
- var chromeThemePath = 'chrome://theme';
- var isDefaultAvatar =
- (path.slice(0, chromeThemePath.length) == chromeThemePath);
- return isDefaultAvatar ? imageset(path + '@scalefactorx'): url(path);
- }
-
- /**
* Generates a CSS -webkit-image-set for a chrome:// url.
* An entry in the image set is added for each of getSupportedScaleFactors().
* The scale-factor-specific url is generated by replacing the first instance
* of 'scalefactor' in |path| with the numeric scale factor.
+ *
* @param {string} path The URL to generate an image set for.
* 'scalefactor' should be a substring of |path|.
* @return {string} The CSS -webkit-image-set.
*/
- function imageset(path) {
+ function getImageSet(path) {
var supportedScaleFactors = getSupportedScaleFactors();
var replaceStartIndex = path.indexOf('scalefactor');
@@ -72,6 +58,20 @@ cr.define('cr.icon', function() {
}
/**
+ * Returns the URL of the image, or an image set of URLs for the provided
+ * path. Resources in chrome://theme have multiple supported scale factors.
michaelpg 2016/09/02 20:00:38 opt nit: single space after period for consistency
+ *
+ * @param {string} path The path of the image.
+ * @return {string} The url, or an image set of URLs.
+ */
+ function getImage(path) {
+ var chromeThemePath = 'chrome://theme';
+ var isChromeThemeUrl =
+ (path.slice(0, chromeThemePath.length) == chromeThemePath);
+ return isChromeThemeUrl ? getImageSet(path + '@scalefactorx') : url(path);
+ }
+
+ /**
* A regular expression for identifying favicon URLs.
* @const {!RegExp}
*/
@@ -79,6 +79,7 @@ cr.define('cr.icon', function() {
/**
* Creates a CSS -webkit-image-set for a favicon request.
+ *
* @param {string} url Either the URL of the original page or of the favicon
* itself.
* @param {number=} opt_size Optional preferred size of the favicon.
@@ -86,11 +87,11 @@ cr.define('cr.icon', function() {
* are 'favicon' and 'touch-icon'. Default is 'favicon'.
* @return {string} -webkit-image-set for the favicon.
*/
- function getFaviconImageSet(url, opt_size, opt_type) {
+ function getFavicon(url, opt_size, opt_type) {
var size = opt_size || 16;
var type = opt_type || 'favicon';
- return imageset(
+ return getImageSet(
'chrome://' + type + '/size/' + size + '@scalefactorx/' +
// Note: Literal 'iconurl' must match |kIconURLParameter| in
// components/favicon_base/favicon_url_parser.cc.
@@ -98,8 +99,7 @@ cr.define('cr.icon', function() {
}
return {
- getSupportedScaleFactors: getSupportedScaleFactors,
- getProfileAvatarIcon: getProfileAvatarIcon,
- getFaviconImageSet: getFaviconImageSet,
+ getImage: getImage,
+ getFavicon: getFavicon,
};
});

Powered by Google App Engine
This is Rietveld 408576698