1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_MAC_SCOPED_SENDING_EVENT_H_
6 #define BASE_MAC_SCOPED_SENDING_EVENT_H_
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "base/message_loop/message_pump_mac.h"
12 // Nested event loops can pump IPC messages, including
13 // script-initiated tab closes, which could release objects that the
14 // nested event loop might message. CrAppProtocol defines how to ask
15 // the embedding NSApplication subclass if an event is currently being
16 // handled, in which case such closes are deferred to the top-level
19 // ScopedSendingEvent allows script-initiated event loops to work like
20 // a nested event loop, as such events do not arrive via -sendEvent:.
21 // CrAppControlProtocol lets ScopedSendingEvent tell the embedding
22 // NSApplication what to return from -handlingSendEvent.
24 @protocol CrAppControlProtocol
<CrAppProtocol
>
25 - (void)setHandlingSendEvent
:(BOOL
)handlingSendEvent
;
31 class BASE_EXPORT ScopedSendingEvent
{
34 ~ScopedSendingEvent();
37 // The NSApp in control at the time the constructor was run, to be
38 // sure the |handling_| setting is restored appropriately.
39 NSObject
<CrAppControlProtocol
>* app_
;
40 BOOL handling_
; // Value of -[app_ handlingSendEvent] at construction.
42 DISALLOW_COPY_AND_ASSIGN(ScopedSendingEvent
);
48 #endif // BASE_MAC_SCOPED_SENDING_EVENT_H_