OLD | NEW |
(Empty) | |
| 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 #import "content/public/browser/event_hook_application_mac.h" |
| 6 |
| 7 #import "base/mac/scoped_sending_event.h" |
| 8 #import "base/logging.h" |
| 9 |
| 10 @implementation EventHookApplication |
| 11 |
| 12 // Initialize NSApplication using the custom subclass. Check whether NSApp |
| 13 // was already initialized using another class, because that would break |
| 14 // some things. |
| 15 + (NSApplication*)sharedApplication { |
| 16 NSApplication* app = [super sharedApplication]; |
| 17 |
| 18 // +sharedApplication initializes the global NSApp, so if a specific |
| 19 // NSApplication subclass is requested, require that to be the one |
| 20 // delivered. The practical effect is to require a consistent NSApp |
| 21 // across the executable. |
| 22 CHECK([NSApp isKindOfClass:self]) |
| 23 << "NSApp must be of type " << [[self className] UTF8String] |
| 24 << ", not " << [[NSApp className] UTF8String]; |
| 25 |
| 26 return app; |
| 27 } |
| 28 |
| 29 - (id)init { |
| 30 if ((self = [super init])) { |
| 31 eventHooks_.reset([[NSMutableArray alloc] init]); |
| 32 } |
| 33 return self; |
| 34 } |
| 35 |
| 36 - (void)addEventHook:(id<EventHookProtocol>)handler { |
| 37 [eventHooks_ addObject:handler]; |
| 38 } |
| 39 |
| 40 - (void)removeEventHook:(id<EventHookProtocol>)handler { |
| 41 [eventHooks_ removeObject:handler]; |
| 42 } |
| 43 |
| 44 - (void)sendEvent:(NSEvent*)event { |
| 45 base::mac::ScopedSendingEvent sendingEventScoper; |
| 46 for (id<EventHookProtocol> handler in eventHooks_.get()) { |
| 47 [handler hookForEvent:event]; |
| 48 } |
| 49 [super sendEvent:event]; |
| 50 } |
| 51 |
| 52 @end |
OLD | NEW |