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.

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

mercurial