summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chrome_browser_application_mac.h25
-rw-r--r--chrome/browser/chrome_browser_application_mac.mm21
-rw-r--r--chrome/browser/chrome_browser_application_mac_unittest.mm5
-rw-r--r--chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h2
-rw-r--r--chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm5
-rw-r--r--chrome/test/base/chrome_test_suite.cc4
-rw-r--r--content/common/chrome_application_mac.h19
-rw-r--r--content/common/chrome_application_mac.mm18
8 files changed, 52 insertions, 47 deletions
diff --git a/chrome/browser/chrome_browser_application_mac.h b/chrome/browser/chrome_browser_application_mac.h
index 510fa5b..bab4b65 100644
--- a/chrome/browser/chrome_browser_application_mac.h
+++ b/chrome/browser/chrome_browser_application_mac.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -10,11 +10,32 @@
#import "content/common/chrome_application_mac.h"
-@interface BrowserCrApplication : CrApplication
+// Event hooks must implement this protocol.
+@protocol CrApplicationEventHookProtocol
+- (void)hookForEvent:(NSEvent*)theEvent;
+@end
+
+@interface BrowserCrApplication : CrApplication {
+ @private
+ // Array of objects implementing CrApplicationEventHookProtocol.
+ scoped_nsobject<NSMutableArray> eventHooks_;
+}
+
// Our implementation of |-terminate:| only attempts to terminate the
// application, i.e., begins a process which may lead to termination. This
// method cancels that process.
- (void)cancelTerminate:(id)sender;
+
+// Add or remove an event hook to be called for every sendEvent:
+// that the application receives. These handlers are called before
+// the normal [NSApplication sendEvent:] call is made.
+
+// This is not a good alternative to a nested event loop. It should
+// be used only when normal event logic and notification breaks down
+// (e.g. when clicking outside a canBecomeKey:NO window to "switch
+// context" out of it).
+- (void)addEventHook:(id<CrApplicationEventHookProtocol>)hook;
+- (void)removeEventHook:(id<CrApplicationEventHookProtocol>)hook;
@end
namespace chrome_browser_application_mac {
diff --git a/chrome/browser/chrome_browser_application_mac.mm b/chrome/browser/chrome_browser_application_mac.mm
index c7706f2..c219252 100644
--- a/chrome/browser/chrome_browser_application_mac.mm
+++ b/chrome/browser/chrome_browser_application_mac.mm
@@ -215,7 +215,10 @@ void SwizzleInit() {
- (id)init {
SwizzleInit();
- return [super init];
+ if ((self = [super init])) {
+ eventHooks_.reset([[NSMutableArray alloc] init]);
+ }
+ return self;
}
////////////////////////////////////////////////////////////////////////////////
@@ -357,6 +360,22 @@ void SwizzleInit() {
return [super sendAction:anAction to:aTarget from:sender];
}
+- (void)addEventHook:(id<CrApplicationEventHookProtocol>)handler {
+ [eventHooks_ addObject:handler];
+}
+
+- (void)removeEventHook:(id<CrApplicationEventHookProtocol>)handler {
+ [eventHooks_ removeObject:handler];
+}
+
+- (void)sendEvent:(NSEvent*)event {
+ content::mac::ScopedSendingEvent sendingEventScoper;
+ for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) {
+ [handler hookForEvent:event];
+ }
+ [super sendEvent:event];
+}
+
// NSExceptions which are caught by the event loop are logged here.
// NSException uses setjmp/longjmp, which can be very bad for C++, so
// we attempt to track and report them.
diff --git a/chrome/browser/chrome_browser_application_mac_unittest.mm b/chrome/browser/chrome_browser_application_mac_unittest.mm
index c5a589c..4511559 100644
--- a/chrome/browser/chrome_browser_application_mac_unittest.mm
+++ b/chrome/browser/chrome_browser_application_mac_unittest.mm
@@ -1,10 +1,11 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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 <Cocoa/Cocoa.h>
#include "base/metrics/histogram.h"
+#import "base/mac/scoped_nsexception_enabler.h"
#import "chrome/browser/chrome_browser_application_mac.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -15,6 +16,8 @@ namespace chrome_browser_application_mac {
// Generate an NSException with the given name.
NSException* ExceptionNamed(NSString* name) {
+ base::mac::ScopedNSExceptionEnabler enabler;
+
return [NSException exceptionWithName:name
reason:@"No reason given"
userInfo:nil];
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h
index 0db88f4..ee3c9ed 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h
@@ -11,13 +11,13 @@
#include "base/memory/scoped_nsobject.h"
#include "base/memory/scoped_ptr.h"
+#import "chrome/browser/chrome_browser_application_mac.h"
#include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_state.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h"
#import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
#include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h"
-#import "content/common/chrome_application_mac.h"
#include "webkit/glue/window_open_disposition.h"
@class BookmarkBarController;
diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm
index 7227cf2..86498e8 100644
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm
@@ -919,9 +919,8 @@ void RecordAppLaunch(Profile* profile, GURL url) {
// "click outside" these windows to detect when they logically lose
// focus.
- (void)watchForExitEvent:(BOOL)watch {
- CrApplication* app = static_cast<CrApplication*>([NSApplication
- sharedApplication]);
- DCHECK([app isKindOfClass:[CrApplication class]]);
+ BrowserCrApplication* app = static_cast<BrowserCrApplication*>(
+ [BrowserCrApplication sharedApplication]);
if (watch) {
if (!watchingForExitEvent_) {
[app addEventHook:self];
diff --git a/chrome/test/base/chrome_test_suite.cc b/chrome/test/base/chrome_test_suite.cc
index 25a6d83..18d76ff 100644
--- a/chrome/test/base/chrome_test_suite.cc
+++ b/chrome/test/base/chrome_test_suite.cc
@@ -31,7 +31,7 @@
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
#include "base/mac/scoped_nsautorelease_pool.h"
-#include "content/common/chrome_application_mac.h"
+#include "chrome/browser/chrome_browser_application_mac.h"
#endif
#if defined(OS_POSIX)
@@ -159,7 +159,7 @@ ChromeTestSuite::~ChromeTestSuite() {
void ChromeTestSuite::Initialize() {
#if defined(OS_MACOSX)
base::mac::ScopedNSAutoreleasePool autorelease_pool;
- chrome_application_mac::RegisterCrApp();
+ chrome_browser_application_mac::RegisterBrowserCrApp();
#endif
base::TestSuite::Initialize();
diff --git a/content/common/chrome_application_mac.h b/content/common/chrome_application_mac.h
index 7a33168c..9778023 100644
--- a/content/common/chrome_application_mac.h
+++ b/content/common/chrome_application_mac.h
@@ -11,19 +11,11 @@
#import <AppKit/AppKit.h>
#include "base/basictypes.h"
-#include "base/memory/scoped_nsobject.h"
#import "content/common/mac/scoped_sending_event.h"
-// Event hooks must implement this protocol.
-@protocol CrApplicationEventHookProtocol
-- (void)hookForEvent:(NSEvent*)theEvent;
-@end
-
@interface CrApplication : NSApplication<CrAppControlProtocol> {
@private
BOOL handlingSendEvent_;
- // Array of objects implementing the CrApplicationEventHookProtocol
- scoped_nsobject<NSMutableArray> eventHooks_;
}
- (BOOL)isHandlingSendEvent;
@@ -31,17 +23,6 @@
// used except in recovering from some sort of exceptional condition.
- (void)clearIsHandlingSendEvent;
-// Add or remove an event hook to be called for every sendEvent:
-// that the application receives. These handlers are called before
-// the normal [NSApplication sendEvent:] call is made.
-
-// This is not a good alternative to a nested event loop. It should
-// be used only when normal event logic and notification breaks down
-// (e.g. when clicking outside a canBecomeKey:NO window to "switch
-// context" out of it).
-- (void)addEventHook:(id<CrApplicationEventHookProtocol>)hook;
-- (void)removeEventHook:(id<CrApplicationEventHookProtocol>)hook;
-
+ (NSApplication*)sharedApplication;
@end
diff --git a/content/common/chrome_application_mac.mm b/content/common/chrome_application_mac.mm
index a5277ff..deec8b3 100644
--- a/content/common/chrome_application_mac.mm
+++ b/content/common/chrome_application_mac.mm
@@ -24,13 +24,6 @@
return app;
}
-- (id)init {
- if ((self = [super init])) {
- eventHooks_.reset([[NSMutableArray alloc] init]);
- }
- return self;
-}
-
- (BOOL)isHandlingSendEvent {
return handlingSendEvent_;
}
@@ -45,20 +38,9 @@
- (void)sendEvent:(NSEvent*)event {
content::mac::ScopedSendingEvent sendingEventScoper;
- for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) {
- [handler hookForEvent:event];
- }
[super sendEvent:event];
}
-- (void)addEventHook:(id<CrApplicationEventHookProtocol>)handler {
- [eventHooks_ addObject:handler];
-}
-
-- (void)removeEventHook:(id<CrApplicationEventHookProtocol>)handler {
- [eventHooks_ removeObject:handler];
-}
-
@end
namespace chrome_application_mac {