scoped_sending_event.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/macros.h"
  8. #include "base/message_loop/message_pump_mac.h"
  9. // Nested event loops can pump IPC messages, including
  10. // script-initiated tab closes, which could release objects that the
  11. // nested event loop might message. CrAppProtocol defines how to ask
  12. // the embedding NSApplication subclass if an event is currently being
  13. // handled, in which case such closes are deferred to the top-level
  14. // event loop.
  15. //
  16. // ScopedSendingEvent allows script-initiated event loops to work like
  17. // a nested event loop, as such events do not arrive via -sendEvent:.
  18. // CrAppControlProtocol lets ScopedSendingEvent tell the embedding
  19. // NSApplication what to return from -handlingSendEvent.
  20. @protocol CrAppControlProtocol<CrAppProtocol>
  21. - (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
  22. @end
  23. namespace base {
  24. namespace mac {
  25. class BASE_EXPORT ScopedSendingEvent {
  26. public:
  27. ScopedSendingEvent();
  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. DISALLOW_COPY_AND_ASSIGN(ScopedSendingEvent);
  35. };
  36. } // namespace mac
  37. } // namespace base
  38. #endif // BASE_MAC_SCOPED_SENDING_EVENT_H_