Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #import "chrome_application_mac.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "base/logging.h" |
michael@0 | 8 | |
michael@0 | 9 | @interface CrApplication () |
michael@0 | 10 | @property(readwrite, |
michael@0 | 11 | getter=isHandlingSendEvent, |
michael@0 | 12 | nonatomic) BOOL handlingSendEvent; |
michael@0 | 13 | @end |
michael@0 | 14 | |
michael@0 | 15 | @implementation CrApplication |
michael@0 | 16 | @synthesize handlingSendEvent = handlingSendEvent_; |
michael@0 | 17 | |
michael@0 | 18 | // Initialize NSApplication using the custom subclass. Check whether NSApp |
michael@0 | 19 | // was already initialized using another class, because that would break |
michael@0 | 20 | // some things. |
michael@0 | 21 | + (NSApplication*)sharedApplication { |
michael@0 | 22 | NSApplication* app = [super sharedApplication]; |
michael@0 | 23 | if (![NSApp isKindOfClass:self]) { |
michael@0 | 24 | CHROMIUM_LOG(ERROR) << "NSApp should be of type " << [[self className] UTF8String] |
michael@0 | 25 | << ", not " << [[NSApp className] UTF8String]; |
michael@0 | 26 | DCHECK(false) << "NSApp is of wrong type"; |
michael@0 | 27 | } |
michael@0 | 28 | return app; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | - (id)init { |
michael@0 | 32 | if ((self = [super init])) { |
michael@0 | 33 | eventHooks_.reset([[NSMutableArray alloc] init]); |
michael@0 | 34 | } |
michael@0 | 35 | return self; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | - (void)sendEvent:(NSEvent*)event { |
michael@0 | 39 | chrome_application_mac::ScopedSendingEvent sendingEventScoper; |
michael@0 | 40 | for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) { |
michael@0 | 41 | [handler hookForEvent:event]; |
michael@0 | 42 | } |
michael@0 | 43 | [super sendEvent:event]; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | - (void)addEventHook:(id<CrApplicationEventHookProtocol>)handler { |
michael@0 | 47 | [eventHooks_ addObject:handler]; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | - (void)removeEventHook:(id<CrApplicationEventHookProtocol>)handler { |
michael@0 | 51 | [eventHooks_ removeObject:handler]; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | @end |
michael@0 | 55 | |
michael@0 | 56 | namespace chrome_application_mac { |
michael@0 | 57 | |
michael@0 | 58 | ScopedSendingEvent::ScopedSendingEvent() |
michael@0 | 59 | : app_(static_cast<CrApplication*>([CrApplication sharedApplication])), |
michael@0 | 60 | handling_([app_ isHandlingSendEvent]) { |
michael@0 | 61 | [app_ setHandlingSendEvent:YES]; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | ScopedSendingEvent::~ScopedSendingEvent() { |
michael@0 | 65 | [app_ setHandlingSendEvent:handling_]; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | } // namespace chrome_application_mac |