Skip to content

Commit

Permalink
[NEW] Add option-click-to-whitelist-site functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
rentzsch committed Jan 27, 2009
1 parent 9e07ae0 commit 2e0a334
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Plugin/Plugin.h
Expand Up @@ -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
44 changes: 41 additions & 3 deletions Plugin/Plugin.m
Expand Up @@ -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


Expand All @@ -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];
}

Expand All @@ -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
Expand Down Expand Up @@ -154,5 +191,6 @@ - (void) _convertTypesForContainer


@synthesize container = _container;
@synthesize host = _host;

@end

0 comments on commit 2e0a334

Please sign in to comment.