Chromium Code Reviews| 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 // <include src="assert.js"> | 5 // <include src="assert.js"> |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Alias for document.getElementById. Found elements must be HTMLElements. | 8 * Alias for document.getElementById. Found elements must be HTMLElements. |
| 9 * @param {string} id The ID of the element to find. | 9 * @param {string} id The ID of the element to find. |
| 10 * @return {HTMLElement} The found element or null if not found. | 10 * @return {HTMLElement} The found element or null if not found. |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 */ | 318 */ |
| 319 function appendParam(url, key, value) { | 319 function appendParam(url, key, value) { |
| 320 var param = encodeURIComponent(key) + '=' + encodeURIComponent(value); | 320 var param = encodeURIComponent(key) + '=' + encodeURIComponent(value); |
| 321 | 321 |
| 322 if (url.indexOf('?') == -1) | 322 if (url.indexOf('?') == -1) |
| 323 return url + '?' + param; | 323 return url + '?' + param; |
| 324 return url + '&' + param; | 324 return url + '&' + param; |
| 325 } | 325 } |
| 326 | 326 |
| 327 /** | 327 /** |
| 328 * A regular expression for identifying favicon URLs. | |
| 329 * @const {!RegExp} | |
| 330 * TODO(dpapad): Move all favicon related methods to a new favicon_util.js file | |
| 331 * and make this RegExp private. | |
| 332 */ | |
| 333 var FAVICON_URL_REGEX = /\.ico$/; | |
|
Dan Beam
2016/04/27 02:18:31
nit: /i
dpapad
2016/04/27 17:21:47
Are you suggesting modifying the regex to /ico$/?
dpapad
2016/04/27 17:24:25
On second thought, you probably meant adding /i at
Dan Beam
2016/04/27 18:46:56
yes, that ^
| |
| 334 | |
| 335 /** | |
| 328 * Creates a CSS -webkit-image-set for a favicon request. | 336 * Creates a CSS -webkit-image-set for a favicon request. |
| 329 * @param {string} url The url for the favicon. | 337 * @param {string} url Either the URL of the original page or of the favicon |
| 338 * itself. | |
| 330 * @param {number=} opt_size Optional preferred size of the favicon. | 339 * @param {number=} opt_size Optional preferred size of the favicon. |
| 331 * @param {string=} opt_type Optional type of favicon to request. Valid values | 340 * @param {string=} opt_type Optional type of favicon to request. Valid values |
| 332 * are 'favicon' and 'touch-icon'. Default is 'favicon'. | 341 * are 'favicon' and 'touch-icon'. Default is 'favicon'. |
| 333 * @return {string} -webkit-image-set for the favicon. | 342 * @return {string} -webkit-image-set for the favicon. |
| 334 */ | 343 */ |
| 335 function getFaviconImageSet(url, opt_size, opt_type) { | 344 function getFaviconImageSet(url, opt_size, opt_type) { |
| 336 var size = opt_size || 16; | 345 var size = opt_size || 16; |
| 337 var type = opt_type || 'favicon'; | 346 var type = opt_type || 'favicon'; |
| 347 | |
| 348 // Note: Literals 'iconurl' and 'origin' must match |kIconURLParameter| and | |
| 349 // |kOriginParameter| in components/favicon_base/favicon_url_parser.cc. | |
| 350 var urlType = FAVICON_URL_REGEX.test(url) ? 'iconurl' : 'origin'; | |
| 351 | |
| 338 return imageset( | 352 return imageset( |
| 339 'chrome://' + type + '/size/' + size + '@scalefactorx/' + url); | 353 'chrome://' + type + '/size/' + size + '@scalefactorx/' + |
| 354 urlType + '/' + url); | |
| 340 } | 355 } |
| 341 | 356 |
| 342 /** | 357 /** |
| 343 * Creates a new URL for a favicon request for the current device pixel ratio. | 358 * Creates a new URL for a favicon request for the current device pixel ratio. |
| 344 * The URL must be updated when the user moves the browser to a screen with a | 359 * The URL must be updated when the user moves the browser to a screen with a |
| 345 * different device pixel ratio. Use getFaviconImageSet() for the updating to | 360 * different device pixel ratio. Use getFaviconImageSet() for the updating to |
| 346 * occur automatically. | 361 * occur automatically. |
| 347 * @param {string} url The url for the favicon. | 362 * @param {string} url The url for the favicon. |
| 348 * @param {number=} opt_size Optional preferred size of the favicon. | 363 * @param {number=} opt_size Optional preferred size of the favicon. |
| 349 * @param {string=} opt_type Optional type of favicon to request. Valid values | 364 * @param {string=} opt_type Optional type of favicon to request. Valid values |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 } | 482 } |
| 468 | 483 |
| 469 /** | 484 /** |
| 470 * Quote a string so it can be used in a regular expression. | 485 * Quote a string so it can be used in a regular expression. |
| 471 * @param {string} str The source string. | 486 * @param {string} str The source string. |
| 472 * @return {string} The escaped string. | 487 * @return {string} The escaped string. |
| 473 */ | 488 */ |
| 474 function quoteString(str) { | 489 function quoteString(str) { |
| 475 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1'); | 490 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1'); |
| 476 } | 491 } |
| OLD | NEW |