/*
* STSafariPlugin.m
*
* SafariTabs
*
* Copyright (c) 2007 Stuart Connolly. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#import "STSafariPlugin.h"
#import "STAppController.h"
#import "STBrowserWindowController.h"
typedef struct objc_method *Method;
struct objc_method {
SEL method_name;
char *method_types;
IMP method_imp;
};
////////////////////////////////////////////// *** DTRenameSelector
BOOL STRenameSelector(Class _class, SEL _oldSelector, SEL _newSelector)
{
Method method = nil;
method = class_getInstanceMethod(_class, _oldSelector);
if (method == nil) {
return NO;
}
method->method_name = _newSelector;
return YES;
}
@implementation STSafariPlugin
////////////////////////////////////////////// *** load
+ (void)load
{
// A special method called by SIMBL once the application has started and all classes are initialized.
// Exchange Safari's applicationWillTerminate: with custom one
STRenameSelector([AppController class], @selector(applicationShouldTerminate:), @selector(_safari_applicationShouldTerminate:));
STRenameSelector([AppController class], @selector(_tc_applicationShouldTerminate:), @selector(applicationShouldTerminate:));
// Exchange Safari's windowShouldClose: with custom one
STRenameSelector([BrowserWindowController class], @selector(windowShouldClose:), @selector(_safari_windowShouldClose:));
STRenameSelector([BrowserWindowController class], @selector(_tc_windowShouldClose:), @selector(windowShouldClose:));
}
////////////////////////////////////////////// *** sharedInstance
+ (STSafariPlugin *)sharedInstance
{
// Returns a single static instance of the plugin
static STSafariPlugin *plugin = nil;
if (plugin == nil) {
plugin = [[STSafariPlugin alloc] init];
}
return plugin;
}
@end