|
Packit |
f0b94e |
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
|
Packit |
f0b94e |
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
Packit |
f0b94e |
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
Packit |
f0b94e |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#ifndef nsBaseAppShell_h__
|
|
Packit |
f0b94e |
#define nsBaseAppShell_h__
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#include "mozilla/Atomics.h"
|
|
Packit |
f0b94e |
#include "nsIAppShell.h"
|
|
Packit |
f0b94e |
#include "nsIThreadInternal.h"
|
|
Packit |
f0b94e |
#include "nsIObserver.h"
|
|
Packit |
f0b94e |
#include "nsIRunnable.h"
|
|
Packit |
f0b94e |
#include "nsCOMPtr.h"
|
|
Packit |
f0b94e |
#include "nsTArray.h"
|
|
Packit |
f0b94e |
#include "prinrval.h"
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* A singleton that manages the UI thread's event queue. Subclass this class
|
|
Packit |
f0b94e |
* to enable platform-specific event queue support.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
class nsBaseAppShell : public nsIAppShell,
|
|
Packit |
f0b94e |
public nsIThreadObserver,
|
|
Packit |
f0b94e |
public nsIObserver {
|
|
Packit |
f0b94e |
public:
|
|
Packit |
f0b94e |
NS_DECL_THREADSAFE_ISUPPORTS
|
|
Packit |
f0b94e |
NS_DECL_NSIAPPSHELL
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
NS_DECL_NSITHREADOBSERVER
|
|
Packit |
f0b94e |
NS_DECL_NSIOBSERVER
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
nsBaseAppShell();
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
protected:
|
|
Packit |
f0b94e |
virtual ~nsBaseAppShell();
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* This method is called by subclasses when the app shell singleton is
|
|
Packit |
f0b94e |
* instantiated.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
nsresult Init();
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* Called by subclasses from a native event. See ScheduleNativeEventCallback.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
void NativeEventCallback();
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* Make a decision as to whether or not NativeEventCallback will
|
|
Packit |
f0b94e |
* trigger gecko event processing when there are pending gecko
|
|
Packit |
f0b94e |
* events.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
virtual void DoProcessMoreGeckoEvents();
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* Implemented by subclasses. Invoke NativeEventCallback from a native
|
|
Packit |
f0b94e |
* event. This method may be called on any thread.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
virtual void ScheduleNativeEventCallback() = 0;
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* Implemented by subclasses. Process the next native event. Only wait for
|
|
Packit |
f0b94e |
* the next native event if mayWait is true. This method is only called on
|
|
Packit |
f0b94e |
* the main application thread.
|
|
Packit |
f0b94e |
*
|
|
Packit |
f0b94e |
* @param mayWait
|
|
Packit |
f0b94e |
* If "true", then this method may wait if necessary for the next available
|
|
Packit |
f0b94e |
* native event. DispatchNativeEvent may be called to unblock a call to
|
|
Packit |
f0b94e |
* ProcessNextNativeEvent that is waiting.
|
|
Packit |
f0b94e |
* @return
|
|
Packit |
f0b94e |
* This method returns "true" if a native event was processed.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
virtual bool ProcessNextNativeEvent(bool mayWait) = 0;
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
int32_t mSuspendNativeCount;
|
|
Packit |
f0b94e |
uint32_t mEventloopNestingLevel;
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
private:
|
|
Packit |
f0b94e |
bool DoProcessNextNativeEvent(bool mayWait);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
bool DispatchDummyEvent(nsIThread* target);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
void IncrementEventloopNestingLevel();
|
|
Packit |
f0b94e |
void DecrementEventloopNestingLevel();
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
nsCOMPtr<nsIRunnable> mDummyEvent;
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* mBlockedWait points back to a slot that controls the wait loop in
|
|
Packit |
f0b94e |
* an outer OnProcessNextEvent invocation. Nested calls always set
|
|
Packit |
f0b94e |
* it to false to unblock an outer loop, since all events may
|
|
Packit |
f0b94e |
* have been consumed by the inner event loop(s).
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
bool* mBlockedWait;
|
|
Packit |
f0b94e |
int32_t mFavorPerf;
|
|
Packit |
f0b94e |
mozilla::Atomic<bool> mNativeEventPending;
|
|
Packit |
f0b94e |
PRIntervalTime mStarvationDelay;
|
|
Packit |
f0b94e |
PRIntervalTime mSwitchTime;
|
|
Packit |
f0b94e |
PRIntervalTime mLastNativeEventTime;
|
|
Packit |
f0b94e |
enum EventloopNestingState {
|
|
Packit |
f0b94e |
eEventloopNone, // top level thread execution
|
|
Packit |
f0b94e |
eEventloopXPCOM, // innermost native event loop is ProcessNextNativeEvent
|
|
Packit |
f0b94e |
eEventloopOther // innermost native event loop is a native library/plugin
|
|
Packit |
f0b94e |
// etc
|
|
Packit |
f0b94e |
};
|
|
Packit |
f0b94e |
EventloopNestingState mEventloopNestingState;
|
|
Packit |
f0b94e |
bool mRunning;
|
|
Packit |
f0b94e |
bool mExiting;
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* mBlockNativeEvent blocks the appshell from processing native events.
|
|
Packit |
f0b94e |
* It is set to true while a nested native event loop (eEventloopOther)
|
|
Packit |
f0b94e |
* is processing gecko events in NativeEventCallback(), thus queuing up
|
|
Packit |
f0b94e |
* native events until we return to that loop (bug 420148).
|
|
Packit |
f0b94e |
* We force mBlockNativeEvent to false in case handling one of the gecko
|
|
Packit |
f0b94e |
* events spins up a nested XPCOM event loop (eg. modal window) which would
|
|
Packit |
f0b94e |
* otherwise lead to a "deadlock" where native events aren't processed at all.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
bool mBlockNativeEvent;
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* Tracks whether we have processed any gecko events in NativeEventCallback so
|
|
Packit |
f0b94e |
* that we can avoid erroneously entering a blocking loop waiting for gecko
|
|
Packit |
f0b94e |
* events to show up during OnProcessNextEvent. This is required because on
|
|
Packit |
f0b94e |
* OS X ProcessGeckoEvents may be invoked inside the context of
|
|
Packit |
f0b94e |
* ProcessNextNativeEvent and may result in NativeEventCallback being invoked
|
|
Packit |
f0b94e |
* and in turn invoking NS_ProcessPendingEvents. Because
|
|
Packit |
f0b94e |
* ProcessNextNativeEvent may be invoked prior to the NS_HasPendingEvents
|
|
Packit |
f0b94e |
* waiting loop, this is the only way to make the loop aware that events may
|
|
Packit |
f0b94e |
* have been processed.
|
|
Packit |
f0b94e |
*
|
|
Packit |
f0b94e |
* This variable is set to false in OnProcessNextEvent prior to the first
|
|
Packit |
f0b94e |
* call to DoProcessNextNativeEvent. It is set to true by
|
|
Packit |
f0b94e |
* NativeEventCallback after calling NS_ProcessPendingEvents.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
bool mProcessedGeckoEvents;
|
|
Packit |
f0b94e |
};
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#endif // nsBaseAppShell_h__
|