embedding/browser/webBrowser/nsEmbedStream.cpp

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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     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 "nsIAsyncInputStream.h"
     7 #include "nsIAsyncOutputStream.h"
     8 #include "nsIDocShell.h"
     9 #include "nsIInterfaceRequestorUtils.h"
    10 #include "nsIPipe.h"
    12 #include "nsEmbedStream.h"
    13 #include "nsError.h"
    14 #include "nsString.h"
    16 NS_IMPL_ISUPPORTS0(nsEmbedStream)
    18 nsEmbedStream::nsEmbedStream()
    19 {
    20   mOwner = nullptr;
    21 }
    23 nsEmbedStream::~nsEmbedStream()
    24 {
    25 }
    27 void
    28 nsEmbedStream::InitOwner(nsIWebBrowser *aOwner)
    29 {
    30   mOwner = aOwner;
    31 }
    33 NS_METHOD
    34 nsEmbedStream::Init(void)
    35 {
    36   return NS_OK;
    37 }
    39 NS_METHOD
    40 nsEmbedStream::OpenStream(nsIURI *aBaseURI, const nsACString& aContentType)
    41 {
    42   nsresult rv;
    43   NS_ENSURE_ARG_POINTER(aBaseURI);
    44   NS_ENSURE_TRUE(IsASCII(aContentType), NS_ERROR_INVALID_ARG);
    46   // if we're already doing a stream, return an error
    47   if (mOutputStream)
    48     return NS_ERROR_IN_PROGRESS;
    50   nsCOMPtr<nsIAsyncInputStream> inputStream;
    51   nsCOMPtr<nsIAsyncOutputStream> outputStream;
    52   rv = NS_NewPipe2(getter_AddRefs(inputStream),
    53                    getter_AddRefs(outputStream),
    54                    true, false, 0, UINT32_MAX);
    55   if (NS_FAILED(rv))
    56     return rv;
    58   nsCOMPtr<nsIDocShell> docShell = do_GetInterface(mOwner);
    59   rv = docShell->LoadStream(inputStream, aBaseURI, aContentType,
    60                             EmptyCString(), nullptr);
    61   if (NS_FAILED(rv))
    62     return rv;
    64   mOutputStream = outputStream;
    65   return rv;
    66 }
    68 NS_METHOD
    69 nsEmbedStream::AppendToStream(const uint8_t *aData, uint32_t aLen)
    70 {
    71   nsresult rv;
    72   NS_ENSURE_STATE(mOutputStream);
    74   uint32_t bytesWritten = 0;
    75   rv = mOutputStream->Write(reinterpret_cast<const char*>(aData),
    76                             aLen, &bytesWritten);
    77   if (NS_FAILED(rv))
    78     return rv;
    80   NS_ASSERTION(bytesWritten == aLen,
    81                "underlying buffer couldn't handle the write");
    82   return rv;
    83 }
    85 NS_METHOD
    86 nsEmbedStream::CloseStream(void)
    87 {
    88   nsresult rv = NS_OK;
    90   // NS_ENSURE_STATE returns NS_ERROR_UNEXPECTED if the condition isn't
    91   // satisfied; this is exactly what we want to return.
    92   NS_ENSURE_STATE(mOutputStream);
    93   mOutputStream->Close();
    94   mOutputStream = 0;
    96   return rv;
    97 }

mercurial