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
{
30 @
property(readonly
) BOOL didLaunch
;
33 @
class AppShellDelegate
;
35 class nsAppShell
: public nsBaseAppShell
{
37 NS_IMETHOD
ResumeNative(void) override
;
43 NS_IMETHOD
Run(void) override
;
44 NS_IMETHOD
Exit(void) override
;
45 NS_IMETHOD
OnProcessNextEvent(nsIThreadInternal
* aThread
,
46 bool aMayWait
) override
;
47 NS_IMETHOD
AfterProcessNextEvent(nsIThreadInternal
* aThread
,
48 bool aEventWasProcessed
) override
;
50 void OnRunLoopActivityChanged(CFRunLoopActivity aActivity
);
52 // public only to be visible to Objective-C code that must call it
55 static void OnMemoryPressureChanged(
56 dispatch_source_memorypressure_flags_t aPressureLevel
);
59 virtual ~nsAppShell();
61 virtual void ScheduleNativeEventCallback() override
;
62 virtual bool ProcessNextNativeEvent(bool aMayWait
) override
;
64 void InitMemoryPressureObserver();
66 static void ProcessGeckoEvents(void* aInfo
);
69 CFMutableArrayRef mAutoreleasePools
;
71 AppShellDelegate
* mDelegate
;
72 CFRunLoopRef mCFRunLoop
;
73 CFRunLoopSourceRef mCFRunLoopSource
;
75 // An observer for the profiler that is notified when the event loop enters
76 // and exits the waiting state.
77 CFRunLoopObserverRef mCFRunLoopObserver
;
79 // Non-null while the native event loop is in the waiting state.
80 ProfilingStack
* mProfilingStackWhileWaiting
= nullptr;
82 // For getting notifications from the OS about memory pressure state changes.
83 dispatch_source_t mMemoryPressureSource
= nullptr;
85 bool mRunningEventLoop
;
88 bool mSkippedNativeCallback
;
89 bool mRunningCocoaEmbedded
;
91 int32_t mNativeEventCallbackDepth
;
92 // Can be set from different threads, so must be modified atomically
93 int32_t mNativeEventScheduledDepth
;
96 #endif // nsAppShell_h_