addon-sdk/source/lib/sdk/places/favicon.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial