Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 "use strict";
7 module.metadata = {
8 "stability": "unstable",
9 "engines": {
10 "Firefox": "*"
11 }
12 };
14 const { Cc, Ci, Cu } = require("chrome");
15 const { defer, reject } = require("../core/promise");
16 const FaviconService = Cc["@mozilla.org/browser/favicon-service;1"].
17 getService(Ci.nsIFaviconService);
18 const AsyncFavicons = FaviconService.QueryInterface(Ci.mozIAsyncFavicons);
19 const { isValidURI } = require("../url");
20 const { newURI, getURL } = require("../url/utils");
22 /**
23 * Takes an object of several possible types and
24 * returns a promise that resolves to the page's favicon URI.
25 * @param {String|Tab} object
26 * @param {Function} (callback)
27 * @returns {Promise}
28 */
30 function getFavicon (object, callback) {
31 let url = getURL(object);
32 let deferred = defer();
34 if (url && isValidURI(url)) {
35 AsyncFavicons.getFaviconURLForPage(newURI(url), function (aURI) {
36 if (aURI && aURI.spec)
37 deferred.resolve(aURI.spec.toString());
38 else
39 deferred.reject(null);
40 });
41 } else {
42 deferred.reject(null);
43 }
45 if (callback) deferred.promise.then(callback, callback);
46 return deferred.promise;
47 }
48 exports.getFavicon = getFavicon;