xpcom/io/nsIBinaryInputStream.idl

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsIInputStream.idl"
     8 /**
     9  * This interface allows consumption of primitive data types from a "binary
    10  * stream" containing untagged, big-endian binary data, i.e. as produced by an
    11  * implementation of nsIBinaryOutputStream.  This might be used, for example,
    12  * to implement network protocols or to read from architecture-neutral disk
    13  * files, i.e. ones that can be read and written by both big-endian and
    14  * little-endian platforms.
    15  *
    16  * @See nsIBinaryOutputStream
    17  */
    19 [scriptable, uuid(42084755-fedc-4310-831c-4f43e7b42e20)]
    20 interface nsIBinaryInputStream : nsIInputStream {
    21     void setInputStream(in nsIInputStream aInputStream);
    23     /**
    24      * Read 8-bits from the stream.
    25      *
    26      * @return that byte to be treated as a boolean.
    27      */
    28     boolean readBoolean();
    30     uint8_t read8();
    31     uint16_t read16();
    32     uint32_t read32();
    33     uint64_t read64();
    35     float readFloat();
    36     double readDouble();
    38     /**
    39      * Read an 8-bit pascal style string from the stream.
    40      * 32-bit length field, followed by length 8-bit chars.
    41      */
    42     ACString readCString();
    44     /**
    45      * Read an 16-bit pascal style string from the stream.
    46      * 32-bit length field, followed by length PRUnichars.
    47      */
    48     AString readString();
    50     /**
    51      * Read an opaque byte array from the stream.
    52      *
    53      * @param aLength the number of bytes that must be read.
    54      *
    55      * @throws NS_ERROR_FAILURE if it can't read aLength bytes
    56      */
    57     void readBytes(in uint32_t aLength,
    58                    [size_is(aLength), retval] out string aString);
    60     /**
    61      * Read an opaque byte array from the stream, storing the results
    62      * as an array of PRUint8s.
    63      *
    64      * @param aLength the number of bytes that must be read.
    65      *
    66      * @throws NS_ERROR_FAILURE if it can't read aLength bytes
    67      */
    68     void readByteArray(in uint32_t aLength,
    69                        [array, size_is(aLength), retval] out uint8_t aBytes);
    71     /**
    72      * Read opaque bytes from the stream, storing the results in an ArrayBuffer.
    73      *
    74      * @param aLength the number of bytes that must be read
    75      * @param aArrayBuffer the arraybuffer in which to store the results
    76      * Note: passing view.buffer, where view is an ArrayBufferView of an
    77      *       ArrayBuffer, is not valid unless view.byteOffset == 0.
    78      *
    79      * @throws NS_ERROR_FAILURE if it can't read aLength bytes
    80      */
    81     [implicit_jscontext]
    82     void readArrayBuffer(in uint32_t aLength, in jsval aArrayBuffer);
    83 };
    85 %{C++
    87 #ifdef MOZILLA_INTERNAL_API
    88 #include "nsString.h"
    90 inline nsresult
    91 NS_ReadOptionalCString(nsIBinaryInputStream* aStream, nsACString& aResult)
    92 {
    93     bool nonnull;
    94     nsresult rv = aStream->ReadBoolean(&nonnull);
    95     if (NS_SUCCEEDED(rv)) {
    96         if (nonnull)
    97             rv = aStream->ReadCString(aResult);
    98         else
    99             aResult.Truncate();
   100     }
   101     return rv;
   102 }
   104 inline nsresult
   105 NS_ReadOptionalString(nsIBinaryInputStream* aStream, nsAString& aResult)
   106 {
   107     bool nonnull;
   108     nsresult rv = aStream->ReadBoolean(&nonnull);
   109     if (NS_SUCCEEDED(rv)) {
   110         if (nonnull)
   111             rv = aStream->ReadString(aResult);
   112         else
   113             aResult.Truncate();
   114     }
   115     return rv;
   116 }
   117 #endif
   119 %}

mercurial