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

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

Issue 1137143004: WebUI for WKWebView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Responses to Eugene Created 5 years, 7 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
(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'] = window ['chrome'] || {};
12
13 window['chrome']['send'] = function(message, args) {
14 __gCrWeb.message.invokeOnHost({'command': 'chrome.send',
15 'message': '' + message,
16 'arguments': args || []});
17 };
18
19 // Chrome defines bind on all functions, so this is expected to exist by
20 // webui's scripts.
21 Function.prototype.bind = function(context) {
22 // Reference to the Function instance.
23 var self = this;
24 // Reference to the current arguments.
25 var curriedArguments = [];
26 for (var i = 1; i < arguments.length; i++)
27 curriedArguments.push(arguments[i]);
28 return function() {
29 var finalArguments = [];
30 for (var i = 0; i < curriedArguments.length; i++)
31 finalArguments.push(curriedArguments[i]);
32 for (var i = 0; i < arguments.length; i++)
33 finalArguments.push(arguments[i]);
34 return self.apply(context, finalArguments);
35 }
36 };
37
38 /*
39 * Sends message requesting favicon at the URL from imageSet for el. Sets
40 * favicon-url attribute on el to the favicon URL.
41 * @param {Element} el The DOM element to request the favicon for.
42 * @param {string} imageset The CSS -webkit-image-set.
43 */
44 window['chrome']['requestFavicon'] = function(el, imageSet) {
45 var cssUrls = imageSet.match(/url\([^\)]+\) \dx/g);
46 // Extract url from CSS -webkit-image-set.
47 var faviconUrl = '';
48 for (var i = 0; i < cssUrls.length; ++i) {
49 var scaleFactorExp = /(\d)x$/;
50 var scaleFactor = getSupportedScaleFactors()[0];
51 if (parseInt(scaleFactorExp.exec(cssUrls[i])[1], 10) === scaleFactor) {
52 var urlExp = /url\(\"(.+)\"\)/;
53 faviconUrl = urlExp.exec(cssUrls[i])[1];
54 break;
55 }
56 }
57 el.setAttribute('favicon-url', url(faviconUrl));
58 chrome.send('webui.requestFavicon', [faviconUrl]);
59 };
60
61 /**
62 * Called to set elements with favicon-url attribute equal to faviconUrl to
63 * provided dataUrl.
64 * @param {string} faviconUrl Favicon URL used to locate favicon element
65 * via the favicon-url attribute.
66 * @param {string} dataUrl The data URL to assign to the favicon element's
67 * backgroundImage.
68 */
69 window['chrome']['setFaviconBackground'] = function(faviconUrl, dataUrl) {
70 var selector = "[favicon-url='" + url(faviconUrl) + "']";
71 var elements = document.querySelectorAll(selector);
72 for (var i = 0; i < elements.length; ++i) {
73 elements[i].style.backgroundImage = url(dataUrl);
74 }
75 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698