addon-sdk/source/lib/sdk/io/data.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 };
michael@0 10
michael@0 11 const { Cc, Ci, Cu } = require("chrome");
michael@0 12 const base64 = require("../base64");
michael@0 13 const IOService = Cc["@mozilla.org/network/io-service;1"].
michael@0 14 getService(Ci.nsIIOService);
michael@0 15
michael@0 16 const { deprecateFunction } = require('../util/deprecate');
michael@0 17 const { NetUtil } = Cu.import("resource://gre/modules/NetUtil.jsm");
michael@0 18 const FaviconService = Cc["@mozilla.org/browser/favicon-service;1"].
michael@0 19 getService(Ci.nsIFaviconService);
michael@0 20
michael@0 21 const PNG_B64 = "data:image/png;base64,";
michael@0 22 const DEF_FAVICON_URI = "chrome://mozapps/skin/places/defaultFavicon.png";
michael@0 23 let DEF_FAVICON = null;
michael@0 24
michael@0 25 /**
michael@0 26 * Takes URI of the page and returns associated favicon URI.
michael@0 27 * If page under passed uri has no favicon then base64 encoded data URI of
michael@0 28 * default faveicon is returned.
michael@0 29 * @param {String} uri
michael@0 30 * @returns {String}
michael@0 31 */
michael@0 32 function getFaviconURIForLocation(uri) {
michael@0 33 let pageURI = NetUtil.newURI(uri);
michael@0 34 try {
michael@0 35 return FaviconService.getFaviconDataAsDataURL(
michael@0 36 FaviconService.getFaviconForPage(pageURI));
michael@0 37 }
michael@0 38 catch(e) {
michael@0 39 if (!DEF_FAVICON) {
michael@0 40 DEF_FAVICON = PNG_B64 +
michael@0 41 base64.encode(getChromeURIContent(DEF_FAVICON_URI));
michael@0 42 }
michael@0 43 return DEF_FAVICON;
michael@0 44 }
michael@0 45 }
michael@0 46 exports.getFaviconURIForLocation = getFaviconURIForLocation;
michael@0 47
michael@0 48 /**
michael@0 49 * Takes chrome URI and returns content under that URI.
michael@0 50 * @param {String} chromeURI
michael@0 51 * @returns {String}
michael@0 52 */
michael@0 53 function getChromeURIContent(chromeURI) {
michael@0 54 let channel = IOService.newChannel(chromeURI, null, null);
michael@0 55 let input = channel.open();
michael@0 56 let stream = Cc["@mozilla.org/binaryinputstream;1"].
michael@0 57 createInstance(Ci.nsIBinaryInputStream);
michael@0 58 stream.setInputStream(input);
michael@0 59 let content = stream.readBytes(input.available());
michael@0 60 stream.close();
michael@0 61 input.close();
michael@0 62 return content;
michael@0 63 }
michael@0 64 exports.getChromeURIContent = deprecateFunction(getChromeURIContent,
michael@0 65 'getChromeURIContent is deprecated, ' +
michael@0 66 'please use require("sdk/net/url").readURI instead.'
michael@0 67 );
michael@0 68
michael@0 69 /**
michael@0 70 * Creates a base-64 encoded ASCII string from a string of binary data.
michael@0 71 */
michael@0 72 exports.base64Encode = deprecateFunction(base64.encode,
michael@0 73 'base64Encode is deprecated, ' +
michael@0 74 'please use require("sdk/base64").encode instead.'
michael@0 75 );
michael@0 76 /**
michael@0 77 * Decodes a string of data which has been encoded using base-64 encoding.
michael@0 78 */
michael@0 79 exports.base64Decode = deprecateFunction(base64.decode,
michael@0 80 'base64Dencode is deprecated, ' +
michael@0 81 'please use require("sdk/base64").decode instead.'
michael@0 82 );

mercurial