scoped_sending_event.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.
  4. #ifndef BASE_MAC_SCOPED_SENDING_EVENT_H_
  5. #define BASE_MAC_SCOPED_SENDING_EVENT_H_
  6. #include "base/base_export.h"
  7. #include "base/message_loop/message_pump_mac.h"
  8. // Nested event loops can pump IPC messages, including
  9. // script-initiated tab closes, which could release objects that the
  10. // nested event loop might message. CrAppProtocol defines how to ask
  11. // the embedding NSApplication subclass if an event is currently being
  12. // handled, in which case such closes are deferred to the top-level
  13. // event loop.
  14. //
  15. // ScopedSendingEvent allows script-initiated event loops to work like
  16. // a nested event loop, as such events do not arrive via -sendEvent:.
  17. // CrAppControlProtocol lets ScopedSendingEvent tell the embedding
  18. // NSApplication what to return from -handlingSendEvent.
  19. @protocol CrAppControlProtocol<CrAppProtocol>
  20. - (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
  21. @end
  22. namespace base::mac {
  23. class BASE_EXPORT ScopedSendingEvent {
  24. public:
  25. ScopedSendingEvent();
  26. ScopedSendingEvent(const ScopedSendingEvent&) = delete;
  27. ScopedSendingEvent& operator=(const ScopedSendingEvent&) = delete;
  28. ~ScopedSendingEvent();
  29. private:
  30. // The NSApp in control at the time the constructor was run, to be
  31. // sure the |handling_| setting is restored appropriately.
  32. NSObject<CrAppControlProtocol>* app_;
  33. BOOL handling_; // Value of -[app_ handlingSendEvent] at construction.
  34. };
  35. } // namespace base::mac
  36. #endif // BASE_MAC_SCOPED_SENDING_EVENT_H_