diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 23:32:43 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-06 23:32:43 +0000 |
commit | d7de57877613a63e36facbd485245918c1131f61 (patch) | |
tree | 164f1422c744e42edd84bb92fe347024ab71ec3c /chrome | |
parent | 5179b9146ce7029e1daedf8607d2bfae50764e7b (diff) | |
download | chromium_src-d7de57877613a63e36facbd485245918c1131f61.zip chromium_src-d7de57877613a63e36facbd485245918c1131f61.tar.gz chromium_src-d7de57877613a63e36facbd485245918c1131f61.tar.bz2 |
[Mac] Remove content/ CrApplication.
Pull the CrAppProtocol autorelease-pool handling down into
MessagePumpCrApplication, which is selected at Create() if NSApp
implements the right protocol. UsingCrApp() allows clients to
confirm the correct setup (unfortunately, synchronizing NSApp
initialization and MessagePump::Create() would be intrusive).
Also push CrAppProtocol and CrAppControlProtocol implementation into
BrowserCrApplication, and reparent that class from NSApplication.
Reparent ServiceCrApplication on NSApplication and rename.
Remove CrApplication registration from gpu, plugin, and renderer
mains.
Remove MockCrApp dependency from remoting sample code.
BUG=102224
Review URL: http://codereview.chromium.org/8771028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113281 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/DEPS | 1 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_application_mac.h | 11 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_application_mac.mm | 34 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_application_mac_unittest.mm | 2 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main_mac.mm | 2 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_mac.mm | 8 | ||||
-rw-r--r-- | chrome/browser/ui/window_snapshot/window_snapshot_mac_unittest.mm | 1 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 3 | ||||
-rw-r--r-- | chrome/service/chrome_service_application_mac.h | 10 | ||||
-rw-r--r-- | chrome/service/chrome_service_application_mac.mm | 14 | ||||
-rw-r--r-- | chrome/service/service_main.cc | 8 |
11 files changed, 62 insertions, 32 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index d5dcd1c..b40dc6b 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -31,7 +31,6 @@ include_rules = [ "-content/common", # TODO(jam): remove all the exceptions. BUG=98716 - "+content/common/chrome_application_mac.h", "+content/common/view_messages.h", # Other libraries. diff --git a/chrome/browser/chrome_browser_application_mac.h b/chrome/browser/chrome_browser_application_mac.h index bab4b65..c6147fd 100644 --- a/chrome/browser/chrome_browser_application_mac.h +++ b/chrome/browser/chrome_browser_application_mac.h @@ -8,15 +8,22 @@ #ifdef __OBJC__ -#import "content/common/chrome_application_mac.h" +#import <AppKit/AppKit.h> + +#import "base/mac/scoped_sending_event.h" +#import "base/memory/scoped_nsobject.h" +#import "base/message_pump_mac.h" // Event hooks must implement this protocol. @protocol CrApplicationEventHookProtocol - (void)hookForEvent:(NSEvent*)theEvent; @end -@interface BrowserCrApplication : CrApplication { +@interface BrowserCrApplication : NSApplication<CrAppProtocol, + CrAppControlProtocol> { @private + BOOL handlingSendEvent_; + // Array of objects implementing CrApplicationEventHookProtocol. scoped_nsobject<NSMutableArray> eventHooks_; } diff --git a/chrome/browser/chrome_browser_application_mac.mm b/chrome/browser/chrome_browser_application_mac.mm index 282ecc3..c498832 100644 --- a/chrome/browser/chrome_browser_application_mac.mm +++ b/chrome/browser/chrome_browser_application_mac.mm @@ -221,6 +221,30 @@ void SwizzleInit() { return self; } +// 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]; + + // +sharedApplication initializes the global NSApp, so if a specific + // NSApplication subclass is requested, require that to be the one + // delivered. The practical effect is to require a consistent NSApp + // across the executable. + CHECK([NSApp isKindOfClass:self]) + << "NSApp must be of type " << [[self className] UTF8String] + << ", not " << [[NSApp className] UTF8String]; + + // If the message loop was initialized before NSApp is setup, the + // message pump will be setup incorrectly. Failing this implies + // that RegisterBrowserCrApp() should be called earlier. + CHECK(base::MessagePumpMac::UsingCrApp()) + << "MessagePumpMac::Create() is using the wrong pump implementation" + << " for " << [[self className] UTF8String]; + + return app; +} + //////////////////////////////////////////////////////////////////////////////// // HISTORICAL COMMENT (by viettrungluu, from // http://codereview.chromium.org/1520006 with mild editing): @@ -368,6 +392,14 @@ void SwizzleInit() { [eventHooks_ removeObject:handler]; } +- (BOOL)isHandlingSendEvent { + return handlingSendEvent_; +} + +- (void)setHandlingSendEvent:(BOOL)handlingSendEvent { + handlingSendEvent_ = handlingSendEvent; +} + - (void)sendEvent:(NSEvent*)event { base::mac::ScopedSendingEvent sendingEventScoper; for (id<CrApplicationEventHookProtocol> handler in eventHooks_.get()) { @@ -396,7 +428,7 @@ void SwizzleInit() { // sidestep scopers is setjmp/longjmp (see above). The following // is to "fix" this while the more fundamental concern is // addressed elsewhere. - [self clearIsHandlingSendEvent]; + [self setHandlingSendEvent:NO]; // If |ScopedNSExceptionEnabler| is used to allow exceptions, and an // uncaught exception is thrown, it will throw past all of the scopers. diff --git a/chrome/browser/chrome_browser_application_mac_unittest.mm b/chrome/browser/chrome_browser_application_mac_unittest.mm index 4511559..9aa005a 100644 --- a/chrome/browser/chrome_browser_application_mac_unittest.mm +++ b/chrome/browser/chrome_browser_application_mac_unittest.mm @@ -4,8 +4,8 @@ #import <Cocoa/Cocoa.h> -#include "base/metrics/histogram.h" #import "base/mac/scoped_nsexception_enabler.h" +#include "base/metrics/histogram.h" #import "chrome/browser/chrome_browser_application_mac.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/chrome_browser_main_mac.mm b/chrome/browser/chrome_browser_main_mac.mm index 02c9d05..b8aaf29 100644 --- a/chrome/browser/chrome_browser_main_mac.mm +++ b/chrome/browser/chrome_browser_main_mac.mm @@ -71,7 +71,7 @@ void ChromeBrowserMainPartsMac::PreMainMessageLoopStart() { // CFRunLoop. // Initialize NSApplication using the custom subclass. - [BrowserCrApplication sharedApplication]; + chrome_browser_application_mac::RegisterBrowserCrApp(); // If ui_task is not NULL, the app is actually a browser_test, so startup is // handled outside of BrowserMain (which is what called this). diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index 121e082..927af25 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -9,6 +9,7 @@ #include <string> #import "base/mac/scoped_sending_event.h" +#import "base/message_pump_mac.h" #import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.h" #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" #include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h" @@ -23,7 +24,6 @@ #include "content/browser/tab_contents/tab_contents_delegate.h" #import "content/browser/tab_contents/web_drag_dest_mac.h" #import "content/browser/tab_contents/web_drag_source_mac.h" -#import "content/common/chrome_application_mac.h" #include "content/common/view_messages.h" #include "skia/ext/skia_utils_mac.h" #import "third_party/mozilla/NSPasteboard+Utils.h" @@ -369,11 +369,7 @@ void TabContentsViewMac::ShowPopupMenu( } bool TabContentsViewMac::IsEventTracking() const { - if ([NSApp isKindOfClass:[CrApplication class]] && - [static_cast<CrApplication*>(NSApp) isHandlingSendEvent]) { - return true; - } - return false; + return base::MessagePumpMac::IsHandlingSendEvent(); } // Arrange to call CloseTab() after we're back to the main event loop. diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_mac_unittest.mm b/chrome/browser/ui/window_snapshot/window_snapshot_mac_unittest.mm index 7641891..0a1faa6 100644 --- a/chrome/browser/ui/window_snapshot/window_snapshot_mac_unittest.mm +++ b/chrome/browser/ui/window_snapshot/window_snapshot_mac_unittest.mm @@ -8,7 +8,6 @@ #include "base/memory/scoped_nsobject.h" #include "base/memory/scoped_ptr.h" -#include "base/test/mock_chrome_application_mac.h" #include "testing/platform_test.h" #include "ui/gfx/rect.h" diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 027703d..e5270b4 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -4428,9 +4428,6 @@ '../third_party/mozilla/NSURL+Utils.m', '../third_party/mozilla/NSWorkspace+Utils.h', '../third_party/mozilla/NSWorkspace+Utils.m', - # Headers so that IB can find classes it needs to resolve classes - # in XIB files. - 'common/chrome_application_mac.h', ], 'include_dirs': [ '../third_party/apple', diff --git a/chrome/service/chrome_service_application_mac.h b/chrome/service/chrome_service_application_mac.h index 554a19f..235c2a8 100644 --- a/chrome/service/chrome_service_application_mac.h +++ b/chrome/service/chrome_service_application_mac.h @@ -8,10 +8,10 @@ #ifdef __OBJC__ -#import "content/common/chrome_application_mac.h" +#import <AppKit/AppKit.h> // Top level Mac Application for the service process. -@interface ServiceCrApplication : CrApplication +@interface ServiceApplication : NSApplication @end @@ -19,9 +19,9 @@ namespace chrome_service_application_mac { -// To be used to instantiate ServiceCrApplication from C++ code. -void RegisterServiceCrApp(); +// To be used to instantiate ServiceApplication from C++ code. +void RegisterServiceApp(); + } // namespace chrome_service_application_mac #endif // CHROME_SERVICE_CHROME_SERVICE_APPLICATION_MAC_H_ - diff --git a/chrome/service/chrome_service_application_mac.mm b/chrome/service/chrome_service_application_mac.mm index 845d9f06..75f6b05 100644 --- a/chrome/service/chrome_service_application_mac.mm +++ b/chrome/service/chrome_service_application_mac.mm @@ -9,14 +9,14 @@ #import "chrome/common/cloud_print/cloud_print_class_mac.h" #include "chrome/common/chrome_switches.h" -@interface ServiceCrApplication () +@interface ServiceApplication () - (void)setCloudPrintHandler; - (void)submitPrint:(NSAppleEventDescriptor*)event; @end -@implementation ServiceCrApplication +@implementation ServiceApplication --(void)setCloudPrintHandler { +- (void)setCloudPrintHandler { NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; [em setEventHandler:self andSelector:@selector(submitPrint:) @@ -90,10 +90,10 @@ namespace chrome_service_application_mac { -void RegisterServiceCrApp() { - ServiceCrApplication* var = - static_cast<ServiceCrApplication*> - ([ServiceCrApplication sharedApplication]); +void RegisterServiceApp() { + ServiceApplication* var = + base::mac::ObjCCastStrict<ServiceApplication>( + [ServiceApplication sharedApplication]); [var setCloudPrintHandler]; } diff --git a/chrome/service/service_main.cc b/chrome/service/service_main.cc index 99d6c83..bcde1ba 100644 --- a/chrome/service/service_main.cc +++ b/chrome/service/service_main.cc @@ -18,6 +18,10 @@ // Mainline routine for running as the service process. int ServiceProcessMain(const content::MainFunctionParams& parameters) { +#if defined(OS_MACOSX) + chrome_service_application_mac::RegisterServiceApp(); +#endif + MessageLoopForUI main_message_loop; main_message_loop.set_thread_name("MainThread"); if (parameters.command_line.HasSwitch(switches::kWaitForDebugger)) { @@ -27,10 +31,6 @@ int ServiceProcessMain(const content::MainFunctionParams& parameters) { VLOG(1) << "Service process launched: " << parameters.command_line.GetCommandLineString(); -#if defined(OS_MACOSX) - chrome_service_application_mac::RegisterServiceCrApp(); -#endif - base::PlatformThread::SetName("CrServiceMain"); // If there is already a service process running, quit now. |