| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // This file adheres to closure-compiler conventions in order to enable | 5 // This file adheres to closure-compiler conventions in order to enable |
| 6 // compilation with ADVANCED_OPTIMIZATIONS. In particular, members that are to | 6 // compilation with ADVANCED_OPTIMIZATIONS. In particular, members that are to |
| 7 // be accessed externally should be specified in this['style'] as opposed to | 7 // be accessed externally should be specified in this['style'] as opposed to |
| 8 // this.style because member identifiers are minified by default. | 8 // this.style because member identifiers are minified by default. |
| 9 // See http://goo.gl/FwOgy | 9 // See http://goo.gl/FwOgy |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 window['chrome']['requestFavicon'] = function(el, imageSet) { | 21 window['chrome']['requestFavicon'] = function(el, imageSet) { |
| 22 var cssUrls = imageSet.match(/url\([^\)]+\) \dx/g); | 22 var cssUrls = imageSet.match(/url\([^\)]+\) \dx/g); |
| 23 // TODO(jyquinn): Review match above (crbug.com/528080). | 23 // TODO(jyquinn): Review match above (crbug.com/528080). |
| 24 if (!cssUrls) { | 24 if (!cssUrls) { |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 // Extract url from CSS -webkit-image-set. | 27 // Extract url from CSS -webkit-image-set. |
| 28 var faviconUrl = ''; | 28 var faviconUrl = ''; |
| 29 for (var i = 0; i < cssUrls.length; ++i) { | 29 for (var i = 0; i < cssUrls.length; ++i) { |
| 30 var scaleFactorExp = /(\d)x$/; | 30 var scaleFactorExp = /(\d)x$/; |
| 31 var scaleFactor = getSupportedScaleFactors()[0]; | 31 var scaleFactor = cr.icon.getSupportedScaleFactors()[0]; |
| 32 if (parseInt(scaleFactorExp.exec(cssUrls[i])[1], 10) === scaleFactor) { | 32 if (parseInt(scaleFactorExp.exec(cssUrls[i])[1], 10) === scaleFactor) { |
| 33 var urlExp = /url\(\"(.+)\"\)/; | 33 var urlExp = /url\(\"(.+)\"\)/; |
| 34 faviconUrl = urlExp.exec(cssUrls[i])[1]; | 34 faviconUrl = urlExp.exec(cssUrls[i])[1]; |
| 35 break; | 35 break; |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 el.setAttribute('favicon-url', url(faviconUrl)); | 38 el.setAttribute('favicon-url', url(faviconUrl)); |
| 39 chrome.send('webui.requestFavicon', [faviconUrl]); | 39 chrome.send('webui.requestFavicon', [faviconUrl]); |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Called to set elements with favicon-url attribute equal to faviconUrl to | 43 * Called to set elements with favicon-url attribute equal to faviconUrl to |
| 44 * provided dataUrl. | 44 * provided dataUrl. |
| 45 * @param {string} faviconUrl Favicon URL used to locate favicon element | 45 * @param {string} faviconUrl Favicon URL used to locate favicon element |
| 46 * via the favicon-url attribute. | 46 * via the favicon-url attribute. |
| 47 * @param {string} dataUrl The data URL to assign to the favicon element's | 47 * @param {string} dataUrl The data URL to assign to the favicon element's |
| 48 * backgroundImage. | 48 * backgroundImage. |
| 49 */ | 49 */ |
| 50 window['chrome']['setFaviconBackground'] = function(faviconUrl, dataUrl) { | 50 window['chrome']['setFaviconBackground'] = function(faviconUrl, dataUrl) { |
| 51 var selector = "[favicon-url='" + url(faviconUrl) + "']"; | 51 var selector = "[favicon-url='" + url(faviconUrl) + "']"; |
| 52 var elements = document.querySelectorAll(selector); | 52 var elements = document.querySelectorAll(selector); |
| 53 for (var i = 0; i < elements.length; ++i) { | 53 for (var i = 0; i < elements.length; ++i) { |
| 54 elements[i].style.backgroundImage = url(dataUrl); | 54 elements[i].style.backgroundImage = url(dataUrl); |
| 55 } | 55 } |
| 56 }; | 56 }; |
| OLD | NEW |