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 | * vim: sw=2 ts=8 et : |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "X11Util.h" |
michael@0 | 9 | #include "nsDebug.h" // for NS_ASSERTION, etc |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | |
michael@0 | 13 | void |
michael@0 | 14 | FindVisualAndDepth(Display* aDisplay, VisualID aVisualID, |
michael@0 | 15 | Visual** aVisual, int* aDepth) |
michael@0 | 16 | { |
michael@0 | 17 | const Screen* screen = DefaultScreenOfDisplay(aDisplay); |
michael@0 | 18 | |
michael@0 | 19 | for (int d = 0; d < screen->ndepths; d++) { |
michael@0 | 20 | Depth *d_info = &screen->depths[d]; |
michael@0 | 21 | for (int v = 0; v < d_info->nvisuals; v++) { |
michael@0 | 22 | Visual* visual = &d_info->visuals[v]; |
michael@0 | 23 | if (visual->visualid == aVisualID) { |
michael@0 | 24 | *aVisual = visual; |
michael@0 | 25 | *aDepth = d_info->depth; |
michael@0 | 26 | return; |
michael@0 | 27 | } |
michael@0 | 28 | } |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | NS_ASSERTION(aVisualID == None, "VisualID not on Screen."); |
michael@0 | 32 | *aVisual = nullptr; |
michael@0 | 33 | *aDepth = 0; |
michael@0 | 34 | return; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | void |
michael@0 | 38 | FinishX(Display* aDisplay) |
michael@0 | 39 | { |
michael@0 | 40 | unsigned long lastRequest = NextRequest(aDisplay) - 1; |
michael@0 | 41 | if (lastRequest == LastKnownRequestProcessed(aDisplay)) |
michael@0 | 42 | return; |
michael@0 | 43 | |
michael@0 | 44 | XSync(aDisplay, False); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | ScopedXErrorHandler::ErrorEvent* ScopedXErrorHandler::sXErrorPtr; |
michael@0 | 48 | |
michael@0 | 49 | int |
michael@0 | 50 | ScopedXErrorHandler::ErrorHandler(Display *, XErrorEvent *ev) |
michael@0 | 51 | { |
michael@0 | 52 | // only record the error if no error was previously recorded. |
michael@0 | 53 | // this means that in case of multiple errors, it's the first error that we report. |
michael@0 | 54 | if (!sXErrorPtr->mError.error_code) |
michael@0 | 55 | sXErrorPtr->mError = *ev; |
michael@0 | 56 | return 0; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | ScopedXErrorHandler::ScopedXErrorHandler() |
michael@0 | 60 | { |
michael@0 | 61 | // let sXErrorPtr point to this object's mXError object, but don't reset this mXError object! |
michael@0 | 62 | // think of the case of nested ScopedXErrorHandler's. |
michael@0 | 63 | mOldXErrorPtr = sXErrorPtr; |
michael@0 | 64 | sXErrorPtr = &mXError; |
michael@0 | 65 | mOldErrorHandler = XSetErrorHandler(ErrorHandler); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | ScopedXErrorHandler::~ScopedXErrorHandler() |
michael@0 | 69 | { |
michael@0 | 70 | sXErrorPtr = mOldXErrorPtr; |
michael@0 | 71 | XSetErrorHandler(mOldErrorHandler); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | bool |
michael@0 | 75 | ScopedXErrorHandler::SyncAndGetError(Display *dpy, XErrorEvent *ev) |
michael@0 | 76 | { |
michael@0 | 77 | FinishX(dpy); |
michael@0 | 78 | |
michael@0 | 79 | bool retval = mXError.mError.error_code != 0; |
michael@0 | 80 | if (ev) |
michael@0 | 81 | *ev = mXError.mError; |
michael@0 | 82 | mXError = ErrorEvent(); // reset |
michael@0 | 83 | return retval; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | } // namespace mozilla |