Index: content/public/browser/event_hook_application_mac.mm |
diff --git a/content/public/browser/event_hook_application_mac.mm b/content/public/browser/event_hook_application_mac.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e21c801c17fd78ba6c4fde8e071cf51d306b25e8 |
--- /dev/null |
+++ b/content/public/browser/event_hook_application_mac.mm |
@@ -0,0 +1,52 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import "content/public/browser/event_hook_application_mac.h" |
+ |
+#import "base/mac/scoped_sending_event.h" |
+#import "base/logging.h" |
+ |
+@implementation EventHookApplication |
+ |
+// Initialize NSApplication using the custom subclass. Check whether NSApp |
+// was already initialized using another class, because that would break |
+// some things. |
++ (NSApplication*)sharedApplication { |
+ NSApplication* app = [super sharedApplication]; |
+ |
+ // +sharedApplication initializes the global NSApp, so if a specific |
+ // NSApplication subclass is requested, require that to be the one |
+ // delivered. The practical effect is to require a consistent NSApp |
+ // across the executable. |
+ CHECK([NSApp isKindOfClass:self]) |
+ << "NSApp must be of type " << [[self className] UTF8String] |
+ << ", not " << [[NSApp className] UTF8String]; |
+ |
+ return app; |
+} |
+ |
+- (id)init { |
+ if ((self = [super init])) { |
+ eventHooks_.reset([[NSMutableArray alloc] init]); |
+ } |
+ return self; |
+} |
+ |
+- (void)addEventHook:(id<EventHookProtocol>)handler { |
+ [eventHooks_ addObject:handler]; |
+} |
+ |
+- (void)removeEventHook:(id<EventHookProtocol>)handler { |
+ [eventHooks_ removeObject:handler]; |
+} |
+ |
+- (void)sendEvent:(NSEvent*)event { |
+ base::mac::ScopedSendingEvent sendingEventScoper; |
+ for (id<EventHookProtocol> handler in eventHooks_.get()) { |
+ [handler hookForEvent:event]; |
+ } |
+ [super sendEvent:event]; |
+} |
+ |
+@end |