Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: ios/web/webui/resources/web_ui_favicons.js

Issue 2280853002: Slightly nicer icon.js APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 goog.require('__crWeb.webUIBase'); 11 goog.require('__crWeb.webUIBase');
12 12
13 goog.provide('__crWeb.webUIFavicons'); 13 goog.provide('__crWeb.webUIFavicons');
michaelpg 2016/09/02 20:00:38 unfamiliar with ios and goog/Closure, so just a qu
Peter Kasting 2016/09/02 20:21:42 (For posterity, we discussed this offline and conc
14 14
15 /** 15 /**
16 * Sends message requesting favicon at the URL from imageSet for el. Sets 16 * Sends message requesting favicon at the URL from imageSet for el. Sets
17 * favicon-url attribute on el to the favicon URL. 17 * favicon-url attribute on el to the favicon URL.
18 * @param {Element} el The DOM element to request the favicon for. 18 * @param {Element} el The DOM element to request the favicon for.
19 * @param {string} imageSet The CSS -webkit-image-set. 19 * @param {string} imageSet The CSS -webkit-image-set.
20 */ 20 */
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 = cr.icon.getSupportedScaleFactors()[0]; 31 var scaleFactor = window.devicePixelRatio;
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 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698