widget/qt/nsAppShell.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* vim:expandtab:shiftwidth=4:tabstop=4:
     3  */
     4 /* This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #include "nsAppShell.h"
     9 #include <QGuiApplication>
    10 #include <unistd.h>
    11 #include <fcntl.h>
    12 #include <errno.h>
    14 #include <qabstracteventdispatcher.h>
    15 #include <qthread.h>
    17 #include "prenv.h"
    18 #include "nsQAppInstance.h"
    20 #ifdef MOZ_LOGGING
    21 #define FORCE_PR_LOG
    22 #include "prlog.h"
    23 #endif
    25 #ifdef PR_LOGGING
    26 PRLogModuleInfo *gWidgetLog = nullptr;
    27 PRLogModuleInfo *gWidgetFocusLog = nullptr;
    28 PRLogModuleInfo *gWidgetIMLog = nullptr;
    29 PRLogModuleInfo *gWidgetDrawLog = nullptr;
    30 #endif
    32 static int sPokeEvent;
    34 nsAppShell::~nsAppShell()
    35 {
    36     nsQAppInstance::Release();
    37 }
    39 nsresult
    40 nsAppShell::Init()
    41 {
    42 #ifdef PR_LOGGING
    43     if (!gWidgetLog)
    44         gWidgetLog = PR_NewLogModule("Widget");
    45     if (!gWidgetFocusLog)
    46         gWidgetFocusLog = PR_NewLogModule("WidgetFocus");
    47     if (!gWidgetIMLog)
    48         gWidgetIMLog = PR_NewLogModule("WidgetIM");
    49     if (!gWidgetDrawLog)
    50         gWidgetDrawLog = PR_NewLogModule("WidgetDraw");
    51 #endif
    52     sPokeEvent = QEvent::registerEventType();
    54     nsQAppInstance::AddRef();
    56     return nsBaseAppShell::Init();
    57 }
    59 void
    60 nsAppShell::ScheduleNativeEventCallback()
    61 {
    62     QCoreApplication::postEvent(this,
    63                                 new QEvent((QEvent::Type) sPokeEvent));
    64 }
    67 bool
    68 nsAppShell::ProcessNextNativeEvent(bool mayWait)
    69 {
    70     QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents;
    72     if (mayWait)
    73         flags |= QEventLoop::WaitForMoreEvents;
    75     QAbstractEventDispatcher *dispatcher =  QAbstractEventDispatcher::instance(QThread::currentThread());
    76     if (!dispatcher)
    77         return false;
    79     return dispatcher->processEvents(flags) ? true : false;
    80 }
    82 bool
    83 nsAppShell::event (QEvent *e)
    84 {
    85     if (e->type() == sPokeEvent) {
    86         NativeEventCallback();
    87         return true;
    88     }
    90     return false;
    91 }

mercurial