Home | History | Annotate | Download | only in mac
      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 
      5 #ifndef BASE_MAC_SCOPED_SENDING_EVENT_H_
      6 #define BASE_MAC_SCOPED_SENDING_EVENT_H_
      7 
      8 #include "base/base_export.h"
      9 #include "base/basictypes.h"
     10 #include "base/message_loop/message_pump_mac.h"
     11 
     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
     17 // event loop.
     18 //
     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.
     23 
     24 @protocol CrAppControlProtocol<CrAppProtocol>
     25 - (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
     26 @end
     27 
     28 namespace base {
     29 namespace mac {
     30 
     31 class BASE_EXPORT ScopedSendingEvent {
     32  public:
     33   ScopedSendingEvent();
     34   ~ScopedSendingEvent();
     35 
     36  private:
     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.
     41 
     42   DISALLOW_COPY_AND_ASSIGN(ScopedSendingEvent);
     43 };
     44 
     45 }  // namespace mac
     46 }  // namespace base
     47 
     48 #endif  // BASE_MAC_SCOPED_SENDING_EVENT_H_
     49