| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /** | 6 /** |
| 7 * @fileoverview Helpers for validating parameters to chrome-search:// iframes. | 7 * @fileoverview Helpers for validating parameters to chrome-search:// iframes. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 * @param {number} component An RGBA component. | 31 * @param {number} component An RGBA component. |
| 32 * @return {boolean} True if the component is valid. | 32 * @return {boolean} True if the component is valid. |
| 33 */ | 33 */ |
| 34 function isValidRBGAComponent(component) { | 34 function isValidRBGAComponent(component) { |
| 35 return isFinite(component) && component >= 0 && component <= 255; | 35 return isFinite(component) && component >= 0 && component <= 255; |
| 36 } | 36 } |
| 37 | 37 |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Converts an Array of color components into RGBA format "rgba(R,G,B,A)". | 40 * Converts an Array of color components into RGBA format "rgba(R,G,B,A)". |
| 41 * @param {Array.<number>} rgbaColor Array of rgba color components. | 41 * @param {Array<number>} rgbaColor Array of rgba color components. |
| 42 * @return {?string} CSS color in RGBA format or null if invalid. | 42 * @return {?string} CSS color in RGBA format or null if invalid. |
| 43 */ | 43 */ |
| 44 function convertArrayToRGBAColor(rgbaColor) { | 44 function convertArrayToRGBAColor(rgbaColor) { |
| 45 // Array must contain 4 valid components. | 45 // Array must contain 4 valid components. |
| 46 if (rgbaColor instanceof Array && rgbaColor.length === 4 && | 46 if (rgbaColor instanceof Array && rgbaColor.length === 4 && |
| 47 isValidRBGAComponent(rgbaColor[0]) && | 47 isValidRBGAComponent(rgbaColor[0]) && |
| 48 isValidRBGAComponent(rgbaColor[1]) && | 48 isValidRBGAComponent(rgbaColor[1]) && |
| 49 isValidRBGAComponent(rgbaColor[2]) && | 49 isValidRBGAComponent(rgbaColor[2]) && |
| 50 isValidRBGAComponent(rgbaColor[3])) { | 50 isValidRBGAComponent(rgbaColor[3])) { |
| 51 return 'rgba(' + | 51 return 'rgba(' + |
| 52 rgbaColor[0] + ',' + | 52 rgbaColor[0] + ',' + |
| 53 rgbaColor[1] + ',' + | 53 rgbaColor[1] + ',' + |
| 54 rgbaColor[2] + ',' + | 54 rgbaColor[2] + ',' + |
| 55 rgbaColor[3] / 255 + ')'; | 55 rgbaColor[3] / 255 + ')'; |
| 56 } | 56 } |
| 57 return null; | 57 return null; |
| 58 } | 58 } |
| OLD | NEW |