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

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

Issue 1919183005: Cleanup: Extract icon related methods outside of util.js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename favicon.html to icon.html Created 4 years, 7 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/util.js
diff --git a/ui/webui/resources/js/util.js b/ui/webui/resources/js/util.js
index 5dcfc92631907c66512689dc514788857a7a4fb7..048a674ed1980061b6cb9802866a25fefdd75a55 100644
--- a/ui/webui/resources/js/util.js
+++ b/ui/webui/resources/js/util.js
@@ -46,30 +46,6 @@ function announceAccessibleMessage(msg) {
}
/**
- * Returns the scale factors supported by this platform for webui
- * resources.
- * @return {Array} The supported scale factors.
- */
-function getSupportedScaleFactors() {
- var supportedScaleFactors = [];
- if (cr.isMac || cr.isChromeOS || cr.isWindows || cr.isLinux) {
- // All desktop platforms support zooming which also updates the
- // renderer's device scale factors (a.k.a devicePixelRatio), and
- // these platforms has high DPI assets for 2.0x. Use 1x and 2x in
- // image-set on these platforms so that the renderer can pick the
- // closest image for the current device scale factor.
- supportedScaleFactors.push(1);
- supportedScaleFactors.push(2);
- } else {
- // For other platforms that use fixed device scale factor, use
- // the window's device pixel ratio.
- // TODO(oshima): Investigate if Android/iOS need to use image-set.
- supportedScaleFactors.push(window.devicePixelRatio);
- }
- return supportedScaleFactors;
-}
-
-/**
* Generates a CSS url string.
* @param {string} s The URL to generate the CSS url for.
* @return {string} The CSS url string.
@@ -89,51 +65,6 @@ function url(s) {
}
/**
- * 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) {
- var supportedScaleFactors = getSupportedScaleFactors();
-
- var replaceStartIndex = path.indexOf('scalefactor');
- if (replaceStartIndex < 0)
- return url(path);
-
- var s = '';
- for (var i = 0; i < supportedScaleFactors.length; ++i) {
- var scaleFactor = supportedScaleFactors[i];
- var pathWithScaleFactor = path.substr(0, replaceStartIndex) + scaleFactor +
- path.substr(replaceStartIndex + 'scalefactor'.length);
-
- s += url(pathWithScaleFactor) + ' ' + scaleFactor + 'x';
-
- if (i != supportedScaleFactors.length - 1)
- s += ', ';
- }
- return '-webkit-image-set(' + s + ')';
-}
-
-/**
* Parses query parameters from Location.
* @param {Location} location The URL to generate the CSS url for.
* @return {Object} Dictionary containing name value pairs for URL
@@ -325,34 +256,6 @@ function appendParam(url, key, value) {
}
/**
- * A regular expression for identifying favicon URLs.
- * @const {!RegExp}
- * TODO(dpapad): Move all favicon related methods to a new favicon_util.js file
- * and make this RegExp private.
- */
-var FAVICON_URL_REGEX = /\.ico$/i;
-
-/**
- * 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.
- * @param {string=} opt_type Optional type of favicon to request. Valid values
- * are 'favicon' and 'touch-icon'. Default is 'favicon'.
- * @return {string} -webkit-image-set for the favicon.
- */
-function getFaviconImageSet(url, opt_size, opt_type) {
- var size = opt_size || 16;
- var type = opt_type || 'favicon';
-
- return imageset(
- 'chrome://' + type + '/size/' + size + '@scalefactorx/' +
- // Note: Literal 'iconurl' must match |kIconURLParameter| in
- // components/favicon_base/favicon_url_parser.cc.
- (FAVICON_URL_REGEX.test(url) ? 'iconurl/' : '') + url);
-}
-
-/**
* Creates an element of a specified type with a specified class name.
* @param {string} type The node type.
* @param {string} className The class name to use.

Powered by Google App Engine
This is Rietveld 408576698