/*
* $Id: STSafariPlugin.m 224 2011-08-13 20:39:45Z stuart $
*
* SafariTabs
* http://stuconnolly.com/projects/safaritabs/
*
* Copyright (c) 2010 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#import "STSafariPlugin.h"
#import "STSafariPluginHandler.h"
#import "STBrowserWindowController.h"
#import "STSessionHandler.h"
#import "STAppController.h"
#import "STApplication.h"
#import "STPreferences.h"
#import "STUpdater.h"
#import "STRuntime.h"
#import "STUtilities.h"
#import "STConstants.h"
@interface STAppController (DeclaredAPI)
- (void)_setupUI;
- (void)st_setupUI;
- (void)safari_setupUI;
- (BOOL)safari_applicationShouldTerminate
:(NSNotification *)notification;
- (void)_handleURLEvent:(id)arg1 withReply:(id)arg2;
- (void)st_handleURLEvent:(id)arg1 withReply:(id)arg2;
- (void)safari_handleURLEvent:(id)arg1 withReply:(id)arg2;
@end
@implementation STSafariPlugin
/*!
* @brief Loads the SafariTabs plugin
*
* SafariTabs' bundle loading method. All runtime method swizzling is performed here.
*/
+ (void)load
{
// Rename existing methods
STRenameMethodSelector(NSClassFromString(@"NSPreferences"), [STPreferences class], @selector(_setupUI), @selector(st_setupUI), @selector(safari_setupUI), YES);
STRenameMethodSelector(NSClassFromString(@"AppController"), [STAppController class], @selector(applicationShouldTerminate:), @selector(st_applicationShouldTerminate:), @selector(safari_applicationShouldTerminate:), YES);
STRenameMethodSelector(NSClassFromString(@"AppController"), [STAppController class], @selector(application:openFile:), @selector(st_application:openFile:), @selector(safari_application:openFile:), YES);
STRenameMethodSelector(NSClassFromString(@"AppController"), [STAppController class], @selector(_handleURLEvent:withReply:), @selector(st_handleURLEvent:withReply:), @selector(safari_handleURLEvent:withReply:), YES);
// Add new methods
STAddMethodsToClassFromClass(NSClassFromString(@"BrowserWindowController"), [STBrowserWindowController class]);
// Output plugin load message
NSLog(@"SafariTabs version %@ (%@) successfully loaded from '%@'", STPluginVersion(), STBundleVersion(), [STPluginBundle() bundlePath]);
// Register plugin defaults
[[NSUserDefaults standardUserDefaults
] registerDefaults
:[NSDictionary dictionaryWithContentsOfFile
:[STPluginBundle
() pathForResource
:STDefaultsPlistName ofType
:@"plist"]]];
[[[STSafariPluginHandler sharedInstance] sessionHandler] pluginLoaded];
}
/*!
* @brief Application singleton
*
* Returns the application's shared instance of the SafariTabs plugin.
*
* @return The application's shared instance of the SafariTabs plugin.
*/
+ (STSafariPlugin *)sharedInstance
{
// Singleton instance
static STSafariPlugin *_sharedPlugin = nil;
// Returns a single static instance of the plugin
if (_sharedPlugin == nil) {
_sharedPlugin = [[STSafariPlugin alloc] init];
}
return _sharedPlugin;
}
#pragma mark -
/*!
* @brief Standard initialization
*
* @return The initialized object
*/
- (id)init
{
if ((self = [super init])) {
_pluginHandler = [[STSafariPluginHandler alloc] init];
}
return self;
}
/*!
* @brief Is the plugin loaded
*
* Indicates whether or not the SafariTabs plugin bundle is loaded into the targetted application.
*
* @return A boolean value indicating whether the plugin is loaded
*/
- (BOOL)isLoaded
{
return [STPluginBundle() isLoaded];
}
/*!
* @brief Dealloc
*/
- (void)dealloc
{
[_pluginHandler release], _pluginHandler = nil;
[super dealloc];
}
@end