ipc/chromium/src/base/chrome_application_mac.mm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/chrome_application_mac.mm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     1.4 +// Copyright (c) 2009 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +#import "chrome_application_mac.h"
     1.9 +
    1.10 +#include "base/logging.h"
    1.11 +
    1.12 +@interface CrApplication ()
    1.13 +@property(readwrite,
    1.14 +          getter=isHandlingSendEvent,
    1.15 +          nonatomic) BOOL handlingSendEvent;
    1.16 +@end
    1.17 +
    1.18 +@implementation CrApplication
    1.19 +@synthesize handlingSendEvent = handlingSendEvent_;
    1.20 +
    1.21 +// Initialize NSApplication using the custom subclass.  Check whether NSApp
    1.22 +// was already initialized using another class, because that would break
    1.23 +// some things.
    1.24 ++ (NSApplication*)sharedApplication {
    1.25 +  NSApplication* app = [super sharedApplication];
    1.26 +  if (![NSApp isKindOfClass:self]) {
    1.27 +    CHROMIUM_LOG(ERROR) << "NSApp should be of type " << [[self className] UTF8String]
    1.28 +                        << ", not " << [[NSApp className] UTF8String];
    1.29 +    DCHECK(false) << "NSApp is of wrong type";
    1.30 +  }
    1.31 +  return app;
    1.32 +}
    1.33 +
    1.34 +- (id)init {
    1.35 +  if ((self = [super init])) {
    1.36 +    eventHooks_.reset([[NSMutableArray alloc] init]);
    1.37 +  }
    1.38 +  return self;
    1.39 +}
    1.40 +
    1.41 +- (void)sendEvent:(NSEvent*)event {
    1.42 +  chrome_application_mac::ScopedSendingEvent sendingEventScoper;
    1.43 +  for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) {
    1.44 +    [handler hookForEvent:event];
    1.45 +  }
    1.46 +  [super sendEvent:event];
    1.47 +}
    1.48 +
    1.49 +- (void)addEventHook:(id<CrApplicationEventHookProtocol>)handler {
    1.50 +  [eventHooks_ addObject:handler];
    1.51 +}
    1.52 +
    1.53 +- (void)removeEventHook:(id<CrApplicationEventHookProtocol>)handler {
    1.54 +  [eventHooks_ removeObject:handler];
    1.55 +}
    1.56 +
    1.57 +@end
    1.58 +
    1.59 +namespace chrome_application_mac {
    1.60 +
    1.61 +ScopedSendingEvent::ScopedSendingEvent()
    1.62 +    : app_(static_cast<CrApplication*>([CrApplication sharedApplication])),
    1.63 +      handling_([app_ isHandlingSendEvent]) {
    1.64 +  [app_ setHandlingSendEvent:YES];
    1.65 +}
    1.66 +
    1.67 +ScopedSendingEvent::~ScopedSendingEvent() {
    1.68 +  [app_ setHandlingSendEvent:handling_];
    1.69 +}
    1.70 +
    1.71 +}  // namespace chrome_application_mac

mercurial