Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // This file adheres to closure-compiler conventions in order to enable | |
| 6 // compilation with ADVANCED_OPTIMIZATIONS. In particular, members that are to | |
| 7 // be accessed externally should be specified in this['style'] as opposed to | |
| 8 // this.style because member identifiers are minified by default. | |
| 9 // See http://goo.gl/FwOgy | |
| 10 | |
| 11 window['chrome'] = {}; | |
|
Eugene But (OOO till 7-30)
2015/05/12 17:47:09
Is "if (!window['chrome']) check necessary here (t
Jackie Quinn
2015/05/12 18:14:55
I think this may be the only file that defines win
| |
| 12 window['chrome']['send'] = function(message, args) { | |
| 13 __gCrWeb.message.invokeOnHost({'command': 'chrome.send', | |
| 14 'message': '' + message, | |
| 15 'arguments': args || []}); | |
| 16 }; | |
| 17 // Chrome defines bind on all functions, so this is expected to exist by | |
| 18 // webui's scripts. | |
| 19 Function.prototype.bind = function(context) { | |
| 20 // Reference to the Function instance. | |
| 21 var m = this; | |
|
Eugene But (OOO till 7-30)
2015/05/12 17:47:10
m is not very informative variable name.
s/m/self
Jackie Quinn
2015/05/12 18:14:55
Done.
| |
| 22 // Reference to the current arguments. | |
| 23 var curriedArguments = []; | |
| 24 for (var i = 1; i < arguments.length; i++) | |
| 25 curriedArguments.push(arguments[i]); | |
| 26 return function() { | |
| 27 var finalArguments = []; | |
| 28 for (var i = 0; i < curriedArguments.length; i++) | |
| 29 finalArguments.push(curriedArguments[i]); | |
| 30 for (var i = 0; i < arguments.length; i++) | |
| 31 finalArguments.push(arguments[i]); | |
| 32 return m.apply(context, finalArguments); | |
| 33 } | |
| 34 }; | |
| 35 | |
| 36 /* | |
| 37 * Send message requesting favicon at the URL from imageSet for el. Sets | |
|
Eugene But (OOO till 7-30)
2015/05/12 17:47:10
s/Send/Sends
Jackie Quinn
2015/05/12 18:14:55
Done.
| |
| 38 * favicon-url attribute on el to the favicon URL. | |
| 39 * @param {Element} el The DOM element to request the favicon for. | |
| 40 * @param {string} imageset The CSS -webkit-image-set. | |
| 41 */ | |
| 42 window['chrome']['requestFavicon'] = function(el, imageSet) { | |
| 43 var cssUrls = imageSet.match(/url\([^\)]+\) \dx/g); | |
| 44 // Extract url from CSS -webkit-image-set. | |
| 45 var faviconUrl = ''; | |
| 46 for (var i = 0; i < cssUrls.length; ++i) { | |
| 47 var scaleFactorExp = /(\d)x$/; | |
| 48 var scaleFactor = getSupportedScaleFactors()[0]; | |
| 49 if (parseInt(scaleFactorExp.exec(cssUrls[i])[1], 10) === scaleFactor) { | |
| 50 var urlExp = /url\(\"(.+)\"\)/; | |
| 51 faviconUrl = urlExp.exec(cssUrls[i])[1]; | |
| 52 break; | |
| 53 } | |
| 54 } | |
| 55 el.setAttribute('favicon-url', url(faviconUrl)); | |
| 56 chrome.send('webui.requestFavicon', [faviconUrl]); | |
| 57 }; | |
| 58 | |
| 59 /** | |
| 60 * Called to set elements with favicon-url attribute equal to faviconUrl to | |
| 61 * provided dataUrl. | |
| 62 * @param {string} faviconUrl Favicon URL used to locate favicon element | |
| 63 * via the favicon-url attribute. | |
| 64 * @param {string} dataUrl The data URL to assign to the favicon element's | |
| 65 * backgroundImage. | |
| 66 */ | |
| 67 window['chrome']['setFaviconBackground'] = function(faviconUrl, dataUrl) { | |
| 68 var selector = "[favicon-url='" + url(faviconUrl) + "']"; | |
| 69 var elements = document.querySelectorAll(selector); | |
| 70 for (var i = 0; i < elements.length; ++i) { | |
| 71 elements[i].style.backgroundImage = url(dataUrl); | |
| 72 } | |
| 73 }; | |
| OLD | NEW |