diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-18 01:18:29 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-18 01:18:29 +0000 |
commit | a366880f8475fa9e0e70ace062af10654b297574 (patch) | |
tree | 5c2a777d77feebefc4b8c0f0c78525d57be93b16 /chrome | |
parent | c811184533d882af419cab0dabe0bf317c6c985f (diff) | |
download | chromium_src-a366880f8475fa9e0e70ace062af10654b297574.zip chromium_src-a366880f8475fa9e0e70ace062af10654b297574.tar.gz chromium_src-a366880f8475fa9e0e70ace062af10654b297574.tar.bz2 |
Remove CrApplication dependency from base
Add a @protocol CrAppProtocol that clients of base must implement in their NSApplication subclass, and let base depend only on this protocol.
Let MessagePumpNSApplication::DoRun() no longer initialize NSApplication (fixes a TODO).
Add a MockCrApplication that the simple unittests in base and app can use, move chrome_application to chrome/common.
Test shell might run nested run loops, so I gave it a real but simplified CrAppProtocol implementation.
BUG=62968,46929
TEST=Everything still works. The PDF plugin prints one fewer warning when loaded.
Review URL: http://codereview.chromium.org/5950003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chrome_browser_application_mac.h | 5 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_application_mac.mm | 7 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_widget_host_view_mac.mm | 1 | ||||
-rw-r--r-- | chrome/browser/tab_contents/popup_menu_helper_mac.mm | 2 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_mac.mm | 2 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h | 2 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/cocoa_test_helper.h | 2 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 2 | ||||
-rw-r--r-- | chrome/common/chrome_application_mac.h | 60 | ||||
-rw-r--r-- | chrome/common/chrome_application_mac.mm | 72 | ||||
-rw-r--r-- | chrome/common/sandbox_mac.mm | 2 | ||||
-rw-r--r-- | chrome/nacl/nacl_main_platform_delegate_mac.mm | 2 | ||||
-rw-r--r-- | chrome/plugin/plugin_main_mac.mm | 2 | ||||
-rw-r--r-- | chrome/renderer/renderer_main_platform_delegate_mac.mm | 2 | ||||
-rw-r--r-- | chrome/test/out_of_proc_test_runner.cc | 8 |
16 files changed, 160 insertions, 13 deletions
diff --git a/chrome/browser/chrome_browser_application_mac.h b/chrome/browser/chrome_browser_application_mac.h index e599c63..a1ebb04 100644 --- a/chrome/browser/chrome_browser_application_mac.h +++ b/chrome/browser/chrome_browser_application_mac.h @@ -8,7 +8,7 @@ #ifdef __OBJC__ -#import "base/chrome_application_mac.h" +#import "chrome/common/chrome_application_mac.h" @interface BrowserCrApplication : CrApplication // Our implementation of |-terminate:| only attempts to terminate the @@ -36,6 +36,9 @@ void RecordExceptionWithUma(NSException* exception); namespace chrome_browser_application_mac { +// To be used to instantiate BrowserCrApplication from C++ code. +void RegisterBrowserCrApp(); + // Calls -[NSApp terminate:]. void Terminate(); diff --git a/chrome/browser/chrome_browser_application_mac.mm b/chrome/browser/chrome_browser_application_mac.mm index 4690fea..aea31b0 100644 --- a/chrome/browser/chrome_browser_application_mac.mm +++ b/chrome/browser/chrome_browser_application_mac.mm @@ -64,7 +64,8 @@ static IMP gOriginalInitIMP = NULL; BOOL fatal = NO; if (aName == NSInternalInconsistencyException) { NSString* const kNSMenuItemArrayBoundsCheck = - @"Invalid parameter not satisfying: (index >= 0) && (index < [_itemArray count])"; + @"Invalid parameter not satisfying: (index >= 0) && " + @"(index < [_itemArray count])"; if ([aReason isEqualToString:kNSMenuItemArrayBoundsCheck]) { fatal = YES; } @@ -141,6 +142,10 @@ void RecordExceptionWithUma(NSException* exception) { BinForException(exception), kUnknownNSException); } +void RegisterBrowserCrApp() { + [BrowserCrApplication sharedApplication]; +}; + void Terminate() { [NSApp terminate:nil]; } diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm index 842bf9a..22175dc 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm +++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm @@ -8,7 +8,6 @@ #include "app/app_switches.h" #include "app/surface/io_surface_support_mac.h" -#import "base/chrome_application_mac.h" #include "base/command_line.h" #include "base/logging.h" #include "base/mac/scoped_cftyperef.h" diff --git a/chrome/browser/tab_contents/popup_menu_helper_mac.mm b/chrome/browser/tab_contents/popup_menu_helper_mac.mm index df8862c..aea6a7b 100644 --- a/chrome/browser/tab_contents/popup_menu_helper_mac.mm +++ b/chrome/browser/tab_contents/popup_menu_helper_mac.mm @@ -6,12 +6,12 @@ #include "chrome/browser/tab_contents/popup_menu_helper_mac.h" -#import "base/chrome_application_mac.h" #include "base/message_loop.h" #include "base/scoped_nsobject.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" #import "chrome/browser/ui/cocoa/base_view.h" +#import "chrome/common/chrome_application_mac.h" #include "chrome/common/notification_source.h" #include "webkit/glue/webmenurunner_mac.h" diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index a6b111a..8d810dd 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -8,7 +8,6 @@ #include <string> -#import "base/chrome_application_mac.h" #include "chrome/browser/global_keyboard_shortcuts_mac.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_view_host_factory.h" @@ -24,6 +23,7 @@ #import "chrome/browser/ui/cocoa/web_drag_source.h" #import "chrome/browser/ui/cocoa/web_drop_target.h" #import "chrome/browser/ui/cocoa/view_id_util.h" +#import "chrome/common/chrome_application_mac.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_source.h" #include "chrome/common/notification_type.h" diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h index a9bca8a..64591ba 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h @@ -9,7 +9,6 @@ #import <Cocoa/Cocoa.h> #include <map> -#import "base/chrome_application_mac.h" #include "base/scoped_nsobject.h" #include "base/scoped_ptr.h" #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.h" @@ -18,6 +17,7 @@ #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/tab_strip_model_observer_bridge.h" +#import "chrome/common/chrome_application_mac.h" #include "webkit/glue/window_open_disposition.h" @class BookmarkBarController; diff --git a/chrome/browser/ui/cocoa/cocoa_test_helper.h b/chrome/browser/ui/cocoa/cocoa_test_helper.h index 3431925..0be5903 100644 --- a/chrome/browser/ui/cocoa/cocoa_test_helper.h +++ b/chrome/browser/ui/cocoa/cocoa_test_helper.h @@ -8,12 +8,12 @@ #import <Cocoa/Cocoa.h> -#import "base/chrome_application_mac.h" #include "base/debug_util.h" #include "base/mac_util.h" #include "base/path_service.h" #import "base/mac/scoped_nsautorelease_pool.h" #import "base/scoped_nsobject.h" +#import "chrome/common/chrome_application_mac.h" #include "chrome/common/chrome_constants.h" #include "testing/platform_test.h" diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index ca20862..45abad8 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3744,7 +3744,7 @@ '../third_party/mozilla/ComplexTextInputPanel.mm', # Headers so that IB can find classes it needs to resolve classes # in XIB files. - '../base/chrome_application_mac.h', + 'common/chrome_application_mac.h', ], 'include_dirs': [ '../third_party/apple', diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index b8d4d5d..80c1b0e 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -28,6 +28,8 @@ 'common/app_mode_common_mac.h', 'common/app_mode_common_mac.mm', 'common/bindings_policy.h', + 'common/chrome_application_mac.h', + 'common/chrome_application_mac.mm', 'common/child_process.cc', 'common/child_process.h', 'common/child_process_info.cc', diff --git a/chrome/common/chrome_application_mac.h b/chrome/common/chrome_application_mac.h new file mode 100644 index 0000000..585601d8 --- /dev/null +++ b/chrome/common/chrome_application_mac.h @@ -0,0 +1,60 @@ +// Copyright (c) 2009 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. + +#ifndef CHROME_COMMON_CHROME_APPLICATION_MAC_H_ +#define CHROME_COMMON_CHROME_APPLICATION_MAC_H_ +#pragma once + +#import <AppKit/AppKit.h> + +#include "base/basictypes.h" +#include "base/message_pump_mac.h" +#include "base/scoped_nsobject.h" + +// Event hooks must implement this protocol. +@protocol CrApplicationEventHookProtocol +- (void)hookForEvent:(NSEvent*)theEvent; +@end + + +@interface CrApplication : NSApplication<CrAppProtocol> { + @private + BOOL handlingSendEvent_; + // Array of objects implementing the CrApplicationEventHookProtocol + scoped_nsobject<NSMutableArray> eventHooks_; +} +- (BOOL)isHandlingSendEvent; + +// 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 + +namespace chrome_application_mac { + +// Controls the state of |handlingSendEvent_| in the event loop so that it is +// reset properly. +class ScopedSendingEvent { + public: + ScopedSendingEvent(); + ~ScopedSendingEvent(); + + private: + CrApplication* app_; + BOOL handling_; + DISALLOW_COPY_AND_ASSIGN(ScopedSendingEvent); +}; + +} // chrome_application_mac + +#endif // CHROME_COMMON_CHROME_APPLICATION_MAC_H_ diff --git a/chrome/common/chrome_application_mac.mm b/chrome/common/chrome_application_mac.mm new file mode 100644 index 0000000..9bd9f67 --- /dev/null +++ b/chrome/common/chrome_application_mac.mm @@ -0,0 +1,72 @@ +// Copyright (c) 2009 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 "chrome/common/chrome_application_mac.h" + +#include "base/logging.h" + +@interface CrApplication () +- (void)setHandlingSendEvent:(BOOL)handlingSendEvent; +@end + +@implementation CrApplication +// 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]; + if (![NSApp isKindOfClass:self]) { + LOG(ERROR) << "NSApp should be of type " << [[self className] UTF8String] + << ", not " << [[NSApp className] UTF8String]; + DCHECK(false) << "NSApp is of wrong type"; + } + return app; +} + +- (id)init { + if ((self = [super init])) { + eventHooks_.reset([[NSMutableArray alloc] init]); + } + return self; +} + +- (BOOL)isHandlingSendEvent { + return handlingSendEvent_; +} + +- (void)setHandlingSendEvent:(BOOL)handlingSendEvent { + handlingSendEvent_ = handlingSendEvent; +} + +- (void)sendEvent:(NSEvent*)event { + chrome_application_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 { + +ScopedSendingEvent::ScopedSendingEvent() + : app_(static_cast<CrApplication*>([CrApplication sharedApplication])), + handling_([app_ isHandlingSendEvent]) { + [app_ setHandlingSendEvent:YES]; +} + +ScopedSendingEvent::~ScopedSendingEvent() { + [app_ setHandlingSendEvent:handling_]; +} + +} // namespace chrome_application_mac diff --git a/chrome/common/sandbox_mac.mm b/chrome/common/sandbox_mac.mm index 58044cc..56ad0b1 100644 --- a/chrome/common/sandbox_mac.mm +++ b/chrome/common/sandbox_mac.mm @@ -17,7 +17,6 @@ extern "C" { #include "app/gfx/gl/gl_context.h" #include "base/basictypes.h" -#include "base/chrome_application_mac.h" #include "base/command_line.h" #include "base/file_util.h" #include "base/mac_util.h" @@ -29,6 +28,7 @@ extern "C" { #include "base/sys_info.h" #include "base/sys_string_conversions.h" #include "base/utf_string_conversions.h" +#include "chrome/common/chrome_application_mac.h" #include "chrome/common/chrome_switches.h" #include "unicode/uchar.h" diff --git a/chrome/nacl/nacl_main_platform_delegate_mac.mm b/chrome/nacl/nacl_main_platform_delegate_mac.mm index 6b7e8b6..39ba8c8 100644 --- a/chrome/nacl/nacl_main_platform_delegate_mac.mm +++ b/chrome/nacl/nacl_main_platform_delegate_mac.mm @@ -5,14 +5,12 @@ #include "chrome/nacl/nacl_main_platform_delegate.h" #import <Cocoa/Cocoa.h> -#import "base/chrome_application_mac.h" #include "base/command_line.h" #include "base/file_path.h" #include "base/logging.h" #include "base/native_library.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/sandbox_mac.h" -#include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" NaClMainPlatformDelegate::NaClMainPlatformDelegate( const MainFunctionParams& parameters) diff --git a/chrome/plugin/plugin_main_mac.mm b/chrome/plugin/plugin_main_mac.mm index 2bde557..5d10a3b 100644 --- a/chrome/plugin/plugin_main_mac.mm +++ b/chrome/plugin/plugin_main_mac.mm @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/chrome_application_mac.h" #include "base/environment.h" #include "base/scoped_ptr.h" #include "base/string_util.h" +#include "chrome/common/chrome_application_mac.h" #include "chrome/common/plugin_carbon_interpose_constants_mac.h" #include "chrome/plugin/plugin_interpose_util_mac.h" diff --git a/chrome/renderer/renderer_main_platform_delegate_mac.mm b/chrome/renderer/renderer_main_platform_delegate_mac.mm index 2b14cd0..eb65d1a 100644 --- a/chrome/renderer/renderer_main_platform_delegate_mac.mm +++ b/chrome/renderer/renderer_main_platform_delegate_mac.mm @@ -6,8 +6,8 @@ #import <Cocoa/Cocoa.h> -#import "base/chrome_application_mac.h" #include "base/command_line.h" +#import "chrome/common/chrome_application_mac.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/sandbox_mac.h" #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" diff --git a/chrome/test/out_of_proc_test_runner.cc b/chrome/test/out_of_proc_test_runner.cc index fbf5ebb..1d2bb10 100644 --- a/chrome/test/out_of_proc_test_runner.cc +++ b/chrome/test/out_of_proc_test_runner.cc @@ -32,6 +32,10 @@ #include "sandbox/src/sandbox_types.h" #endif // defined(OS_WIN) +#if defined(OS_MACOSX) +#include "chrome/browser/chrome_browser_application_mac.h" +#endif // defined(OS_MACOSX) + #if defined(OS_WIN) // The entry point signature of chrome.dll. typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, wchar_t*); @@ -454,6 +458,10 @@ void PrintUsage() { } // namespace int main(int argc, char** argv) { +#if defined(OS_MACOSX) + chrome_browser_application_mac::RegisterBrowserCrApp(); +#endif + CommandLine::Init(argc, argv); const CommandLine* command_line = CommandLine::ForCurrentProcess(); |