1*6777b538SAndroid Build Coastguard Worker // Copyright 2012 The Chromium Authors 2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file. 4*6777b538SAndroid Build Coastguard Worker 5*6777b538SAndroid Build Coastguard Worker #ifndef BASE_MAC_SCOPED_SENDING_EVENT_H_ 6*6777b538SAndroid Build Coastguard Worker #define BASE_MAC_SCOPED_SENDING_EVENT_H_ 7*6777b538SAndroid Build Coastguard Worker 8*6777b538SAndroid Build Coastguard Worker #include "base/base_export.h" 9*6777b538SAndroid Build Coastguard Worker #include "base/message_loop/message_pump_apple.h" 10*6777b538SAndroid Build Coastguard Worker 11*6777b538SAndroid Build Coastguard Worker // Nested event loops can pump IPC messages, including 12*6777b538SAndroid Build Coastguard Worker // script-initiated tab closes, which could release objects that the 13*6777b538SAndroid Build Coastguard Worker // nested event loop might message. CrAppProtocol defines how to ask 14*6777b538SAndroid Build Coastguard Worker // the embedding NSApplication subclass if an event is currently being 15*6777b538SAndroid Build Coastguard Worker // handled, in which case such closes are deferred to the top-level 16*6777b538SAndroid Build Coastguard Worker // event loop. 17*6777b538SAndroid Build Coastguard Worker // 18*6777b538SAndroid Build Coastguard Worker // ScopedSendingEvent allows script-initiated event loops to work like 19*6777b538SAndroid Build Coastguard Worker // a nested event loop, as such events do not arrive via -sendEvent:. 20*6777b538SAndroid Build Coastguard Worker // CrAppControlProtocol lets ScopedSendingEvent tell the embedding 21*6777b538SAndroid Build Coastguard Worker // NSApplication what to return from -handlingSendEvent. 22*6777b538SAndroid Build Coastguard Worker 23*6777b538SAndroid Build Coastguard Worker @protocol CrAppControlProtocol<CrAppProtocol> 24*6777b538SAndroid Build Coastguard Worker - (void)setHandlingSendEvent:(BOOL)handlingSendEvent; 25*6777b538SAndroid Build Coastguard Worker @end 26*6777b538SAndroid Build Coastguard Worker 27*6777b538SAndroid Build Coastguard Worker namespace base::mac { 28*6777b538SAndroid Build Coastguard Worker 29*6777b538SAndroid Build Coastguard Worker class BASE_EXPORT ScopedSendingEvent { 30*6777b538SAndroid Build Coastguard Worker public: 31*6777b538SAndroid Build Coastguard Worker ScopedSendingEvent(); 32*6777b538SAndroid Build Coastguard Worker 33*6777b538SAndroid Build Coastguard Worker ScopedSendingEvent(const ScopedSendingEvent&) = delete; 34*6777b538SAndroid Build Coastguard Worker ScopedSendingEvent& operator=(const ScopedSendingEvent&) = delete; 35*6777b538SAndroid Build Coastguard Worker 36*6777b538SAndroid Build Coastguard Worker ~ScopedSendingEvent(); 37*6777b538SAndroid Build Coastguard Worker 38*6777b538SAndroid Build Coastguard Worker private: 39*6777b538SAndroid Build Coastguard Worker // The NSApp in control at the time the constructor was run, to be 40*6777b538SAndroid Build Coastguard Worker // sure the |handling_| setting is restored appropriately. 41*6777b538SAndroid Build Coastguard Worker NSObject<CrAppControlProtocol>* app_; 42*6777b538SAndroid Build Coastguard Worker BOOL handling_; // Value of -[app_ handlingSendEvent] at construction. 43*6777b538SAndroid Build Coastguard Worker }; 44*6777b538SAndroid Build Coastguard Worker 45*6777b538SAndroid Build Coastguard Worker } // namespace base::mac 46*6777b538SAndroid Build Coastguard Worker 47*6777b538SAndroid Build Coastguard Worker #endif // BASE_MAC_SCOPED_SENDING_EVENT_H_ 48