OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * The global object. | 6 * The global object. |
7 * @type {!Object} | 7 * @type {!Object} |
8 * @const | 8 * @const |
9 */ | 9 */ |
10 var global = this; | 10 var global = this; |
(...skipping 20 matching lines...) Expand all Loading... | |
31 // restore | 31 // restore |
32 global[callbackName] = old; | 32 global[callbackName] = old; |
33 | 33 |
34 var args = Array.prototype.slice.call(arguments); | 34 var args = Array.prototype.slice.call(arguments); |
35 return callback.apply(global, args); | 35 return callback.apply(global, args); |
36 }; | 36 }; |
37 chrome.send(name, params); | 37 chrome.send(name, params); |
38 } | 38 } |
39 | 39 |
40 /** | 40 /** |
41 * Returns the scale factors supported by this platform. | |
42 * @return {array} The supported scale factors. | |
43 */ | |
44 function getSupportedScaleFactors() { | |
45 var supported_scale_factors = new Array(); | |
kevers
2013/01/04 20:21:10
Using C++ naming convention here and below. Shoul
pkotwicz
2013/01/04 21:21:39
Done.
Dan Beam
2013/01/04 21:34:28
This is not just style, [] always invokes the buil
| |
46 if (cr.isMac || cr.isChromeOS) { | |
47 supported_scale_factors.push(1); | |
48 supported_scale_factors.push(2); | |
49 } else { | |
50 // Windows must be restarted to display at a different scale factor. | |
51 supported_scale_factors.push(window.devicePixelRatio); | |
52 } | |
53 return supported_scale_factors; | |
54 } | |
55 | |
56 /** | |
41 * Generates a CSS url string. | 57 * Generates a CSS url string. |
42 * @param {string} s The URL to generate the CSS url for. | 58 * @param {string} s The URL to generate the CSS url for. |
43 * @return {string} The CSS url string. | 59 * @return {string} The CSS url string. |
44 */ | 60 */ |
45 function url(s) { | 61 function url(s) { |
46 // http://www.w3.org/TR/css3-values/#uris | 62 // http://www.w3.org/TR/css3-values/#uris |
47 // Parentheses, commas, whitespace characters, single quotes (') and double | 63 // Parentheses, commas, whitespace characters, single quotes (') and double |
48 // quotes (") appearing in a URI must be escaped with a backslash | 64 // quotes (") appearing in a URI must be escaped with a backslash |
49 var s2 = s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g, '\\$1'); | 65 var s2 = s.replace(/(\(|\)|\,|\s|\'|\"|\\)/g, '\\$1'); |
50 // WebKit has a bug when it comes to URLs that end with \ | 66 // WebKit has a bug when it comes to URLs that end with \ |
51 // https://bugs.webkit.org/show_bug.cgi?id=28885 | 67 // https://bugs.webkit.org/show_bug.cgi?id=28885 |
52 if (/\\\\$/.test(s2)) { | 68 if (/\\\\$/.test(s2)) { |
53 // Add a space to work around the WebKit bug. | 69 // Add a space to work around the WebKit bug. |
54 s2 += ' '; | 70 s2 += ' '; |
55 } | 71 } |
56 return 'url("' + s2 + '")'; | 72 return 'url("' + s2 + '")'; |
57 } | 73 } |
58 | 74 |
59 /** | 75 /** |
76 * Generates a CSS -webkit-image-set for a chrome:// url. | |
77 * An entry in the image set is added for each of getSupportedScaleFactors(). | |
78 * The scale-factor-specific url is generated by replacing the first instance of | |
79 * 'scalefactor' in |path| with the numeric scale factor. | |
80 * @param {string} path The URL to generate an image set for. | |
81 * 'scalefactor' should be a substring of |path|. | |
82 * @return {string} The CSS -webkit-image-set. | |
83 */ | |
84 function imageset(path) { | |
85 var supported_scale_factors = getSupportedScaleFactors(); | |
86 | |
87 var replace_start_index = path.indexOf('scalefactor'); | |
88 if (replace_start_index < 0) | |
89 return; | |
90 | |
91 var s = ''; | |
92 for (var i = 0; i < supported_scale_factors.length; ++i) { | |
93 var scale_factor = supported_scale_factors[i]; | |
94 var path_with_scale_factor = | |
95 path.substr(0, replace_start_index) + scale_factor + | |
96 path.substr(replace_start_index + 11); | |
97 | |
98 s += url(path_with_scale_factor) + ' ' + scale_factor + 'x'; | |
99 | |
100 if (i != supported_scale_factors.length - 1) | |
101 s += ', '; | |
102 } | |
103 return '-webkit-image-set(' + s + ')'; | |
104 } | |
105 | |
106 /** | |
60 * Parses query parameters from Location. | 107 * Parses query parameters from Location. |
61 * @param {string} location The URL to generate the CSS url for. | 108 * @param {string} location The URL to generate the CSS url for. |
62 * @return {object} Dictionary containing name value pairs for URL | 109 * @return {object} Dictionary containing name value pairs for URL |
63 */ | 110 */ |
64 function parseQueryParams(location) { | 111 function parseQueryParams(location) { |
65 var params = {}; | 112 var params = {}; |
66 var query = unescape(location.search.substring(1)); | 113 var query = unescape(location.search.substring(1)); |
67 var vars = query.split('&'); | 114 var vars = query.split('&'); |
68 for (var i = 0; i < vars.length; i++) { | 115 for (var i = 0; i < vars.length; i++) { |
69 var pair = vars[i].split('='); | 116 var pair = vars[i].split('='); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 */ | 268 */ |
222 function appendParam(url, key, value) { | 269 function appendParam(url, key, value) { |
223 var param = encodeURIComponent(key) + '=' + encodeURIComponent(value); | 270 var param = encodeURIComponent(key) + '=' + encodeURIComponent(value); |
224 | 271 |
225 if (url.indexOf('?') == -1) | 272 if (url.indexOf('?') == -1) |
226 return url + '?' + param; | 273 return url + '?' + param; |
227 return url + '&' + param; | 274 return url + '&' + param; |
228 } | 275 } |
229 | 276 |
230 /** | 277 /** |
231 * Creates a new URL for a favicon request. | 278 * Creates a CSS -webkit-image-set for a favicon request. |
232 * @param {string} url The url for the favicon. | 279 * @param {string} url The url for the favicon. |
233 * @param {number=} opt_size Optional preferred size of the favicon. | 280 * @param {number=} opt_size Optional preferred size of the favicon. |
234 * @return {string} Updated URL for the favicon. | 281 * @param {boolean=} opt_sessionFavicon Optional flag to indicate if |
282 * requesting a session favicon. | |
283 * @return {string} -webkit-image-set for the favicon. | |
235 */ | 284 */ |
236 function getFaviconUrl(url, opt_size) { | 285 function getFaviconImageSet(url, opt_size, opt_sessionFavicon) { |
237 var size = opt_size || 16; | 286 var size = opt_size || 16; |
238 return 'chrome://favicon/size/' + size + '@' + | 287 var type = opt_sessionFavicon ? 'session-favicon' : 'favicon'; |
239 window.devicePixelRatio + 'x/' + url; | 288 return imageset( |
289 'chrome://' + type + '/size/' + size + '@scalefactorx/' + url); | |
240 } | 290 } |
241 | 291 |
242 /** | 292 /** |
293 * Creates a new URL for a request of the 1x favicon. | |
294 * @param {string} url The url for the favicon. | |
295 * @param {number=} opt_size Optional preferred size of the favicon. | |
296 * @param {boolean=} opt_sessionFavicon Optional flag to indicate if | |
297 * requesting a session favicon. | |
298 * @return {string} Updated URL for the favicon. | |
299 */ | |
300 function get1xFaviconUrl(url, opt_size, opt_sessionFavicon) { | |
301 var size = opt_size || 16; | |
302 var type = opt_sessionFavicon ? 'session-favicon' : 'favicon'; | |
303 return 'chrome://' + type + '/size/' + size + '@1x/' + url; | |
304 } | |
305 | |
306 /** | |
243 * Creates an element of a specified type with a specified class name. | 307 * Creates an element of a specified type with a specified class name. |
244 * @param {string} type The node type. | 308 * @param {string} type The node type. |
245 * @param {string} className The class name to use. | 309 * @param {string} className The class name to use. |
246 * @return {Element} The created element. | 310 * @return {Element} The created element. |
247 */ | 311 */ |
248 function createElementWithClassName(type, className) { | 312 function createElementWithClassName(type, className) { |
249 var elm = document.createElement(type); | 313 var elm = document.createElement(type); |
250 elm.className = className; | 314 elm.className = className; |
251 return elm; | 315 return elm; |
252 } | 316 } |
OLD | NEW |