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: 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 "nsComplexBreaker.h" |
michael@0 | 7 | |
michael@0 | 8 | #include <windows.h> |
michael@0 | 9 | |
michael@0 | 10 | #include <usp10.h> |
michael@0 | 11 | |
michael@0 | 12 | #include "nsUTF8Utils.h" |
michael@0 | 13 | #include "nsString.h" |
michael@0 | 14 | #include "nsTArray.h" |
michael@0 | 15 | |
michael@0 | 16 | void |
michael@0 | 17 | NS_GetComplexLineBreaks(const char16_t* aText, uint32_t aLength, |
michael@0 | 18 | uint8_t* aBreakBefore) |
michael@0 | 19 | { |
michael@0 | 20 | NS_ASSERTION(aText, "aText shouldn't be null"); |
michael@0 | 21 | |
michael@0 | 22 | int outItems = 0; |
michael@0 | 23 | HRESULT result; |
michael@0 | 24 | nsAutoTArray<SCRIPT_ITEM, 64> items; |
michael@0 | 25 | char16ptr_t text = aText; |
michael@0 | 26 | |
michael@0 | 27 | memset(aBreakBefore, false, aLength); |
michael@0 | 28 | |
michael@0 | 29 | if (!items.AppendElements(64)) |
michael@0 | 30 | return; |
michael@0 | 31 | |
michael@0 | 32 | do { |
michael@0 | 33 | result = ScriptItemize(text, aLength, items.Length(), nullptr, nullptr, |
michael@0 | 34 | items.Elements(), &outItems); |
michael@0 | 35 | |
michael@0 | 36 | if (result == E_OUTOFMEMORY) { |
michael@0 | 37 | if (!items.AppendElements(items.Length())) |
michael@0 | 38 | return; |
michael@0 | 39 | } |
michael@0 | 40 | } while (result == E_OUTOFMEMORY); |
michael@0 | 41 | |
michael@0 | 42 | for (int iItem = 0; iItem < outItems; ++iItem) { |
michael@0 | 43 | uint32_t endOffset = (iItem + 1 == outItems ? aLength : items[iItem + 1].iCharPos); |
michael@0 | 44 | uint32_t startOffset = items[iItem].iCharPos; |
michael@0 | 45 | nsAutoTArray<SCRIPT_LOGATTR, 64> sla; |
michael@0 | 46 | |
michael@0 | 47 | if (!sla.AppendElements(endOffset - startOffset)) |
michael@0 | 48 | return; |
michael@0 | 49 | |
michael@0 | 50 | if (ScriptBreak(text + startOffset, endOffset - startOffset, |
michael@0 | 51 | &items[iItem].a, sla.Elements()) < 0) |
michael@0 | 52 | return; |
michael@0 | 53 | |
michael@0 | 54 | for (uint32_t j=0; j+startOffset < endOffset; ++j) { |
michael@0 | 55 | aBreakBefore[j+startOffset] = sla[j].fSoftBreak; |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | } |