addon-sdk/source/lib/sdk/system/child_process/README.md

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 # subprocess
     4 Created by [Jan Gerber](j@mailb.org), with contributions from [Patrick Brunschwig](patrick@enigmail.net), subprocess.jsm is used as the underlying library, supporting the Addon-SDK's implementation of Node's `child-process` API.
     6 `subprocess.jsm` is originally from [http://hg.mozilla.org/ipccode/](http://hg.mozilla.org/ipccode/).
     8 How to Use subprocess.jsm in your Add-on
     9 ----------------------------------------
    11 1. copy subprocess.jsm and subprocess_worker_*.js into the modules/ directory
    12    of your add-on.
    14 2. add this line to chrome.manifest:
    15  resource EXTENSION modules/
    17 3. import it where needed:
    18  Components.utils.import("resource://EXTENSION/subprocess.jsm");
    20 This object allows to start a process, and read/write data to/from it
    21 using stdin/stdout/stderr streams.
    23 Usage example:
    25   var p = subprocess.call({
    26     command: '/bin/foo',
    27     arguments: ['-v', 'foo'],
    28     environment: [ "XYZ=abc", "MYVAR=def" ],
    29     charset: 'UTF-8',
    30     workdir: '/home/foo',
    31     //stdin: "some value to write to stdin\nfoobar",
    32     stdin: function(stdin) {
    33       stdin.write("some value to write to stdin\nfoobar");
    34       stdin.close();
    35     },
    36     stdout: function(data) {
    37       dump("got data on stdout:" + data + "\n");
    38     },
    39     stderr: function(data) {
    40       dump("got data on stderr:" + data + "\n");
    41     },
    42     done: function(result) {
    43       dump("process terminated with " + result.exitCode + "\n");
    44     },
    45     mergeStderr: false
    46   });
    48   p.wait(); // wait for the subprocess to terminate,
    49             // this will block the main thread,
    50             // only do if you can wait that long
    53 Description of subprocess.call(...) Parameters
    54 ----------------------------------------------
    55 Apart from <command>, all arguments are optional.
    57  command: either a |nsIFile| object pointing to an executable file or a
    58               String containing the platform-dependent path to an executable
    59               file.
    61  arguments: optional string array containing the arguments to the command.
    63  environment: optional string array containing environment variables to pass
    64               to the command. The array elements must have the form
    65               "VAR=data". Please note that if environment is defined, it
    66               replaces any existing environment variables for the subprocess.
    68  charset: Output is decoded with given charset and a string is returned.
    69               If charset is undefined, "UTF-8" is used as default.
    70               To get binary data, set this to null and the returned string
    71               is not decoded in any way.
    73  workdir: Optional; either a |nsIFile| object or string containing the
    74               platform-dependent path to a directory to become the current
    75               working directory of the subprocess.
    77  stdin: Optional input data for the process to be passed on standard
    78               input. stdin can either be a string or a function.
    79               A |string| gets written to stdin and stdin gets closed;
    80               A |function| gets passed an object with write and close function.
    81               Please note that the write() function will return almost immediately;
    82               data is always written asynchronously on a separate thread.
    84  stdout: An optional function that can receive output data from the
    85               process. The stdout-function is called asynchronously; it can be
    86               called mutliple times during the execution of a process.
    87               At a minimum at each occurance of \n or \r.
    88               Please note that null-characters might need to be escaped
    89               with something like 'data.replace(/\0/g, "\\0");'.
    91  stderr: An optional function that can receive stderr data from the
    92               process. The stderr-function is called asynchronously; it can be
    93               called mutliple times during the execution of a process. Please
    94               note that null-characters might need to be escaped with
    95               something like 'data.replace(/\0/g, "\\0");'.
    96               (on windows it only gets called once right now)
    98  done: Optional function that is called when the process has terminated.
    99               The exit code from the process available via result.exitCode. If
   100               stdout is not defined, then the output from stdout is available
   101               via result.stdout. stderr data is in result.stderr
   103  mergeStderr: Optional boolean value. If true, stderr is merged with stdout;
   104               no data will be provided to stderr.
   107 Description of object returned by subprocess.call(...)
   108 ------------------------------------------------------
   109 The object returned by subprocess.call offers a few methods that can be
   110 executed:
   112  wait(): waits for the subprocess to terminate. It is not required to use
   113               wait; done will be called in any case when the subprocess terminated.
   115  kill(): kill the subprocess. Any open pipes will be closed and
   116               done will be called.
   119 Other methods exported by subprocess
   120 ------------------------------------
   121 The following functions help debugging and provide logging facilities.
   123  registerDebugHandler(functionRef): register a handler that is called to get
   124                                       debugging information
   125  registerLogHandler(functionRef): register a handler that is called to get error
   126                                       messages
   128  example:
   129     subprocess.registerLogHandler( function(s) { dump(s); } );

mercurial