1 // Copyright (c) 2009 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 #import "chrome_application_mac.h" 6 7 #include "base/logging.h" 8 9 @interface CrApplication () 10 @property(readwrite, 11 getter=isHandlingSendEvent, 12 nonatomic) BOOL handlingSendEvent; 13 @end 14 15 @implementation CrApplication 16 @synthesize handlingSendEvent = handlingSendEvent_; 17 18 // Initialize NSApplication using the custom subclass. Check whether NSApp 19 // was already initialized using another class, because that would break 20 // some things. 21 + (NSApplication*)sharedApplication { 22 NSApplication* app = [super sharedApplication]; 23 if (![NSApp isKindOfClass:self]) { 24 LOG(ERROR) << "NSApp should be of type " << [[self className] UTF8String] 25 << ", not " << [[NSApp className] UTF8String]; 26 DCHECK(false) << "NSApp is of wrong type"; 27 } 28 return app; 29 } 30 31 - (void)sendEvent:(NSEvent*)event { 32 chrome_application_mac::ScopedSendingEvent sendingEventScoper; 33 [super sendEvent:event]; 34 } 35 36 @end 37 38 namespace chrome_application_mac { 39 40 ScopedSendingEvent::ScopedSendingEvent() 41 : app_(static_cast<CrApplication*>([CrApplication sharedApplication])), 42 handling_([app_ isHandlingSendEvent]) { 43 [app_ setHandlingSendEvent:YES]; 44 } 45 46 ScopedSendingEvent::~ScopedSendingEvent() { 47 [app_ setHandlingSendEvent:handling_]; 48 } 49 50 } // namespace chrome_application_mac 51