tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GeckoViewOutputStream.cpp (1740B)


      1 /* -*- Mode: c++; c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil; -*-
      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/. */
      5 
      6 #include "GeckoViewOutputStream.h"
      7 #include "mozilla/fallible.h"
      8 
      9 using namespace mozilla;
     10 
     11 NS_IMPL_ISUPPORTS(GeckoViewOutputStream, nsIOutputStream);
     12 
     13 NS_IMETHODIMP
     14 GeckoViewOutputStream::Close() {
     15  mStream->SendEof();
     16  return NS_OK;
     17 }
     18 
     19 NS_IMETHODIMP
     20 GeckoViewOutputStream::Flush() { return NS_ERROR_NOT_IMPLEMENTED; }
     21 
     22 NS_IMETHODIMP
     23 GeckoViewOutputStream::StreamStatus() {
     24  return mStream->IsStreamClosed() ? NS_BASE_STREAM_CLOSED : NS_OK;
     25 }
     26 
     27 NS_IMETHODIMP
     28 GeckoViewOutputStream::Write(const char* buf, uint32_t count,
     29                             uint32_t* retval) {
     30  jni::ByteArray::LocalRef buffer = jni::ByteArray::New(
     31      reinterpret_cast<const int8_t*>(buf), count, fallible);
     32  if (!buffer) {
     33    return NS_ERROR_OUT_OF_MEMORY;
     34  }
     35  if (NS_FAILED(mStream->AppendBuffer(buffer))) {
     36    // The stream was closed, abort reading this channel.
     37    return NS_BASE_STREAM_CLOSED;
     38  }
     39  // Return amount of bytes written
     40  *retval = count;
     41 
     42  return NS_OK;
     43 }
     44 
     45 NS_IMETHODIMP
     46 GeckoViewOutputStream::WriteFrom(nsIInputStream* fromStream, uint32_t count,
     47                                 uint32_t* retval) {
     48  return NS_ERROR_NOT_IMPLEMENTED;
     49 }
     50 
     51 NS_IMETHODIMP
     52 GeckoViewOutputStream::WriteSegments(nsReadSegmentFun reader, void* closure,
     53                                     uint32_t count, uint32_t* retval) {
     54  return NS_ERROR_NOT_IMPLEMENTED;
     55 }
     56 
     57 NS_IMETHODIMP
     58 GeckoViewOutputStream::IsNonBlocking(bool* retval) {
     59  *retval = true;
     60  return NS_OK;
     61 }