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 "unicpriv.h" |
michael@0 | 7 | #include "nsUnicodeEncodeHelper.h" |
michael@0 | 8 | #include "nsDebug.h" |
michael@0 | 9 | |
michael@0 | 10 | //---------------------------------------------------------------------- |
michael@0 | 11 | // Class nsUnicodeEncodeHelper [implementation] |
michael@0 | 12 | nsresult nsUnicodeEncodeHelper::ConvertByTable( |
michael@0 | 13 | const char16_t * aSrc, |
michael@0 | 14 | int32_t * aSrcLength, |
michael@0 | 15 | char * aDest, |
michael@0 | 16 | int32_t * aDestLength, |
michael@0 | 17 | uScanClassID aScanClass, |
michael@0 | 18 | uShiftOutTable * aShiftOutTable, |
michael@0 | 19 | uMappingTable * aMappingTable) |
michael@0 | 20 | { |
michael@0 | 21 | const char16_t * src = aSrc; |
michael@0 | 22 | const char16_t * srcEnd = aSrc + *aSrcLength; |
michael@0 | 23 | char * dest = aDest; |
michael@0 | 24 | int32_t destLen = *aDestLength; |
michael@0 | 25 | |
michael@0 | 26 | char16_t med; |
michael@0 | 27 | int32_t bcw; // byte count for write; |
michael@0 | 28 | nsresult res = NS_OK; |
michael@0 | 29 | |
michael@0 | 30 | while (src < srcEnd) { |
michael@0 | 31 | if (!uMapCode((uTable*) aMappingTable, static_cast<char16_t>(*(src++)), reinterpret_cast<uint16_t*>(&med))) { |
michael@0 | 32 | if (aScanClass == u1ByteCharset && *(src - 1) < 0x20) { |
michael@0 | 33 | // some tables are missing the 0x00 - 0x20 part |
michael@0 | 34 | med = *(src - 1); |
michael@0 | 35 | } else { |
michael@0 | 36 | res = NS_ERROR_UENC_NOMAPPING; |
michael@0 | 37 | break; |
michael@0 | 38 | } |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | bool charFound; |
michael@0 | 42 | if (aScanClass == uMultibytesCharset) { |
michael@0 | 43 | NS_ASSERTION(aShiftOutTable, "shift table missing"); |
michael@0 | 44 | charFound = uGenerateShift(aShiftOutTable, 0, med, |
michael@0 | 45 | (uint8_t *)dest, destLen, |
michael@0 | 46 | (uint32_t *)&bcw); |
michael@0 | 47 | } else { |
michael@0 | 48 | charFound = uGenerate(aScanClass, 0, med, |
michael@0 | 49 | (uint8_t *)dest, destLen, |
michael@0 | 50 | (uint32_t *)&bcw); |
michael@0 | 51 | } |
michael@0 | 52 | if (!charFound) { |
michael@0 | 53 | src--; |
michael@0 | 54 | res = NS_OK_UENC_MOREOUTPUT; |
michael@0 | 55 | break; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | dest += bcw; |
michael@0 | 59 | destLen -= bcw; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | *aSrcLength = src - aSrc; |
michael@0 | 63 | *aDestLength = dest - aDest; |
michael@0 | 64 | return res; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | nsresult nsUnicodeEncodeHelper::ConvertByMultiTable( |
michael@0 | 68 | const char16_t * aSrc, |
michael@0 | 69 | int32_t * aSrcLength, |
michael@0 | 70 | char * aDest, |
michael@0 | 71 | int32_t * aDestLength, |
michael@0 | 72 | int32_t aTableCount, |
michael@0 | 73 | uScanClassID * aScanClassArray, |
michael@0 | 74 | uShiftOutTable ** aShiftOutTable, |
michael@0 | 75 | uMappingTable ** aMappingTable) |
michael@0 | 76 | { |
michael@0 | 77 | const char16_t * src = aSrc; |
michael@0 | 78 | const char16_t * srcEnd = aSrc + *aSrcLength; |
michael@0 | 79 | char * dest = aDest; |
michael@0 | 80 | int32_t destLen = *aDestLength; |
michael@0 | 81 | |
michael@0 | 82 | char16_t med; |
michael@0 | 83 | int32_t bcw; // byte count for write; |
michael@0 | 84 | nsresult res = NS_OK; |
michael@0 | 85 | int32_t i; |
michael@0 | 86 | |
michael@0 | 87 | while (src < srcEnd) { |
michael@0 | 88 | for (i=0; i<aTableCount; i++) |
michael@0 | 89 | if (uMapCode((uTable*) aMappingTable[i], static_cast<uint16_t>(*src), reinterpret_cast<uint16_t*>(&med))) break; |
michael@0 | 90 | |
michael@0 | 91 | src++; |
michael@0 | 92 | if (i == aTableCount) { |
michael@0 | 93 | res = NS_ERROR_UENC_NOMAPPING; |
michael@0 | 94 | break; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | bool charFound; |
michael@0 | 98 | if (aScanClassArray[i] == uMultibytesCharset) { |
michael@0 | 99 | NS_ASSERTION(aShiftOutTable[i], "shift table missing"); |
michael@0 | 100 | charFound = uGenerateShift(aShiftOutTable[i], 0, med, |
michael@0 | 101 | (uint8_t *)dest, destLen, |
michael@0 | 102 | (uint32_t *)&bcw); |
michael@0 | 103 | } |
michael@0 | 104 | else |
michael@0 | 105 | charFound = uGenerate(aScanClassArray[i], 0, med, |
michael@0 | 106 | (uint8_t *)dest, destLen, |
michael@0 | 107 | (uint32_t *)&bcw); |
michael@0 | 108 | if (!charFound) { |
michael@0 | 109 | src--; |
michael@0 | 110 | res = NS_OK_UENC_MOREOUTPUT; |
michael@0 | 111 | break; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | dest += bcw; |
michael@0 | 115 | destLen -= bcw; |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | *aSrcLength = src - aSrc; |
michael@0 | 119 | *aDestLength = dest - aDest; |
michael@0 | 120 | return res; |
michael@0 | 121 | } |