addon-sdk/source/lib/node/os.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 } = require('chrome');
michael@0 12 const system = require('../sdk/system');
michael@0 13 const runtime = require('../sdk/system/runtime');
michael@0 14 const oscpu = Cc["@mozilla.org/network/protocol;1?name=http"]
michael@0 15 .getService(Ci.nsIHttpProtocolHandler).oscpu;
michael@0 16 const hostname = Cc["@mozilla.org/network/dns-service;1"]
michael@0 17 .getService(Ci.nsIDNSService).myHostName;
michael@0 18 const isWindows = system.platform === 'win32';
michael@0 19 const endianness = ((new Uint32Array((new Uint8Array([1,2,3,4])).buffer))[0] === 0x04030201) ? 'LE' : 'BE';
michael@0 20
michael@0 21 /**
michael@0 22 * Returns a path to a temp directory
michael@0 23 */
michael@0 24 exports.tmpdir = () => system.pathFor('TmpD');
michael@0 25
michael@0 26 /**
michael@0 27 * Returns the endianness of the architecture: either 'LE' or 'BE'
michael@0 28 */
michael@0 29 exports.endianness = () => endianness;
michael@0 30
michael@0 31 /**
michael@0 32 * Returns hostname of the machine
michael@0 33 */
michael@0 34 exports.hostname = () => hostname;
michael@0 35
michael@0 36 /**
michael@0 37 * Name of the OS type
michael@0 38 * Possible values:
michael@0 39 * https://developer.mozilla.org/en/OS_TARGET
michael@0 40 */
michael@0 41 exports.type = () => runtime.OS;
michael@0 42
michael@0 43 /**
michael@0 44 * Name of the OS Platform in lower case string.
michael@0 45 * Possible values:
michael@0 46 * https://developer.mozilla.org/en/OS_TARGET
michael@0 47 */
michael@0 48 exports.platform = () => system.platform;
michael@0 49
michael@0 50 /**
michael@0 51 * Type of processor architecture running:
michael@0 52 * 'arm', 'ia32', 'x86', 'x64'
michael@0 53 */
michael@0 54 exports.arch = () => system.architecture;
michael@0 55
michael@0 56 /**
michael@0 57 * Returns the operating system release.
michael@0 58 */
michael@0 59 exports.release = () => {
michael@0 60 let match = oscpu.match(/(\d[\.\d]*)/);
michael@0 61 return match && match.length > 1 ? match[1] : oscpu;
michael@0 62 };
michael@0 63
michael@0 64 /**
michael@0 65 * Returns EOL character for the OS
michael@0 66 */
michael@0 67 exports.EOL = isWindows ? '\r\n' : '\n';
michael@0 68
michael@0 69 /**
michael@0 70 * Returns [0, 0, 0], as this is not implemented.
michael@0 71 */
michael@0 72 exports.loadavg = () => [0, 0, 0];
michael@0 73
michael@0 74 ['uptime', 'totalmem', 'freemem', 'cpus'].forEach(method => {
michael@0 75 exports[method] = () => { throw new Error('os.' + method + ' is not supported.'); };
michael@0 76 });

mercurial