1 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * Runs the main native Cocoa run loop, interrupting it as needed to process
14 #import <AppKit/NSApplication.h>
16 #include "nsBaseAppShell.h"
22 class nsAvailableMemoryWatcherBase
;
27 // Subclass of NSApplication for filtering out certain events.
28 @interface GeckoNSApplication
: NSApplication
{
32 @
class AppShellDelegate
;
34 class nsAppShell
: public nsBaseAppShell
{
36 NS_IMETHOD
ResumeNative(void) override
;
42 NS_IMETHOD
Run(void) override
;
43 NS_IMETHOD
Exit(void) override
;
44 NS_IMETHOD
OnProcessNextEvent(nsIThreadInternal
* aThread
, bool aMayWait
) override
;
45 NS_IMETHOD
AfterProcessNextEvent(nsIThreadInternal
* aThread
, bool aEventWasProcessed
) override
;
47 void OnRunLoopActivityChanged(CFRunLoopActivity aActivity
);
49 // public only to be visible to Objective-C code that must call it
52 static void OnMemoryPressureChanged(dispatch_source_memorypressure_flags_t aPressureLevel
);
55 virtual ~nsAppShell();
57 virtual void ScheduleNativeEventCallback() override
;
58 virtual bool ProcessNextNativeEvent(bool aMayWait
) override
;
60 void InitMemoryPressureObserver();
62 static void ProcessGeckoEvents(void* aInfo
);
65 CFMutableArrayRef mAutoreleasePools
;
67 AppShellDelegate
* mDelegate
;
68 CFRunLoopRef mCFRunLoop
;
69 CFRunLoopSourceRef mCFRunLoopSource
;
71 // An observer for the profiler that is notified when the event loop enters
72 // and exits the waiting state.
73 CFRunLoopObserverRef mCFRunLoopObserver
;
75 // Non-null while the native event loop is in the waiting state.
76 ProfilingStack
* mProfilingStackWhileWaiting
= nullptr;
78 // For getting notifications from the OS about memory pressure state changes.
79 dispatch_source_t mMemoryPressureSource
= nullptr;
81 bool mRunningEventLoop
;
84 bool mSkippedNativeCallback
;
85 bool mRunningCocoaEmbedded
;
87 int32_t mNativeEventCallbackDepth
;
88 // Can be set from different threads, so must be modified atomically
89 int32_t mNativeEventScheduledDepth
;
92 #endif // nsAppShell_h_