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.

     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;

mercurial