Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
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: 4 -*- */ |
michael@0 | 2 | /* vim:expandtab:shiftwidth=4:tabstop=4: |
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 "nsAppShell.h" |
michael@0 | 9 | #include <QGuiApplication> |
michael@0 | 10 | #include <unistd.h> |
michael@0 | 11 | #include <fcntl.h> |
michael@0 | 12 | #include <errno.h> |
michael@0 | 13 | |
michael@0 | 14 | #include <qabstracteventdispatcher.h> |
michael@0 | 15 | #include <qthread.h> |
michael@0 | 16 | |
michael@0 | 17 | #include "prenv.h" |
michael@0 | 18 | #include "nsQAppInstance.h" |
michael@0 | 19 | |
michael@0 | 20 | #ifdef MOZ_LOGGING |
michael@0 | 21 | #define FORCE_PR_LOG |
michael@0 | 22 | #include "prlog.h" |
michael@0 | 23 | #endif |
michael@0 | 24 | |
michael@0 | 25 | #ifdef PR_LOGGING |
michael@0 | 26 | PRLogModuleInfo *gWidgetLog = nullptr; |
michael@0 | 27 | PRLogModuleInfo *gWidgetFocusLog = nullptr; |
michael@0 | 28 | PRLogModuleInfo *gWidgetIMLog = nullptr; |
michael@0 | 29 | PRLogModuleInfo *gWidgetDrawLog = nullptr; |
michael@0 | 30 | #endif |
michael@0 | 31 | |
michael@0 | 32 | static int sPokeEvent; |
michael@0 | 33 | |
michael@0 | 34 | nsAppShell::~nsAppShell() |
michael@0 | 35 | { |
michael@0 | 36 | nsQAppInstance::Release(); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | nsresult |
michael@0 | 40 | nsAppShell::Init() |
michael@0 | 41 | { |
michael@0 | 42 | #ifdef PR_LOGGING |
michael@0 | 43 | if (!gWidgetLog) |
michael@0 | 44 | gWidgetLog = PR_NewLogModule("Widget"); |
michael@0 | 45 | if (!gWidgetFocusLog) |
michael@0 | 46 | gWidgetFocusLog = PR_NewLogModule("WidgetFocus"); |
michael@0 | 47 | if (!gWidgetIMLog) |
michael@0 | 48 | gWidgetIMLog = PR_NewLogModule("WidgetIM"); |
michael@0 | 49 | if (!gWidgetDrawLog) |
michael@0 | 50 | gWidgetDrawLog = PR_NewLogModule("WidgetDraw"); |
michael@0 | 51 | #endif |
michael@0 | 52 | sPokeEvent = QEvent::registerEventType(); |
michael@0 | 53 | |
michael@0 | 54 | nsQAppInstance::AddRef(); |
michael@0 | 55 | |
michael@0 | 56 | return nsBaseAppShell::Init(); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | void |
michael@0 | 60 | nsAppShell::ScheduleNativeEventCallback() |
michael@0 | 61 | { |
michael@0 | 62 | QCoreApplication::postEvent(this, |
michael@0 | 63 | new QEvent((QEvent::Type) sPokeEvent)); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | bool |
michael@0 | 68 | nsAppShell::ProcessNextNativeEvent(bool mayWait) |
michael@0 | 69 | { |
michael@0 | 70 | QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents; |
michael@0 | 71 | |
michael@0 | 72 | if (mayWait) |
michael@0 | 73 | flags |= QEventLoop::WaitForMoreEvents; |
michael@0 | 74 | |
michael@0 | 75 | QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance(QThread::currentThread()); |
michael@0 | 76 | if (!dispatcher) |
michael@0 | 77 | return false; |
michael@0 | 78 | |
michael@0 | 79 | return dispatcher->processEvents(flags) ? true : false; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | bool |
michael@0 | 83 | nsAppShell::event (QEvent *e) |
michael@0 | 84 | { |
michael@0 | 85 | if (e->type() == sPokeEvent) { |
michael@0 | 86 | NativeEventCallback(); |
michael@0 | 87 | return true; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | return false; |
michael@0 | 91 | } |