Index: chrome/browser/resources/shared/js/util.js |
diff --git a/chrome/browser/resources/shared/js/util.js b/chrome/browser/resources/shared/js/util.js |
index 1377f40c4ff2a4f5bc90832f9e6182a6104189dd..917fa685bed641086a7888caf34e31b98cf6f520 100644 |
--- a/chrome/browser/resources/shared/js/util.js |
+++ b/chrome/browser/resources/shared/js/util.js |
@@ -38,6 +38,22 @@ function chromeSend(name, params, callbackName, callback) { |
} |
/** |
+ * Returns the scale factors supported by this platform. |
+ * @return {array} The supported scale factors. |
+ */ |
+function getSupportedScaleFactors() { |
+ var supportedScaleFactors = []; |
+ if (cr.isMac || cr.isChromeOS) { |
+ supportedScaleFactors.push(1); |
+ supportedScaleFactors.push(2); |
+ } else { |
+ // Windows must be restarted to display at a different scale factor. |
+ 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. |
@@ -57,6 +73,36 @@ function url(s) { |
} |
/** |
+ * 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 {string} location The URL to generate the CSS url for. |
* @return {object} Dictionary containing name value pairs for URL |
@@ -228,14 +274,34 @@ function appendParam(url, key, value) { |
} |
/** |
- * Creates a new URL for a favicon request. |
+ * Creates a CSS -webkit-image-set 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} -webkit-image-set for the favicon. |
+ */ |
+function getFaviconImageSet(url, opt_size, opt_sessionFavicon) { |
+ var size = opt_size || 16; |
+ var type = opt_sessionFavicon ? 'session-favicon' : 'favicon'; |
+ return imageset( |
+ 'chrome://' + type + '/size/' + size + '@scalefactorx/' + url); |
+} |
+ |
+/** |
+ * Creates a new URL for a favicon request for the current device pixel ratio. |
+ * The URL must be updated when the user moves the browser to a screen with a |
+ * different device pixel ratio. Use getFaviconImageSet() for the updating to |
+ * occur automatically. |
* @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, opt_sessionFavicon) { |
+function getFaviconUrlForCurrentDevicePixelRatio(url, |
+ opt_size, |
+ opt_sessionFavicon) { |
var size = opt_size || 16; |
var type = opt_sessionFavicon ? 'session-favicon' : 'favicon'; |
return 'chrome://' + type + '/size/' + size + '@' + |