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: 8; 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 | #ifndef mozilla_RegistryMessageUtils_h |
michael@0 | 7 | #define mozilla_RegistryMessageUtils_h |
michael@0 | 8 | |
michael@0 | 9 | #include "ipc/IPCMessageUtils.h" |
michael@0 | 10 | #include "nsString.h" |
michael@0 | 11 | |
michael@0 | 12 | struct SerializedURI |
michael@0 | 13 | { |
michael@0 | 14 | nsCString spec; |
michael@0 | 15 | nsCString charset; |
michael@0 | 16 | }; |
michael@0 | 17 | |
michael@0 | 18 | struct ChromePackage |
michael@0 | 19 | { |
michael@0 | 20 | nsCString package; |
michael@0 | 21 | SerializedURI contentBaseURI; |
michael@0 | 22 | SerializedURI localeBaseURI; |
michael@0 | 23 | SerializedURI skinBaseURI; |
michael@0 | 24 | uint32_t flags; |
michael@0 | 25 | }; |
michael@0 | 26 | |
michael@0 | 27 | struct ResourceMapping |
michael@0 | 28 | { |
michael@0 | 29 | nsCString resource; |
michael@0 | 30 | SerializedURI resolvedURI; |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | struct OverrideMapping |
michael@0 | 34 | { |
michael@0 | 35 | SerializedURI originalURI; |
michael@0 | 36 | SerializedURI overrideURI; |
michael@0 | 37 | }; |
michael@0 | 38 | |
michael@0 | 39 | namespace IPC { |
michael@0 | 40 | |
michael@0 | 41 | template<> |
michael@0 | 42 | struct ParamTraits<SerializedURI> |
michael@0 | 43 | { |
michael@0 | 44 | typedef SerializedURI paramType; |
michael@0 | 45 | |
michael@0 | 46 | static void Write(Message* aMsg, const paramType& aParam) |
michael@0 | 47 | { |
michael@0 | 48 | WriteParam(aMsg, aParam.spec); |
michael@0 | 49 | WriteParam(aMsg, aParam.charset); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | static bool Read(const Message* aMsg, void** aIter, paramType* aResult) |
michael@0 | 53 | { |
michael@0 | 54 | nsCString spec, charset; |
michael@0 | 55 | if (ReadParam(aMsg, aIter, &spec) && |
michael@0 | 56 | ReadParam(aMsg, aIter, &charset)) { |
michael@0 | 57 | aResult->spec = spec; |
michael@0 | 58 | aResult->charset = charset; |
michael@0 | 59 | return true; |
michael@0 | 60 | } |
michael@0 | 61 | return false; |
michael@0 | 62 | } |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | template <> |
michael@0 | 66 | struct ParamTraits<ChromePackage> |
michael@0 | 67 | { |
michael@0 | 68 | typedef ChromePackage paramType; |
michael@0 | 69 | |
michael@0 | 70 | static void Write(Message* aMsg, const paramType& aParam) |
michael@0 | 71 | { |
michael@0 | 72 | WriteParam(aMsg, aParam.package); |
michael@0 | 73 | WriteParam(aMsg, aParam.contentBaseURI); |
michael@0 | 74 | WriteParam(aMsg, aParam.localeBaseURI); |
michael@0 | 75 | WriteParam(aMsg, aParam.skinBaseURI); |
michael@0 | 76 | WriteParam(aMsg, aParam.flags); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | static bool Read(const Message* aMsg, void** aIter, paramType* aResult) |
michael@0 | 80 | { |
michael@0 | 81 | nsCString package; |
michael@0 | 82 | SerializedURI contentBaseURI, localeBaseURI, skinBaseURI; |
michael@0 | 83 | uint32_t flags; |
michael@0 | 84 | |
michael@0 | 85 | if (ReadParam(aMsg, aIter, &package) && |
michael@0 | 86 | ReadParam(aMsg, aIter, &contentBaseURI) && |
michael@0 | 87 | ReadParam(aMsg, aIter, &localeBaseURI) && |
michael@0 | 88 | ReadParam(aMsg, aIter, &skinBaseURI) && |
michael@0 | 89 | ReadParam(aMsg, aIter, &flags)) { |
michael@0 | 90 | aResult->package = package; |
michael@0 | 91 | aResult->contentBaseURI = contentBaseURI; |
michael@0 | 92 | aResult->localeBaseURI = localeBaseURI; |
michael@0 | 93 | aResult->skinBaseURI = skinBaseURI; |
michael@0 | 94 | aResult->flags = flags; |
michael@0 | 95 | return true; |
michael@0 | 96 | } |
michael@0 | 97 | return false; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | static void Log(const paramType& aParam, std::wstring* aLog) |
michael@0 | 101 | { |
michael@0 | 102 | aLog->append(StringPrintf(L"[%s, %s, %s, %s, %u]", aParam.package.get(), |
michael@0 | 103 | aParam.contentBaseURI.spec.get(), |
michael@0 | 104 | aParam.localeBaseURI.spec.get(), |
michael@0 | 105 | aParam.skinBaseURI.spec.get(), aParam.flags)); |
michael@0 | 106 | } |
michael@0 | 107 | }; |
michael@0 | 108 | |
michael@0 | 109 | template <> |
michael@0 | 110 | struct ParamTraits<ResourceMapping> |
michael@0 | 111 | { |
michael@0 | 112 | typedef ResourceMapping paramType; |
michael@0 | 113 | |
michael@0 | 114 | static void Write(Message* aMsg, const paramType& aParam) |
michael@0 | 115 | { |
michael@0 | 116 | WriteParam(aMsg, aParam.resource); |
michael@0 | 117 | WriteParam(aMsg, aParam.resolvedURI); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | static bool Read(const Message* aMsg, void** aIter, paramType* aResult) |
michael@0 | 121 | { |
michael@0 | 122 | nsCString resource; |
michael@0 | 123 | SerializedURI resolvedURI; |
michael@0 | 124 | |
michael@0 | 125 | if (ReadParam(aMsg, aIter, &resource) && |
michael@0 | 126 | ReadParam(aMsg, aIter, &resolvedURI)) { |
michael@0 | 127 | aResult->resource = resource; |
michael@0 | 128 | aResult->resolvedURI = resolvedURI; |
michael@0 | 129 | return true; |
michael@0 | 130 | } |
michael@0 | 131 | return false; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | static void Log(const paramType& aParam, std::wstring* aLog) |
michael@0 | 135 | { |
michael@0 | 136 | aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.resource.get(), |
michael@0 | 137 | aParam.resolvedURI.spec.get())); |
michael@0 | 138 | } |
michael@0 | 139 | }; |
michael@0 | 140 | |
michael@0 | 141 | template <> |
michael@0 | 142 | struct ParamTraits<OverrideMapping> |
michael@0 | 143 | { |
michael@0 | 144 | typedef OverrideMapping paramType; |
michael@0 | 145 | |
michael@0 | 146 | static void Write(Message* aMsg, const paramType& aParam) |
michael@0 | 147 | { |
michael@0 | 148 | WriteParam(aMsg, aParam.originalURI); |
michael@0 | 149 | WriteParam(aMsg, aParam.overrideURI); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | static bool Read(const Message* aMsg, void** aIter, paramType* aResult) |
michael@0 | 153 | { |
michael@0 | 154 | SerializedURI originalURI; |
michael@0 | 155 | SerializedURI overrideURI; |
michael@0 | 156 | |
michael@0 | 157 | if (ReadParam(aMsg, aIter, &originalURI) && |
michael@0 | 158 | ReadParam(aMsg, aIter, &overrideURI)) { |
michael@0 | 159 | aResult->originalURI = originalURI; |
michael@0 | 160 | aResult->overrideURI = overrideURI; |
michael@0 | 161 | return true; |
michael@0 | 162 | } |
michael@0 | 163 | return false; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | static void Log(const paramType& aParam, std::wstring* aLog) |
michael@0 | 167 | { |
michael@0 | 168 | aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.originalURI.spec.get(), |
michael@0 | 169 | aParam.overrideURI.spec.get())); |
michael@0 | 170 | } |
michael@0 | 171 | }; |
michael@0 | 172 | |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | #endif // RegistryMessageUtils_h |