Bug 1776444 [wpt PR 34582] - Revert "Add TimedHTMLParserBudget to fieldtrial_testing_...
[gecko.git] / widget / cocoa / nsAppShell.h
blob009768794f6e788241915789c5312c6755d5197a
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/. */
6 /*
7 * Runs the main native Cocoa run loop, interrupting it as needed to process
8 * Gecko events.
9 */
11 #ifndef nsAppShell_h_
12 #define nsAppShell_h_
14 #import <AppKit/NSApplication.h>
16 #include "nsBaseAppShell.h"
17 #include "nsTArray.h"
19 class ProfilingStack;
21 namespace mozilla {
22 class nsAvailableMemoryWatcherBase;
25 // GeckoNSApplication
27 // Subclass of NSApplication for filtering out certain events.
28 @interface GeckoNSApplication : NSApplication {
30 @end
32 @class AppShellDelegate;
34 class nsAppShell : public nsBaseAppShell {
35 public:
36 NS_IMETHOD ResumeNative(void) override;
38 nsAppShell();
40 nsresult Init();
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
50 void WillTerminate();
52 static void OnMemoryPressureChanged(dispatch_source_memorypressure_flags_t aPressureLevel);
54 protected:
55 virtual ~nsAppShell();
57 virtual void ScheduleNativeEventCallback() override;
58 virtual bool ProcessNextNativeEvent(bool aMayWait) override;
60 void InitMemoryPressureObserver();
62 static void ProcessGeckoEvents(void* aInfo);
64 protected:
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;
82 bool mStarted;
83 bool mTerminated;
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_