Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C; tab-width: 4; 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 | #ifndef nsCyrillicDetector_h__ |
michael@0 | 6 | #define nsCyrillicDetector_h__ |
michael@0 | 7 | |
michael@0 | 8 | #include "nsCyrillicClass.h" |
michael@0 | 9 | |
michael@0 | 10 | |
michael@0 | 11 | |
michael@0 | 12 | |
michael@0 | 13 | // {2002F781-3960-11d3-B3C3-00805F8A6670} |
michael@0 | 14 | #define NS_RU_PROBDETECTOR_CID \ |
michael@0 | 15 | { 0x2002f781, 0x3960, 0x11d3, { 0xb3, 0xc3, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } } |
michael@0 | 16 | |
michael@0 | 17 | |
michael@0 | 18 | // {2002F782-3960-11d3-B3C3-00805F8A6670} |
michael@0 | 19 | #define NS_UK_PROBDETECTOR_CID \ |
michael@0 | 20 | { 0x2002f782, 0x3960, 0x11d3, { 0xb3, 0xc3, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } } |
michael@0 | 21 | |
michael@0 | 22 | // {2002F783-3960-11d3-B3C3-00805F8A6670} |
michael@0 | 23 | #define NS_RU_STRING_PROBDETECTOR_CID \ |
michael@0 | 24 | { 0x2002f783, 0x3960, 0x11d3, { 0xb3, 0xc3, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } } |
michael@0 | 25 | |
michael@0 | 26 | // {2002F784-3960-11d3-B3C3-00805F8A6670} |
michael@0 | 27 | #define NS_UK_STRING_PROBDETECTOR_CID \ |
michael@0 | 28 | { 0x2002f784, 0x3960, 0x11d3, { 0xb3, 0xc3, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } } |
michael@0 | 29 | |
michael@0 | 30 | static const uint8_t *gCyrillicCls[5] = |
michael@0 | 31 | { |
michael@0 | 32 | CP1251Map, |
michael@0 | 33 | KOI8Map, |
michael@0 | 34 | ISO88595Map, |
michael@0 | 35 | MacCyrillicMap, |
michael@0 | 36 | IBM866Map |
michael@0 | 37 | }; |
michael@0 | 38 | |
michael@0 | 39 | static const char * gRussian[5] = { |
michael@0 | 40 | "windows-1251", |
michael@0 | 41 | "KOI8-R", |
michael@0 | 42 | "ISO-8859-5", |
michael@0 | 43 | "x-mac-cyrillic", |
michael@0 | 44 | "IBM866" |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | static const char * gUkrainian[5] = { |
michael@0 | 48 | "windows-1251", |
michael@0 | 49 | "KOI8-U", |
michael@0 | 50 | "ISO-8859-5", |
michael@0 | 51 | "x-mac-cyrillic", |
michael@0 | 52 | "IBM866" |
michael@0 | 53 | }; |
michael@0 | 54 | |
michael@0 | 55 | #define NUM_CYR_CHARSET 5 |
michael@0 | 56 | |
michael@0 | 57 | class nsCyrillicDetector |
michael@0 | 58 | { |
michael@0 | 59 | public: |
michael@0 | 60 | nsCyrillicDetector(uint8_t aItems, |
michael@0 | 61 | const uint8_t ** aCyrillicClass, |
michael@0 | 62 | const char **aCharsets) { |
michael@0 | 63 | mItems = aItems; |
michael@0 | 64 | mCyrillicClass = aCyrillicClass; |
michael@0 | 65 | mCharsets = aCharsets; |
michael@0 | 66 | for(unsigned i=0;i<mItems;i++) |
michael@0 | 67 | mProb[i] = mLastCls[i] =0; |
michael@0 | 68 | mDone = false; |
michael@0 | 69 | } |
michael@0 | 70 | virtual ~nsCyrillicDetector() {} |
michael@0 | 71 | virtual void HandleData(const char* aBuf, uint32_t aLen); |
michael@0 | 72 | virtual void DataEnd(); |
michael@0 | 73 | protected: |
michael@0 | 74 | virtual void Report(const char* aCharset) = 0; |
michael@0 | 75 | bool mDone; |
michael@0 | 76 | |
michael@0 | 77 | private: |
michael@0 | 78 | uint8_t mItems; |
michael@0 | 79 | const uint8_t ** mCyrillicClass; |
michael@0 | 80 | const char** mCharsets; |
michael@0 | 81 | uint32_t mProb[NUM_CYR_CHARSET]; |
michael@0 | 82 | uint8_t mLastCls[NUM_CYR_CHARSET]; |
michael@0 | 83 | }; |
michael@0 | 84 | |
michael@0 | 85 | class nsCyrXPCOMDetector : |
michael@0 | 86 | public nsCyrillicDetector, |
michael@0 | 87 | public nsICharsetDetector |
michael@0 | 88 | { |
michael@0 | 89 | public: |
michael@0 | 90 | // nsISupports interface |
michael@0 | 91 | NS_DECL_ISUPPORTS |
michael@0 | 92 | nsCyrXPCOMDetector(uint8_t aItems, |
michael@0 | 93 | const uint8_t ** aCyrillicClass, |
michael@0 | 94 | const char **aCharsets); |
michael@0 | 95 | virtual ~nsCyrXPCOMDetector(); |
michael@0 | 96 | NS_IMETHOD Init(nsICharsetDetectionObserver* aObserver); |
michael@0 | 97 | NS_IMETHOD DoIt(const char* aBuf, uint32_t aLen, bool *oDontFeedMe); |
michael@0 | 98 | NS_IMETHOD Done(); |
michael@0 | 99 | protected: |
michael@0 | 100 | virtual void Report(const char* aCharset); |
michael@0 | 101 | private: |
michael@0 | 102 | nsCOMPtr<nsICharsetDetectionObserver> mObserver; |
michael@0 | 103 | }; |
michael@0 | 104 | |
michael@0 | 105 | class nsCyrXPCOMStringDetector : |
michael@0 | 106 | public nsCyrillicDetector, |
michael@0 | 107 | public nsIStringCharsetDetector |
michael@0 | 108 | { |
michael@0 | 109 | public: |
michael@0 | 110 | // nsISupports interface |
michael@0 | 111 | NS_DECL_ISUPPORTS |
michael@0 | 112 | nsCyrXPCOMStringDetector(uint8_t aItems, |
michael@0 | 113 | const uint8_t ** aCyrillicClass, |
michael@0 | 114 | const char **aCharsets); |
michael@0 | 115 | virtual ~nsCyrXPCOMStringDetector(); |
michael@0 | 116 | NS_IMETHOD DoIt(const char* aBuf, uint32_t aLen, |
michael@0 | 117 | const char** oCharset, nsDetectionConfident &oConf); |
michael@0 | 118 | protected: |
michael@0 | 119 | virtual void Report(const char* aCharset); |
michael@0 | 120 | private: |
michael@0 | 121 | nsCOMPtr<nsICharsetDetectionObserver> mObserver; |
michael@0 | 122 | const char* mResult; |
michael@0 | 123 | }; |
michael@0 | 124 | |
michael@0 | 125 | class nsRUProbDetector : public nsCyrXPCOMDetector |
michael@0 | 126 | { |
michael@0 | 127 | public: |
michael@0 | 128 | nsRUProbDetector() |
michael@0 | 129 | : nsCyrXPCOMDetector(5, gCyrillicCls, gRussian) {} |
michael@0 | 130 | }; |
michael@0 | 131 | |
michael@0 | 132 | class nsRUStringProbDetector : public nsCyrXPCOMStringDetector |
michael@0 | 133 | { |
michael@0 | 134 | public: |
michael@0 | 135 | nsRUStringProbDetector() |
michael@0 | 136 | : nsCyrXPCOMStringDetector(5, gCyrillicCls, gRussian) {} |
michael@0 | 137 | }; |
michael@0 | 138 | |
michael@0 | 139 | class nsUKProbDetector : public nsCyrXPCOMDetector |
michael@0 | 140 | { |
michael@0 | 141 | public: |
michael@0 | 142 | nsUKProbDetector() |
michael@0 | 143 | : nsCyrXPCOMDetector(5, gCyrillicCls, gUkrainian) {} |
michael@0 | 144 | }; |
michael@0 | 145 | |
michael@0 | 146 | class nsUKStringProbDetector : public nsCyrXPCOMStringDetector |
michael@0 | 147 | { |
michael@0 | 148 | public: |
michael@0 | 149 | nsUKStringProbDetector() |
michael@0 | 150 | : nsCyrXPCOMStringDetector(5, gCyrillicCls, gUkrainian) {} |
michael@0 | 151 | }; |
michael@0 | 152 | |
michael@0 | 153 | #endif |