Permalink
Browse files

[NEW] Add option-click-to-whitelist-site functionality.

  • Loading branch information...
1 parent 9e07ae0 commit 2e0a334cacd887444237a55e01a0368f928883d6 @rentzsch committed Jan 27, 2009
Showing with 43 additions and 3 deletions.
  1. +2 −0 Plugin/Plugin.h
  2. +41 −3 Plugin/Plugin.m
View
@@ -30,12 +30,14 @@ THE SOFTWARE.
@interface CTFClickToFlashPlugin : NSView <WebPlugInViewFactory> {
DOMElement *_container;
+ NSString *_host;
}
+ (NSView *)plugInViewWithArguments:(NSDictionary *)arguments;
- (id) initWithArguments:(NSDictionary *)arguments;
@property (retain) DOMElement *container;
+@property (retain) NSString *host;
@end
View
@@ -29,12 +29,13 @@ of this software and associated documentation files (the "Software"), to deal
static NSString *sFlashOldMIMEType = @"application/x-shockwave-flash";
static NSString *sFlashNewMIMEType = @"application/futuresplash";
-
+static NSString *sHostWhitelistDefaultsKey = @"ClickToFlash.whitelist";
@interface CTFClickToFlashPlugin (Internal)
- (NSColor *) _backgroundColorOfElement:(DOMElement *)element;
- (void) _convertTypesForContainer;
- (void) _drawBackground;
+- (BOOL) _isHostWhitelisted;
@end
@@ -55,15 +56,27 @@ + (NSView *)plugInViewWithArguments:(NSDictionary *)arguments
- (id) initWithArguments:(NSDictionary *)arguments
{
- [super init];
- self.container = [arguments objectForKey:WebPlugInContainingElementKey];
+ self = [super init];
+ if (self) {
+ self.container = [arguments objectForKey:WebPlugInContainingElementKey];
+
+ NSURL *base = [arguments objectForKey:WebPlugInBaseURLKey];
+ if (base) {
+ self.host = [base host];
+ if ([self _isHostWhitelisted]) {
+ [self performSelector:@selector(_convertTypesForContainer) withObject:nil afterDelay:0];
+ }
+ }
+ }
+
return self;
}
- (void) dealloc
{
self.container = nil;
+ self.host = nil;
[super dealloc];
}
@@ -82,9 +95,33 @@ - (BOOL) acceptsFirstMouse
- (void) mouseDown:(NSEvent *)event
{
+ if (self.host && (([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) == NSAlternateKeyMask) && ![self _isHostWhitelisted]) {
+ NSString *title = [NSString stringWithFormat:NSLocalizedString(@"Add %@ to the white list?", @"Add %@ to the white list?"), self.host];
+ int val = NSRunAlertPanel(title,
+ NSLocalizedString(@"Always load flash for this site?", @"Always load flash for this site?"),
+ @"Always Load", @"Don't Load", nil);
+ if (!val) {
+ return;
+ }
+
+ NSMutableArray *hostWhitelist = [[[[NSUserDefaults standardUserDefaults] stringArrayForKey:sHostWhitelistDefaultsKey] mutableCopy] autorelease];
+ if (hostWhitelist) {
+ [hostWhitelist addObject:self.host];
+ } else {
+ hostWhitelist = [NSMutableArray arrayWithObject:self.host];
+ }
+ [[NSUserDefaults standardUserDefaults] setObject:hostWhitelist forKey:sHostWhitelistDefaultsKey];
+ }
+
[self _convertTypesForContainer];
}
+- (BOOL) _isHostWhitelisted
+{
+ NSArray *hostWhitelist = [[NSUserDefaults standardUserDefaults] stringArrayForKey:sHostWhitelistDefaultsKey];
+ return hostWhitelist && [hostWhitelist containsObject:self.host];
+}
+
#pragma mark -
#pragma mark Drawing
@@ -154,5 +191,6 @@ - (void) _convertTypesForContainer
@synthesize container = _container;
+@synthesize host = _host;
@end

0 comments on commit 2e0a334

Please sign in to comment.