tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

chrome_application_mac.mm (1927B)


      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, getter=isHandlingSendEvent, nonatomic)
     11    BOOL handlingSendEvent;
     12 @end
     13 
     14 @implementation CrApplication
     15 @synthesize handlingSendEvent = handlingSendEvent_;
     16 
     17 // Initialize NSApplication using the custom subclass.  Check whether NSApp
     18 // was already initialized using another class, because that would break
     19 // some things.
     20 + (NSApplication*)sharedApplication {
     21  NSApplication* app = [super sharedApplication];
     22  if (![NSApp isKindOfClass:self]) {
     23    CHROMIUM_LOG(ERROR) << "NSApp should be of type "
     24                        << [[self className] UTF8String] << ", not "
     25                        << [[NSApp className] UTF8String];
     26    DCHECK(false) << "NSApp is of wrong type";
     27  }
     28  return app;
     29 }
     30 
     31 - (id)init {
     32  if ((self = [super init])) {
     33    eventHooks_.reset([[NSMutableArray alloc] init]);
     34  }
     35  return self;
     36 }
     37 
     38 - (void)sendEvent:(NSEvent*)event {
     39  chrome_application_mac::ScopedSendingEvent sendingEventScoper;
     40  for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) {
     41    [handler hookForEvent:event];
     42  }
     43  [super sendEvent:event];
     44 }
     45 
     46 - (void)addEventHook:(id<CrApplicationEventHookProtocol>)handler {
     47  [eventHooks_ addObject:handler];
     48 }
     49 
     50 - (void)removeEventHook:(id<CrApplicationEventHookProtocol>)handler {
     51  [eventHooks_ removeObject:handler];
     52 }
     53 
     54 @end
     55 
     56 namespace chrome_application_mac {
     57 
     58 ScopedSendingEvent::ScopedSendingEvent()
     59    : app_(static_cast<CrApplication*>([CrApplication sharedApplication])),
     60      handling_([app_ isHandlingSendEvent]) {
     61  [app_ setHandlingSendEvent:YES];
     62 }
     63 
     64 ScopedSendingEvent::~ScopedSendingEvent() {
     65  [app_ setHandlingSendEvent:handling_];
     66 }
     67 
     68 }  // namespace chrome_application_mac