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. | 8 * Alias for document.getElementById. |
| 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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 * @return {string} -webkit-image-set for the favicon. | 339 * @return {string} -webkit-image-set for the favicon. |
| 340 */ | 340 */ |
| 341 function getFaviconImageSet(url, opt_size, opt_type) { | 341 function getFaviconImageSet(url, opt_size, opt_type) { |
| 342 var size = opt_size || 16; | 342 var size = opt_size || 16; |
| 343 var type = opt_type || 'favicon'; | 343 var type = opt_type || 'favicon'; |
| 344 return imageset( | 344 return imageset( |
| 345 'chrome://' + type + '/size/' + size + '@scalefactorx/' + url); | 345 'chrome://' + type + '/size/' + size + '@scalefactorx/' + url); |
| 346 } | 346 } |
| 347 | 347 |
| 348 /** | 348 /** |
| 349 * Creates a CSS -webkit-image-set based on whether the url is secure. | |
| 350 * @param {string} url The url for the icon. | |
| 351 * @param {boolean} isUrlSecure True if the url is secure. | |
| 352 * @return {string} -webkit-image-set for the icon. | |
| 353 */ | |
| 354 function getIconBasedOnUrlSecurity(url, isUrlSecure) { | |
| 355 return isUrlSecure ? | |
| 356 getLargeiconOrFallbackIconImageSet(url, 16) : | |
| 357 getFaviconImageSet('', 16); | |
|
pkotwicz
2015/10/15 15:44:26
This code confuses me.
Here is my understanding o
kolos1
2015/10/15 20:22:46
If the url is insecure, we show 'blank' icon.
If
pkotwicz
2015/10/15 21:10:55
Sorry for my misunderstanding. I think that we sho
kolos1
2015/10/16 14:19:26
Thanks for your advices.
Could you share your op
| |
| 358 } | |
| 359 | |
| 360 /** | |
| 361 * Creates a CSS -webkit-image-set for a large icon request. The service | |
| 362 * chrome://large-icon/ return a fallback icon, if there is no available icon. | |
| 363 * @param(string) path The url for the large icon. | |
| 364 * @param {number=} opt_size Optional preferred size of the large icon. | |
| 365 * @return {string} -webkit-image-set for the large icon. | |
| 366 */ | |
| 367 function getLargeiconOrFallbackIconImageSet(path, opt_size) { | |
| 368 // Description of fallback icon's parameters can be found in | |
| 369 // chrome/browser/ui/webui/fallback_icon_source.h. | |
| 370 // The first parameter is ignored, since the size of icon should be defined in | |
| 371 // the following way 'chrome://large-icon/size/...'. | |
| 372 var fallback_icon_parameters = 'fallback/,777,FFF,0.625,0.4/'; | |
| 373 var size = opt_size || 16; | |
| 374 var supportedScaleFactors = getSupportedScaleFactors(); | |
| 375 var result = ''; | |
| 376 for (var i = 0; i < supportedScaleFactors.length; ++i) { | |
| 377 var scaleFactor = supportedScaleFactors[i]; | |
| 378 var scaledSize = Math.round(size * scaleFactor); | |
| 379 var large_icon = 'chrome://large-icon/' + scaledSize + '/' + | |
| 380 fallback_icon_parameters + path; | |
| 381 result += url(large_icon) + ' ' + scaleFactor + 'x'; | |
| 382 if (i != supportedScaleFactors.length - 1) | |
| 383 result += ', '; | |
| 384 } | |
| 385 return '-webkit-image-set(' + result + ')'; | |
| 386 } | |
| 387 | |
| 388 /** | |
| 349 * Creates a new URL for a favicon request for the current device pixel ratio. | 389 * Creates a new URL for a favicon request for the current device pixel ratio. |
| 350 * The URL must be updated when the user moves the browser to a screen with a | 390 * The URL must be updated when the user moves the browser to a screen with a |
| 351 * different device pixel ratio. Use getFaviconImageSet() for the updating to | 391 * different device pixel ratio. Use getFaviconImageSet() for the updating to |
| 352 * occur automatically. | 392 * occur automatically. |
| 353 * @param {string} url The url for the favicon. | 393 * @param {string} url The url for the favicon. |
| 354 * @param {number=} opt_size Optional preferred size of the favicon. | 394 * @param {number=} opt_size Optional preferred size of the favicon. |
| 355 * @param {string=} opt_type Optional type of favicon to request. Valid values | 395 * @param {string=} opt_type Optional type of favicon to request. Valid values |
| 356 * are 'favicon' and 'touch-icon'. Default is 'favicon'. | 396 * are 'favicon' and 'touch-icon'. Default is 'favicon'. |
| 357 * @return {string} Updated URL for the favicon. | 397 * @return {string} Updated URL for the favicon. |
| 358 */ | 398 */ |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 * @param {number} maxLength The maximum length allowed for the string. | 495 * @param {number} maxLength The maximum length allowed for the string. |
| 456 * @return {string} The original string if its length does not exceed | 496 * @return {string} The original string if its length does not exceed |
| 457 * |maxLength|. Otherwise the first |maxLength| - 1 characters with '...' | 497 * |maxLength|. Otherwise the first |maxLength| - 1 characters with '...' |
| 458 * appended. | 498 * appended. |
| 459 */ | 499 */ |
| 460 function elide(original, maxLength) { | 500 function elide(original, maxLength) { |
| 461 if (original.length <= maxLength) | 501 if (original.length <= maxLength) |
| 462 return original; | 502 return original; |
| 463 return original.substring(0, maxLength - 1) + '\u2026'; | 503 return original.substring(0, maxLength - 1) + '\u2026'; |
| 464 } | 504 } |
| OLD | NEW |