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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include <stdlib.h> |
michael@0 | 6 | #include "nsIStorageStream.h" |
michael@0 | 7 | #include "nsIInputStream.h" |
michael@0 | 8 | #include "nsIOutputStream.h" |
michael@0 | 9 | #include "nsCOMPtr.h" |
michael@0 | 10 | |
michael@0 | 11 | int main() |
michael@0 | 12 | { |
michael@0 | 13 | char kData[4096]; |
michael@0 | 14 | memset(kData, 0, sizeof(kData)); |
michael@0 | 15 | |
michael@0 | 16 | nsresult rv; |
michael@0 | 17 | nsCOMPtr<nsIStorageStream> stor; |
michael@0 | 18 | |
michael@0 | 19 | rv = NS_NewStorageStream(4096, UINT32_MAX, getter_AddRefs(stor)); |
michael@0 | 20 | if (NS_FAILED(rv)) |
michael@0 | 21 | return -1; |
michael@0 | 22 | |
michael@0 | 23 | nsCOMPtr<nsIOutputStream> out; |
michael@0 | 24 | rv = stor->GetOutputStream(0, getter_AddRefs(out)); |
michael@0 | 25 | if (NS_FAILED(rv)) |
michael@0 | 26 | return -1; |
michael@0 | 27 | |
michael@0 | 28 | uint32_t n; |
michael@0 | 29 | |
michael@0 | 30 | rv = out->Write(kData, sizeof(kData), &n); |
michael@0 | 31 | if (NS_FAILED(rv)) |
michael@0 | 32 | return -1; |
michael@0 | 33 | |
michael@0 | 34 | rv = out->Write(kData, sizeof(kData), &n); |
michael@0 | 35 | if (NS_FAILED(rv)) |
michael@0 | 36 | return -1; |
michael@0 | 37 | |
michael@0 | 38 | rv = out->Close(); |
michael@0 | 39 | if (NS_FAILED(rv)) |
michael@0 | 40 | return -1; |
michael@0 | 41 | |
michael@0 | 42 | out = nullptr; |
michael@0 | 43 | |
michael@0 | 44 | nsCOMPtr<nsIInputStream> in; |
michael@0 | 45 | rv = stor->NewInputStream(0, getter_AddRefs(in)); |
michael@0 | 46 | if (NS_FAILED(rv)) |
michael@0 | 47 | return -1; |
michael@0 | 48 | |
michael@0 | 49 | char buf[4096]; |
michael@0 | 50 | |
michael@0 | 51 | // consume contents of input stream |
michael@0 | 52 | do { |
michael@0 | 53 | rv = in->Read(buf, sizeof(buf), &n); |
michael@0 | 54 | if (NS_FAILED(rv)) |
michael@0 | 55 | return -1; |
michael@0 | 56 | } while (n != 0); |
michael@0 | 57 | |
michael@0 | 58 | rv = in->Close(); |
michael@0 | 59 | if (NS_FAILED(rv)) |
michael@0 | 60 | return -1; |
michael@0 | 61 | in = nullptr; |
michael@0 | 62 | |
michael@0 | 63 | // now, write 3 more full 4k segments + 11 bytes, starting at 8192 |
michael@0 | 64 | // total written equals 20491 bytes |
michael@0 | 65 | |
michael@0 | 66 | rv = stor->GetOutputStream(8192, getter_AddRefs(out)); |
michael@0 | 67 | if (NS_FAILED(rv)) |
michael@0 | 68 | return -1; |
michael@0 | 69 | |
michael@0 | 70 | rv = out->Write(kData, sizeof(kData), &n); |
michael@0 | 71 | if (NS_FAILED(rv)) |
michael@0 | 72 | return -1; |
michael@0 | 73 | |
michael@0 | 74 | rv = out->Write(kData, sizeof(kData), &n); |
michael@0 | 75 | if (NS_FAILED(rv)) |
michael@0 | 76 | return -1; |
michael@0 | 77 | |
michael@0 | 78 | rv = out->Write(kData, sizeof(kData), &n); |
michael@0 | 79 | if (NS_FAILED(rv)) |
michael@0 | 80 | return -1; |
michael@0 | 81 | |
michael@0 | 82 | rv = out->Write(kData, 11, &n); |
michael@0 | 83 | if (NS_FAILED(rv)) |
michael@0 | 84 | return -1; |
michael@0 | 85 | |
michael@0 | 86 | rv = out->Close(); |
michael@0 | 87 | if (NS_FAILED(rv)) |
michael@0 | 88 | return -1; |
michael@0 | 89 | |
michael@0 | 90 | out = nullptr; |
michael@0 | 91 | |
michael@0 | 92 | // now, read all |
michael@0 | 93 | rv = stor->NewInputStream(0, getter_AddRefs(in)); |
michael@0 | 94 | if (NS_FAILED(rv)) |
michael@0 | 95 | return -1; |
michael@0 | 96 | |
michael@0 | 97 | // consume contents of input stream |
michael@0 | 98 | do { |
michael@0 | 99 | rv = in->Read(buf, sizeof(buf), &n); |
michael@0 | 100 | if (NS_FAILED(rv)) |
michael@0 | 101 | return -1; |
michael@0 | 102 | } while (n != 0); |
michael@0 | 103 | |
michael@0 | 104 | rv = in->Close(); |
michael@0 | 105 | if (NS_FAILED(rv)) |
michael@0 | 106 | return -1; |
michael@0 | 107 | in = nullptr; |
michael@0 | 108 | |
michael@0 | 109 | return 0; |
michael@0 | 110 | } |