Sat, 03 Jan 2015 20:18:00 +0100
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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsIAsyncInputStream.h" |
michael@0 | 7 | #include "nsIAsyncOutputStream.h" |
michael@0 | 8 | #include "nsIDocShell.h" |
michael@0 | 9 | #include "nsIInterfaceRequestorUtils.h" |
michael@0 | 10 | #include "nsIPipe.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "nsEmbedStream.h" |
michael@0 | 13 | #include "nsError.h" |
michael@0 | 14 | #include "nsString.h" |
michael@0 | 15 | |
michael@0 | 16 | NS_IMPL_ISUPPORTS0(nsEmbedStream) |
michael@0 | 17 | |
michael@0 | 18 | nsEmbedStream::nsEmbedStream() |
michael@0 | 19 | { |
michael@0 | 20 | mOwner = nullptr; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | nsEmbedStream::~nsEmbedStream() |
michael@0 | 24 | { |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | void |
michael@0 | 28 | nsEmbedStream::InitOwner(nsIWebBrowser *aOwner) |
michael@0 | 29 | { |
michael@0 | 30 | mOwner = aOwner; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | NS_METHOD |
michael@0 | 34 | nsEmbedStream::Init(void) |
michael@0 | 35 | { |
michael@0 | 36 | return NS_OK; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | NS_METHOD |
michael@0 | 40 | nsEmbedStream::OpenStream(nsIURI *aBaseURI, const nsACString& aContentType) |
michael@0 | 41 | { |
michael@0 | 42 | nsresult rv; |
michael@0 | 43 | NS_ENSURE_ARG_POINTER(aBaseURI); |
michael@0 | 44 | NS_ENSURE_TRUE(IsASCII(aContentType), NS_ERROR_INVALID_ARG); |
michael@0 | 45 | |
michael@0 | 46 | // if we're already doing a stream, return an error |
michael@0 | 47 | if (mOutputStream) |
michael@0 | 48 | return NS_ERROR_IN_PROGRESS; |
michael@0 | 49 | |
michael@0 | 50 | nsCOMPtr<nsIAsyncInputStream> inputStream; |
michael@0 | 51 | nsCOMPtr<nsIAsyncOutputStream> outputStream; |
michael@0 | 52 | rv = NS_NewPipe2(getter_AddRefs(inputStream), |
michael@0 | 53 | getter_AddRefs(outputStream), |
michael@0 | 54 | true, false, 0, UINT32_MAX); |
michael@0 | 55 | if (NS_FAILED(rv)) |
michael@0 | 56 | return rv; |
michael@0 | 57 | |
michael@0 | 58 | nsCOMPtr<nsIDocShell> docShell = do_GetInterface(mOwner); |
michael@0 | 59 | rv = docShell->LoadStream(inputStream, aBaseURI, aContentType, |
michael@0 | 60 | EmptyCString(), nullptr); |
michael@0 | 61 | if (NS_FAILED(rv)) |
michael@0 | 62 | return rv; |
michael@0 | 63 | |
michael@0 | 64 | mOutputStream = outputStream; |
michael@0 | 65 | return rv; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | NS_METHOD |
michael@0 | 69 | nsEmbedStream::AppendToStream(const uint8_t *aData, uint32_t aLen) |
michael@0 | 70 | { |
michael@0 | 71 | nsresult rv; |
michael@0 | 72 | NS_ENSURE_STATE(mOutputStream); |
michael@0 | 73 | |
michael@0 | 74 | uint32_t bytesWritten = 0; |
michael@0 | 75 | rv = mOutputStream->Write(reinterpret_cast<const char*>(aData), |
michael@0 | 76 | aLen, &bytesWritten); |
michael@0 | 77 | if (NS_FAILED(rv)) |
michael@0 | 78 | return rv; |
michael@0 | 79 | |
michael@0 | 80 | NS_ASSERTION(bytesWritten == aLen, |
michael@0 | 81 | "underlying buffer couldn't handle the write"); |
michael@0 | 82 | return rv; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | NS_METHOD |
michael@0 | 86 | nsEmbedStream::CloseStream(void) |
michael@0 | 87 | { |
michael@0 | 88 | nsresult rv = NS_OK; |
michael@0 | 89 | |
michael@0 | 90 | // NS_ENSURE_STATE returns NS_ERROR_UNEXPECTED if the condition isn't |
michael@0 | 91 | // satisfied; this is exactly what we want to return. |
michael@0 | 92 | NS_ENSURE_STATE(mOutputStream); |
michael@0 | 93 | mOutputStream->Close(); |
michael@0 | 94 | mOutputStream = 0; |
michael@0 | 95 | |
michael@0 | 96 | return rv; |
michael@0 | 97 | } |